detect: add email.to keyword

email.to matches on MIME EMAIL TO
This keyword maps to the EVE field email.to[]
It is a sticky buffer
Supports prefiltering

Ticket: #7596
pull/12836/head
Alice Akaki 1 year ago committed by Victor Julien
parent 09aed7e243
commit 5d6a072e35

@ -50,3 +50,27 @@ Example of a signature that would alert if a packet contains the MIME field ``su
.. container:: example-rule .. container:: example-rule
alert smtp any any -> any any (msg:"Test mime email subject"; :example-rule-emphasis:`email.subject; content:"This is a test email";` sid:1;) alert smtp any any -> any any (msg:"Test mime email subject"; :example-rule-emphasis:`email.subject; content:"This is a test email";` sid:1;)
email.to
--------
Matches the MIME ``To`` field of an email.
Comparison is case-sensitive.
Syntax::
email.to; content:"<content to match against>";
``email.to`` is a 'sticky buffer' and can be used as a ``fast_pattern``.
This keyword maps to the EVE field ``email.to``
Example
^^^^^^^
Example of a signature that would alert if a packet contains the MIME field ``to`` with the value ``172.16.92.2@linuxbox``
.. container:: example-rule
alert smtp any any -> any any (msg:"Test mime email to"; :example-rule-emphasis:`email.to; content:"172.16.92.2@linuxbox";` sid:1;)

@ -24,6 +24,7 @@
static int g_mime_email_from_buffer_id = 0; static int g_mime_email_from_buffer_id = 0;
static int g_mime_email_subject_buffer_id = 0; static int g_mime_email_subject_buffer_id = 0;
static int g_mime_email_to_buffer_id = 0;
static int DetectMimeEmailFromSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg) static int DetectMimeEmailFromSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
{ {
@ -99,6 +100,42 @@ static InspectionBuffer *GetMimeEmailSubjectData(DetectEngineThreadCtx *det_ctx,
return buffer; return buffer;
} }
static int DetectMimeEmailToSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
{
if (DetectBufferSetActiveList(de_ctx, s, g_mime_email_to_buffer_id) < 0)
return -1;
if (DetectSignatureSetAppProto(s, ALPROTO_SMTP) < 0)
return -1;
return 0;
}
static InspectionBuffer *GetMimeEmailToData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms, Flow *f, const uint8_t _flow_flags, void *txv,
const int list_id)
{
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
if (buffer->inspect == NULL) {
SMTPTransaction *tx = (SMTPTransaction *)txv;
const uint8_t *b_email_to = NULL;
uint32_t b_email_to_len = 0;
if ((tx->mime_state != NULL)) {
if (SCDetectMimeEmailGetData(tx->mime_state, &b_email_to, &b_email_to_len, "to") != 1)
return NULL;
}
if (b_email_to == NULL || b_email_to_len == 0)
return NULL;
InspectionBufferSetup(det_ctx, list_id, buffer, b_email_to, b_email_to_len);
InspectionBufferApplyTransforms(buffer, transforms);
}
return buffer;
}
void DetectEmailRegister(void) void DetectEmailRegister(void)
{ {
SCSigTableElmt kw = { 0 }; SCSigTableElmt kw = { 0 };
@ -124,4 +161,15 @@ void DetectEmailRegister(void)
"MIME EMAIL SUBJECT", ALPROTO_SMTP, false, "MIME EMAIL SUBJECT", ALPROTO_SMTP, false,
true, // to server true, // to server
GetMimeEmailSubjectData); GetMimeEmailSubjectData);
kw.name = "email.to";
kw.desc = "'To' field from an email";
kw.url = "/rules/email-keywords.html#email.to";
kw.Setup = (int (*)(void *, void *, const char *))DetectMimeEmailToSetup;
kw.flags = SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
DetectHelperKeywordRegister(&kw);
g_mime_email_to_buffer_id =
DetectHelperBufferMpmRegister("email.to", "MIME EMAIL TO", ALPROTO_SMTP, false,
true, // to server
GetMimeEmailToData);
} }

Loading…
Cancel
Save