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(
874 if (line->
len >= 4) {
876 if (line->
buf[3] !=
'-') {
880 if (line->
buf[3] ==
'-') {
902 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
921 SCLogDebug(
"unable to match reply with request");
936 SMTPTransactionComplete(state);
957 SMTPTransactionComplete(state);
971 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
990 while (i < line->
len) {
991 if (line->
buf[i] !=
' ') {
1000 if (i == line->
len) {
1007 if (line->
len - i <
len) {
1010 memcpy(strbuf, line->
buf + i,
len);
1020 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1021 uint8_t **target, uint16_t *target_len)
1023 int i = prefix_len + 1;
1025 while (i < line->
len) {
1026 if (line->
buf[i] !=
' ') {
1035 while (spc_i < line->
len) {
1036 if (line->
buf[spc_i] ==
' ') {
1043 if (*target == NULL)
1045 memcpy(*target, line->
buf + i, spc_i - i);
1046 (*target)[spc_i - i] =
'\0';
1047 if (spc_i - i > UINT16_MAX) {
1048 *target_len = UINT16_MAX;
1051 *target_len = (uint16_t)(spc_i - i);
1063 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1072 return SMTPParseCommandWithParam(
1079 uint16_t rcptto_len;
1081 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1084 rcptto_str->
str = rcptto;
1085 rcptto_str->
len = rcptto_len;
1101 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1103 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1111 #define rawmsgname "rawmsg"
1130 static int SMTPProcessRequest(
1138 frame->
len = (int64_t)line->
len;
1155 tx = SMTPTransactionCreate(state);
1167 if (frame != NULL && state->
curr_tx) {
1170 tx->
tx_data.updated_ts =
true;
1183 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1185 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1211 if (data_frame == NULL) {
1212 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1221 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1222 r = SMTPParseCommandBDAT(state, line);
1228 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1229 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1230 r = SMTPParseCommandHELO(state, line);
1235 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1236 r = SMTPParseCommandMAILFROM(state, line);
1241 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1242 r = SMTPParseCommandRCPTTO(state, line);
1247 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1257 if (SMTPInsertCommandIntoCommandBuffer(state->
current_command, state) == -1) {
1266 return SMTPProcessCommandDATA(state, tx, f, line);
1269 return SMTPProcessCommandBDAT(state, line);
1278 static inline void ResetLine(
SMTPLine *line)
1307 static int SMTPPreProcessCommands(
1319 bool line_complete =
false;
1320 const int32_t input_len = input->
len;
1322 for (int32_t i = 0; i < input_len; i++) {
1324 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1330 line_complete =
true;
1331 }
else if (input->
buf[
offset + i] == 0x0a) {
1334 line_complete =
true;
1337 if (line_complete || (i == input_len - 1)) {
1344 SCLogDebug(
"Possible boundary, yield to GetLine");
1348 int32_t total_consumed =
offset + i + 1;
1349 int32_t current_line_consumed = total_consumed - input->
consumed;
1354 if (line->
len < 0) {
1359 input->
len -= current_line_consumed;
1361 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1364 line_complete =
false;
1382 static AppLayerResult SMTPParse(uint8_t direction,
Flow *f,
SMTPState *state,
1387 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1388 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1390 if (input_buf == NULL &&
1395 }
else if (input_buf == NULL || input_len == 0) {
1399 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1400 SMTPLine line = { NULL, 0, 0,
false };
1403 if (direction == 0) {
1407 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1411 }
else if (ret < 0) {
1415 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1416 while (res.status == 0) {
1417 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1438 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1442 }
else if (ret < 0) {
1446 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1448 if (res.status == 1)
1452 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1453 while (res.status == 0) {
1454 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1464 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1466 if (res.status == 1)
1474 StreamSlice stream_slice,
void *local_data)
1479 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1483 StreamSlice stream_slice,
void *local_data)
1488 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1503 if (smtp_state->
cmds == NULL) {
1532 static void *SMTPLocalStorageAlloc(
void)
1541 if (td->
pmq == NULL) {
1554 static void SMTPLocalStorageFree(
void *ptr)
1558 if (td->
pmq != NULL) {
1578 if (tx->
tx_data.events != NULL)
1581 if (tx->
tx_data.de_state != NULL)
1590 SMTPStringFree(
str);
1601 static void SMTPStateFree(
void *p)
1605 if (smtp_state->
cmds != NULL) {
1609 if (smtp_state->
helo) {
1614 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1616 SMTPTransactionFree(tx, smtp_state);
1622 static void SMTPSetMpmState(
void)
1625 if (
unlikely(smtp_mpm_ctx == NULL)) {
1642 static void SMTPFreeMpmState(
void)
1644 if (smtp_mpm_ctx != NULL) {
1647 smtp_mpm_ctx = NULL;
1651 static int SMTPStateGetEventInfo(
1652 const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
1655 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
1661 static int SMTPStateGetEventInfoById(
1662 uint8_t event_id,
const char **event_name, AppLayerEventType *event_type)
1665 if (*event_name == NULL) {
1667 "smtp's enum map table.",
1673 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
1678 static AppProto SMTPServerProbingParser(
1679 Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1686 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1690 if (input[3] !=
' ' && input[3] !=
'-') {
1696 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1707 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1718 static int SMTPRegisterPatternsForProtocolDetection(
void)
1721 "EHLO", 4, 0, STREAM_TOSERVER) < 0)
1726 "HELO", 4, 0, STREAM_TOSERVER) < 0)
1731 "QUIT", 4, 0, STREAM_TOSERVER) < 0)
1736 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1739 NULL, SMTPServerProbingParser);
1745 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1750 if (tx_id < tx->tx_id)
1752 else if (tx_id > tx->
tx_id)
1755 if (tx == smtp_state->
curr_tx)
1758 SMTPTransactionFree(tx, state);
1766 static uint64_t SMTPStateGetTxCnt(
void *state)
1777 static void *SMTPStateGetTx(
void *state, uint64_t
id)
1783 if (smtp_state->
curr_tx == NULL)
1789 if (tx->
tx_id ==
id)
1796 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
1802 static AppLayerGetFileState SMTPGetTxFiles(
void *txv, uint8_t direction)
1807 if (direction & STREAM_TOSERVER) {
1819 static AppLayerStateData *SMTPGetStateData(
void *vstate)
1829 static AppLayerGetTxIterTuple SMTPGetTxIterator(
const uint8_t ipproto,
const AppProto alproto,
1833 AppLayerGetTxIterTuple no_tuple = { NULL, 0,
false };
1836 if (state->
un.
ptr == NULL) {
1842 while (tx_ptr->
tx_id < min_tx_id) {
1848 if (tx_ptr->
tx_id >= max_tx_id) {
1852 AppLayerGetTxIterTuple tuple = {
1855 .has_next = (state->
un.
ptr != NULL),
1868 const char *proto_name =
"smtp";
1872 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
1875 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
1884 SMTPParseClientRecord);
1886 SMTPParseServerRecord);
1892 SMTPLocalStorageFree);
1904 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
1906 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
1931 static void SMTPTestInitConfig(
void)
1945 static int SMTPParserTest01(
void)
1952 uint8_t welcome_reply[] = {
1953 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
1954 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1955 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
1956 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
1957 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
1960 uint32_t welcome_reply_len =
sizeof(welcome_reply);
1963 uint8_t request1[] = {
1964 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
1965 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
1966 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
1968 uint32_t request1_len =
sizeof(request1);
1975 uint8_t reply1[] = {
1976 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
1977 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1978 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
1979 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
1980 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
1981 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
1982 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
1983 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
1984 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
1985 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
1986 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
1987 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
1988 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
1989 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
1990 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
1991 0x44, 0x45, 0x53, 0x0d, 0x0a
1993 uint32_t reply1_len =
sizeof(reply1);
1996 uint8_t request2[] = {
1997 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2000 uint32_t request2_len =
sizeof(request2);
2002 uint8_t reply2[] = {
2003 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2004 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2005 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2006 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2008 uint32_t reply2_len =
sizeof(reply2);
2013 memset(&f, 0,
sizeof(f));
2014 memset(&ssn, 0,
sizeof(ssn));
2018 f.
proto = IPPROTO_TCP;
2022 SMTPTestInitConfig();
2025 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2027 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2031 if (smtp_state == NULL) {
2032 printf(
"no smtp state: ");
2037 printf(
"smtp parser in inconsistent state\n");
2042 STREAM_TOSERVER, request1, request1_len);
2044 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2050 printf(
"smtp parser in inconsistent state\n");
2055 STREAM_TOCLIENT, reply1, reply1_len);
2057 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2062 printf(
"smtp parser in inconsistent state\n");
2067 STREAM_TOSERVER, request2, request2_len);
2069 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2075 printf(
"smtp parser in inconsistent state\n");
2080 STREAM_TOCLIENT, reply2, reply2_len);
2082 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2088 printf(
"smtp parser in inconsistent state\n");
2108 static int SMTPParserTest02(
void)
2115 uint8_t welcome_reply[] = {
2116 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2117 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2118 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2119 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2120 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2123 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2126 uint8_t request1[] = {
2127 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2128 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2130 uint32_t request1_len =
sizeof(request1);
2137 uint8_t reply1[] = {
2138 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2139 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2140 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2141 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2142 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2143 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2144 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2145 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2146 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2147 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2148 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2149 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2150 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2151 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2152 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2154 uint32_t reply1_len =
sizeof(reply1);
2157 uint8_t request2[] = {
2158 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2159 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2160 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2163 uint32_t request2_len =
sizeof(request2);
2165 uint8_t reply2[] = {
2166 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2167 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2169 uint32_t reply2_len =
sizeof(reply2);
2172 uint8_t request3[] = {
2173 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2174 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2175 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2178 uint32_t request3_len =
sizeof(request3);
2180 uint8_t reply3[] = {
2181 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2182 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2184 uint32_t reply3_len =
sizeof(reply3);
2187 uint8_t request4[] = {
2188 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2190 uint32_t request4_len =
sizeof(request4);
2192 uint8_t reply4[] = {
2193 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2194 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2195 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2196 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2197 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2199 uint32_t reply4_len =
sizeof(reply4);
2202 uint8_t request5_1[] = {
2203 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2204 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2205 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2207 uint32_t request5_1_len =
sizeof(request5_1);
2209 uint8_t request5_2[] = {
2210 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2211 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2212 0x6f, 0x6d, 0x0d, 0x0a
2214 uint32_t request5_2_len =
sizeof(request5_2);
2216 uint8_t request5_3[] = {
2219 uint32_t request5_3_len =
sizeof(request5_3);
2221 uint8_t request5_4[] = {
2222 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2223 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2224 0x6c, 0x31, 0x0d, 0x0a
2226 uint32_t request5_4_len =
sizeof(request5_4);
2228 uint8_t request5_5[] = {
2231 uint32_t request5_5_len =
sizeof(request5_5);
2233 uint8_t reply5[] = {
2234 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2235 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2236 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2237 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2238 0x46, 0x32, 0x0d, 0x0a
2240 uint32_t reply5_len =
sizeof(reply5);
2243 uint8_t request6[] = {
2244 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2245 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2246 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2249 uint32_t request6_len =
sizeof(request6);
2251 uint8_t reply6[] = {
2252 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2253 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2255 uint32_t reply6_len =
sizeof(reply6);
2258 uint8_t request7[] = {
2259 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2260 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2261 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2264 uint32_t request7_len =
sizeof(request7);
2266 uint8_t reply7[] = {
2267 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2268 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2270 uint32_t reply7_len =
sizeof(reply7);
2273 uint8_t request8[] = {
2274 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2276 uint32_t request8_len =
sizeof(request8);
2278 uint8_t reply8[] = {
2279 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2280 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2281 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2282 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2283 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2285 uint32_t reply8_len =
sizeof(reply8);
2288 uint8_t request9_1[] = {
2289 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2290 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2291 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2293 uint32_t request9_1_len =
sizeof(request9_1);
2295 uint8_t request9_2[] = {
2296 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2297 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2298 0x6f, 0x6d, 0x0d, 0x0a
2300 uint32_t request9_2_len =
sizeof(request9_2);
2302 uint8_t request9_3[] = {
2305 uint32_t request9_3_len =
sizeof(request9_3);
2307 uint8_t request9_4[] = {
2308 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2309 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2310 0x6c, 0x32, 0x0d, 0x0a
2312 uint32_t request9_4_len =
sizeof(request9_4);
2314 uint8_t request9_5[] = {
2317 uint32_t request9_5_len =
sizeof(request9_5);
2319 uint8_t reply9[] = {
2320 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2321 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2322 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2323 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2324 0x46, 0x32, 0x0d, 0x0a
2326 uint32_t reply9_len =
sizeof(reply9);
2329 uint8_t request10[] = {
2330 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2332 uint32_t request10_len =
sizeof(request10);
2334 uint8_t reply10[] = {
2335 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2336 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2338 uint32_t reply10_len =
sizeof(reply10);
2343 memset(&f, 0,
sizeof(f));
2344 memset(&ssn, 0,
sizeof(ssn));
2348 f.
proto = IPPROTO_TCP;
2352 SMTPTestInitConfig();
2355 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2357 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2361 if (smtp_state == NULL) {
2362 printf(
"no smtp state: ");
2367 printf(
"smtp parser in inconsistent state\n");
2372 STREAM_TOSERVER, request1, request1_len);
2374 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2380 printf(
"smtp parser in inconsistent state\n");
2385 STREAM_TOCLIENT, reply1, reply1_len);
2387 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2392 printf(
"smtp parser in inconsistent state\n");
2397 STREAM_TOSERVER, request2, request2_len);
2399 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2405 printf(
"smtp parser in inconsistent state\n");
2410 STREAM_TOCLIENT, reply2, reply2_len);
2412 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2417 printf(
"smtp parser in inconsistent state\n");
2422 STREAM_TOSERVER, request3, request3_len);
2424 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2430 printf(
"smtp parser in inconsistent state\n");
2435 STREAM_TOCLIENT, reply3, reply3_len);
2437 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2442 printf(
"smtp parser in inconsistent state\n");
2447 STREAM_TOSERVER, request4, request4_len);
2449 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2455 printf(
"smtp parser in inconsistent state\n");
2460 STREAM_TOCLIENT, reply4, reply4_len);
2462 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2468 printf(
"smtp parser in inconsistent state\n");
2473 STREAM_TOSERVER, request5_1, request5_1_len);
2475 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2482 printf(
"smtp parser in inconsistent state\n");
2487 STREAM_TOSERVER, request5_2, request5_2_len);
2489 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2496 printf(
"smtp parser in inconsistent state\n");
2501 STREAM_TOSERVER, request5_3, request5_3_len);
2503 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2510 printf(
"smtp parser in inconsistent state\n");
2515 STREAM_TOSERVER, request5_4, request5_4_len);
2517 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2524 printf(
"smtp parser in inconsistent state\n");
2529 STREAM_TOSERVER, request5_5, request5_5_len);
2531 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2537 printf(
"smtp parser in inconsistent state\n");
2542 STREAM_TOCLIENT, reply5, reply5_len);
2544 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2549 printf(
"smtp parser in inconsistent state\n");
2554 STREAM_TOSERVER, request6, request6_len);
2556 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2562 printf(
"smtp parser in inconsistent state\n");
2567 STREAM_TOCLIENT, reply6, reply6_len);
2569 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2574 printf(
"smtp parser in inconsistent state\n");
2579 STREAM_TOSERVER, request7, request7_len);
2581 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2587 printf(
"smtp parser in inconsistent state\n");
2592 STREAM_TOCLIENT, reply7, reply7_len);
2594 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2599 printf(
"smtp parser in inconsistent state\n");
2604 STREAM_TOSERVER, request8, request8_len);
2606 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2612 printf(
"smtp parser in inconsistent state\n");
2617 STREAM_TOCLIENT, reply8, reply8_len);
2619 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2625 printf(
"smtp parser in inconsistent state\n");
2630 STREAM_TOSERVER, request9_1, request9_1_len);
2632 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2639 printf(
"smtp parser in inconsistent state\n");
2644 STREAM_TOSERVER, request9_2, request9_2_len);
2646 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2653 printf(
"smtp parser in inconsistent state\n");
2658 STREAM_TOSERVER, request9_3, request9_3_len);
2660 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2667 printf(
"smtp parser in inconsistent state\n");
2672 STREAM_TOSERVER, request9_4, request9_4_len);
2674 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2681 printf(
"smtp parser in inconsistent state\n");
2686 STREAM_TOSERVER, request9_5, request9_5_len);
2688 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2694 printf(
"smtp parser in inconsistent state\n");
2699 STREAM_TOCLIENT, reply9, reply9_len);
2701 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2706 printf(
"smtp parser in inconsistent state\n");
2711 STREAM_TOSERVER, request10, request10_len);
2713 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2719 printf(
"smtp parser in inconsistent state\n");
2724 STREAM_TOCLIENT, reply10, reply10_len);
2726 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2731 printf(
"smtp parser in inconsistent state\n");
2747 static int SMTPParserTest03(
void)
2754 uint8_t welcome_reply[] = {
2755 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2756 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2757 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2758 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2759 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2760 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2762 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2765 uint8_t request1[] = {
2766 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2767 0x2e, 0x63, 0x6f, 0x6d, 0x0a
2769 uint32_t request1_len =
sizeof(request1);
2779 uint8_t reply1[] = {
2780 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2781 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2782 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2783 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2784 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2785 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2786 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2787 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2788 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2789 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2790 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2791 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2792 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2793 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2794 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2795 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2796 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2798 uint32_t reply1_len =
sizeof(reply1);
2805 uint8_t request2[] = {
2806 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2807 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2808 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2809 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
2810 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2811 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2812 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
2813 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
2814 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
2816 uint32_t request2_len =
sizeof(request2);
2821 uint8_t reply2[] = {
2822 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2823 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
2824 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
2825 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
2826 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
2827 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
2828 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
2829 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
2832 uint32_t reply2_len =
sizeof(reply2);
2837 memset(&f, 0,
sizeof(f));
2838 memset(&ssn, 0,
sizeof(ssn));
2842 f.
proto = IPPROTO_TCP;
2846 SMTPTestInitConfig();
2849 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2851 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2855 if (smtp_state == NULL) {
2856 printf(
"no smtp state: ");
2861 printf(
"smtp parser in inconsistent state\n");
2866 STREAM_TOSERVER, request1, request1_len);
2868 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2874 printf(
"smtp parser in inconsistent state\n");
2879 STREAM_TOCLIENT, reply1, reply1_len);
2881 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2887 printf(
"smtp parser in inconsistent state\n");
2892 STREAM_TOSERVER, request2, request2_len);
2894 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2904 printf(
"smtp parser in inconsistent state\n");
2909 STREAM_TOCLIENT, reply2, reply2_len);
2911 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2918 printf(
"smtp parser in inconsistent state\n");
2934 static int SMTPParserTest04(
void)
2941 uint8_t welcome_reply[] = {
2942 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2943 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2944 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2945 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2946 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2947 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2949 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2952 uint8_t request1[] = {
2953 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2954 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2955 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2956 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2957 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2958 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2960 uint32_t request1_len =
sizeof(request1);
2965 memset(&f, 0,
sizeof(f));
2966 memset(&ssn, 0,
sizeof(ssn));
2970 f.
proto = IPPROTO_TCP;
2974 SMTPTestInitConfig();
2977 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2979 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2983 if (smtp_state == NULL) {
2984 printf(
"no smtp state: ");
2989 printf(
"smtp parser in inconsistent state\n");
2994 STREAM_TOSERVER, request1, request1_len);
2996 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3002 printf(
"smtp parser in inconsistent state\n");
3018 static int SMTPParserTest05(
void)
3025 uint8_t welcome_reply[] = {
3026 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3027 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3028 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3029 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3030 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3031 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3033 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3036 uint8_t request1[] = {
3037 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3038 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3040 uint32_t request1_len =
sizeof(request1);
3050 uint8_t reply1[] = {
3051 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3052 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3053 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3054 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3055 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3056 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3057 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3058 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3059 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3060 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3061 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3062 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3063 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3064 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3065 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3066 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3067 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3069 uint32_t reply1_len =
sizeof(reply1);
3072 uint8_t request2[] = {
3073 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3076 uint32_t request2_len =
sizeof(request2);
3078 uint8_t reply2[] = {
3079 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3080 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3081 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3082 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3083 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3086 uint32_t reply2_len =
sizeof(reply2);
3089 uint8_t request3[] = {
3090 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3093 uint32_t request3_len =
sizeof(request3);
3095 uint8_t reply3[] = {
3096 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3097 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3099 uint32_t reply3_len =
sizeof(reply3);
3104 memset(&f, 0,
sizeof(f));
3105 memset(&ssn, 0,
sizeof(ssn));
3109 f.
proto = IPPROTO_TCP;
3113 SMTPTestInitConfig();
3116 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3118 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3122 if (smtp_state == NULL) {
3123 printf(
"no smtp state: ");
3128 printf(
"smtp parser in inconsistent state\n");
3133 STREAM_TOSERVER, request1, request1_len);
3135 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3141 printf(
"smtp parser in inconsistent state\n");
3146 STREAM_TOCLIENT, reply1, reply1_len);
3148 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3154 printf(
"smtp parser in inconsistent state\n");
3159 STREAM_TOSERVER, request2, request2_len);
3161 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3168 printf(
"smtp parser in inconsistent state\n");
3173 STREAM_TOCLIENT, reply2, reply2_len);
3175 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3181 printf(
"smtp parser in inconsistent state\n");
3193 STREAM_TOSERVER, request3, request3_len);
3195 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3202 printf(
"smtp parser in inconsistent state\n");
3207 STREAM_TOCLIENT, reply3, reply3_len);
3209 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3215 printf(
"smtp parser in inconsistent state\n");
3231 static int SMTPParserTest06(
void)
3237 uint8_t welcome_reply[] = {
3238 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3239 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3240 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3241 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3242 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3243 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3244 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3245 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3246 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3247 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3248 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3249 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3250 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3251 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3252 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3253 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3254 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3255 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3256 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3257 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3258 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3259 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3260 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3261 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3262 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3263 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3264 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3265 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3266 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3267 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3268 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3269 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3270 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3271 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3272 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3273 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3274 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3275 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3276 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3278 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3280 uint8_t request1[] = {
3281 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3282 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3283 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3284 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3287 uint32_t request1_len =
sizeof(request1);
3289 uint8_t reply1[] = {
3290 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3291 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3292 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3293 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3294 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3295 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3296 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3297 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3298 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3299 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3300 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3301 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3302 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3303 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3304 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3305 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3306 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3307 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3308 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3309 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3310 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3313 uint32_t reply1_len =
sizeof(reply1);
3316 uint8_t request2[] = {
3317 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3318 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3319 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3322 uint32_t request2_len =
sizeof(request2);
3324 uint8_t reply2[] = {
3325 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3326 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3328 uint32_t reply2_len =
sizeof(reply2);
3331 uint8_t request3[] = {
3332 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3333 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3334 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3337 uint32_t request3_len =
sizeof(request3);
3339 uint8_t reply3[] = {
3340 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3341 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3343 uint32_t reply3_len =
sizeof(reply3);
3346 uint8_t request4[] = {
3347 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3350 uint32_t request4_len =
sizeof(request4);
3352 uint8_t request5[] = {
3353 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3354 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3355 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3356 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3358 uint32_t request5_len =
sizeof(request5);
3360 uint8_t request6[] = {
3361 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3362 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3365 uint32_t request6_len =
sizeof(request6);
3370 memset(&f, 0,
sizeof(f));
3371 memset(&ssn, 0,
sizeof(ssn));
3375 f.
proto = IPPROTO_TCP;
3379 SMTPTestInitConfig();
3382 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3384 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3388 if (smtp_state == NULL) {
3389 printf(
"no smtp state: ");
3394 printf(
"smtp parser in inconsistent state\n");
3399 STREAM_TOSERVER, request1, request1_len);
3401 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3407 printf(
"smtp parser in inconsistent state\n");
3412 STREAM_TOCLIENT, reply1, reply1_len);
3414 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3419 printf(
"smtp parser in inconsistent state\n");
3424 STREAM_TOSERVER, request2, request2_len);
3426 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3432 printf(
"smtp parser in inconsistent state\n");
3437 STREAM_TOCLIENT, reply2, reply2_len);
3439 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3444 printf(
"smtp parser in inconsistent state\n");
3449 STREAM_TOSERVER, request3, request3_len);
3451 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3457 printf(
"smtp parser in inconsistent state\n");
3462 STREAM_TOCLIENT, reply3, reply3_len);
3464 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3469 printf(
"smtp parser in inconsistent state\n");
3474 STREAM_TOSERVER, request4, request4_len);
3476 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3484 printf(
"smtp parser in inconsistent state\n");
3489 STREAM_TOSERVER, request5, request5_len);
3491 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3498 printf(
"smtp parser in inconsistent state\n");
3503 STREAM_TOSERVER, request6, request6_len);
3505 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3511 printf(
"smtp parser in inconsistent state\n");
3524 static int SMTPParserTest12(
void)
3538 uint8_t request1[] = {
3539 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3540 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3542 int32_t request1_len =
sizeof(request1);
3546 uint8_t reply1[] = {
3547 0x31, 0x38, 0x38, 0x0d, 0x0a,
3549 uint32_t reply1_len =
sizeof(reply1);
3553 memset(&th_v, 0,
sizeof(th_v));
3554 memset(&f, 0,
sizeof(f));
3555 memset(&ssn, 0,
sizeof(ssn));
3561 f.
proto = IPPROTO_TCP;
3570 SMTPTestInitConfig();
3579 "(msg:\"SMTP event handling\"; "
3580 "app-layer-event: smtp.invalid_reply; "
3589 STREAM_TOSERVER | STREAM_START, request1,
3592 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3597 if (smtp_state == NULL) {
3598 printf(
"no smtp state: ");
3606 printf(
"sid 1 matched. It shouldn't match: ");
3611 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3614 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3622 printf(
"sid 1 didn't match. Should have matched: ");
3643 static int SMTPParserTest13(
void)
3657 uint8_t request1[] = {
3658 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3659 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3661 int32_t request1_len =
sizeof(request1);
3665 uint8_t reply1[] = {
3666 0x32, 0x35, 0x30, 0x0d, 0x0a,
3668 uint32_t reply1_len =
sizeof(reply1);
3675 uint8_t request2[] = {
3676 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3677 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3678 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3679 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3680 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3681 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3682 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3683 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3686 uint32_t request2_len =
sizeof(request2);
3690 memset(&th_v, 0,
sizeof(th_v));
3691 memset(&f, 0,
sizeof(f));
3692 memset(&ssn, 0,
sizeof(ssn));
3698 f.
proto = IPPROTO_TCP;
3707 SMTPTestInitConfig();
3716 "(msg:\"SMTP event handling\"; "
3718 "smtp.invalid_pipelined_sequence; "
3727 STREAM_TOSERVER | STREAM_START, request1,
3730 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3735 if (smtp_state == NULL) {
3736 printf(
"no smtp state: ");
3744 printf(
"sid 1 matched. It shouldn't match: ");
3749 STREAM_TOCLIENT, reply1, reply1_len);
3751 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3759 printf(
"sid 1 matched. It shouldn't match: ");
3764 STREAM_TOSERVER, request2, request2_len);
3766 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3774 printf(
"sid 1 didn't match. Should have matched: ");
3798 static int SMTPParserTest14(
void)
3805 static uint8_t welcome_reply[] = {
3806 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
3807 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3808 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
3809 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
3810 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
3813 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
3816 static uint8_t request1[] = {
3817 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3818 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3820 static uint32_t request1_len =
sizeof(request1);
3827 static uint8_t reply1[] = {
3828 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3829 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3830 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3831 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3832 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3833 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3834 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3835 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3836 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3837 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3838 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3839 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3840 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3841 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3842 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3844 static uint32_t reply1_len =
sizeof(reply1);
3847 static uint8_t request2[] = {
3848 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3849 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3850 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3853 static uint32_t request2_len =
sizeof(request2);
3855 static uint8_t reply2[] = {
3856 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3857 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3859 static uint32_t reply2_len =
sizeof(reply2);
3862 static uint8_t request3[] = {
3863 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3864 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3865 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3868 static uint32_t request3_len =
sizeof(request3);
3870 static uint8_t reply3[] = {
3871 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3872 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3874 static uint32_t reply3_len =
sizeof(reply3);
3877 static uint8_t request4[] = {
3878 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
3880 static uint32_t request4_len =
sizeof(request4);
3882 static uint8_t reply4[] = {
3883 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
3884 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
3885 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
3886 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
3887 0x4c, 0x46, 0x3e, 0x0d, 0x0a
3889 static uint32_t reply4_len =
sizeof(reply4);
3892 static uint64_t filesize = 133;
3893 static uint8_t request4_msg[] = {
3894 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
3895 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
3896 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3897 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
3898 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
3899 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
3900 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
3901 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3902 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
3903 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
3904 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
3905 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
3906 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
3907 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
3908 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
3909 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
3910 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
3911 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
3912 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
3913 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
3914 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
3915 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
3916 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3917 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
3918 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
3919 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
3920 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
3921 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
3922 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
3923 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3924 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
3925 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3926 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3927 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
3928 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3929 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3930 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3931 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3932 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
3933 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
3934 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
3935 0x41, 0x3D, 0x3D, 0x0D,0x0A };
3936 static uint32_t request4_msg_len =
sizeof(request4_msg);
3939 static uint8_t request4_end[] = {
3940 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
3942 static uint32_t request4_end_len =
sizeof(request4_end);
3944 static uint8_t reply4_end[] = {
3945 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3946 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
3947 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
3948 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
3949 0x46, 0x32, 0x0d, 0x0a
3951 static uint32_t reply4_end_len =
sizeof(reply4_end);
3954 static uint8_t request5[] = {
3955 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3957 static uint32_t request5_len =
sizeof(request5);
3959 static uint8_t reply5[] = {
3960 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3961 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3963 static uint32_t reply5_len =
sizeof(reply5);
3968 memset(&f, 0,
sizeof(f));
3969 memset(&ssn, 0,
sizeof(ssn));
3973 f.
proto = IPPROTO_TCP;
3977 SMTPTestInitConfig();
3981 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3983 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3987 if (smtp_state == NULL) {
3988 printf(
"no smtp state: ");
3993 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3998 STREAM_TOSERVER, request1, request1_len);
4000 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4006 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4012 STREAM_TOCLIENT, reply1, reply1_len);
4014 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4018 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4019 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4025 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4031 STREAM_TOSERVER, request2, request2_len);
4033 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4039 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4045 STREAM_TOCLIENT, reply2, reply2_len);
4047 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4053 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4061 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4067 STREAM_TOSERVER, request3, request3_len);
4069 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4075 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4081 STREAM_TOCLIENT, reply3, reply3_len);
4083 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4088 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4094 SCMimeSmtpConfigDecodeBase64(1);
4095 SCMimeSmtpConfigDecodeQuoted(1);
4099 STREAM_TOSERVER, request4, request4_len);
4101 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4108 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4114 STREAM_TOCLIENT, reply4, reply4_len);
4116 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4122 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4128 STREAM_TOSERVER, request4_msg, request4_msg_len);
4130 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4138 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4144 STREAM_TOSERVER, request4_end, request4_end_len);
4146 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4154 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4163 if (files != NULL && files->
head != NULL) {
4166 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4167 printf(
"smtp-mime file name is incorrect");
4171 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4174 static uint8_t org_binary[] = {
4175 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4176 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4178 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4179 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4180 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4181 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4182 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4183 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4184 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4185 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4186 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4187 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4189 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4190 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4191 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4194 org_binary,
sizeof(org_binary)) != 1)
4196 printf(
"smtp-mime file data incorrect\n");
4203 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4205 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4210 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4216 STREAM_TOSERVER, request5, request5_len);
4218 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4224 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4230 STREAM_TOCLIENT, reply5, reply5_len);
4232 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4237 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);