Skip to content

feat(imports): add nmap XML importer#184

Open
rachit367 wants to merge 1 commit into
reconurge:mainfrom
rachit367:feat/nmap-xml-importer
Open

feat(imports): add nmap XML importer#184
rachit367 wants to merge 1 commit into
reconurge:mainfrom
rachit367:feat/nmap-xml-importer

Conversation

@rachit367

Copy link
Copy Markdown

What

Adds an nmap XML importer so an existing scan can be imported into a sketch, instead of re-scanning a target or adding ports by hand.

Closes #107

Why

From the issue: during assessments people often run nmap manually with specific flags, and naabu can also export in nmap XML. Letting Flowsint ingest that XML enriches a sketch with the hosts/ports already discovered. This reuses the existing two-phase import pipeline (analyze → execute) — no new infrastructure.

How it plugs in

The import pipeline dispatches parsers by file extension (flowsint_core/imports/file_parser.py) and each parser is a function returning a FileParseResult of typed entities + edges, which the pipeline persists. The new parser follows that exact contract (same shape as the existing JSON parser).

  • flowsint_core/imports/nmap/parse_nmap.py (new) — parse_nmap_xml() turns an nmap report into:
    • Ip entities (one per up host; down hosts skipped; IPv4 preferred, IPv6 supported, MAC ignored)
    • Port entities (number, protocol, state, service, and a banner composed from service product/version/extrainfo)
    • IP -[HAS_PORT]-> Port edges (the same relationship label the ip_to_ports enricher uses)
  • Wiring: .xml added to ALLOWED_EXTENSIONS (core dispatcher) + the analyze route's filename validation (flowsint-api/.../sketches.py) + the import sheet's accepted extensions (flowsint-app/.../import-sheet.tsx). Ip and Port already exist, so no type changes were needed.

Security

Import files are untrusted, so the XML is parsed with defusedxml (new flowsint-core dependency) to prevent XXE / billion-laughs attacks. Element type hints still come from the stdlib (identical types, not a parsing path).

Testing

uv run --package flowsint-core pytest flowsint-core/tests/import/ -q
56 passed   # 10 new nmap tests + existing import suite, no regressions

New tests (pure-parse, no DB): IP/port extraction, port fields + banner composition, HAS_PORT edges, down-host skipping, IPv6, invalid-port skipping, empty/invalid XML handling, and dispatch through parse_import_file.

Scope note: this maps the core of an nmap scan (hosts + ports + service info). NSE script output (which could map to the existing Script type) is intentionally left out to keep the PR focused; happy to add it as a follow-up if wanted.

Adds support for importing an existing nmap (or naabu nmap-XML) scan into
a sketch, so analysts can bring scans they ran manually instead of
re-scanning or adding ports by hand (reconurge#107).

- New parser `parse_nmap_xml` (flowsint_core/imports/nmap) that turns an
  nmap XML report into Ip + Port entities and IP-[HAS_PORT]->Port edges,
  matching the existing two-phase import contract (returns FileParseResult
  with typed objects; the pipeline persists them). Down hosts are skipped;
  port banner is composed from service product/version/extrainfo.
- Wired into the extension dispatcher: `.xml` added to ALLOWED_EXTENSIONS
  in file_parser.py and to the analyze route's filename validation, and
  to the frontend import sheet's accepted extensions.
- XML is parsed with defusedxml to guard against XXE / billion-laughs in
  untrusted import files (new flowsint-core dependency).

Tests cover IP/port extraction, port fields + banner, HAS_PORT edges,
down-host skipping, IPv6, invalid-port skipping, empty/invalid XML, and
dispatch through parse_import_file. No DB required.

Closes reconurge#107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Nmap importer

1 participant