@@ -60,6 +60,8 @@ def __init__(self, timeout, threshold, itf=None, maxsize=8192, daemon=True, logf
60
60
self .long_scans = entry .EntryLog (maxsize )
61
61
# Port scan weight threshold
62
62
self .threshold = threshold
63
+ # Custom thresholds
64
+ self .custom_thresholds = {}
63
65
# Timeout for scan entries
64
66
self .timeout = timeout
65
67
# Long-period scan timeouts
@@ -125,6 +127,10 @@ def log_scan(self, scan):
125
127
# Continuing an already detected scan
126
128
tup = [scan .type , srcip ,dstip , ports ]
127
129
if not scan .slow_scan :
130
+ # We dont want a continuing scan to log too many times
131
+ # so update the threshold for the scan's hash
132
+ custom_threshold = levelParams ['max' ][1 ]
133
+ self .custom_thresholds [scan .hash ] = custom_threshold
128
134
if scan .type != TCP_IDLE_SCAN :
129
135
line = 'Continuing %s scan from %s to %s (ports:%s)'
130
136
else :
@@ -163,6 +169,10 @@ def inspect_scan(self, scan, slow_scan=False):
163
169
else :
164
170
threshold = self .threshold
165
171
172
+ if scan .hash in self .custom_thresholds :
173
+ # Pick up custom threshold
174
+ threshold = self .custom_thresholds [scan .hash ]
175
+
166
176
# print(threshold, scan.weight)
167
177
# Sure scan
168
178
is_scan = (scan .weight >= threshold )
@@ -293,9 +303,11 @@ def inspect_scan(self, scan, slow_scan=False):
293
303
else :
294
304
return False
295
305
296
- def process (self , ts , pkt ):
306
+ def process (self , ts , pkt , decode = None ):
297
307
""" Process an incoming packet looking for scan signatures """
298
308
309
+ pkt = decode (pkt )
310
+
299
311
# Dont process non-IP packets
300
312
if not 'ip' in pkt .__dict__ :
301
313
return
@@ -397,16 +409,15 @@ def process(self, ts, pkt):
397
409
398
410
def loop (self ):
399
411
""" Run the main logic in a loop listening to packets """
412
+
400
413
pc = pcap .pcap (name = self .itf , promisc = True , immediate = True , timeout_ms = 500 )
401
414
decode = { pcap .DLT_LOOP :dpkt .loopback .Loopback ,
402
415
pcap .DLT_NULL :dpkt .loopback .Loopback ,
403
416
pcap .DLT_EN10MB :dpkt .ethernet .Ethernet } [pc .datalink ()]
404
417
405
418
try :
406
419
print ('listening on %s: %s' % (pc .name , pc .filter ))
407
- for ts , pkt in pc :
408
- # print(ts, pkt)
409
- self .process (ts , decode (pkt ))
420
+ pc .loop (- 1 , self .process , decode )
410
421
except KeyboardInterrupt :
411
422
if not self .daemon :
412
423
nrecv , ndrop , nifdrop = pc .stats ()
0 commit comments