0P3N Blog Blog Post

TCP Reverse Shell Using Python

By: r00t_privilege
January 31, 2017
tcp-reverse-shellEstimated reading time: 1 minuteThis article is about creating a reverse shell session over TCP using Python Sockets. Let me explain what happens in a general sense.First, the server binds its IP address and a PORT to a socket [note that I implemented a fixed solution for other people whose routers change IPs whenever they restart them]. Second, the client initiates a TCP connection to the client on that socket. This clearly doesn't generate any alert, except a simple connection to a remote server using TCP. After the client(s) connects, we select a target and basically, everything that you write (Server Side) is sent over the socket. Then the client executes it in a subprocess like a command, but it still doesn't trigger any alert for antivirus or firewall. The result of the execution is sent back to the server so you can read the result.I put two versions, one encrypted and the other one clear text, with various function implementations. If you are interested in my code, please visit: https://github.com/chmodxxx/tcp_reverse_shellAny remarks on things I can improve are welcome. Thank you.

Build your Cybersecurity or IT Career

Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry