forked from fribbels/Fribbels-Epic-7-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.py
85 lines (66 loc) · 2.17 KB
/
scanner.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from scapy.all import *
import io,sys,json,os
import threading
import time
acks = {}
prevAcks = [-1 for i in range(len(list(conf.ifaces.data.values())))];
existingIpIds = {}
existingTcpSeqs = {}
def try_buffer(currAck):
buffers = acks[currAck];
buffers = sorted(buffers, key=lambda x: x['seq'])
finalBuffer = b''
for i in buffers:
finalBuffer += i['data']
hexStr = ''
try:
hexStr = finalBuffer.hex();
except:
hexStr = ''.join(x.encode('hex') for x in finalBuffer);
print(hexStr);
print('&');
def check_packet(packet):
if IP in packet:
if Raw in packet and packet[Raw].load:
currAck = packet.ack
currSeq = packet[TCP].seq
packet_bytes = bytes(packet[Raw].load)
# packet.show()
if existingIpIds.get(packet[IP].id) == None:
existingIpIds[packet[IP].id] = True
else:
return
if existingTcpSeqs.get(packet[TCP].seq) == None:
existingTcpSeqs[packet[TCP].seq] = True
else:
return
if currAck in acks:
acks[currAck].append({'data': packet_bytes, 'seq': packet[TCP].seq})
else:
acks[currAck] = [{'data': packet_bytes, 'seq': packet[TCP].seq}]
# if 'F' in packet[TCP].flags:
# try_buffer(currAck)
def terminate():
os._exit(0)
def thread_sniff():
try:
# EpicSeven traffic was confirmed to travel over tcp port 3333 via Wireshark
# Omitting sniff() iface parameter to force all interfaces to be sniffed.
# This may lead to more processing but prevents needing to specify an network interface manually in some cases.
sniff(prn=lambda x: check_packet(x), filter="tcp and ( port 3333 )", session=TCPSession)
except:
pass
x = threading.Thread(target=thread_sniff)
x.daemon = True;
x.start()
t = threading.Timer(3600.0, terminate)
t.start()
loop = True
while loop:
line = sys.stdin.readline()
if "E" in line:
for ack in acks:
try_buffer(ack)
loop = False
print("DONE\n")
sys.stdout.flush()