-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
64 lines (51 loc) · 1.85 KB
/
main.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
#!/usr/bin/env python3.6
from Source.Facade.ArgParseHelper import ArgParseHelper
from Source.ProcessPacket import ProcessPacket
from Source.DomainInfoExtractor import Extractor
from Source.SVMModel import SVMModel
import json
import sys
import socket
from Source.Sniffer.ethernet import Ethernet
from Source.Sniffer.ipv4 import IPv4
from Source.Sniffer.tcp import TCP
from Source.Sniffer.ssl import RecordProtocol, ServerHello
import tempfile
import ast
__author__ = "David Debreceni Jr"
def main():
print('Training Model...')
print('This may take a bit...')
svm = SVMModel()
svm.train_model()
print(svm.model_accuracy())
print('Training Complete!')
print('Starting Sniffer.')
sniffer = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x003))
print('Sniffer Created!')
print('Please browse the internet as you see fit.')
data = []
while True:
try:
raw_buffer = sniffer.recvfrom(65565)[0]
ethernet = Ethernet(raw_buffer[0:14])
if ethernet.Type == 'IPv4':
ip = IPv4(raw_buffer[14:34])
if ip.Protocol == "TCP":
tcp = TCP(raw_buffer[34:])
rec = RecordProtocol(raw_buffer[34+tcp.Data_Offset:39+tcp.Data_Offset])
server = ServerHello(raw_buffer[39+tcp.Data_Offset:])
if server.Handshake_Type == "Server_Hello":
data.append([server.Version, server.Cipher_Suite])
#svm.test_model(server.Version, server.Cipher_Suite)
except ValueError as e:
continue
except KeyboardInterrupt:
svm.test_model(data)
if input() == 'q':
sys.exit()
else:
data = []
continue
if __name__ == "__main__":
main()