-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathnmap_rescan.py
More file actions
executable file
·73 lines (58 loc) · 2.05 KB
/
nmap_rescan.py
File metadata and controls
executable file
·73 lines (58 loc) · 2.05 KB
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
#!/usr/bin/env python2.7
###########
# IMPORTS #
###########
from __future__ import print_function
import sys
import argparse
import os
import modules.nmap as nmap
#############
# FUNCTIONS #
#############
def error(*objects):
print("[!]", *objects, file=sys.stderr)
def info(*objects):
print("[+]", *objects, file=sys.stdout)
def scan_hosts(files):
info("Parsing nmap xml file(s) ...")
hosts = nmap.parse_hosts(files, True)
info("Starting scans ...")
for host in tqdm(hosts, leave=True):
ports = set()
found = nmap.parse_ports_for_address(files, host)
for port in found:
ports.add(port.split('/', 1)[0])
print("sudo nmap -v -Pn -sS -sV --version-intensity 9 -O --script=default --traceroute -T4 -p T:%s --initial-rtt-timeout=200ms --min-rtt-timeout=100ms --max-rtt-timeout=$maxrtt --defeat-rst-ratelimit --open --stats-every 15s -oA tcp_%s %s" % (ports, host, host))
########
# MAIN #
########
if __name__ == '__main__':
desc = 'Parse nmap xml output and rescan previosuly identified ' \
'hosts and any open ports.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-o', '--output',
action='store',
help='directory to output results',
metavar='PATH')
parser.add_argument('files',
action='store',
nargs='+',
help='nmap xml file(s) to parse',
metavar='INPUT')
args = parser.parse_args()
for xml in args.files:
if not os.path.isfile(xml):
error("File '%s' does not exist!" % xml)
exit()
if not os.access(xml, os.R_OK):
error("File '%s' is not readable!" % xml)
exit()
if args.output:
if os.path.exists(args.output):
error("Directory '%s' already exists!" % args.output)
exit()
os.mkdir(args.output)
dump_data(args.files, args.output)
else:
print_report(args.files)