59 #define FILEDATA_CONTENT_LIMIT 100000
61 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
63 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
66 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
68 #define SMTP_COMMAND_BUFFER_STEPS 5
75 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
77 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
79 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
81 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
87 #define SMTP_COMMAND_STARTTLS 1
88 #define SMTP_COMMAND_DATA 2
89 #define SMTP_COMMAND_BDAT 3
94 #define SMTP_COMMAND_DATA_MODE 4
96 #define SMTP_COMMAND_OTHER_CMD 5
97 #define SMTP_COMMAND_RSET 6
98 #define SMTP_COMMAND_QUIT 7
100 #define SMTP_DEFAULT_MAX_TX 256
103 #define SMTP_NO_TX_ID UINT64_MAX
178 static int SMTPGetFrameIdByName(
const char *frame_name)
187 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
207 static int SMTPStateGetStateIdByName(
const char *
name,
const uint8_t direction)
210 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
218 static const char *SMTPStateGetStateNameById(
const int id,
const uint8_t direction)
221 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
225 static inline void SMTPSetProgressTS(
SMTPTransaction *tx, uint8_t progress)
232 static inline void SMTPSetProgressTC(
SMTPTransaction *tx, uint8_t progress)
240 static bool SMTPTransactionRequestIsComplete(
const SMTPTransaction *tx)
250 #define SMTP_MPM mpm_default_matcher
252 static MpmCtx *smtp_mpm_ctx = NULL;
360 #define SCHEME_SUFFIX_LEN 3
368 static void SMTPConfigure(
void) {
372 uint32_t content_limit = 0;
373 uint32_t content_inspect_min_size = 0;
374 uint32_t content_inspect_window = 0;
377 if (config != NULL) {
388 SCMimeSmtpConfigDecodeBase64(val);
393 SCMimeSmtpConfigDecodeQuoted(val);
398 if (imval < 0 || imval > UINT32_MAX) {
399 FatalError(
"Invalid value for header-value-depth");
401 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
406 SCMimeSmtpConfigExtractUrls(val);
413 if (extract_urls_schemes) {
417 size_t scheme_len = strlen(scheme->
val);
419 FatalError(
"extract-urls-schemes entry '%s' is too long", scheme->
val);
421 if (scheme->
val[scheme_len - 1] !=
'/') {
424 int r = snprintf(tmp,
sizeof(tmp),
"%s://", scheme->
val);
425 if (r != (
int)scheme_len) {
426 FatalError(
"snprintf failure for SMTP url extraction scheme.");
430 FatalError(
"extract-urls-schemes entry SCStrdup failure.");
433 scheme->
val = new_val;
435 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
437 FatalError(
"Failed to add smtp extract url scheme");
443 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
448 SCMimeSmtpConfigLogUrlScheme(val);
455 SCMimeSmtpConfigBodyMd5(
false);
457 SCMimeSmtpConfigBodyMd5(
true);
458 }
else if (strcmp(strval,
"auto") != 0) {
469 if (strcasecmp(
"content-limit",
p->name) == 0) {
477 if (strcasecmp(
"content-inspect-min-size",
p->name) == 0) {
479 SCLogWarning(
"parsing content-inspect-min-size %s failed",
p->val);
485 if (strcasecmp(
"content-inspect-window",
p->name) == 0) {
487 SCLogWarning(
"parsing content-inspect-window %s failed",
p->val);
502 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
503 "options can't be enabled at the same time, "
504 "disabling raw extraction");
510 const char *
str = NULL;
523 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
553 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
555 }
else if (tx == NULL) {
556 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
558 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
568 if (tx == NULL || file == NULL) {
573 FlagDetectStateNewFile(tx);
605 if (direction == 0 &&
612 }
else if (direction == 1) {
615 if (frame != NULL && state->
curr_tx) {
622 const uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
625 if (lf_idx == NULL) {
638 uint32_t o_consumed = input->
consumed;
639 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
647 line->
buf = input->
buf + o_consumed;
650 frame->
len = (int64_t)line->
len;
658 if (discard_till_lf) {
660 if (direction == 0) {
680 static int SMTPInsertCommandIntoCommandBuffer(
728 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
757 static void SetMimeEvents(
SMTPState *state, uint32_t events)
763 if (events & MIME_ANOM_INVALID_BASE64) {
766 if (events & MIME_ANOM_INVALID_QP) {
769 if (events & MIME_ANOM_LONG_LINE) {
772 if (events & MIME_ANOM_LONG_ENC_LINE) {
775 if (events & MIME_ANOM_LONG_HEADER_NAME) {
778 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
781 if (events & MIME_ANOM_LONG_BOUNDARY) {
784 if (events & MIME_ANOM_LONG_FILENAME) {
820 static int SMTPProcessCommandDATA(
832 if (line->
len == 1 && line->
buf[0] ==
'.') {
850 SMTPTransactionCompleteTS(tx);
864 const uint8_t *filename = NULL;
865 uint16_t filename_len = 0;
870 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
872 SetMimeEvents(state, events);
874 case MimeSmtpFileOpen:
878 if (filename_len == 0) {
885 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
900 case MimeSmtpFileChunk:
909 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
920 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
925 case MimeSmtpFileClose:
928 SCLogDebug(
"FileCloseFile() failed: %d", ret);
936 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
945 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
954 if (tx->
tx_id == tx_id) {
957 if (tx->
tx_id > tx_id) {
978 static int SMTPProcessReply(
989 if (reply_tx != NULL) {
1000 if (line->
len >= 4) {
1002 if (line->
buf[3] !=
'-') {
1006 if (line->
buf[3] ==
'-') {
1024 SCLogDebug(
"invalid reply code %02x %02x %02x", line->
buf[0], line->
buf[1], line->
buf[2]);
1028 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
1047 SCLogDebug(
"unable to match reply with request");
1062 SMTPTransactionComplete(reply_tx);
1085 SMTPTransactionCompleteTC(reply_tx);
1090 SMTPTransactionComplete(reply_tx);
1095 SMTPTransactionComplete(reply_tx);
1109 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1129 while (i < line->
len) {
1130 if (line->
buf[i] !=
' ') {
1139 if (i == line->
len) {
1146 if (line->
len - i <
len) {
1149 memcpy(strbuf, line->
buf + i,
len);
1159 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1160 uint8_t **target, uint16_t *target_len)
1162 int i = prefix_len + 1;
1164 while (i < line->
len) {
1165 if (line->
buf[i] !=
' ') {
1174 while (spc_i < line->
len) {
1175 if (line->
buf[spc_i] ==
' ') {
1182 if (*target == NULL)
1184 memcpy(*target, line->
buf + i, spc_i - i);
1185 (*target)[spc_i - i] =
'\0';
1186 if (spc_i - i > UINT16_MAX) {
1187 *target_len = UINT16_MAX;
1190 *target_len = (uint16_t)(spc_i - i);
1202 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1211 return SMTPParseCommandWithParam(
1218 uint16_t rcptto_len;
1220 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1223 rcptto_str->
str = rcptto;
1224 rcptto_str->
len = rcptto_len;
1240 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1242 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1250 #define rawmsgname "rawmsg"
1269 static int SMTPProcessRequest(
1277 frame->
len = (int64_t)line->
len;
1293 const bool no_new_tx = NoNewTx(state, line);
1294 if ((state->
curr_tx == NULL && (state->
tx_cnt == 0 || !no_new_tx)) ||
1295 (SMTPTransactionRequestIsComplete(state->
curr_tx) && !no_new_tx)) {
1296 tx = SMTPTransactionCreate(state);
1308 if (frame != NULL && state->
curr_tx) {
1327 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1329 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1356 if (data_frame == NULL) {
1357 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1366 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1367 r = SMTPParseCommandBDAT(state, line);
1374 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1375 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1376 r = SMTPParseCommandHELO(state, line);
1381 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1382 r = SMTPParseCommandMAILFROM(state, line);
1387 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1388 r = SMTPParseCommandRCPTTO(state, line);
1393 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1397 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1405 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1414 return SMTPProcessCommandDATA(state, tx, f, line);
1417 return SMTPProcessCommandBDAT(state, line);
1426 static inline void ResetLine(
SMTPLine *line)
1455 static int SMTPPreProcessCommands(
1467 bool line_complete =
false;
1468 const int32_t input_len = input->
len;
1470 for (int32_t i = 0; i < input_len; i++) {
1472 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1478 line_complete =
true;
1479 }
else if (input->
buf[
offset + i] == 0x0a) {
1482 line_complete =
true;
1485 if (line_complete || (i == input_len - 1)) {
1492 SCLogDebug(
"Possible boundary, yield to GetLine");
1496 int32_t total_consumed =
offset + i + 1;
1497 int32_t current_line_consumed = total_consumed - input->
consumed;
1502 if (line->
len < 0) {
1507 input->
len -= current_line_consumed;
1509 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1512 line_complete =
false;
1535 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1536 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1538 if (input_buf == NULL &&
1543 }
else if (input_buf == NULL || input_len == 0) {
1547 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1548 SMTPLine line = { NULL, 0, 0,
false };
1551 if (direction == 0) {
1555 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1559 }
else if (ret < 0) {
1563 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1564 while (res.
status == 0) {
1565 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1586 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1590 }
else if (ret < 0) {
1594 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1600 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1601 while (res.
status == 0) {
1602 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1612 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1627 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1636 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1651 if (smtp_state->
cmds == NULL) {
1686 static void *SMTPLocalStorageAlloc(
void)
1695 if (td->
pmq == NULL) {
1708 static void SMTPLocalStorageFree(
void *ptr)
1712 if (td->
pmq != NULL) {
1740 SMTPStringFree(
str);
1751 static void SMTPStateFree(
void *
p)
1755 if (smtp_state->
cmds != NULL) {
1762 if (smtp_state->
helo) {
1767 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1769 SMTPTransactionFree(tx, smtp_state);
1775 static void SMTPSetMpmState(
void)
1778 if (
unlikely(smtp_mpm_ctx == NULL)) {
1794 static void SMTPFreeMpmState(
void)
1796 if (smtp_mpm_ctx != NULL) {
1799 smtp_mpm_ctx = NULL;
1803 static int SMTPStateGetEventInfo(
1813 static int SMTPStateGetEventInfoById(
1817 if (*event_name == NULL) {
1819 "smtp's enum map table.",
1832 static AppProto SMTPClientProbingParserCheckPort(
1833 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1841 static AppProto SMTPServerProbingParser(
1842 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1849 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1853 if (input[3] !=
' ' && input[3] !=
'-') {
1859 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1870 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1881 static int SMTPRegisterPatternsForProtocolDetection(
void)
1884 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1888 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1892 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1897 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1900 NULL, SMTPServerProbingParser);
1906 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1911 if (tx_id < tx->tx_id)
1913 else if (tx_id > tx->
tx_id)
1916 if (tx == smtp_state->
curr_tx)
1919 SMTPTransactionFree(tx, state);
1927 static uint64_t SMTPStateGetTxCnt(
void *state)
1938 static void *SMTPStateGetTx(
void *state, uint64_t
id)
1944 if (smtp_state->
curr_tx == NULL)
1950 if (tx->
tx_id ==
id)
1957 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
1960 if (direction & STREAM_TOSERVER) {
1971 if (direction & STREAM_TOSERVER) {
2000 if (state->
un.
ptr == NULL) {
2006 while (tx_ptr->
tx_id < min_tx_id) {
2012 if (tx_ptr->
tx_id >= max_tx_id) {
2019 .has_next = (state->
un.
ptr != NULL),
2032 const char *proto_name =
"smtp";
2036 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
2039 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
2048 SMTPParseClientRecord);
2050 SMTPParseServerRecord);
2056 SMTPLocalStorageFree);
2069 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
2071 IPPROTO_TCP,
ALPROTO_SMTP, SMTPStateGetStateIdByName, SMTPStateGetStateNameById);
2073 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2098 static void SMTPTestInitConfig(
void)
2112 static int SMTPParserTest01(
void)
2119 uint8_t welcome_reply[] = {
2120 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2121 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2122 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2123 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2124 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2127 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2130 uint8_t request1[] = {
2131 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
2132 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
2133 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
2135 uint32_t request1_len =
sizeof(request1);
2142 uint8_t reply1[] = {
2143 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
2144 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2145 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
2146 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
2147 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
2148 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
2149 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
2150 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
2151 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
2152 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
2153 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2154 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2155 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2156 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2157 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2158 0x44, 0x45, 0x53, 0x0d, 0x0a
2160 uint32_t reply1_len =
sizeof(reply1);
2163 uint8_t request2[] = {
2164 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2167 uint32_t request2_len =
sizeof(request2);
2169 uint8_t reply2[] = {
2170 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2171 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2172 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2173 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2175 uint32_t reply2_len =
sizeof(reply2);
2180 memset(&f, 0,
sizeof(f));
2181 memset(&ssn, 0,
sizeof(ssn));
2185 f.
proto = IPPROTO_TCP;
2189 SMTPTestInitConfig();
2192 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2194 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2198 if (smtp_state == NULL) {
2199 printf(
"no smtp state: ");
2204 printf(
"smtp parser in inconsistent state\n");
2209 STREAM_TOSERVER, request1, request1_len);
2211 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2217 printf(
"smtp parser in inconsistent state\n");
2222 STREAM_TOCLIENT, reply1, reply1_len);
2224 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2229 printf(
"smtp parser in inconsistent state\n");
2234 STREAM_TOSERVER, request2, request2_len);
2236 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2242 printf(
"smtp parser in inconsistent state\n");
2247 STREAM_TOCLIENT, reply2, reply2_len);
2249 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2255 printf(
"smtp parser in inconsistent state\n");
2275 static int SMTPParserTest02(
void)
2282 uint8_t welcome_reply[] = {
2283 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2284 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2285 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2286 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2287 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2290 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2293 uint8_t request1[] = {
2294 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2295 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2297 uint32_t request1_len =
sizeof(request1);
2304 uint8_t reply1[] = {
2305 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2306 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2307 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2308 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2309 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2310 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2311 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2312 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2313 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2314 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2315 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2316 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2317 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2318 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2319 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2321 uint32_t reply1_len =
sizeof(reply1);
2324 uint8_t request2[] = {
2325 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2326 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2327 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2330 uint32_t request2_len =
sizeof(request2);
2332 uint8_t reply2[] = {
2333 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2334 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2336 uint32_t reply2_len =
sizeof(reply2);
2339 uint8_t request3[] = {
2340 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2341 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2342 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2345 uint32_t request3_len =
sizeof(request3);
2347 uint8_t reply3[] = {
2348 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2349 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2351 uint32_t reply3_len =
sizeof(reply3);
2354 uint8_t request4[] = {
2355 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2357 uint32_t request4_len =
sizeof(request4);
2359 uint8_t reply4[] = {
2360 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2361 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2362 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2363 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2364 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2366 uint32_t reply4_len =
sizeof(reply4);
2369 uint8_t request5_1[] = {
2370 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2371 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2372 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2374 uint32_t request5_1_len =
sizeof(request5_1);
2376 uint8_t request5_2[] = {
2377 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2378 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2379 0x6f, 0x6d, 0x0d, 0x0a
2381 uint32_t request5_2_len =
sizeof(request5_2);
2383 uint8_t request5_3[] = {
2386 uint32_t request5_3_len =
sizeof(request5_3);
2388 uint8_t request5_4[] = {
2389 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2390 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2391 0x6c, 0x31, 0x0d, 0x0a
2393 uint32_t request5_4_len =
sizeof(request5_4);
2395 uint8_t request5_5[] = {
2398 uint32_t request5_5_len =
sizeof(request5_5);
2400 uint8_t reply5[] = {
2401 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2402 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2403 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2404 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2405 0x46, 0x32, 0x0d, 0x0a
2407 uint32_t reply5_len =
sizeof(reply5);
2410 uint8_t request6[] = {
2411 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2412 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2413 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2416 uint32_t request6_len =
sizeof(request6);
2418 uint8_t reply6[] = {
2419 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2420 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2422 uint32_t reply6_len =
sizeof(reply6);
2425 uint8_t request7[] = {
2426 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2427 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2428 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2431 uint32_t request7_len =
sizeof(request7);
2433 uint8_t reply7[] = {
2434 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2435 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2437 uint32_t reply7_len =
sizeof(reply7);
2440 uint8_t request8[] = {
2441 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2443 uint32_t request8_len =
sizeof(request8);
2445 uint8_t reply8[] = {
2446 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2447 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2448 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2449 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2450 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2452 uint32_t reply8_len =
sizeof(reply8);
2455 uint8_t request9_1[] = {
2456 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2457 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2458 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2460 uint32_t request9_1_len =
sizeof(request9_1);
2462 uint8_t request9_2[] = {
2463 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2464 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2465 0x6f, 0x6d, 0x0d, 0x0a
2467 uint32_t request9_2_len =
sizeof(request9_2);
2469 uint8_t request9_3[] = {
2472 uint32_t request9_3_len =
sizeof(request9_3);
2474 uint8_t request9_4[] = {
2475 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2476 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2477 0x6c, 0x32, 0x0d, 0x0a
2479 uint32_t request9_4_len =
sizeof(request9_4);
2481 uint8_t request9_5[] = {
2484 uint32_t request9_5_len =
sizeof(request9_5);
2486 uint8_t reply9[] = {
2487 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2488 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2489 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2490 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2491 0x46, 0x32, 0x0d, 0x0a
2493 uint32_t reply9_len =
sizeof(reply9);
2496 uint8_t request10[] = {
2497 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2499 uint32_t request10_len =
sizeof(request10);
2501 uint8_t reply10[] = {
2502 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2503 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2505 uint32_t reply10_len =
sizeof(reply10);
2510 memset(&f, 0,
sizeof(f));
2511 memset(&ssn, 0,
sizeof(ssn));
2515 f.
proto = IPPROTO_TCP;
2519 SMTPTestInitConfig();
2522 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2524 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2528 if (smtp_state == NULL) {
2529 printf(
"no smtp state: ");
2534 printf(
"smtp parser in inconsistent state\n");
2539 STREAM_TOSERVER, request1, request1_len);
2541 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2547 printf(
"smtp parser in inconsistent state\n");
2552 STREAM_TOCLIENT, reply1, reply1_len);
2554 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2559 printf(
"smtp parser in inconsistent state\n");
2564 STREAM_TOSERVER, request2, request2_len);
2566 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2572 printf(
"smtp parser in inconsistent state\n");
2577 STREAM_TOCLIENT, reply2, reply2_len);
2579 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2584 printf(
"smtp parser in inconsistent state\n");
2589 STREAM_TOSERVER, request3, request3_len);
2591 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2597 printf(
"smtp parser in inconsistent state\n");
2602 STREAM_TOCLIENT, reply3, reply3_len);
2604 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2609 printf(
"smtp parser in inconsistent state\n");
2614 STREAM_TOSERVER, request4, request4_len);
2616 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2622 printf(
"smtp parser in inconsistent state\n");
2627 STREAM_TOCLIENT, reply4, reply4_len);
2629 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2635 printf(
"smtp parser in inconsistent state\n");
2640 STREAM_TOSERVER, request5_1, request5_1_len);
2642 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2649 printf(
"smtp parser in inconsistent state\n");
2654 STREAM_TOSERVER, request5_2, request5_2_len);
2656 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2663 printf(
"smtp parser in inconsistent state\n");
2668 STREAM_TOSERVER, request5_3, request5_3_len);
2670 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2677 printf(
"smtp parser in inconsistent state\n");
2682 STREAM_TOSERVER, request5_4, request5_4_len);
2684 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2691 printf(
"smtp parser in inconsistent state\n");
2696 STREAM_TOSERVER, request5_5, request5_5_len);
2698 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2704 printf(
"smtp parser in inconsistent state\n");
2709 STREAM_TOCLIENT, reply5, reply5_len);
2711 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2716 printf(
"smtp parser in inconsistent state\n");
2721 STREAM_TOSERVER, request6, request6_len);
2723 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2729 printf(
"smtp parser in inconsistent state\n");
2734 STREAM_TOCLIENT, reply6, reply6_len);
2736 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2741 printf(
"smtp parser in inconsistent state\n");
2746 STREAM_TOSERVER, request7, request7_len);
2748 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2754 printf(
"smtp parser in inconsistent state\n");
2759 STREAM_TOCLIENT, reply7, reply7_len);
2761 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2766 printf(
"smtp parser in inconsistent state\n");
2771 STREAM_TOSERVER, request8, request8_len);
2773 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2779 printf(
"smtp parser in inconsistent state\n");
2784 STREAM_TOCLIENT, reply8, reply8_len);
2786 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2792 printf(
"smtp parser in inconsistent state\n");
2797 STREAM_TOSERVER, request9_1, request9_1_len);
2799 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2806 printf(
"smtp parser in inconsistent state\n");
2811 STREAM_TOSERVER, request9_2, request9_2_len);
2813 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2820 printf(
"smtp parser in inconsistent state\n");
2825 STREAM_TOSERVER, request9_3, request9_3_len);
2827 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2834 printf(
"smtp parser in inconsistent state\n");
2839 STREAM_TOSERVER, request9_4, request9_4_len);
2841 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2848 printf(
"smtp parser in inconsistent state\n");
2853 STREAM_TOSERVER, request9_5, request9_5_len);
2855 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2861 printf(
"smtp parser in inconsistent state\n");
2866 STREAM_TOCLIENT, reply9, reply9_len);
2868 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2873 printf(
"smtp parser in inconsistent state\n");
2878 STREAM_TOSERVER, request10, request10_len);
2880 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2886 printf(
"smtp parser in inconsistent state\n");
2891 STREAM_TOCLIENT, reply10, reply10_len);
2893 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2898 printf(
"smtp parser in inconsistent state\n");
2914 static int SMTPParserTest03(
void)
2921 uint8_t welcome_reply[] = {
2922 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2923 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2924 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2925 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2926 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2927 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2929 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2932 uint8_t request1[] = {
2933 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2934 0x2e, 0x63, 0x6f, 0x6d, 0x0a
2936 uint32_t request1_len =
sizeof(request1);
2946 uint8_t reply1[] = {
2947 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2948 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2949 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2950 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2951 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2952 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2953 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2954 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2955 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2956 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2957 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2958 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2959 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2960 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2961 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2962 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2963 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2965 uint32_t reply1_len =
sizeof(reply1);
2972 uint8_t request2[] = {
2973 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2974 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2975 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2976 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
2977 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2978 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2979 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
2980 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
2981 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
2983 uint32_t request2_len =
sizeof(request2);
2988 uint8_t reply2[] = {
2989 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2990 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
2991 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
2992 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
2993 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
2994 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
2995 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
2996 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
2999 uint32_t reply2_len =
sizeof(reply2);
3004 memset(&f, 0,
sizeof(f));
3005 memset(&ssn, 0,
sizeof(ssn));
3009 f.
proto = IPPROTO_TCP;
3013 SMTPTestInitConfig();
3016 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3018 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3022 if (smtp_state == NULL) {
3023 printf(
"no smtp state: ");
3028 printf(
"smtp parser in inconsistent state\n");
3033 STREAM_TOSERVER, request1, request1_len);
3035 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3041 printf(
"smtp parser in inconsistent state\n");
3046 STREAM_TOCLIENT, reply1, reply1_len);
3048 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3054 printf(
"smtp parser in inconsistent state\n");
3059 STREAM_TOSERVER, request2, request2_len);
3061 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3071 printf(
"smtp parser in inconsistent state\n");
3076 STREAM_TOCLIENT, reply2, reply2_len);
3078 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3085 printf(
"smtp parser in inconsistent state\n");
3101 static int SMTPParserTest04(
void)
3108 uint8_t welcome_reply[] = {
3109 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3110 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3111 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3112 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3113 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3114 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3116 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3119 uint8_t request1[] = {
3120 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3121 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3122 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3123 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3124 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3125 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3127 uint32_t request1_len =
sizeof(request1);
3132 memset(&f, 0,
sizeof(f));
3133 memset(&ssn, 0,
sizeof(ssn));
3137 f.
proto = IPPROTO_TCP;
3141 SMTPTestInitConfig();
3144 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3146 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3150 if (smtp_state == NULL) {
3151 printf(
"no smtp state: ");
3156 printf(
"smtp parser in inconsistent state\n");
3161 STREAM_TOSERVER, request1, request1_len);
3163 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3169 printf(
"smtp parser in inconsistent state\n");
3185 static int SMTPParserTest05(
void)
3192 uint8_t welcome_reply[] = {
3193 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3194 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3195 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3196 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3197 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3198 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3200 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3203 uint8_t request1[] = {
3204 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3205 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3207 uint32_t request1_len =
sizeof(request1);
3217 uint8_t reply1[] = {
3218 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3219 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3220 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3221 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3222 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3223 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3224 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3225 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3226 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3227 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3228 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3229 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3230 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3231 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3232 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3233 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3234 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3236 uint32_t reply1_len =
sizeof(reply1);
3239 uint8_t request2[] = {
3240 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3243 uint32_t request2_len =
sizeof(request2);
3245 uint8_t reply2[] = {
3246 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3247 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3248 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3249 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3250 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3253 uint32_t reply2_len =
sizeof(reply2);
3256 uint8_t request3[] = {
3257 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3260 uint32_t request3_len =
sizeof(request3);
3262 uint8_t reply3[] = {
3263 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3264 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3266 uint32_t reply3_len =
sizeof(reply3);
3271 memset(&f, 0,
sizeof(f));
3272 memset(&ssn, 0,
sizeof(ssn));
3276 f.
proto = IPPROTO_TCP;
3280 SMTPTestInitConfig();
3283 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3285 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3289 if (smtp_state == NULL) {
3290 printf(
"no smtp state: ");
3295 printf(
"smtp parser in inconsistent state\n");
3300 STREAM_TOSERVER, request1, request1_len);
3302 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3308 printf(
"smtp parser in inconsistent state\n");
3313 STREAM_TOCLIENT, reply1, reply1_len);
3315 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3321 printf(
"smtp parser in inconsistent state\n");
3326 STREAM_TOSERVER, request2, request2_len);
3328 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3335 printf(
"smtp parser in inconsistent state\n");
3340 STREAM_TOCLIENT, reply2, reply2_len);
3342 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3348 printf(
"smtp parser in inconsistent state\n");
3360 STREAM_TOSERVER, request3, request3_len);
3362 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3369 printf(
"smtp parser in inconsistent state\n");
3374 STREAM_TOCLIENT, reply3, reply3_len);
3376 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3382 printf(
"smtp parser in inconsistent state\n");
3398 static int SMTPParserTest06(
void)
3404 uint8_t welcome_reply[] = {
3405 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3406 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3407 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3408 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3409 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3410 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3411 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3412 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3413 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3414 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3415 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3416 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3417 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3418 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3419 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3420 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3421 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3422 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3423 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3424 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3425 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3426 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3427 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3428 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3429 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3430 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3431 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3432 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3433 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3434 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3435 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3436 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3437 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3438 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3439 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3440 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3441 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3442 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3443 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3445 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3447 uint8_t request1[] = {
3448 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3449 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3450 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3451 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3454 uint32_t request1_len =
sizeof(request1);
3456 uint8_t reply1[] = {
3457 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3458 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3459 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3460 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3461 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3462 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3463 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3464 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3465 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3466 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3467 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3468 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3469 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3470 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3471 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3472 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3473 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3474 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3475 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3476 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3477 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3480 uint32_t reply1_len =
sizeof(reply1);
3483 uint8_t request2[] = {
3484 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3485 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3486 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3489 uint32_t request2_len =
sizeof(request2);
3491 uint8_t reply2[] = {
3492 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3493 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3495 uint32_t reply2_len =
sizeof(reply2);
3498 uint8_t request3[] = {
3499 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3500 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3501 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3504 uint32_t request3_len =
sizeof(request3);
3506 uint8_t reply3[] = {
3507 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3508 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3510 uint32_t reply3_len =
sizeof(reply3);
3513 uint8_t request4[] = {
3514 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3517 uint32_t request4_len =
sizeof(request4);
3519 uint8_t request5[] = {
3520 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3521 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3522 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3523 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3525 uint32_t request5_len =
sizeof(request5);
3527 uint8_t request6[] = {
3528 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3529 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3532 uint32_t request6_len =
sizeof(request6);
3537 memset(&f, 0,
sizeof(f));
3538 memset(&ssn, 0,
sizeof(ssn));
3542 f.
proto = IPPROTO_TCP;
3546 SMTPTestInitConfig();
3549 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3551 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3555 if (smtp_state == NULL) {
3556 printf(
"no smtp state: ");
3561 printf(
"smtp parser in inconsistent state\n");
3566 STREAM_TOSERVER, request1, request1_len);
3568 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3574 printf(
"smtp parser in inconsistent state\n");
3579 STREAM_TOCLIENT, reply1, reply1_len);
3581 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3586 printf(
"smtp parser in inconsistent state\n");
3591 STREAM_TOSERVER, request2, request2_len);
3593 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3599 printf(
"smtp parser in inconsistent state\n");
3604 STREAM_TOCLIENT, reply2, reply2_len);
3606 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3611 printf(
"smtp parser in inconsistent state\n");
3616 STREAM_TOSERVER, request3, request3_len);
3618 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3624 printf(
"smtp parser in inconsistent state\n");
3629 STREAM_TOCLIENT, reply3, reply3_len);
3631 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3636 printf(
"smtp parser in inconsistent state\n");
3641 STREAM_TOSERVER, request4, request4_len);
3643 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3651 printf(
"smtp parser in inconsistent state\n");
3656 STREAM_TOSERVER, request5, request5_len);
3658 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3665 printf(
"smtp parser in inconsistent state\n");
3670 STREAM_TOSERVER, request6, request6_len);
3672 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3678 printf(
"smtp parser in inconsistent state\n");
3691 static int SMTPParserTest12(
void)
3705 uint8_t request1[] = {
3706 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3707 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3709 int32_t request1_len =
sizeof(request1);
3713 uint8_t reply1[] = {
3714 0x31, 0x38, 0x38, 0x0d, 0x0a,
3716 uint32_t reply1_len =
sizeof(reply1);
3722 memset(&f, 0,
sizeof(f));
3723 memset(&ssn, 0,
sizeof(ssn));
3729 f.
proto = IPPROTO_TCP;
3738 SMTPTestInitConfig();
3747 "(msg:\"SMTP event handling\"; "
3748 "app-layer-event: smtp.invalid_reply; "
3757 STREAM_TOSERVER | STREAM_START, request1,
3760 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3765 if (smtp_state == NULL) {
3766 printf(
"no smtp state: ");
3774 printf(
"sid 1 matched. It shouldn't match: ");
3779 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3782 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3790 printf(
"sid 1 didn't match. Should have matched: ");
3808 static int SMTPParserTest13(
void)
3822 uint8_t request1[] = {
3823 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3824 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3826 int32_t request1_len =
sizeof(request1);
3830 uint8_t reply1[] = {
3831 0x32, 0x35, 0x30, 0x0d, 0x0a,
3833 uint32_t reply1_len =
sizeof(reply1);
3840 uint8_t request2[] = {
3841 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3842 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3843 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3844 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3845 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3846 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3847 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3848 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3851 uint32_t request2_len =
sizeof(request2);
3857 memset(&f, 0,
sizeof(f));
3858 memset(&ssn, 0,
sizeof(ssn));
3864 f.
proto = IPPROTO_TCP;
3873 SMTPTestInitConfig();
3882 "(msg:\"SMTP event handling\"; "
3884 "smtp.invalid_pipelined_sequence; "
3893 STREAM_TOSERVER | STREAM_START, request1,
3896 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3901 if (smtp_state == NULL) {
3902 printf(
"no smtp state: ");
3910 printf(
"sid 1 matched. It shouldn't match: ");
3915 STREAM_TOCLIENT, reply1, reply1_len);
3917 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3925 printf(
"sid 1 matched. It shouldn't match: ");
3930 STREAM_TOSERVER, request2, request2_len);
3932 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3940 printf(
"sid 1 didn't match. Should have matched: ");
3960 static int SMTPParserTest14(
void)
3967 static uint8_t welcome_reply[] = {
3968 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
3969 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3970 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
3971 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
3972 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
3975 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
3978 static uint8_t request1[] = {
3979 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3980 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3982 static uint32_t request1_len =
sizeof(request1);
3989 static uint8_t reply1[] = {
3990 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3991 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3992 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3993 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3994 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3995 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3996 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3997 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3998 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3999 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
4000 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
4001 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
4002 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
4003 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
4004 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
4006 static uint32_t reply1_len =
sizeof(reply1);
4009 static uint8_t request2[] = {
4010 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
4011 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
4012 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
4015 static uint32_t request2_len =
sizeof(request2);
4017 static uint8_t reply2[] = {
4018 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4019 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4021 static uint32_t reply2_len =
sizeof(reply2);
4024 static uint8_t request3[] = {
4025 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
4026 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
4027 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
4030 static uint32_t request3_len =
sizeof(request3);
4032 static uint8_t reply3[] = {
4033 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4034 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4036 static uint32_t reply3_len =
sizeof(reply3);
4039 static uint8_t request4[] = {
4040 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
4042 static uint32_t request4_len =
sizeof(request4);
4044 static uint8_t reply4[] = {
4045 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
4046 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
4047 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
4048 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
4049 0x4c, 0x46, 0x3e, 0x0d, 0x0a
4051 static uint32_t reply4_len =
sizeof(reply4);
4054 static uint64_t filesize = 133;
4055 static uint8_t request4_msg[] = {
4056 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
4057 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
4058 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4059 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
4060 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
4061 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
4062 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
4063 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4064 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
4065 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
4066 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
4067 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
4068 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
4069 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
4070 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
4071 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
4072 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
4073 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
4074 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
4075 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
4076 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
4077 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
4078 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4079 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
4080 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
4081 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
4082 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
4083 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
4084 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
4085 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4086 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
4087 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4088 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4089 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
4090 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4091 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4092 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4093 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4094 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
4095 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
4096 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
4097 0x41, 0x3D, 0x3D, 0x0D,0x0A };
4098 static uint32_t request4_msg_len =
sizeof(request4_msg);
4101 static uint8_t request4_end[] = {
4102 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4104 static uint32_t request4_end_len =
sizeof(request4_end);
4106 static uint8_t reply4_end[] = {
4107 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4108 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
4109 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
4110 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
4111 0x46, 0x32, 0x0d, 0x0a
4113 static uint32_t reply4_end_len =
sizeof(reply4_end);
4116 static uint8_t request5[] = {
4117 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
4119 static uint32_t request5_len =
sizeof(request5);
4121 static uint8_t reply5[] = {
4122 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4123 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
4125 static uint32_t reply5_len =
sizeof(reply5);
4130 memset(&f, 0,
sizeof(f));
4131 memset(&ssn, 0,
sizeof(ssn));
4135 f.
proto = IPPROTO_TCP;
4139 SMTPTestInitConfig();
4143 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
4145 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4149 if (smtp_state == NULL) {
4150 printf(
"no smtp state: ");
4155 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4160 STREAM_TOSERVER, request1, request1_len);
4162 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4168 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4174 STREAM_TOCLIENT, reply1, reply1_len);
4176 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4180 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4181 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4187 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4193 STREAM_TOSERVER, request2, request2_len);
4195 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4201 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4207 STREAM_TOCLIENT, reply2, reply2_len);
4209 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4215 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4223 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4229 STREAM_TOSERVER, request3, request3_len);
4231 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4237 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4243 STREAM_TOCLIENT, reply3, reply3_len);
4245 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4250 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4256 SCMimeSmtpConfigDecodeBase64(1);
4257 SCMimeSmtpConfigDecodeQuoted(1);
4261 STREAM_TOSERVER, request4, request4_len);
4263 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4270 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4276 STREAM_TOCLIENT, reply4, reply4_len);
4278 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4284 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4290 STREAM_TOSERVER, request4_msg, request4_msg_len);
4292 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4300 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4306 STREAM_TOSERVER, request4_end, request4_end_len);
4308 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4316 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4325 if (files != NULL && files->
head != NULL) {
4328 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4329 printf(
"smtp-mime file name is incorrect");
4333 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4336 static uint8_t org_binary[] = {
4337 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4338 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4340 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4341 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4342 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4343 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4344 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4345 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4346 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4347 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4348 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4349 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4351 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4352 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4353 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4356 org_binary,
sizeof(org_binary)) != 1)
4358 printf(
"smtp-mime file data incorrect\n");
4365 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4367 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4372 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4378 STREAM_TOSERVER, request5, request5_len);
4380 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4386 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4392 STREAM_TOCLIENT, reply5, reply5_len);
4394 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4399 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);