mirror of
https://github.com/OISF/suricata.git
synced 2026-10-12 02:07:10 +00:00
detect: add email.x_mailer keyword
email.x_mailer matches on MIME EMAIL X-Mailer This keyword maps to the EVE field email.x_mailer It is a sticky buffer Supports prefiltering Ticket: #7598
This commit is contained in:
committed by
Victor Julien
parent
52e12410ed
commit
341369f203
@@ -146,3 +146,27 @@ Example of a signature that would alert if a packet contains the MIME field ``me
|
||||
.. container:: example-rule
|
||||
|
||||
alert smtp any any -> any any (msg:"Test mime email message id"; :example-rule-emphasis:`email.message_id; content:"<[email protected]>";` sid:1;)
|
||||
|
||||
email.x_mailer
|
||||
--------------
|
||||
|
||||
Matches the MIME ``X-Mailer`` field of an email.
|
||||
|
||||
Comparison is case-sensitive.
|
||||
|
||||
Syntax::
|
||||
|
||||
email.x_mailer; content:"<content to match against>";
|
||||
|
||||
``email.x_mailer`` is a 'sticky buffer' and can be used as a ``fast_pattern``.
|
||||
|
||||
This keyword maps to the EVE field ``email.x_mailer``
|
||||
|
||||
Example
|
||||
^^^^^^^
|
||||
|
||||
Example of a signature that would alert if a packet contains the MIME field ``x-mailer`` with the value ``Microsoft Office Outlook, Build 11.0.5510``
|
||||
|
||||
.. container:: example-rule
|
||||
|
||||
alert smtp any any -> any any (msg:"Test mime email x-mailer"; :example-rule-emphasis:`email.x_mailer; content:"Microsoft Office Outlook, Build 11.0.5510";` sid:1;)
|
||||
|
||||
@@ -28,6 +28,7 @@ static int g_mime_email_to_buffer_id = 0;
|
||||
static int g_mime_email_cc_buffer_id = 0;
|
||||
static int g_mime_email_date_buffer_id = 0;
|
||||
static int g_mime_email_message_id_buffer_id = 0;
|
||||
static int g_mime_email_x_mailer_buffer_id = 0;
|
||||
|
||||
static int DetectMimeEmailFromSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
|
||||
{
|
||||
@@ -237,6 +238,41 @@ static InspectionBuffer *GetMimeEmailMessageIdData(DetectEngineThreadCtx *det_ct
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static int DetectMimeEmailXMailerSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
|
||||
{
|
||||
if (DetectBufferSetActiveList(de_ctx, s, g_mime_email_x_mailer_buffer_id) < 0)
|
||||
return -1;
|
||||
|
||||
if (DetectSignatureSetAppProto(s, ALPROTO_SMTP) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static InspectionBuffer *GetMimeEmailXMailerData(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_x_mailer = NULL;
|
||||
uint32_t b_email_x_mailer_len = 0;
|
||||
|
||||
if (tx->mime_state == NULL)
|
||||
return NULL;
|
||||
|
||||
if (SCDetectMimeEmailGetData(
|
||||
tx->mime_state, &b_email_x_mailer, &b_email_x_mailer_len, "x-mailer") != 1)
|
||||
return NULL;
|
||||
|
||||
InspectionBufferSetup(det_ctx, list_id, buffer, b_email_x_mailer, b_email_x_mailer_len);
|
||||
InspectionBufferApplyTransforms(buffer, transforms);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void DetectEmailRegister(void)
|
||||
{
|
||||
SCSigTableElmt kw = { 0 };
|
||||
@@ -306,4 +342,15 @@ void DetectEmailRegister(void)
|
||||
"MIME EMAIL Message-Id", ALPROTO_SMTP, false,
|
||||
true, // to server
|
||||
GetMimeEmailMessageIdData);
|
||||
|
||||
kw.name = "email.x_mailer";
|
||||
kw.desc = "'X-Mailer' field from an email";
|
||||
kw.url = "/rules/email-keywords.html#email.x_mailer";
|
||||
kw.Setup = (int (*)(void *, void *, const char *))DetectMimeEmailXMailerSetup;
|
||||
kw.flags = SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
|
||||
DetectHelperKeywordRegister(&kw);
|
||||
g_mime_email_x_mailer_buffer_id = DetectHelperBufferMpmRegister("email.x_mailer",
|
||||
"MIME EMAIL X-Mailer", ALPROTO_SMTP, false,
|
||||
true, // to server
|
||||
GetMimeEmailXMailerData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user