Skip to content

Commit

Permalink
Fix nmap probes file parsing (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-l- committed Jun 16, 2023
1 parent 4af0e34 commit a73ed7b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ivre/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,11 +1215,21 @@ def parse_line(line: bytes) -> None:
elif line.startswith(b"Probe "):
_NMAP_CUR_PROBE = []
_NMAP_CUR_FALLBACK = []
probe: Optional[bytes]
proto, name, probe = line[6:].split(b" ", 2)
if not (len(probe) >= 3 and probe[:2] == b"q|" and probe[-1:] == b"|"):
if not (len(probe) >= 3 and probe[:2] == b"q|"):
LOGGER.warning("Invalid nmap probe %r", probe)
else:
probe = nmap_decode_data(probe[2:-1].decode(), arbitrary_escapes=True)
return
while not probe[-1:] == b"|":
try:
probe = probe.rsplit(b" ", 1)[-2]
except IndexError:
LOGGER.warning("Invalid nmap probe %r", probe)
probe = None
break
if probe is None:
return
probe = nmap_decode_data(probe[2:-1].decode(), arbitrary_escapes=True)
assert _NMAP_CUR_PROBE is not None
assert _NMAP_CUR_FALLBACK is not None
_NMAP_PROBES.setdefault(proto.lower().decode(), {})[name.decode()] = {
Expand Down

0 comments on commit a73ed7b

Please sign in to comment.