IMAP protocol parser, logger and sticky buffers v9#15730
Conversation
This introduces a parser for IMAP protocol.
An IMAP transaction has two states driven by the 'complete' field:
- Open (complete = false): waiting for a matching tagged response.
- Complete (complete = true): tagged response received, or special
conditions met (BYE, server greeting).
Completion logic (is_complete):
- If a tagged request exists: requires a matching tagged response.
- No tagged request + BYE: complete (server closing).
- No tagged request + any response: complete (server greeting).
Transactions are created in three places:
1. Request parser: every parsed command creates a new tx.
2. Response parser (tagged, no matching request): midstream/async;
orphan tagged response gets its own tx.
3. Response parser (untagged, no incomplete tx): server greeting or
unsolicited response.
Once open, messages accumulate:
- Request side: continuation and literal data attach to the most
recent incomplete tx.
- Response side: untagged responses attach to the most recent
incomplete tx; tagged responses attach via find_request(tag).
Email extraction happens at most once per tx:
- From literal data in APPEND commands (request side).
- From FETCH response data (response side).
Seven hard limits prevent unbounded growth:
- IMAP_MAX_TX (256, configurable): total transactions. Exceeded:
all incomplete txs force-completed with TooManyTransactions event.
- IMAP_MAX_MSGS_PER_TX (512): requests/responses per tx. Exceeded:
message silently dropped.
- IMAP_MAX_LINES (512): request/response lines per tx. Exceeded:
line silently dropped.
- IMAP_MAX_BODY_SIZE (10MB): email body in ImapParsedEmail.
Exceeded: body truncated, BodyTooLarge event.
- IMAX_MAX_HEADERS (512): Numbers of headers parsed and stored. Exceeded:
TooManyHeaders event.
- IMAP_MAX_LINE_SIZE (8KB): request/response line max length. Exceeded:
LineTooLong event.
- Literal size (u32): bounded by declared size in {N} specifier.
IMAP_MAX_TX only is configurable limit via app-layer.protocols.imap.max-tx.
Ticket OISF#8276
This introduces a logger for IMAP protocol. Ticket OISF#8276
This implements the following sticky buffers for IMAP protocol: - imap.request - imap.response The following frames have been added: - imap.body - imap.headers - imap.pdu The following email sticky buffers have been updated to work with IMAP: - email.from - email.subject - email.to - email.cc - email.date - email.message_id - email.x_mailer The following email sticky buffers have been added and are supported only for IMAP: - email.command - email.body - email.header - email.header.name - email.header.value Ticket OISF#8276
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #15730 +/- ##
=========================================
Coverage 82.96% 82.97%
=========================================
Files 1003 1006 +3
Lines 275031 277647 +2616
=========================================
+ Hits 228192 230366 +2174
- Misses 46839 47281 +442
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| suricata.yaml is now 1 MiB instead of 0/unlimited. | ||
| - LLMNR protocol parser, logger and sticky buffers are implemented. | ||
| - IMAP protocol parser is enabled by default. | ||
| - IMAP logger and sticky buffers are implemented. |
There was a problem hiding this comment.
this is not a changelog, only important changes to existing deployments should be mentioned
| #[derive(Default, Debug)] | ||
| pub struct ImapTransaction { | ||
| pub tx_id: u64, | ||
| pub complete: bool, |
There was a problem hiding this comment.
we'll need a per direction tx state (progress) tracking. A Tx can be complete in one direction, but not the other. We need this for the firewall work. In the simplest form this would be complete_ts, complete_tc. It needs to be real time too, so ts can't wait for tc.
| }; | ||
| let _ = helper_keyword_register_multi_buffer(&kw); | ||
|
|
||
| G_IMAP_REQUEST_BUFFER_ID = SCDetectHelperMultiBufferMpmRegister( |
There was a problem hiding this comment.
these are registered at progress 0, but it's unclear if that is the correct time. See also the required progress tracking update mention elsewhere in the PR.
| LiteralInfo, IMAP_MAX_BODY_SIZE, IMAP_MAX_LINE_SIZE, | ||
| }; | ||
| use nom::character::complete::crlf; | ||
| use nom7 as nom; |
There was a problem hiding this comment.
new parser should use nom 8
|
WARNING:
Pipeline = 32260 |
Changes:
Link to ticket: https://redmine.openinfosecfoundation.org/issues/8276
Previous PR: #15648
SV_BRANCH=OISF/suricata-verify#2908