Skip to content

Commit

Permalink
Passive/p0f: tiny fixes for ivre p0f2db
Browse files Browse the repository at this point in the history
  • Loading branch information
p-l- committed Sep 22, 2021
1 parent 90c1a5b commit 4f332aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ivre/parser/p0f.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


CONTAINER_TYPE = re.compile(b"^(table|set|vector)\\[([a-z]+)\\]$")
LINE_RE = re.compile(r"^\[(?P<time>[^\]]+)\] (?P<data>.*)$")


class P0fFile(Parser):
Expand All @@ -50,18 +51,14 @@ def __next__(self) -> Dict[str, Any]:
return self.parse_line(next(self.fdesc).strip())

def parse_line(self, line: bytes) -> Dict[str, Any]:
line_s = line.decode()
LINE_RE = re.compile(r"^\[(?P<time>[^\]]+)\] (?P<data>.*)$")
m = LINE_RE.match(line_s)
m = LINE_RE.match(line.decode())
if not m:
return {}
res: Dict[str, Any] = {}
# time of event
time = m.group("time")
res["ts"] = datetime.datetime.strptime("%s" % time, "%Y/%m/%d %H:%M:%S")
res["ts"] = datetime.datetime.strptime(m.group("time"), "%Y/%m/%d %H:%M:%S")
# data of event
data = m.group("data")
for entry in data.split("|"):
for entry in m.group("data").split("|"):
k, v = entry.split("=", 1)
if k in res:
LOGGER.warning("Duplicate key in line [%r]", line)
Expand Down
1 change: 1 addition & 0 deletions ivre/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"iphost",
"localscan",
"macinfo",
"p0f2db",
"passiverecon2db",
"passivereconworker",
"plotdb",
Expand Down

0 comments on commit 4f332aa

Please sign in to comment.