alert smtp any any -> any any (msg:"SURICATA SMTP duplicate fields"; flow:established,to_server; app-layer-event:smtp.duplicate_fields; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220018; rev:1;)
alert smtp any any -> any any (msg:"SURICATA SMTP unparsable content"; flow:established,to_server; app-layer-event:smtp.unparsable_content; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220019; rev:1;)
-# next sid 2220020
+alert smtp any any -> any any (msg:"SURICATA SMTP filename truncated"; flow:established,to_server; app-layer-event:smtp.mime_long_filename; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220020; rev:1;)
+# next sid 2220021
-/* Copyright (C) 2007-2012 Open Information Security Foundation
+/* Copyright (C) 2007-2020 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE },
{ "MIME_LONG_BOUNDARY",
SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG },
+ { "MIME_LONG_FILENAME",
+ SMTP_DECODER_EVENT_MIME_LONG_FILENAME },
/* Invalid behavior or content */
{ "DUPLICATE_FIELDS",
if (msg->anomaly_flags & ANOM_LONG_BOUNDARY) {
SMTPSetEvent(state, SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG);
}
+ if (msg->anomaly_flags & ANOM_LONG_FILENAME) {
+ SMTPSetEvent(state, SMTP_DECODER_EVENT_MIME_LONG_FILENAME);
+ }
}
/**
* \param search_end The end of the search (ie. \")
* \param tlen The output length of the token (if found)
* \param max_len The maximum offset in which to search
+ * \param toolong Set if the field value was truncated to max_len.
*
* \return A pointer to the token if found, otherwise NULL if not found
*/
static uint8_t * FindMimeHeaderToken(MimeDecField *field, const char *search_start,
const char *search_end, uint32_t *tlen)
{
- return FindMimeHeaderTokenRestrict(field, search_start, search_end, tlen, 0);
+ return FindMimeHeaderTokenRestrict(field, search_start, search_end, tlen, 0, NULL);
}
/**
/* Check for file attachment in content disposition */
field = MimeDecFindField(entity, CTNT_DISP_STR);
if (field != NULL) {
- bptr = FindMimeHeaderTokenRestrict(field, "filename=", TOK_END_STR, &blen, NAME_MAX);
+ bool truncated_name = false;
+ bptr = FindMimeHeaderTokenRestrict(field, "filename=", TOK_END_STR, &blen, NAME_MAX, &truncated_name);
if (bptr != NULL) {
SCLogDebug("File attachment found in disposition");
entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
}
memcpy(entity->filename, bptr, blen);
entity->filename_len = blen;
+
+ if (truncated_name) {
+ state->stack->top->data->anomaly_flags |= ANOM_LONG_FILENAME;
+ state->msg->anomaly_flags |= ANOM_LONG_FILENAME;
+ }
}
}
/* Look for file name (if not already found) */
if (!(entity->ctnt_flags & CTNT_IS_ATTACHMENT)) {
- bptr = FindMimeHeaderTokenRestrict(field, "name=", TOK_END_STR, &blen, NAME_MAX);
+ bool truncated_name = false;
+ bptr = FindMimeHeaderTokenRestrict(field, "name=", TOK_END_STR, &blen, NAME_MAX, &truncated_name);
if (bptr != NULL) {
SCLogDebug("File attachment found");
entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
}
memcpy(entity->filename, bptr, blen);
entity->filename_len = blen;
+
+ if (truncated_name) {
+ state->stack->top->data->anomaly_flags |= ANOM_LONG_FILENAME;
+ state->msg->anomaly_flags |= ANOM_LONG_FILENAME;
+ }
}
}