Advertisement
Joker0day

sdp

Dec 20th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <?php
  2. ini_set("memory_limit","512M");
  3. set_time_limit(0);
  4. ignore_user_abort(true);
  5. error_reporting(E_ERROR);
  6.  
  7. if(threadfound($argv)==true){
  8. die(thread($argv[1], $argv[2], $argv[3]));
  9. } else {
  10. die(start_threading($argv[1], $argv[2], $argv[3], $argv[4]));
  11. }
  12.  
  13. function MSEARCH($host, $timeout = 1) {
  14. $data = "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n";
  15. $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  16. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
  17. socket_connect($socket, $host, 1900);
  18. socket_send($socket, $data, strLen($data), 0);
  19. $buf = "";
  20. $from = "";
  21. $port = 0;
  22. @socket_recvfrom($socket, $buf, 1000, 0, $from, $port);
  23. socket_close($socket);
  24. return $buf;
  25. }
  26.  
  27. function thread($ip, $output, $responselength) {
  28. $len = strlen(MSEARCH($ip, 1));
  29. if($len>=$responselength){
  30. addentry($output, $ip.' '.$len);
  31. print("\n".$ip." ".$len." [x".round($len/108, 2)."]");
  32. }
  33. }
  34.  
  35. function start_threading($input, $output, $responselength, $maxthreads) {
  36. $self = basename($_SERVER["SCRIPT_FILENAME"], '.php').'.php';
  37. $usage = "Usage: php {$self} [Input.txt] [Output.txt] [Response Size] [Threads]";
  38. if(strlen($input)==0){
  39. $error = "Error: Invalid Filename!";
  40. }
  41. if(strlen($output)==0){
  42. $error.= "\nError: Invalid Filename!";
  43. }
  44. if(is_numeric($responselength)==false){
  45. $error.= "\nError: Invalid Response Length!";
  46. }
  47. if($maxthreads<1||$maxthreads>1000){
  48. $error.= "\nError: Invalid Threads!";
  49. }
  50. if(strlen($error)>=1){
  51. die($error."\n".$usage."\n");
  52. }
  53. print("\nSSDP Filter\nCoded by Jocker4\n\n");
  54. $threads = 0;
  55. $threadarr = array();
  56. $j = 0;
  57. $handle = fopen($input, "r");
  58. while(!feof($handle)){
  59. $line = fgets($handle, 4096);
  60. if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $line, $match)) {
  61. if (filter_var($match[0], FILTER_VALIDATE_IP)) {
  62. $ip = $match[0];
  63. JMP:
  64. if($threads < $maxthreads){
  65. $pipe[$j] = popen('php'.' '.$self.' '.$ip.' '.$output.' '.$responselength.' '.'THREAD', 'w');
  66. $threadarr[] = $j;
  67. $j = $j + 1;
  68. $threads = $threads + 1;
  69. } else {
  70. usleep(50000);
  71. foreach($threadarr as $index){
  72. pclose($pipe[$index]);
  73. $threads = $threads - 1;
  74. }
  75. $j = 0;
  76. unset($threadarr);
  77. goto JMP;
  78. }
  79. }
  80. }
  81. }
  82. fclose($handle);
  83. }
  84.  
  85. function threadfound(array $argv){
  86. $thread = false;
  87. foreach ($argv as $arg){
  88. if($arg=='THREAD'){
  89. $thread = true;
  90. break;
  91. }
  92. }
  93. return $thread;
  94. }
  95.  
  96. function addentry($file, $entry){
  97. if(!file_exists($file)){
  98. touch($file);
  99. chmod($file, 0777);
  100. }
  101. $fh = fopen($file, 'a') or die("Can't open file: ".$file);
  102. fwrite($fh, "\n".$entry);
  103. fclose($fh);
  104. }
  105.  
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement