feat(dpi): add IMAP protocol detection and metadata extraction#268
feat(dpi): add IMAP protocol detection and metadata extraction#2680xghost42 wants to merge 1 commit into
Conversation
Adds best-effort Deep Packet Inspection for the plaintext IMAP4rev1 control channel (RFC 3501, RFC 7888 LITERAL+, RFC 2595 STARTTLS, RFC 4978 COMPRESS). Port 993 (IMAPS) is TLS-wrapped and is claimed by the HTTPS/TLS analyzer instead. Detection: port 143 plus a signature that recognises all three IMAP frame shapes — tagged client request, tagged/untagged server response, command continuation. RFC 3501 tag grammar enforced (printable ASCII, length-capped) to keep parsing cheap on hostile traffic. Metadata: tag, command + args, status (OK/NO/BAD/BYE/PREAUTH), response message, username from LOGIN <user>, server software extracted from the * OK / * PREAUTH greeting (skips the bracketed CAPABILITY list). Display formatter shows 'IMAP LOGIN (alice)' for requests and 'IMAP OK (Dovecot)' for greetings. Per-flow merge keeps identity fields first-wins and dialog state latest-wins. Tests: 14 unit tests covering server greeting (Dovecot extracted past the [CAPABILITY ...] list), PREAUTH greeting, LOGIN with bare and quoted usernames, SELECT, UID FETCH, tagged OK/NO responses, untagged 23 EXISTS, command continuation, STARTTLS, HTTP/unknown/bare-tag rejection. cargo test --all-features: 338 passed. cargo clippy --all-features --all-targets -- -D warnings: clean. cargo fmt --all -- --check: clean. Tracks ROADMAP DPI Enhancements (IMAP).
|
@0xghost42 thanks for the PR. Also on this one, before merging I want to take a bit more time to think about whether IMAP DPI is the right addition for RustNet, and I would also like to hear from other users. My main hesitation is basically the same as for So the open question is whether enough RustNet users actually run setups where they would see plaintext IMAP. If you (or anyone reading this) have a concrete use case for this, please leave a note here so I can gauge demand. I will keep the PR open in the meantime. Therefore also here I would like to mention that I appreciate the work but I want to think it through before merging. |
|
@domcyrus same concern noted. Adding concrete use cases here too in case demand signal matters: Plaintext IMAP visibility is still useful for:
If maintenance surface is the worry, happy to keep the parser tight: detect via Will let this sit and see if others chime in. Either call works — close if it still doesn't pencil out. |
Summary
Adds best-effort Deep Packet Inspection for the plaintext IMAP4rev1 control channel (RFC 3501, RFC 7888 LITERAL+, RFC 2595 STARTTLS, RFC 4978 COMPRESS). Port 993 (IMAPS) is TLS-wrapped and is claimed by the HTTPS/TLS analyzer.
Tracks the DPI Enhancements roadmap item for IMAP.
What it does
Detection
Extracted metadata
Surfaces
Tests
14 new unit tests in `src/network/dpi/imap.rs`:
Full suite locally on macOS / Apple Silicon:
Files touched
Test plan