-
Notifications
You must be signed in to change notification settings - Fork 0
/
detector.py
executable file
·48 lines (35 loc) · 1.31 KB
/
detector.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
#! /usr/bin/env python3
import sys
import dpkt
from prettytable import PrettyTable
#Import strategies
from strategies.tcpsyn import tcpSynScan
from strategies.tcpconnect import tcpConnectScan
from strategies.tcpnull import tcpNullScan
from strategies.tcpxmas import tcpXmasScan
from strategies.tcpfin import tcpFinScan
from strategies.udp import udpScan
def main(argv):
if(len(sys.argv)) != 2:
print("Incorrect arguments: python3 port-scanner-detector.py <input.pcap>")
sys.exit()
filename = sys.argv[1]
#Run detection modules and print results
printResults("tcpSyn",tcpSynScan(filename))
printResults("tcpConnect",tcpConnectScan(filename))
printResults("tcpNull",tcpNullScan(filename))
printResults("tcpXmas",tcpXmasScan(filename))
printResults("tcpFin",tcpFinScan(filename))
printResults("udp",udpScan(filename))
def printResults(strategyName, results):
print("\n-----||",strategyName,"||-----\n")
if(len(results) == 0):
print("No port scans detected\n")
return
table = PrettyTable()
table.field_names = ["Suspect source", "Reason"]
for idx,result in enumerate(results):
table.add_row([result['suspect'],result['reason']])
print(table.get_string(title=strategyName)+"\n")
if __name__ == "__main__":
main(sys.argv[1:])