feat: hostname resolution via reverse DNS and passive OS inference from banners - #42
Merged
Merged
Conversation
…om banners Closes #37 Two enrichment steps added after nmap in orchestrate_scan(): ## Hostname (dns_lookup.py) - resolve_hostnames() performs socket.gethostbyaddr() for any host nmap did not name (no PTR in XML) - Per-IP SIGALRM timeout (1s) prevents a slow resolver stalling scans - Fails gracefully — missing PTR leaves hostname as empty string ## OS hints (os_inference.py) - enrich_os_guesses() infers os_guess from service/version banners for any host where os_guess is still empty after nmap - SSH banner patterns: Ubuntu, Debian, Raspbian, FreeBSD, Windows, etc. - HTTP Server header patterns: OpenWrt, DD-WRT, Synology DSM, QNAP, etc. - Service-name fallbacks: microsoft-ds/msrpc/RDP → Windows ## Tests (test_enrichment.py) — 21 unit tests - OS inference: 12 tests covering SSH banners, HTTP headers, service-name hints, priority ordering, no-match case - Hostname: 6 tests covering PTR resolution, existing-name guard, OSError/TimeoutError graceful handling, selective querying Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #37
Changes
backend/app/scanner/dns_lookup.py(new)Reverse DNS fallback for hosts nmap couldn't name. Uses
socket.gethostbyaddr()with a per-IP SIGALRM timeout (1 s) to avoid stalling the scan on unresponsive resolvers.backend/app/scanner/os_inference.py(new)Passive OS inference from service/version banners — no elevated privileges required. Recognises:
microsoft-ds,msrpc,ms-wbt-server→ Windowsbackend/app/scanner/__init__.pyTwo new steps wired into
orchestrate_scan()after nmap completes:resolve_hostnames()— fills missing hostnamesenrich_os_guesses()— fills missing os_guessbackend/tests/test_enrichment.py(new — 21 unit tests)Full coverage of both modules: banner matching, priority ordering, graceful failure, no-overwrite guard.