58 #define FILEDATA_CONTENT_LIMIT 100000
60 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
62 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
65 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
67 #define SMTP_COMMAND_BUFFER_STEPS 5
74 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
76 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
78 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
80 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
86 #define SMTP_COMMAND_STARTTLS 1
87 #define SMTP_COMMAND_DATA 2
88 #define SMTP_COMMAND_BDAT 3
93 #define SMTP_COMMAND_DATA_MODE 4
95 #define SMTP_COMMAND_OTHER_CMD 5
96 #define SMTP_COMMAND_RSET 6
98 #define SMTP_DEFAULT_MAX_TX 256
173 static int SMTPGetFrameIdByName(
const char *frame_name)
182 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
193 #define SMTP_MPM mpm_default_matcher
195 static MpmCtx *smtp_mpm_ctx = NULL;
303 #define SCHEME_SUFFIX_LEN 3
311 static void SMTPConfigure(
void) {
315 uint32_t content_limit = 0;
316 uint32_t content_inspect_min_size = 0;
317 uint32_t content_inspect_window = 0;
320 if (config != NULL) {
321 ConfNode *extract_urls_schemes = NULL;
331 SCMimeSmtpConfigDecodeBase64(val);
336 SCMimeSmtpConfigDecodeQuoted(val);
341 if (imval < 0 || imval > UINT32_MAX) {
342 FatalError(
"Invalid value for header-value-depth");
344 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
349 SCMimeSmtpConfigExtractUrls(val);
356 if (extract_urls_schemes) {
359 SCMimeSmtpConfigExtractUrlsSchemeReset();
361 size_t scheme_len = strlen(scheme->
val);
363 FatalError(
"Too long value for extract-urls-schemes");
365 if (scheme->
val[scheme_len - 1] !=
'/') {
367 char *new_val =
SCMalloc(scheme_len + 1);
371 int r = snprintf(new_val, scheme_len + 1,
"%s://", scheme->
val);
372 if (r != (
int)scheme_len) {
373 FatalError(
"snprintf failure for SMTP url extraction scheme.");
376 scheme->
val = new_val;
378 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
380 FatalError(
"Failed to add smtp extract url scheme");
386 SCMimeSmtpConfigExtractUrlsSchemeReset();
387 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
392 SCMimeSmtpConfigLogUrlScheme(val);
397 SCMimeSmtpConfigBodyMd5(val);
406 if (strcasecmp(
"content-limit", p->
name) == 0) {
414 if (strcasecmp(
"content-inspect-min-size", p->
name) == 0) {
422 if (strcasecmp(
"content-inspect-window", p->
name) == 0) {
434 if (
ConfGetBool(
"app-layer.protocols.smtp.raw-extraction",
439 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
440 "options can't be enabled at the same time, "
441 "disabling raw extraction");
447 const char *
str = NULL;
448 if (
ConfGet(
"app-layer.protocols.smtp.max-tx", &
str) == 1) {
460 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
483 tx->
tx_data.file_tx = STREAM_TOSERVER;
489 if (tx && tx->
tx_data.de_state) {
490 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
492 }
else if (tx == NULL) {
493 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
494 }
else if (tx->
tx_data.de_state == NULL) {
495 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
505 if (tx == NULL || file == NULL) {
510 FlagDetectStateNewFile(tx);
542 if (direction == 0 &&
549 }
else if (direction == 1) {
552 if (frame != NULL && state->
curr_tx) {
559 uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
562 if (lf_idx == NULL) {
575 uint32_t o_consumed = input->
consumed;
576 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
584 line->
buf = input->
buf + o_consumed;
587 frame->
len = (int64_t)line->
len;
595 if (discard_till_lf) {
597 if (direction == 0) {
617 static int SMTPInsertCommandIntoCommandBuffer(uint8_t command,
SMTPState *state)
650 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
678 static void SetMimeEvents(
SMTPState *state, uint32_t events)
684 if (events & MIME_ANOM_INVALID_BASE64) {
687 if (events & MIME_ANOM_INVALID_QP) {
690 if (events & MIME_ANOM_LONG_LINE) {
693 if (events & MIME_ANOM_LONG_ENC_LINE) {
696 if (events & MIME_ANOM_LONG_HEADER_NAME) {
699 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
702 if (events & MIME_ANOM_LONG_BOUNDARY) {
705 if (events & MIME_ANOM_LONG_FILENAME) {
710 static inline void SMTPTransactionComplete(
SMTPState *state)
721 static int SMTPProcessCommandDATA(
733 if (line->
len == 1 && line->
buf[0] ==
'.') {
751 SMTPTransactionComplete(state);
766 const uint8_t *filename = NULL;
767 uint16_t filename_len = 0;
772 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
774 SetMimeEvents(state, events);
776 case MimeSmtpFileOpen:
780 if (filename_len == 0) {
787 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
802 case MimeSmtpFileChunk:
811 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
822 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
827 case MimeSmtpFileClose:
830 SCLogDebug(
"FileCloseFile() failed: %d", ret);
838 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
847 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
853 static int SMTPProcessReply(
871 if (line->
len >= 4) {
873 if (line->
buf[3] !=
'-') {
877 if (line->
buf[3] ==
'-') {
899 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
918 SCLogDebug(
"unable to match reply with request");
933 SMTPTransactionComplete(state);
954 SMTPTransactionComplete(state);
968 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
987 while (i < line->
len) {
988 if (line->
buf[i] !=
' ') {
997 if (i == line->
len) {
1004 if (line->
len - i <
len) {
1007 memcpy(strbuf, line->
buf + i,
len);
1017 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1018 uint8_t **target, uint16_t *target_len)
1020 int i = prefix_len + 1;
1022 while (i < line->
len) {
1023 if (line->
buf[i] !=
' ') {
1032 while (spc_i < line->
len) {
1033 if (line->
buf[spc_i] ==
' ') {
1040 if (*target == NULL)
1042 memcpy(*target, line->
buf + i, spc_i - i);
1043 (*target)[spc_i - i] =
'\0';
1044 if (spc_i - i > UINT16_MAX) {
1045 *target_len = UINT16_MAX;
1048 *target_len = (uint16_t)(spc_i - i);
1060 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1069 return SMTPParseCommandWithParam(
1076 uint16_t rcptto_len;
1078 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1081 rcptto_str->
str = rcptto;
1082 rcptto_str->
len = rcptto_len;
1098 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1100 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1108 #define rawmsgname "rawmsg"
1127 static int SMTPProcessRequest(
1135 frame->
len = (int64_t)line->
len;
1152 tx = SMTPTransactionCreate(state);
1164 if (frame != NULL && state->
curr_tx) {
1179 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1181 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1207 if (data_frame == NULL) {
1208 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1217 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1218 r = SMTPParseCommandBDAT(state, line);
1224 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1225 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1226 r = SMTPParseCommandHELO(state, line);
1231 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1232 r = SMTPParseCommandMAILFROM(state, line);
1237 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1238 r = SMTPParseCommandRCPTTO(state, line);
1243 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1253 if (SMTPInsertCommandIntoCommandBuffer(state->
current_command, state) == -1) {
1262 return SMTPProcessCommandDATA(state, tx, f, line);
1265 return SMTPProcessCommandBDAT(state, line);
1274 static inline void ResetLine(
SMTPLine *line)
1303 static int SMTPPreProcessCommands(
1315 bool line_complete =
false;
1316 const int32_t input_len = input->
len;
1318 for (int32_t i = 0; i < input_len; i++) {
1320 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1326 line_complete =
true;
1327 }
else if (input->
buf[
offset + i] == 0x0a) {
1330 line_complete =
true;
1333 if (line_complete || (i == input_len - 1)) {
1340 SCLogDebug(
"Possible boundary, yield to GetLine");
1344 int32_t total_consumed =
offset + i + 1;
1345 int32_t current_line_consumed = total_consumed - input->
consumed;
1350 if (line->
len < 0) {
1355 input->
len -= current_line_consumed;
1357 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1360 line_complete =
false;
1378 static AppLayerResult SMTPParse(uint8_t direction,
Flow *f,
SMTPState *state,
1383 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1384 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1386 if (input_buf == NULL &&
1391 }
else if (input_buf == NULL || input_len == 0) {
1395 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1396 SMTPLine line = { NULL, 0, 0,
false };
1399 if (direction == 0) {
1403 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1407 }
else if (ret < 0) {
1411 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1412 while (res.status == 0) {
1413 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1434 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1438 }
else if (ret < 0) {
1442 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1444 if (res.status == 1)
1448 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1449 while (res.status == 0) {
1450 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1460 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1462 if (res.status == 1)
1470 StreamSlice stream_slice,
void *local_data)
1475 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1479 StreamSlice stream_slice,
void *local_data)
1484 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1499 if (smtp_state->
cmds == NULL) {
1528 static void *SMTPLocalStorageAlloc(
void)
1537 if (td->
pmq == NULL) {
1550 static void SMTPLocalStorageFree(
void *ptr)
1554 if (td->
pmq != NULL) {
1574 if (tx->
tx_data.events != NULL)
1577 if (tx->
tx_data.de_state != NULL)
1586 SMTPStringFree(
str);
1597 static void SMTPStateFree(
void *p)
1601 if (smtp_state->
cmds != NULL) {
1605 if (smtp_state->
helo) {
1610 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1612 SMTPTransactionFree(tx, smtp_state);
1618 static void SMTPSetMpmState(
void)
1621 if (
unlikely(smtp_mpm_ctx == NULL)) {
1638 static void SMTPFreeMpmState(
void)
1640 if (smtp_mpm_ctx != NULL) {
1643 smtp_mpm_ctx = NULL;
1647 static int SMTPStateGetEventInfo(
1648 const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
1651 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
1657 static int SMTPStateGetEventInfoById(
1658 uint8_t event_id,
const char **event_name, AppLayerEventType *event_type)
1661 if (*event_name == NULL) {
1663 "smtp's enum map table.",
1669 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
1674 static AppProto SMTPServerProbingParser(
1675 Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1682 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1686 if (input[3] !=
' ' && input[3] !=
'-') {
1692 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1703 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1714 static int SMTPRegisterPatternsForProtocolDetection(
void)
1717 "EHLO", 4, 0, STREAM_TOSERVER) < 0)
1722 "HELO", 4, 0, STREAM_TOSERVER) < 0)
1727 "QUIT", 4, 0, STREAM_TOSERVER) < 0)
1732 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1735 NULL, SMTPServerProbingParser);
1741 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1746 if (tx_id < tx->tx_id)
1748 else if (tx_id > tx->
tx_id)
1751 if (tx == smtp_state->
curr_tx)
1754 SMTPTransactionFree(tx, state);
1762 static uint64_t SMTPStateGetTxCnt(
void *state)
1773 static void *SMTPStateGetTx(
void *state, uint64_t
id)
1779 if (smtp_state->
curr_tx == NULL)
1785 if (tx->
tx_id ==
id)
1792 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
1798 static AppLayerGetFileState SMTPGetTxFiles(
void *txv, uint8_t direction)
1803 if (direction & STREAM_TOSERVER) {
1815 static AppLayerStateData *SMTPGetStateData(
void *vstate)
1825 static AppLayerGetTxIterTuple SMTPGetTxIterator(
const uint8_t ipproto,
const AppProto alproto,
1829 AppLayerGetTxIterTuple no_tuple = { NULL, 0,
false };
1832 if (state->
un.
ptr == NULL) {
1838 while (tx_ptr->
tx_id < min_tx_id) {
1844 if (tx_ptr->
tx_id >= max_tx_id) {
1848 AppLayerGetTxIterTuple tuple = {
1851 .has_next = (state->
un.
ptr != NULL),
1864 const char *proto_name =
"smtp";
1868 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
1871 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
1880 SMTPParseClientRecord);
1882 SMTPParseServerRecord);
1888 SMTPLocalStorageFree);
1900 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
1902 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
1927 static void SMTPTestInitConfig(
void)
1941 static int SMTPParserTest01(
void)
1948 uint8_t welcome_reply[] = {
1949 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
1950 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1951 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
1952 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
1953 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
1956 uint32_t welcome_reply_len =
sizeof(welcome_reply);
1959 uint8_t request1[] = {
1960 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
1961 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
1962 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
1964 uint32_t request1_len =
sizeof(request1);
1971 uint8_t reply1[] = {
1972 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
1973 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1974 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
1975 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
1976 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
1977 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
1978 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
1979 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
1980 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
1981 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
1982 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
1983 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
1984 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
1985 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
1986 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
1987 0x44, 0x45, 0x53, 0x0d, 0x0a
1989 uint32_t reply1_len =
sizeof(reply1);
1992 uint8_t request2[] = {
1993 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
1996 uint32_t request2_len =
sizeof(request2);
1998 uint8_t reply2[] = {
1999 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2000 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2001 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2002 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2004 uint32_t reply2_len =
sizeof(reply2);
2009 memset(&f, 0,
sizeof(f));
2010 memset(&ssn, 0,
sizeof(ssn));
2014 f.
proto = IPPROTO_TCP;
2018 SMTPTestInitConfig();
2021 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2023 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2027 if (smtp_state == NULL) {
2028 printf(
"no smtp state: ");
2033 printf(
"smtp parser in inconsistent state\n");
2038 STREAM_TOSERVER, request1, request1_len);
2040 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2046 printf(
"smtp parser in inconsistent state\n");
2051 STREAM_TOCLIENT, reply1, reply1_len);
2053 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2058 printf(
"smtp parser in inconsistent state\n");
2063 STREAM_TOSERVER, request2, request2_len);
2065 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2071 printf(
"smtp parser in inconsistent state\n");
2076 STREAM_TOCLIENT, reply2, reply2_len);
2078 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2084 printf(
"smtp parser in inconsistent state\n");
2104 static int SMTPParserTest02(
void)
2111 uint8_t welcome_reply[] = {
2112 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2113 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2114 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2115 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2116 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2119 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2122 uint8_t request1[] = {
2123 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2124 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2126 uint32_t request1_len =
sizeof(request1);
2133 uint8_t reply1[] = {
2134 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2135 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2136 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2137 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2138 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2139 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2140 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2141 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2142 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2143 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2144 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2145 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2146 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2147 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2148 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2150 uint32_t reply1_len =
sizeof(reply1);
2153 uint8_t request2[] = {
2154 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2155 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2156 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2159 uint32_t request2_len =
sizeof(request2);
2161 uint8_t reply2[] = {
2162 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2163 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2165 uint32_t reply2_len =
sizeof(reply2);
2168 uint8_t request3[] = {
2169 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2170 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2171 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2174 uint32_t request3_len =
sizeof(request3);
2176 uint8_t reply3[] = {
2177 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2178 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2180 uint32_t reply3_len =
sizeof(reply3);
2183 uint8_t request4[] = {
2184 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2186 uint32_t request4_len =
sizeof(request4);
2188 uint8_t reply4[] = {
2189 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2190 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2191 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2192 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2193 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2195 uint32_t reply4_len =
sizeof(reply4);
2198 uint8_t request5_1[] = {
2199 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2200 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2201 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2203 uint32_t request5_1_len =
sizeof(request5_1);
2205 uint8_t request5_2[] = {
2206 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2207 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2208 0x6f, 0x6d, 0x0d, 0x0a
2210 uint32_t request5_2_len =
sizeof(request5_2);
2212 uint8_t request5_3[] = {
2215 uint32_t request5_3_len =
sizeof(request5_3);
2217 uint8_t request5_4[] = {
2218 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2219 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2220 0x6c, 0x31, 0x0d, 0x0a
2222 uint32_t request5_4_len =
sizeof(request5_4);
2224 uint8_t request5_5[] = {
2227 uint32_t request5_5_len =
sizeof(request5_5);
2229 uint8_t reply5[] = {
2230 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2231 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2232 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2233 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2234 0x46, 0x32, 0x0d, 0x0a
2236 uint32_t reply5_len =
sizeof(reply5);
2239 uint8_t request6[] = {
2240 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2241 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2242 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2245 uint32_t request6_len =
sizeof(request6);
2247 uint8_t reply6[] = {
2248 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2249 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2251 uint32_t reply6_len =
sizeof(reply6);
2254 uint8_t request7[] = {
2255 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2256 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2257 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2260 uint32_t request7_len =
sizeof(request7);
2262 uint8_t reply7[] = {
2263 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2264 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2266 uint32_t reply7_len =
sizeof(reply7);
2269 uint8_t request8[] = {
2270 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2272 uint32_t request8_len =
sizeof(request8);
2274 uint8_t reply8[] = {
2275 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2276 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2277 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2278 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2279 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2281 uint32_t reply8_len =
sizeof(reply8);
2284 uint8_t request9_1[] = {
2285 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2286 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2287 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2289 uint32_t request9_1_len =
sizeof(request9_1);
2291 uint8_t request9_2[] = {
2292 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2293 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2294 0x6f, 0x6d, 0x0d, 0x0a
2296 uint32_t request9_2_len =
sizeof(request9_2);
2298 uint8_t request9_3[] = {
2301 uint32_t request9_3_len =
sizeof(request9_3);
2303 uint8_t request9_4[] = {
2304 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2305 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2306 0x6c, 0x32, 0x0d, 0x0a
2308 uint32_t request9_4_len =
sizeof(request9_4);
2310 uint8_t request9_5[] = {
2313 uint32_t request9_5_len =
sizeof(request9_5);
2315 uint8_t reply9[] = {
2316 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2317 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2318 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2319 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2320 0x46, 0x32, 0x0d, 0x0a
2322 uint32_t reply9_len =
sizeof(reply9);
2325 uint8_t request10[] = {
2326 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2328 uint32_t request10_len =
sizeof(request10);
2330 uint8_t reply10[] = {
2331 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2332 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2334 uint32_t reply10_len =
sizeof(reply10);
2339 memset(&f, 0,
sizeof(f));
2340 memset(&ssn, 0,
sizeof(ssn));
2344 f.
proto = IPPROTO_TCP;
2348 SMTPTestInitConfig();
2351 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2353 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2357 if (smtp_state == NULL) {
2358 printf(
"no smtp state: ");
2363 printf(
"smtp parser in inconsistent state\n");
2368 STREAM_TOSERVER, request1, request1_len);
2370 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2376 printf(
"smtp parser in inconsistent state\n");
2381 STREAM_TOCLIENT, reply1, reply1_len);
2383 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2388 printf(
"smtp parser in inconsistent state\n");
2393 STREAM_TOSERVER, request2, request2_len);
2395 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2401 printf(
"smtp parser in inconsistent state\n");
2406 STREAM_TOCLIENT, reply2, reply2_len);
2408 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2413 printf(
"smtp parser in inconsistent state\n");
2418 STREAM_TOSERVER, request3, request3_len);
2420 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2426 printf(
"smtp parser in inconsistent state\n");
2431 STREAM_TOCLIENT, reply3, reply3_len);
2433 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2438 printf(
"smtp parser in inconsistent state\n");
2443 STREAM_TOSERVER, request4, request4_len);
2445 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2451 printf(
"smtp parser in inconsistent state\n");
2456 STREAM_TOCLIENT, reply4, reply4_len);
2458 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2464 printf(
"smtp parser in inconsistent state\n");
2469 STREAM_TOSERVER, request5_1, request5_1_len);
2471 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2478 printf(
"smtp parser in inconsistent state\n");
2483 STREAM_TOSERVER, request5_2, request5_2_len);
2485 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2492 printf(
"smtp parser in inconsistent state\n");
2497 STREAM_TOSERVER, request5_3, request5_3_len);
2499 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2506 printf(
"smtp parser in inconsistent state\n");
2511 STREAM_TOSERVER, request5_4, request5_4_len);
2513 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2520 printf(
"smtp parser in inconsistent state\n");
2525 STREAM_TOSERVER, request5_5, request5_5_len);
2527 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2533 printf(
"smtp parser in inconsistent state\n");
2538 STREAM_TOCLIENT, reply5, reply5_len);
2540 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2545 printf(
"smtp parser in inconsistent state\n");
2550 STREAM_TOSERVER, request6, request6_len);
2552 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2558 printf(
"smtp parser in inconsistent state\n");
2563 STREAM_TOCLIENT, reply6, reply6_len);
2565 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2570 printf(
"smtp parser in inconsistent state\n");
2575 STREAM_TOSERVER, request7, request7_len);
2577 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2583 printf(
"smtp parser in inconsistent state\n");
2588 STREAM_TOCLIENT, reply7, reply7_len);
2590 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2595 printf(
"smtp parser in inconsistent state\n");
2600 STREAM_TOSERVER, request8, request8_len);
2602 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2608 printf(
"smtp parser in inconsistent state\n");
2613 STREAM_TOCLIENT, reply8, reply8_len);
2615 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2621 printf(
"smtp parser in inconsistent state\n");
2626 STREAM_TOSERVER, request9_1, request9_1_len);
2628 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2635 printf(
"smtp parser in inconsistent state\n");
2640 STREAM_TOSERVER, request9_2, request9_2_len);
2642 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2649 printf(
"smtp parser in inconsistent state\n");
2654 STREAM_TOSERVER, request9_3, request9_3_len);
2656 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2663 printf(
"smtp parser in inconsistent state\n");
2668 STREAM_TOSERVER, request9_4, request9_4_len);
2670 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2677 printf(
"smtp parser in inconsistent state\n");
2682 STREAM_TOSERVER, request9_5, request9_5_len);
2684 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2690 printf(
"smtp parser in inconsistent state\n");
2695 STREAM_TOCLIENT, reply9, reply9_len);
2697 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2702 printf(
"smtp parser in inconsistent state\n");
2707 STREAM_TOSERVER, request10, request10_len);
2709 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2715 printf(
"smtp parser in inconsistent state\n");
2720 STREAM_TOCLIENT, reply10, reply10_len);
2722 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2727 printf(
"smtp parser in inconsistent state\n");
2743 static int SMTPParserTest03(
void)
2750 uint8_t welcome_reply[] = {
2751 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2752 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2753 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2754 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2755 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2756 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2758 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2761 uint8_t request1[] = {
2762 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2763 0x2e, 0x63, 0x6f, 0x6d, 0x0a
2765 uint32_t request1_len =
sizeof(request1);
2775 uint8_t reply1[] = {
2776 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2777 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2778 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2779 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2780 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2781 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2782 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2783 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2784 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2785 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2786 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2787 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2788 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2789 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2790 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2791 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2792 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2794 uint32_t reply1_len =
sizeof(reply1);
2801 uint8_t request2[] = {
2802 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2803 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2804 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2805 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
2806 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2807 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2808 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
2809 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
2810 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
2812 uint32_t request2_len =
sizeof(request2);
2817 uint8_t reply2[] = {
2818 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2819 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
2820 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
2821 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
2822 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
2823 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
2824 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
2825 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
2828 uint32_t reply2_len =
sizeof(reply2);
2833 memset(&f, 0,
sizeof(f));
2834 memset(&ssn, 0,
sizeof(ssn));
2838 f.
proto = IPPROTO_TCP;
2842 SMTPTestInitConfig();
2845 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2847 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2851 if (smtp_state == NULL) {
2852 printf(
"no smtp state: ");
2857 printf(
"smtp parser in inconsistent state\n");
2862 STREAM_TOSERVER, request1, request1_len);
2864 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2870 printf(
"smtp parser in inconsistent state\n");
2875 STREAM_TOCLIENT, reply1, reply1_len);
2877 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2883 printf(
"smtp parser in inconsistent state\n");
2888 STREAM_TOSERVER, request2, request2_len);
2890 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2900 printf(
"smtp parser in inconsistent state\n");
2905 STREAM_TOCLIENT, reply2, reply2_len);
2907 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2914 printf(
"smtp parser in inconsistent state\n");
2930 static int SMTPParserTest04(
void)
2937 uint8_t welcome_reply[] = {
2938 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2939 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2940 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2941 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2942 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2943 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2945 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2948 uint8_t request1[] = {
2949 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2950 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2951 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2952 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2953 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2954 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2956 uint32_t request1_len =
sizeof(request1);
2961 memset(&f, 0,
sizeof(f));
2962 memset(&ssn, 0,
sizeof(ssn));
2966 f.
proto = IPPROTO_TCP;
2970 SMTPTestInitConfig();
2973 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2975 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2979 if (smtp_state == NULL) {
2980 printf(
"no smtp state: ");
2985 printf(
"smtp parser in inconsistent state\n");
2990 STREAM_TOSERVER, request1, request1_len);
2992 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2998 printf(
"smtp parser in inconsistent state\n");
3014 static int SMTPParserTest05(
void)
3021 uint8_t welcome_reply[] = {
3022 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3023 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3024 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3025 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3026 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3027 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3029 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3032 uint8_t request1[] = {
3033 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3034 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3036 uint32_t request1_len =
sizeof(request1);
3046 uint8_t reply1[] = {
3047 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3048 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3049 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3050 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3051 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3052 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3053 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3054 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3055 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3056 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3057 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3058 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3059 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3060 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3061 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3062 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3063 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3065 uint32_t reply1_len =
sizeof(reply1);
3068 uint8_t request2[] = {
3069 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3072 uint32_t request2_len =
sizeof(request2);
3074 uint8_t reply2[] = {
3075 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3076 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3077 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3078 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3079 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3082 uint32_t reply2_len =
sizeof(reply2);
3085 uint8_t request3[] = {
3086 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3089 uint32_t request3_len =
sizeof(request3);
3091 uint8_t reply3[] = {
3092 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3093 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3095 uint32_t reply3_len =
sizeof(reply3);
3100 memset(&f, 0,
sizeof(f));
3101 memset(&ssn, 0,
sizeof(ssn));
3105 f.
proto = IPPROTO_TCP;
3109 SMTPTestInitConfig();
3112 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3114 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3118 if (smtp_state == NULL) {
3119 printf(
"no smtp state: ");
3124 printf(
"smtp parser in inconsistent state\n");
3129 STREAM_TOSERVER, request1, request1_len);
3131 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3137 printf(
"smtp parser in inconsistent state\n");
3142 STREAM_TOCLIENT, reply1, reply1_len);
3144 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3150 printf(
"smtp parser in inconsistent state\n");
3155 STREAM_TOSERVER, request2, request2_len);
3157 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3164 printf(
"smtp parser in inconsistent state\n");
3169 STREAM_TOCLIENT, reply2, reply2_len);
3171 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3177 printf(
"smtp parser in inconsistent state\n");
3189 STREAM_TOSERVER, request3, request3_len);
3191 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3198 printf(
"smtp parser in inconsistent state\n");
3203 STREAM_TOCLIENT, reply3, reply3_len);
3205 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3211 printf(
"smtp parser in inconsistent state\n");
3227 static int SMTPParserTest06(
void)
3233 uint8_t welcome_reply[] = {
3234 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3235 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3236 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3237 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3238 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3239 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3240 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3241 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3242 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3243 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3244 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3245 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3246 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3247 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3248 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3249 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3250 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3251 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3252 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3253 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3254 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3255 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3256 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3257 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3258 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3259 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3260 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3261 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3262 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3263 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3264 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3265 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3266 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3267 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3268 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3269 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3270 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3271 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3272 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3274 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3276 uint8_t request1[] = {
3277 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3278 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3279 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3280 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3283 uint32_t request1_len =
sizeof(request1);
3285 uint8_t reply1[] = {
3286 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3287 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3288 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3289 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3290 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3291 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3292 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3293 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3294 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3295 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3296 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3297 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3298 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3299 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3300 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3301 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3302 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3303 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3304 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3305 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3306 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3309 uint32_t reply1_len =
sizeof(reply1);
3312 uint8_t request2[] = {
3313 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3314 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3315 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3318 uint32_t request2_len =
sizeof(request2);
3320 uint8_t reply2[] = {
3321 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3322 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3324 uint32_t reply2_len =
sizeof(reply2);
3327 uint8_t request3[] = {
3328 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3329 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3330 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3333 uint32_t request3_len =
sizeof(request3);
3335 uint8_t reply3[] = {
3336 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3337 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3339 uint32_t reply3_len =
sizeof(reply3);
3342 uint8_t request4[] = {
3343 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3346 uint32_t request4_len =
sizeof(request4);
3348 uint8_t request5[] = {
3349 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3350 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3351 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3352 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3354 uint32_t request5_len =
sizeof(request5);
3356 uint8_t request6[] = {
3357 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3358 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3361 uint32_t request6_len =
sizeof(request6);
3366 memset(&f, 0,
sizeof(f));
3367 memset(&ssn, 0,
sizeof(ssn));
3371 f.
proto = IPPROTO_TCP;
3375 SMTPTestInitConfig();
3378 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3380 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3384 if (smtp_state == NULL) {
3385 printf(
"no smtp state: ");
3390 printf(
"smtp parser in inconsistent state\n");
3395 STREAM_TOSERVER, request1, request1_len);
3397 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3403 printf(
"smtp parser in inconsistent state\n");
3408 STREAM_TOCLIENT, reply1, reply1_len);
3410 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3415 printf(
"smtp parser in inconsistent state\n");
3420 STREAM_TOSERVER, request2, request2_len);
3422 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3428 printf(
"smtp parser in inconsistent state\n");
3433 STREAM_TOCLIENT, reply2, reply2_len);
3435 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3440 printf(
"smtp parser in inconsistent state\n");
3445 STREAM_TOSERVER, request3, request3_len);
3447 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3453 printf(
"smtp parser in inconsistent state\n");
3458 STREAM_TOCLIENT, reply3, reply3_len);
3460 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3465 printf(
"smtp parser in inconsistent state\n");
3470 STREAM_TOSERVER, request4, request4_len);
3472 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3480 printf(
"smtp parser in inconsistent state\n");
3485 STREAM_TOSERVER, request5, request5_len);
3487 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3494 printf(
"smtp parser in inconsistent state\n");
3499 STREAM_TOSERVER, request6, request6_len);
3501 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3507 printf(
"smtp parser in inconsistent state\n");
3520 static int SMTPParserTest12(
void)
3534 uint8_t request1[] = {
3535 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3536 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3538 int32_t request1_len =
sizeof(request1);
3542 uint8_t reply1[] = {
3543 0x31, 0x38, 0x38, 0x0d, 0x0a,
3545 uint32_t reply1_len =
sizeof(reply1);
3549 memset(&th_v, 0,
sizeof(th_v));
3550 memset(&f, 0,
sizeof(f));
3551 memset(&ssn, 0,
sizeof(ssn));
3557 f.
proto = IPPROTO_TCP;
3566 SMTPTestInitConfig();
3575 "(msg:\"SMTP event handling\"; "
3576 "app-layer-event: smtp.invalid_reply; "
3585 STREAM_TOSERVER | STREAM_START, request1,
3588 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3593 if (smtp_state == NULL) {
3594 printf(
"no smtp state: ");
3602 printf(
"sid 1 matched. It shouldn't match: ");
3607 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3610 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3618 printf(
"sid 1 didn't match. Should have matched: ");
3639 static int SMTPParserTest13(
void)
3653 uint8_t request1[] = {
3654 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3655 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3657 int32_t request1_len =
sizeof(request1);
3661 uint8_t reply1[] = {
3662 0x32, 0x35, 0x30, 0x0d, 0x0a,
3664 uint32_t reply1_len =
sizeof(reply1);
3671 uint8_t request2[] = {
3672 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3673 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3674 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3675 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3676 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3677 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3678 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3679 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3682 uint32_t request2_len =
sizeof(request2);
3686 memset(&th_v, 0,
sizeof(th_v));
3687 memset(&f, 0,
sizeof(f));
3688 memset(&ssn, 0,
sizeof(ssn));
3694 f.
proto = IPPROTO_TCP;
3703 SMTPTestInitConfig();
3712 "(msg:\"SMTP event handling\"; "
3714 "smtp.invalid_pipelined_sequence; "
3723 STREAM_TOSERVER | STREAM_START, request1,
3726 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3731 if (smtp_state == NULL) {
3732 printf(
"no smtp state: ");
3740 printf(
"sid 1 matched. It shouldn't match: ");
3745 STREAM_TOCLIENT, reply1, reply1_len);
3747 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3755 printf(
"sid 1 matched. It shouldn't match: ");
3760 STREAM_TOSERVER, request2, request2_len);
3762 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3770 printf(
"sid 1 didn't match. Should have matched: ");
3794 static int SMTPParserTest14(
void)
3801 static uint8_t welcome_reply[] = {
3802 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
3803 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3804 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
3805 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
3806 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
3809 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
3812 static uint8_t request1[] = {
3813 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3814 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3816 static uint32_t request1_len =
sizeof(request1);
3823 static uint8_t reply1[] = {
3824 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3825 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3826 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3827 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3828 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3829 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3830 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3831 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3832 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3833 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3834 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3835 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3836 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3837 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3838 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3840 static uint32_t reply1_len =
sizeof(reply1);
3843 static uint8_t request2[] = {
3844 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3845 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3846 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3849 static uint32_t request2_len =
sizeof(request2);
3851 static uint8_t reply2[] = {
3852 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3853 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3855 static uint32_t reply2_len =
sizeof(reply2);
3858 static uint8_t request3[] = {
3859 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3860 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3861 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3864 static uint32_t request3_len =
sizeof(request3);
3866 static uint8_t reply3[] = {
3867 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3868 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3870 static uint32_t reply3_len =
sizeof(reply3);
3873 static uint8_t request4[] = {
3874 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
3876 static uint32_t request4_len =
sizeof(request4);
3878 static uint8_t reply4[] = {
3879 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
3880 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
3881 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
3882 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
3883 0x4c, 0x46, 0x3e, 0x0d, 0x0a
3885 static uint32_t reply4_len =
sizeof(reply4);
3888 static uint64_t filesize = 133;
3889 static uint8_t request4_msg[] = {
3890 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
3891 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
3892 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3893 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
3894 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
3895 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
3896 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
3897 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3898 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
3899 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
3900 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
3901 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
3902 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
3903 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
3904 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
3905 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
3906 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
3907 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
3908 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
3909 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
3910 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
3911 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
3912 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3913 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
3914 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
3915 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
3916 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
3917 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
3918 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
3919 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3920 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
3921 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3922 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3923 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
3924 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3925 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3926 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3927 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3928 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
3929 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
3930 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
3931 0x41, 0x3D, 0x3D, 0x0D,0x0A };
3932 static uint32_t request4_msg_len =
sizeof(request4_msg);
3935 static uint8_t request4_end[] = {
3936 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
3938 static uint32_t request4_end_len =
sizeof(request4_end);
3940 static uint8_t reply4_end[] = {
3941 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3942 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
3943 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
3944 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
3945 0x46, 0x32, 0x0d, 0x0a
3947 static uint32_t reply4_end_len =
sizeof(reply4_end);
3950 static uint8_t request5[] = {
3951 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3953 static uint32_t request5_len =
sizeof(request5);
3955 static uint8_t reply5[] = {
3956 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3957 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3959 static uint32_t reply5_len =
sizeof(reply5);
3964 memset(&f, 0,
sizeof(f));
3965 memset(&ssn, 0,
sizeof(ssn));
3969 f.
proto = IPPROTO_TCP;
3973 SMTPTestInitConfig();
3977 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3979 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3983 if (smtp_state == NULL) {
3984 printf(
"no smtp state: ");
3989 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3994 STREAM_TOSERVER, request1, request1_len);
3996 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4002 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4008 STREAM_TOCLIENT, reply1, reply1_len);
4010 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4014 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4015 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4021 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4027 STREAM_TOSERVER, request2, request2_len);
4029 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4035 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4041 STREAM_TOCLIENT, reply2, reply2_len);
4043 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4049 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4057 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4063 STREAM_TOSERVER, request3, request3_len);
4065 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4071 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4077 STREAM_TOCLIENT, reply3, reply3_len);
4079 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4084 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4090 SCMimeSmtpConfigDecodeBase64(1);
4091 SCMimeSmtpConfigDecodeQuoted(1);
4095 STREAM_TOSERVER, request4, request4_len);
4097 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4104 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4110 STREAM_TOCLIENT, reply4, reply4_len);
4112 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4118 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4124 STREAM_TOSERVER, request4_msg, request4_msg_len);
4126 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4134 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4140 STREAM_TOSERVER, request4_end, request4_end_len);
4142 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4150 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4159 if (files != NULL && files->
head != NULL) {
4162 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4163 printf(
"smtp-mime file name is incorrect");
4167 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4170 static uint8_t org_binary[] = {
4171 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4172 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4174 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4175 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4176 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4177 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4178 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4179 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4180 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4181 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4182 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4183 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4185 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4186 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4187 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4190 org_binary,
sizeof(org_binary)) != 1)
4192 printf(
"smtp-mime file data incorrect\n");
4199 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4201 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4206 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4212 STREAM_TOSERVER, request5, request5_len);
4214 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4220 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4226 STREAM_TOCLIENT, reply5, reply5_len);
4228 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4233 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);