Skip to content

Commit 510b318

Browse files
committed
Fixed gnmap parsing to support masscan format properly
1 parent 0de1ade commit 510b318

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

httpscreenshot.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,26 @@ def parseGnmap(inFile, autodetect):
125125
>>> targets
126126
{'127.0.0.1': [[443, True], [8080, False]]}
127127
"""
128+
hostRe=re.compile('Host:\s*[^\s]+')
129+
servicesRe=re.compile('Ports:\s*.*')
128130
targets = {}
129131
for hostLine in inFile:
130132
if hostLine.strip() == "":
131133
break
132134
currentTarget = []
133135
# Pull out the IP address (or hostnames) and HTTP service ports
134-
fields = hostLine.split(" ")
135-
ip = fields[
136-
1] # not going to regex match this with ip address b/c could be a hostname
137-
for item in fields:
136+
137+
ipHostRes = hostRe.search(hostLine)
138+
139+
if ipHostRes is None:
140+
continue
141+
142+
ipHost = ipHostRes.group()
143+
ip = ipHost.split(':')[1].strip()
144+
145+
services = servicesRe.search(hostLine).group().split()
146+
147+
for item in services:
138148
# Make sure we have an open port with an http type service on it
139149
if (item.find("http") != -1 or autodetect) and re.findall(
140150
"\d+/open", item):
@@ -160,7 +170,10 @@ def parseGnmap(inFile, autodetect):
160170
currentTarget.append([port, https])
161171

162172
if len(currentTarget) > 0:
163-
targets[ip] = currentTarget
173+
if ip in targets:
174+
targets[ip].extend(currentTarget)
175+
else:
176+
targets[ip] = currentTarget
164177
return targets
165178

166179

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pillow
66
PySocks
77
python-libnmap
88
pyvirtualdisplay
9+
reload

0 commit comments

Comments
 (0)