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
99 #define SMTP_DEFAULT_MAX_TX 256
174 static int SMTPGetFrameIdByName(
const char *frame_name)
183 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
194 #define SMTP_MPM mpm_default_matcher
196 static MpmCtx *smtp_mpm_ctx = NULL;
304 #define SCHEME_SUFFIX_LEN 3
312 static void SMTPConfigure(
void) {
316 uint32_t content_limit = 0;
317 uint32_t content_inspect_min_size = 0;
318 uint32_t content_inspect_window = 0;
321 if (config != NULL) {
332 SCMimeSmtpConfigDecodeBase64(val);
337 SCMimeSmtpConfigDecodeQuoted(val);
342 if (imval < 0 || imval > UINT32_MAX) {
343 FatalError(
"Invalid value for header-value-depth");
345 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
350 SCMimeSmtpConfigExtractUrls(val);
357 if (extract_urls_schemes) {
361 size_t scheme_len = strlen(scheme->
val);
363 FatalError(
"extract-urls-schemes entry '%s' is too long", scheme->
val);
365 if (scheme->
val[scheme_len - 1] !=
'/') {
368 int r = snprintf(tmp,
sizeof(tmp),
"%s://", scheme->
val);
369 if (r != (
int)scheme_len) {
370 FatalError(
"snprintf failure for SMTP url extraction scheme.");
374 FatalError(
"extract-urls-schemes entry SCStrdup failure.");
377 scheme->
val = new_val;
379 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
381 FatalError(
"Failed to add smtp extract url scheme");
387 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
392 SCMimeSmtpConfigLogUrlScheme(val);
399 SCMimeSmtpConfigBodyMd5(
false);
401 SCMimeSmtpConfigBodyMd5(
true);
402 }
else if (strcmp(strval,
"auto") != 0) {
413 if (strcasecmp(
"content-limit", p->
name) == 0) {
421 if (strcasecmp(
"content-inspect-min-size", p->
name) == 0) {
429 if (strcasecmp(
"content-inspect-window", p->
name) == 0) {
446 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
447 "options can't be enabled at the same time, "
448 "disabling raw extraction");
454 const char *
str = NULL;
455 if (
SCConfGet(
"app-layer.protocols.smtp.max-tx", &
str) == 1) {
467 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
497 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
499 }
else if (tx == NULL) {
500 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
502 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
512 if (tx == NULL || file == NULL) {
517 FlagDetectStateNewFile(tx);
549 if (direction == 0 &&
556 }
else if (direction == 1) {
559 if (frame != NULL && state->
curr_tx) {
566 uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
569 if (lf_idx == NULL) {
582 uint32_t o_consumed = input->
consumed;
583 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
591 line->
buf = input->
buf + o_consumed;
594 frame->
len = (int64_t)line->
len;
602 if (discard_till_lf) {
604 if (direction == 0) {
624 static int SMTPInsertCommandIntoCommandBuffer(uint8_t command,
SMTPState *state)
657 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
685 static void SetMimeEvents(
SMTPState *state, uint32_t events)
691 if (events & MIME_ANOM_INVALID_BASE64) {
694 if (events & MIME_ANOM_INVALID_QP) {
697 if (events & MIME_ANOM_LONG_LINE) {
700 if (events & MIME_ANOM_LONG_ENC_LINE) {
703 if (events & MIME_ANOM_LONG_HEADER_NAME) {
706 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
709 if (events & MIME_ANOM_LONG_BOUNDARY) {
712 if (events & MIME_ANOM_LONG_FILENAME) {
717 static inline void SMTPTransactionComplete(
SMTPState *state)
728 static int SMTPProcessCommandDATA(
740 if (line->
len == 1 && line->
buf[0] ==
'.') {
758 SMTPTransactionComplete(state);
773 const uint8_t *filename = NULL;
774 uint16_t filename_len = 0;
779 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
781 SetMimeEvents(state, events);
783 case MimeSmtpFileOpen:
787 if (filename_len == 0) {
794 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
809 case MimeSmtpFileChunk:
818 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
829 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
834 case MimeSmtpFileClose:
837 SCLogDebug(
"FileCloseFile() failed: %d", ret);
845 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
854 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
860 static int SMTPProcessReply(
881 if (line->
len >= 4) {
883 if (line->
buf[3] !=
'-') {
887 if (line->
buf[3] ==
'-') {
909 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
928 SCLogDebug(
"unable to match reply with request");
943 SMTPTransactionComplete(state);
964 SMTPTransactionComplete(state);
978 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
998 while (i < line->
len) {
999 if (line->
buf[i] !=
' ') {
1008 if (i == line->
len) {
1015 if (line->
len - i <
len) {
1018 memcpy(strbuf, line->
buf + i,
len);
1028 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1029 uint8_t **target, uint16_t *target_len)
1031 int i = prefix_len + 1;
1033 while (i < line->
len) {
1034 if (line->
buf[i] !=
' ') {
1043 while (spc_i < line->
len) {
1044 if (line->
buf[spc_i] ==
' ') {
1051 if (*target == NULL)
1053 memcpy(*target, line->
buf + i, spc_i - i);
1054 (*target)[spc_i - i] =
'\0';
1055 if (spc_i - i > UINT16_MAX) {
1056 *target_len = UINT16_MAX;
1059 *target_len = (uint16_t)(spc_i - i);
1071 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1080 return SMTPParseCommandWithParam(
1087 uint16_t rcptto_len;
1089 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1092 rcptto_str->
str = rcptto;
1093 rcptto_str->
len = rcptto_len;
1109 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1111 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1119 #define rawmsgname "rawmsg"
1138 static int SMTPProcessRequest(
1146 frame->
len = (int64_t)line->
len;
1163 tx = SMTPTransactionCreate(state);
1175 if (frame != NULL && state->
curr_tx) {
1192 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1194 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1220 if (data_frame == NULL) {
1221 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1230 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1231 r = SMTPParseCommandBDAT(state, line);
1237 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1238 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1239 r = SMTPParseCommandHELO(state, line);
1244 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1245 r = SMTPParseCommandMAILFROM(state, line);
1250 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1251 r = SMTPParseCommandRCPTTO(state, line);
1256 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1266 if (SMTPInsertCommandIntoCommandBuffer(state->
current_command, state) == -1) {
1275 return SMTPProcessCommandDATA(state, tx, f, line);
1278 return SMTPProcessCommandBDAT(state, line);
1287 static inline void ResetLine(
SMTPLine *line)
1316 static int SMTPPreProcessCommands(
1328 bool line_complete =
false;
1329 const int32_t input_len = input->
len;
1331 for (int32_t i = 0; i < input_len; i++) {
1333 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1339 line_complete =
true;
1340 }
else if (input->
buf[
offset + i] == 0x0a) {
1343 line_complete =
true;
1346 if (line_complete || (i == input_len - 1)) {
1353 SCLogDebug(
"Possible boundary, yield to GetLine");
1357 int32_t total_consumed =
offset + i + 1;
1358 int32_t current_line_consumed = total_consumed - input->
consumed;
1363 if (line->
len < 0) {
1368 input->
len -= current_line_consumed;
1370 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1373 line_complete =
false;
1396 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1397 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1399 if (input_buf == NULL &&
1404 }
else if (input_buf == NULL || input_len == 0) {
1408 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1409 SMTPLine line = { NULL, 0, 0,
false };
1412 if (direction == 0) {
1416 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1420 }
else if (ret < 0) {
1424 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1425 while (res.
status == 0) {
1426 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1447 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1451 }
else if (ret < 0) {
1455 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1461 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1462 while (res.
status == 0) {
1463 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1473 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1488 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1497 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1512 if (smtp_state->
cmds == NULL) {
1541 static void *SMTPLocalStorageAlloc(
void)
1550 if (td->
pmq == NULL) {
1563 static void SMTPLocalStorageFree(
void *ptr)
1567 if (td->
pmq != NULL) {
1595 SMTPStringFree(
str);
1606 static void SMTPStateFree(
void *p)
1610 if (smtp_state->
cmds != NULL) {
1614 if (smtp_state->
helo) {
1619 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1621 SMTPTransactionFree(tx, smtp_state);
1627 static void SMTPSetMpmState(
void)
1630 if (
unlikely(smtp_mpm_ctx == NULL)) {
1646 static void SMTPFreeMpmState(
void)
1648 if (smtp_mpm_ctx != NULL) {
1651 smtp_mpm_ctx = NULL;
1655 static int SMTPStateGetEventInfo(
1665 static int SMTPStateGetEventInfoById(
1669 if (*event_name == NULL) {
1671 "smtp's enum map table.",
1684 static AppProto SMTPClientProbingParserCheckPort(
1685 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1693 static AppProto SMTPServerProbingParser(
1694 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1701 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1705 if (input[3] !=
' ' && input[3] !=
'-') {
1711 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1722 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1733 static int SMTPRegisterPatternsForProtocolDetection(
void)
1736 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1740 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1744 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1749 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1752 NULL, SMTPServerProbingParser);
1758 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1763 if (tx_id < tx->tx_id)
1765 else if (tx_id > tx->
tx_id)
1768 if (tx == smtp_state->
curr_tx)
1771 SMTPTransactionFree(tx, state);
1779 static uint64_t SMTPStateGetTxCnt(
void *state)
1790 static void *SMTPStateGetTx(
void *state, uint64_t
id)
1796 if (smtp_state->
curr_tx == NULL)
1802 if (tx->
tx_id ==
id)
1809 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
1820 if (direction & STREAM_TOSERVER) {
1849 if (state->
un.
ptr == NULL) {
1855 while (tx_ptr->
tx_id < min_tx_id) {
1861 if (tx_ptr->
tx_id >= max_tx_id) {
1868 .has_next = (state->
un.
ptr != NULL),
1881 const char *proto_name =
"smtp";
1885 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
1888 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
1897 SMTPParseClientRecord);
1899 SMTPParseServerRecord);
1905 SMTPLocalStorageFree);
1917 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
1919 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
1944 static void SMTPTestInitConfig(
void)
1958 static int SMTPParserTest01(
void)
1965 uint8_t welcome_reply[] = {
1966 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
1967 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1968 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
1969 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
1970 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
1973 uint32_t welcome_reply_len =
sizeof(welcome_reply);
1976 uint8_t request1[] = {
1977 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
1978 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
1979 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
1981 uint32_t request1_len =
sizeof(request1);
1988 uint8_t reply1[] = {
1989 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
1990 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1991 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
1992 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
1993 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
1994 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
1995 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
1996 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
1997 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
1998 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
1999 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2000 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2001 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2002 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2003 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2004 0x44, 0x45, 0x53, 0x0d, 0x0a
2006 uint32_t reply1_len =
sizeof(reply1);
2009 uint8_t request2[] = {
2010 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2013 uint32_t request2_len =
sizeof(request2);
2015 uint8_t reply2[] = {
2016 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2017 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2018 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2019 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2021 uint32_t reply2_len =
sizeof(reply2);
2026 memset(&f, 0,
sizeof(f));
2027 memset(&ssn, 0,
sizeof(ssn));
2031 f.
proto = IPPROTO_TCP;
2035 SMTPTestInitConfig();
2038 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2040 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2044 if (smtp_state == NULL) {
2045 printf(
"no smtp state: ");
2050 printf(
"smtp parser in inconsistent state\n");
2055 STREAM_TOSERVER, request1, request1_len);
2057 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2063 printf(
"smtp parser in inconsistent state\n");
2068 STREAM_TOCLIENT, reply1, reply1_len);
2070 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2075 printf(
"smtp parser in inconsistent state\n");
2080 STREAM_TOSERVER, request2, request2_len);
2082 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2088 printf(
"smtp parser in inconsistent state\n");
2093 STREAM_TOCLIENT, reply2, reply2_len);
2095 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2101 printf(
"smtp parser in inconsistent state\n");
2121 static int SMTPParserTest02(
void)
2128 uint8_t welcome_reply[] = {
2129 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2130 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2131 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2132 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2133 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2136 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2139 uint8_t request1[] = {
2140 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2141 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2143 uint32_t request1_len =
sizeof(request1);
2150 uint8_t reply1[] = {
2151 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2152 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2153 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2154 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2155 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2156 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2157 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2158 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2159 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2160 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2161 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2162 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2163 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2164 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2165 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2167 uint32_t reply1_len =
sizeof(reply1);
2170 uint8_t request2[] = {
2171 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2172 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2173 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2176 uint32_t request2_len =
sizeof(request2);
2178 uint8_t reply2[] = {
2179 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2180 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2182 uint32_t reply2_len =
sizeof(reply2);
2185 uint8_t request3[] = {
2186 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2187 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2188 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2191 uint32_t request3_len =
sizeof(request3);
2193 uint8_t reply3[] = {
2194 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2195 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2197 uint32_t reply3_len =
sizeof(reply3);
2200 uint8_t request4[] = {
2201 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2203 uint32_t request4_len =
sizeof(request4);
2205 uint8_t reply4[] = {
2206 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2207 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2208 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2209 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2210 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2212 uint32_t reply4_len =
sizeof(reply4);
2215 uint8_t request5_1[] = {
2216 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2217 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2218 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2220 uint32_t request5_1_len =
sizeof(request5_1);
2222 uint8_t request5_2[] = {
2223 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2224 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2225 0x6f, 0x6d, 0x0d, 0x0a
2227 uint32_t request5_2_len =
sizeof(request5_2);
2229 uint8_t request5_3[] = {
2232 uint32_t request5_3_len =
sizeof(request5_3);
2234 uint8_t request5_4[] = {
2235 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2236 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2237 0x6c, 0x31, 0x0d, 0x0a
2239 uint32_t request5_4_len =
sizeof(request5_4);
2241 uint8_t request5_5[] = {
2244 uint32_t request5_5_len =
sizeof(request5_5);
2246 uint8_t reply5[] = {
2247 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2248 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2249 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2250 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2251 0x46, 0x32, 0x0d, 0x0a
2253 uint32_t reply5_len =
sizeof(reply5);
2256 uint8_t request6[] = {
2257 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2258 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2259 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2262 uint32_t request6_len =
sizeof(request6);
2264 uint8_t reply6[] = {
2265 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2266 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2268 uint32_t reply6_len =
sizeof(reply6);
2271 uint8_t request7[] = {
2272 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2273 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2274 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2277 uint32_t request7_len =
sizeof(request7);
2279 uint8_t reply7[] = {
2280 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2281 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2283 uint32_t reply7_len =
sizeof(reply7);
2286 uint8_t request8[] = {
2287 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2289 uint32_t request8_len =
sizeof(request8);
2291 uint8_t reply8[] = {
2292 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2293 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2294 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2295 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2296 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2298 uint32_t reply8_len =
sizeof(reply8);
2301 uint8_t request9_1[] = {
2302 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2303 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2304 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2306 uint32_t request9_1_len =
sizeof(request9_1);
2308 uint8_t request9_2[] = {
2309 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2310 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2311 0x6f, 0x6d, 0x0d, 0x0a
2313 uint32_t request9_2_len =
sizeof(request9_2);
2315 uint8_t request9_3[] = {
2318 uint32_t request9_3_len =
sizeof(request9_3);
2320 uint8_t request9_4[] = {
2321 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2322 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2323 0x6c, 0x32, 0x0d, 0x0a
2325 uint32_t request9_4_len =
sizeof(request9_4);
2327 uint8_t request9_5[] = {
2330 uint32_t request9_5_len =
sizeof(request9_5);
2332 uint8_t reply9[] = {
2333 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2334 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2335 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2336 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2337 0x46, 0x32, 0x0d, 0x0a
2339 uint32_t reply9_len =
sizeof(reply9);
2342 uint8_t request10[] = {
2343 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2345 uint32_t request10_len =
sizeof(request10);
2347 uint8_t reply10[] = {
2348 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2349 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2351 uint32_t reply10_len =
sizeof(reply10);
2356 memset(&f, 0,
sizeof(f));
2357 memset(&ssn, 0,
sizeof(ssn));
2361 f.
proto = IPPROTO_TCP;
2365 SMTPTestInitConfig();
2368 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2370 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2374 if (smtp_state == NULL) {
2375 printf(
"no smtp state: ");
2380 printf(
"smtp parser in inconsistent state\n");
2385 STREAM_TOSERVER, request1, request1_len);
2387 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2393 printf(
"smtp parser in inconsistent state\n");
2398 STREAM_TOCLIENT, reply1, reply1_len);
2400 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2405 printf(
"smtp parser in inconsistent state\n");
2410 STREAM_TOSERVER, request2, request2_len);
2412 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2418 printf(
"smtp parser in inconsistent state\n");
2423 STREAM_TOCLIENT, reply2, reply2_len);
2425 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2430 printf(
"smtp parser in inconsistent state\n");
2435 STREAM_TOSERVER, request3, request3_len);
2437 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2443 printf(
"smtp parser in inconsistent state\n");
2448 STREAM_TOCLIENT, reply3, reply3_len);
2450 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2455 printf(
"smtp parser in inconsistent state\n");
2460 STREAM_TOSERVER, request4, request4_len);
2462 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2468 printf(
"smtp parser in inconsistent state\n");
2473 STREAM_TOCLIENT, reply4, reply4_len);
2475 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2481 printf(
"smtp parser in inconsistent state\n");
2486 STREAM_TOSERVER, request5_1, request5_1_len);
2488 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2495 printf(
"smtp parser in inconsistent state\n");
2500 STREAM_TOSERVER, request5_2, request5_2_len);
2502 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2509 printf(
"smtp parser in inconsistent state\n");
2514 STREAM_TOSERVER, request5_3, request5_3_len);
2516 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2523 printf(
"smtp parser in inconsistent state\n");
2528 STREAM_TOSERVER, request5_4, request5_4_len);
2530 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2537 printf(
"smtp parser in inconsistent state\n");
2542 STREAM_TOSERVER, request5_5, request5_5_len);
2544 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2550 printf(
"smtp parser in inconsistent state\n");
2555 STREAM_TOCLIENT, reply5, reply5_len);
2557 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2562 printf(
"smtp parser in inconsistent state\n");
2567 STREAM_TOSERVER, request6, request6_len);
2569 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2575 printf(
"smtp parser in inconsistent state\n");
2580 STREAM_TOCLIENT, reply6, reply6_len);
2582 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2587 printf(
"smtp parser in inconsistent state\n");
2592 STREAM_TOSERVER, request7, request7_len);
2594 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2600 printf(
"smtp parser in inconsistent state\n");
2605 STREAM_TOCLIENT, reply7, reply7_len);
2607 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2612 printf(
"smtp parser in inconsistent state\n");
2617 STREAM_TOSERVER, request8, request8_len);
2619 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2625 printf(
"smtp parser in inconsistent state\n");
2630 STREAM_TOCLIENT, reply8, reply8_len);
2632 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2638 printf(
"smtp parser in inconsistent state\n");
2643 STREAM_TOSERVER, request9_1, request9_1_len);
2645 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2652 printf(
"smtp parser in inconsistent state\n");
2657 STREAM_TOSERVER, request9_2, request9_2_len);
2659 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2666 printf(
"smtp parser in inconsistent state\n");
2671 STREAM_TOSERVER, request9_3, request9_3_len);
2673 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2680 printf(
"smtp parser in inconsistent state\n");
2685 STREAM_TOSERVER, request9_4, request9_4_len);
2687 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2694 printf(
"smtp parser in inconsistent state\n");
2699 STREAM_TOSERVER, request9_5, request9_5_len);
2701 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2707 printf(
"smtp parser in inconsistent state\n");
2712 STREAM_TOCLIENT, reply9, reply9_len);
2714 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2719 printf(
"smtp parser in inconsistent state\n");
2724 STREAM_TOSERVER, request10, request10_len);
2726 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2732 printf(
"smtp parser in inconsistent state\n");
2737 STREAM_TOCLIENT, reply10, reply10_len);
2739 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2744 printf(
"smtp parser in inconsistent state\n");
2760 static int SMTPParserTest03(
void)
2767 uint8_t welcome_reply[] = {
2768 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2769 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2770 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2771 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2772 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2773 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2775 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2778 uint8_t request1[] = {
2779 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2780 0x2e, 0x63, 0x6f, 0x6d, 0x0a
2782 uint32_t request1_len =
sizeof(request1);
2792 uint8_t reply1[] = {
2793 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2794 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2795 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2796 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2797 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2798 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2799 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2800 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2801 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2802 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2803 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2804 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2805 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2806 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2807 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2808 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2809 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2811 uint32_t reply1_len =
sizeof(reply1);
2818 uint8_t request2[] = {
2819 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2820 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2821 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2822 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
2823 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2824 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2825 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
2826 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
2827 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
2829 uint32_t request2_len =
sizeof(request2);
2834 uint8_t reply2[] = {
2835 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2836 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
2837 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
2838 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
2839 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
2840 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
2841 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
2842 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
2845 uint32_t reply2_len =
sizeof(reply2);
2850 memset(&f, 0,
sizeof(f));
2851 memset(&ssn, 0,
sizeof(ssn));
2855 f.
proto = IPPROTO_TCP;
2859 SMTPTestInitConfig();
2862 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2864 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2868 if (smtp_state == NULL) {
2869 printf(
"no smtp state: ");
2874 printf(
"smtp parser in inconsistent state\n");
2879 STREAM_TOSERVER, request1, request1_len);
2881 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2887 printf(
"smtp parser in inconsistent state\n");
2892 STREAM_TOCLIENT, reply1, reply1_len);
2894 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2900 printf(
"smtp parser in inconsistent state\n");
2905 STREAM_TOSERVER, request2, request2_len);
2907 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2917 printf(
"smtp parser in inconsistent state\n");
2922 STREAM_TOCLIENT, reply2, reply2_len);
2924 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2931 printf(
"smtp parser in inconsistent state\n");
2947 static int SMTPParserTest04(
void)
2954 uint8_t welcome_reply[] = {
2955 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2956 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2957 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2958 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2959 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2960 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2962 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2965 uint8_t request1[] = {
2966 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2967 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2968 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2969 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2970 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2971 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2973 uint32_t request1_len =
sizeof(request1);
2978 memset(&f, 0,
sizeof(f));
2979 memset(&ssn, 0,
sizeof(ssn));
2983 f.
proto = IPPROTO_TCP;
2987 SMTPTestInitConfig();
2990 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2992 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2996 if (smtp_state == NULL) {
2997 printf(
"no smtp state: ");
3002 printf(
"smtp parser in inconsistent state\n");
3007 STREAM_TOSERVER, request1, request1_len);
3009 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3015 printf(
"smtp parser in inconsistent state\n");
3031 static int SMTPParserTest05(
void)
3038 uint8_t welcome_reply[] = {
3039 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3040 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3041 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3042 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3043 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3044 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3046 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3049 uint8_t request1[] = {
3050 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3051 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3053 uint32_t request1_len =
sizeof(request1);
3063 uint8_t reply1[] = {
3064 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3065 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3066 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3067 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3068 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3069 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3070 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3071 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3072 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3073 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3074 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3075 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3076 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3077 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3078 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3079 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3080 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3082 uint32_t reply1_len =
sizeof(reply1);
3085 uint8_t request2[] = {
3086 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3089 uint32_t request2_len =
sizeof(request2);
3091 uint8_t reply2[] = {
3092 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3093 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3094 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3095 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3096 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3099 uint32_t reply2_len =
sizeof(reply2);
3102 uint8_t request3[] = {
3103 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3106 uint32_t request3_len =
sizeof(request3);
3108 uint8_t reply3[] = {
3109 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3110 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3112 uint32_t reply3_len =
sizeof(reply3);
3117 memset(&f, 0,
sizeof(f));
3118 memset(&ssn, 0,
sizeof(ssn));
3122 f.
proto = IPPROTO_TCP;
3126 SMTPTestInitConfig();
3129 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3131 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3135 if (smtp_state == NULL) {
3136 printf(
"no smtp state: ");
3141 printf(
"smtp parser in inconsistent state\n");
3146 STREAM_TOSERVER, request1, request1_len);
3148 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3154 printf(
"smtp parser in inconsistent state\n");
3159 STREAM_TOCLIENT, reply1, reply1_len);
3161 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3167 printf(
"smtp parser in inconsistent state\n");
3172 STREAM_TOSERVER, request2, request2_len);
3174 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3181 printf(
"smtp parser in inconsistent state\n");
3186 STREAM_TOCLIENT, reply2, reply2_len);
3188 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3194 printf(
"smtp parser in inconsistent state\n");
3206 STREAM_TOSERVER, request3, request3_len);
3208 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3215 printf(
"smtp parser in inconsistent state\n");
3220 STREAM_TOCLIENT, reply3, reply3_len);
3222 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3228 printf(
"smtp parser in inconsistent state\n");
3244 static int SMTPParserTest06(
void)
3250 uint8_t welcome_reply[] = {
3251 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3252 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3253 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3254 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3255 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3256 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3257 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3258 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3259 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3260 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3261 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3262 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3263 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3264 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3265 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3266 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3267 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3268 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3269 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3270 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3271 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3272 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3273 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3274 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3275 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3276 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3277 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3278 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3279 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3280 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3281 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3282 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3283 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3284 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3285 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3286 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3287 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3288 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3289 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3291 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3293 uint8_t request1[] = {
3294 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3295 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3296 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3297 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3300 uint32_t request1_len =
sizeof(request1);
3302 uint8_t reply1[] = {
3303 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3304 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3305 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3306 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3307 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3308 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3309 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3310 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3311 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3312 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3313 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3314 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3315 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3316 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3317 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3318 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3319 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3320 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3321 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3322 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3323 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3326 uint32_t reply1_len =
sizeof(reply1);
3329 uint8_t request2[] = {
3330 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3331 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3332 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3335 uint32_t request2_len =
sizeof(request2);
3337 uint8_t reply2[] = {
3338 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3339 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3341 uint32_t reply2_len =
sizeof(reply2);
3344 uint8_t request3[] = {
3345 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3346 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3347 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3350 uint32_t request3_len =
sizeof(request3);
3352 uint8_t reply3[] = {
3353 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3354 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3356 uint32_t reply3_len =
sizeof(reply3);
3359 uint8_t request4[] = {
3360 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3363 uint32_t request4_len =
sizeof(request4);
3365 uint8_t request5[] = {
3366 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3367 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3368 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3369 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3371 uint32_t request5_len =
sizeof(request5);
3373 uint8_t request6[] = {
3374 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3375 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3378 uint32_t request6_len =
sizeof(request6);
3383 memset(&f, 0,
sizeof(f));
3384 memset(&ssn, 0,
sizeof(ssn));
3388 f.
proto = IPPROTO_TCP;
3392 SMTPTestInitConfig();
3395 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3397 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3401 if (smtp_state == NULL) {
3402 printf(
"no smtp state: ");
3407 printf(
"smtp parser in inconsistent state\n");
3412 STREAM_TOSERVER, request1, request1_len);
3414 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3420 printf(
"smtp parser in inconsistent state\n");
3425 STREAM_TOCLIENT, reply1, reply1_len);
3427 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3432 printf(
"smtp parser in inconsistent state\n");
3437 STREAM_TOSERVER, request2, request2_len);
3439 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3445 printf(
"smtp parser in inconsistent state\n");
3450 STREAM_TOCLIENT, reply2, reply2_len);
3452 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3457 printf(
"smtp parser in inconsistent state\n");
3462 STREAM_TOSERVER, request3, request3_len);
3464 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3470 printf(
"smtp parser in inconsistent state\n");
3475 STREAM_TOCLIENT, reply3, reply3_len);
3477 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3482 printf(
"smtp parser in inconsistent state\n");
3487 STREAM_TOSERVER, request4, request4_len);
3489 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3497 printf(
"smtp parser in inconsistent state\n");
3502 STREAM_TOSERVER, request5, request5_len);
3504 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3511 printf(
"smtp parser in inconsistent state\n");
3516 STREAM_TOSERVER, request6, request6_len);
3518 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3524 printf(
"smtp parser in inconsistent state\n");
3537 static int SMTPParserTest12(
void)
3551 uint8_t request1[] = {
3552 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3553 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3555 int32_t request1_len =
sizeof(request1);
3559 uint8_t reply1[] = {
3560 0x31, 0x38, 0x38, 0x0d, 0x0a,
3562 uint32_t reply1_len =
sizeof(reply1);
3566 memset(&th_v, 0,
sizeof(th_v));
3568 memset(&f, 0,
sizeof(f));
3569 memset(&ssn, 0,
sizeof(ssn));
3575 f.
proto = IPPROTO_TCP;
3584 SMTPTestInitConfig();
3593 "(msg:\"SMTP event handling\"; "
3594 "app-layer-event: smtp.invalid_reply; "
3603 STREAM_TOSERVER | STREAM_START, request1,
3606 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3611 if (smtp_state == NULL) {
3612 printf(
"no smtp state: ");
3620 printf(
"sid 1 matched. It shouldn't match: ");
3625 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3628 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3636 printf(
"sid 1 didn't match. Should have matched: ");
3654 static int SMTPParserTest13(
void)
3668 uint8_t request1[] = {
3669 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3670 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3672 int32_t request1_len =
sizeof(request1);
3676 uint8_t reply1[] = {
3677 0x32, 0x35, 0x30, 0x0d, 0x0a,
3679 uint32_t reply1_len =
sizeof(reply1);
3686 uint8_t request2[] = {
3687 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3688 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3689 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3690 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3691 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3692 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3693 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3694 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3697 uint32_t request2_len =
sizeof(request2);
3701 memset(&th_v, 0,
sizeof(th_v));
3703 memset(&f, 0,
sizeof(f));
3704 memset(&ssn, 0,
sizeof(ssn));
3710 f.
proto = IPPROTO_TCP;
3719 SMTPTestInitConfig();
3728 "(msg:\"SMTP event handling\"; "
3730 "smtp.invalid_pipelined_sequence; "
3739 STREAM_TOSERVER | STREAM_START, request1,
3742 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3747 if (smtp_state == NULL) {
3748 printf(
"no smtp state: ");
3756 printf(
"sid 1 matched. It shouldn't match: ");
3761 STREAM_TOCLIENT, reply1, reply1_len);
3763 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3771 printf(
"sid 1 matched. It shouldn't match: ");
3776 STREAM_TOSERVER, request2, request2_len);
3778 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3786 printf(
"sid 1 didn't match. Should have matched: ");
3806 static int SMTPParserTest14(
void)
3813 static uint8_t welcome_reply[] = {
3814 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
3815 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3816 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
3817 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
3818 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
3821 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
3824 static uint8_t request1[] = {
3825 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3826 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3828 static uint32_t request1_len =
sizeof(request1);
3835 static uint8_t reply1[] = {
3836 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3837 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3838 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3839 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3840 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3841 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3842 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3843 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3844 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3845 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3846 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3847 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3848 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3849 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3850 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3852 static uint32_t reply1_len =
sizeof(reply1);
3855 static uint8_t request2[] = {
3856 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3857 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3858 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3861 static uint32_t request2_len =
sizeof(request2);
3863 static uint8_t reply2[] = {
3864 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3865 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3867 static uint32_t reply2_len =
sizeof(reply2);
3870 static uint8_t request3[] = {
3871 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3872 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3873 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3876 static uint32_t request3_len =
sizeof(request3);
3878 static uint8_t reply3[] = {
3879 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3880 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3882 static uint32_t reply3_len =
sizeof(reply3);
3885 static uint8_t request4[] = {
3886 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
3888 static uint32_t request4_len =
sizeof(request4);
3890 static uint8_t reply4[] = {
3891 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
3892 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
3893 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
3894 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
3895 0x4c, 0x46, 0x3e, 0x0d, 0x0a
3897 static uint32_t reply4_len =
sizeof(reply4);
3900 static uint64_t filesize = 133;
3901 static uint8_t request4_msg[] = {
3902 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
3903 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
3904 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3905 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
3906 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
3907 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
3908 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
3909 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3910 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
3911 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
3912 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
3913 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
3914 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
3915 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
3916 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
3917 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
3918 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
3919 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
3920 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
3921 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
3922 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
3923 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
3924 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3925 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
3926 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
3927 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
3928 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
3929 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
3930 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
3931 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3932 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
3933 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3934 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3935 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
3936 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3937 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3938 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3939 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3940 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
3941 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
3942 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
3943 0x41, 0x3D, 0x3D, 0x0D,0x0A };
3944 static uint32_t request4_msg_len =
sizeof(request4_msg);
3947 static uint8_t request4_end[] = {
3948 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
3950 static uint32_t request4_end_len =
sizeof(request4_end);
3952 static uint8_t reply4_end[] = {
3953 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3954 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
3955 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
3956 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
3957 0x46, 0x32, 0x0d, 0x0a
3959 static uint32_t reply4_end_len =
sizeof(reply4_end);
3962 static uint8_t request5[] = {
3963 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3965 static uint32_t request5_len =
sizeof(request5);
3967 static uint8_t reply5[] = {
3968 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3969 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3971 static uint32_t reply5_len =
sizeof(reply5);
3976 memset(&f, 0,
sizeof(f));
3977 memset(&ssn, 0,
sizeof(ssn));
3981 f.
proto = IPPROTO_TCP;
3985 SMTPTestInitConfig();
3989 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3991 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3995 if (smtp_state == NULL) {
3996 printf(
"no smtp state: ");
4001 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4006 STREAM_TOSERVER, request1, request1_len);
4008 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4014 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4020 STREAM_TOCLIENT, reply1, reply1_len);
4022 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4026 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4027 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4033 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4039 STREAM_TOSERVER, request2, request2_len);
4041 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4047 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4053 STREAM_TOCLIENT, reply2, reply2_len);
4055 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4061 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4069 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4075 STREAM_TOSERVER, request3, request3_len);
4077 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4083 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4089 STREAM_TOCLIENT, reply3, reply3_len);
4091 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4096 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4102 SCMimeSmtpConfigDecodeBase64(1);
4103 SCMimeSmtpConfigDecodeQuoted(1);
4107 STREAM_TOSERVER, request4, request4_len);
4109 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4116 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4122 STREAM_TOCLIENT, reply4, reply4_len);
4124 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4130 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4136 STREAM_TOSERVER, request4_msg, request4_msg_len);
4138 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4146 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4152 STREAM_TOSERVER, request4_end, request4_end_len);
4154 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4162 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4171 if (files != NULL && files->
head != NULL) {
4174 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4175 printf(
"smtp-mime file name is incorrect");
4179 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4182 static uint8_t org_binary[] = {
4183 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4184 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4186 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4187 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4188 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4189 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4190 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4191 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4192 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4193 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4194 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4195 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4197 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4198 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4199 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4202 org_binary,
sizeof(org_binary)) != 1)
4204 printf(
"smtp-mime file data incorrect\n");
4211 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4213 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4218 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4224 STREAM_TOSERVER, request5, request5_len);
4226 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4232 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4238 STREAM_TOCLIENT, reply5, reply5_len);
4240 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4245 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);