Skip to content

IMAP protocol parser, logger and sticky buffers v3#14995

Closed
glongo wants to merge 4 commits into
OISF:mainfrom
glongo:dev-imap-proto-v3
Closed

IMAP protocol parser, logger and sticky buffers v3#14995
glongo wants to merge 4 commits into
OISF:mainfrom
glongo:dev-imap-proto-v3

Conversation

@glongo
Copy link
Copy Markdown
Contributor

@glongo glongo commented Mar 9, 2026

PR mainly for discussion purposes.

Changes:

  • Request and response lines are now bounded
  • Email keywords (except email.body_md5 and email.url) can match on IMAP packets
  • IMAP body is no longer logged
  • Doc slightly updated but more work is still needed

Main discussion point is:
Shoud we use JsonGenericDirFlowLogger or JsonGenericDirPacketLogger to log IMAP events?

Link to ticket: https://redmine.openinfosecfoundation.org/issues/8276

Previous PR: #14822

SV_BRANCH=OISF/suricata-verify#2908

glongo added 4 commits March 9, 2026 11:43
This introduces a parser for IMAP protocol.

Ticket OISF#8276
This introduces a logger for IMAP protocol.

Ticket OISF#8276
This implement the following sticky buffers for IMAP protocol:
- imap.request
- imap.response
- imap.email.direction
- imap.email.header
- imap.email.header.name
- imap.email.header.value
- imap.email.body

Ticket OISF#8276
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 82.25144% with 432 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.58%. Comparing base (1d06103) to head (503b6af).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14995      +/-   ##
==========================================
- Coverage   82.60%   82.58%   -0.03%     
==========================================
  Files         990      993       +3     
  Lines      271506   273898    +2392     
==========================================
+ Hits       224290   226194    +1904     
- Misses      47216    47704     +488     
Flag Coverage Δ
fuzzcorpus 60.47% <10.87%> (-0.53%) ⬇️
livemode 18.23% <10.00%> (-0.20%) ⬇️
netns 18.23% <10.00%> (-0.14%) ⬇️
pcap 45.35% <62.63%> (+0.11%) ⬆️
suricata-verify 66.21% <75.93%> (+0.08%) ⬆️
unittests 58.76% <52.38%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 79.336% (+0.01%) from 79.323%
when pulling 503b6af on glongo:dev-imap-proto-v3
into 1d06103 on OISF:main.

@suricata-qa
Copy link
Copy Markdown

Information: QA ran without warnings.

Pipeline = 30106

Comment thread rust/src/imap/imap.rs

#[derive(AppLayerEvent)]
enum ImapEvent {
TooManyTransactions,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget to add a file imap-event.rules for this ;-)

Copy link
Copy Markdown
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work, needs imap-events.rules at least

CI : ✅
Code : will look
Commits segmentation : I would squash more but I guess it is ok
Commit messages : Should also mention the email.* keywords, right ?
Git ID set : looks fine for me
CLA : you already contributed
Doc update : there is a section missing in doc/userguide/output/eve/eve-json-format.rst to describe the eve json output of an imap event. Also should there be lua support ? (code or ticket to track it for later)
Redmine ticket : ok, set to in review. Should we close https://redmine.openinfosecfoundation.org/issues/3244 as duplicate ?
Rustfmt : rustfmt rust/src/imap/*.rs clean :-)
Tests : left somme comments there
Dependencies added: none

@catenacyber
Copy link
Copy Markdown
Contributor

Do we keywords file file.data that should work for attachments as is the case for SMTP ?

Comment thread src/detect-email.c

if (SCDetectSignatureSetAppProto(s, ALPROTO_SMTP) < 0)
AppProto alprotos[] = { ALPROTO_SMTP, ALPROTO_IMAP, ALPROTO_UNKNOWN };
if (DetectSignatureSetMultiAppProto(s, alprotos) < 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this :-)

Comment thread rust/src/imap/detect.rs
) -> *mut DetectUintData<u8> {
let ft_name: &CStr = CStr::from_ptr(ustr);
if let Ok(s) = ft_name.to_str() {
if let Some(ctx) = detect_parse_uint_enum::<u8, ImapEmailDirection>(s) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use the strings, not numbers like 0/1/8

Comment thread rust/src/imap/imap.rs
pub complete: bool,

pub requests: Vec<ImapMessage>,
pub responses: Vec<ImapMessage>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these stateful structruers bounded ?
Or does suricata OOM if stream.depth is 0 and a server does not stop sending responses to the same request ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread rust/src/imap/imap.rs
&stream_slice,
start,
-1_i64,
ImapFrameType::Pdu as u8,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SV test missing for frames

Comment thread rust/src/imap/imap.rs
pub struct ImapParsedEmail {
pub direction: u8,
pub body: Vec<u8>,
pub headers: Vec<Vec<u8>>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these fields bounded as well ?

@glongo
Copy link
Copy Markdown
Contributor Author

glongo commented Mar 19, 2026

Replaced with #15064

@glongo glongo closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants