Skip to content

Commit 8be39e7

Browse files
committed
Change in format strings for logging scans
1 parent 58954cd commit 8be39e7

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

scanlogger.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ def log_scan(self, scan):
127127
""" Log the scan to file and/or console """
128128

129129
srcip, dstip = utils.scan_ip2quad(scan)
130+
zombie_host = utils.ip2quad(scan.zombie)
130131
ports = ','.join([str(port) for port in scan.ports])
132+
template = '{type} scan (flags:{flags}) from {srcip} to {dstip} (ports: {ports})'
133+
line = ''
131134

132135
if not scan.duplicate:
133136
# Newly detected scan
134-
tup = [scan.type,scan.flags,srcip,dstip, ports]
135-
136137
if not scan.slow_scan:
137138
if scan.type != TCP_IDLE_SCAN:
138-
line = '%s scan (flags:%d) from %s to %s (ports:%s)'
139+
line = template
139140
else:
140-
tup.append(utils.ip2quad(scan.zombie))
141-
line = '%s scan (flags: %d) from %s to %s (ports: %s) using zombie host %s'
141+
line = template + ' using zombie host {zombie_host}'
142142
else:
143-
tup.append(scan.time_avg)
143+
# tup.append(scan.time_avg)
144144
if scan.maybe:
145-
line = 'Possible slow %s scan (flags:%d) from %s to %s (ports:%s), average timediff %.2fs'
145+
line = 'Possible slow ' + template + ', mean timediff: {time_avg:.2f}s'
146146
else:
147-
line = 'Slow %s scan (flags:%d) from %s to %s (ports:%s), average timediff %.2fs'
147+
line = 'Slow ' + template + ', mean timediff: {time_avg:.2f}s'
148148
else:
149149
if self.ignore_dups:
150150
# Not logging continued/duplicate scans
@@ -158,15 +158,16 @@ def log_scan(self, scan):
158158
custom_threshold = levelParams['max'][1]
159159
self.custom_thresholds[scan.hash] = custom_threshold
160160
if scan.type != TCP_IDLE_SCAN:
161-
line = 'Continuing %s scan from %s to %s (ports:%s)'
161+
line = 'Continuing ' + template
162162
else:
163-
tup.append(utils.ip2quad(scan.zombie))
164-
line = 'Continuing %s scan from %s to %s (ports: %s) using zombie host %s'
163+
line = 'Continuing ' + template + ' using zombie host {zombie_host}'
165164
else:
166-
tup.append(scan.time_avg)
167-
line = 'Continuing slow %s scan from %s to %s (ports:%s), average timediff %.2fs'
165+
line = 'Continuing slow ' + template + ', mean timediff: {time_avg:.2f}s'
168166

169-
msg = line % tuple(tup)
167+
# Context dictionary
168+
context_dict = locals()
169+
context_dict.update(scan.__dict__)
170+
msg = line.format(**context_dict)
170171
self.log(msg)
171172

172173
def update_ports(self, scan, dport, flags):

0 commit comments

Comments
 (0)