59 #define FILEDATA_CONTENT_LIMIT 100000
61 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
63 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
66 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
68 #define SMTP_COMMAND_BUFFER_STEPS 5
75 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
77 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
79 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
81 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
87 #define SMTP_COMMAND_STARTTLS 1
88 #define SMTP_COMMAND_DATA 2
89 #define SMTP_COMMAND_BDAT 3
94 #define SMTP_COMMAND_DATA_MODE 4
96 #define SMTP_COMMAND_OTHER_CMD 5
97 #define SMTP_COMMAND_RSET 6
98 #define SMTP_COMMAND_QUIT 7
100 #define SMTP_COMMAND_BDAT_LAST 8
102 #define SMTP_DEFAULT_MAX_TX 256
105 #define SMTP_NO_TX_ID UINT64_MAX
181 static int SMTPGetFrameIdByName(
const char *frame_name)
190 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
210 static int SMTPStateGetStateIdByName(
const char *
name,
const uint8_t direction)
213 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
221 static const char *SMTPStateGetStateNameById(
const int id,
const uint8_t direction)
224 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
228 static inline void SMTPSetProgressTS(
SMTPTransaction *tx, uint8_t progress)
235 static inline void SMTPSetProgressTC(
SMTPTransaction *tx, uint8_t progress)
261 static bool SMTPTransactionRequestIsComplete(
const SMTPTransaction *tx)
271 #define SMTP_MPM mpm_default_matcher
273 static MpmCtx *smtp_mpm_ctx = NULL;
381 #define SCHEME_SUFFIX_LEN 3
389 static void SMTPConfigure(
void) {
393 uint32_t content_limit = 0;
394 uint32_t content_inspect_min_size = 0;
395 uint32_t content_inspect_window = 0;
398 if (config != NULL) {
409 SCMimeSmtpConfigDecodeBase64(val);
414 SCMimeSmtpConfigDecodeQuoted(val);
419 if (imval < 0 || imval > UINT32_MAX) {
420 FatalError(
"Invalid value for header-value-depth");
422 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
427 SCMimeSmtpConfigExtractUrls(val);
434 if (extract_urls_schemes) {
438 size_t scheme_len = strlen(scheme->
val);
440 FatalError(
"extract-urls-schemes entry '%s' is too long", scheme->
val);
442 if (scheme->
val[scheme_len - 1] !=
'/') {
445 int r = snprintf(tmp,
sizeof(tmp),
"%s://", scheme->
val);
446 if (r != (
int)scheme_len) {
447 FatalError(
"snprintf failure for SMTP url extraction scheme.");
451 FatalError(
"extract-urls-schemes entry SCStrdup failure.");
454 scheme->
val = new_val;
456 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
458 FatalError(
"Failed to add smtp extract url scheme");
464 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
469 SCMimeSmtpConfigLogUrlScheme(val);
476 SCMimeSmtpConfigBodyMd5(
false);
478 SCMimeSmtpConfigBodyMd5(
true);
479 }
else if (strcmp(strval,
"auto") != 0) {
490 if (strcasecmp(
"content-limit",
p->name) == 0) {
498 if (strcasecmp(
"content-inspect-min-size",
p->name) == 0) {
500 SCLogWarning(
"parsing content-inspect-min-size %s failed",
p->val);
506 if (strcasecmp(
"content-inspect-window",
p->name) == 0) {
508 SCLogWarning(
"parsing content-inspect-window %s failed",
p->val);
523 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
524 "options can't be enabled at the same time, "
525 "disabling raw extraction");
531 const char *
str = NULL;
544 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
575 if (tx->
tx_id == tx_id) {
578 if (tx->
tx_id > tx_id) {
602 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
604 }
else if (tx == NULL) {
605 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
607 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
617 if (tx == NULL || file == NULL) {
622 FlagDetectStateNewFile(tx);
654 if (direction == 0 &&
661 }
else if (direction == 1) {
665 if (frame != NULL && reply_tx != NULL) {
672 const uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
675 if (lf_idx == NULL) {
688 uint32_t o_consumed = input->
consumed;
689 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
697 line->
buf = input->
buf + o_consumed;
700 frame->
len = (int64_t)line->
len;
708 if (discard_till_lf) {
710 if (direction == 0) {
730 static int SMTPInsertCommandIntoCommandBuffer(
778 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
803 SMTPTransactionCompleteTS(tx);
810 static void SetMimeEvents(
SMTPState *state, uint32_t events)
816 if (events & MIME_ANOM_INVALID_BASE64) {
819 if (events & MIME_ANOM_INVALID_QP) {
822 if (events & MIME_ANOM_LONG_LINE) {
825 if (events & MIME_ANOM_LONG_ENC_LINE) {
828 if (events & MIME_ANOM_LONG_HEADER_NAME) {
831 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
834 if (events & MIME_ANOM_LONG_BOUNDARY) {
837 if (events & MIME_ANOM_LONG_FILENAME) {
855 static int SMTPProcessCommandDATA(
867 if (line->
len == 1 && line->
buf[0] ==
'.') {
885 SMTPTransactionCompleteTS(tx);
899 const uint8_t *filename = NULL;
900 uint16_t filename_len = 0;
905 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
907 SetMimeEvents(state, events);
909 case MimeSmtpFileOpen:
913 if (filename_len == 0) {
920 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
935 case MimeSmtpFileChunk:
944 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
955 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
960 case MimeSmtpFileClose:
963 SCLogDebug(
"FileCloseFile() failed: %d", ret);
971 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
980 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
985 static int SMTPProcessReply(
996 if (reply_tx != NULL) {
1001 if (line->
len < 3) {
1007 if (line->
len >= 4) {
1009 if (line->
buf[3] !=
'-') {
1013 if (line->
buf[3] ==
'-') {
1031 SCLogDebug(
"invalid reply code %02x %02x %02x", line->
buf[0], line->
buf[1], line->
buf[2]);
1035 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
1054 SCLogDebug(
"unable to match reply with request");
1069 SMTPTransactionComplete(reply_tx);
1092 SMTPTransactionCompleteTC(reply_tx);
1096 SMTPTransactionCompleteTC(reply_tx);
1101 SMTPTransactionComplete(reply_tx);
1106 SMTPTransactionComplete(reply_tx);
1120 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1135 static int SMTPParseCommandBDAT(
SMTPState *state,
const SMTPLine *line,
bool *last)
1142 while (i < line->
len) {
1143 if (line->
buf[i] !=
' ') {
1152 if (i == line->
len) {
1159 if (line->
len - i <
len) {
1162 memcpy(strbuf, line->
buf + i,
len);
1172 if (i < line->
len && line->
buf[i] !=
' ') {
1175 while (i < line->
len && line->
buf[i] ==
' ') {
1178 if (line->
len - i == 4 && SCMemcmpLowercase(
"last", line->
buf + i, 4) == 0) {
1180 }
else if (i != line->
len) {
1187 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1188 uint8_t **target, uint16_t *target_len)
1190 int i = prefix_len + 1;
1192 while (i < line->
len) {
1193 if (line->
buf[i] !=
' ') {
1202 while (spc_i < line->
len) {
1203 if (line->
buf[spc_i] ==
' ') {
1210 if (*target == NULL)
1212 memcpy(*target, line->
buf + i, spc_i - i);
1213 (*target)[spc_i - i] =
'\0';
1214 if (spc_i - i > UINT16_MAX) {
1215 *target_len = UINT16_MAX;
1218 *target_len = (uint16_t)(spc_i - i);
1230 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1239 return SMTPParseCommandWithParam(
1246 uint16_t rcptto_len;
1248 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1251 rcptto_str->
str = rcptto;
1252 rcptto_str->
len = rcptto_len;
1268 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1270 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1278 #define rawmsgname "rawmsg"
1297 static int SMTPProcessRequest(
1305 frame->
len = (int64_t)line->
len;
1321 const bool no_new_tx = NoNewTx(state, line);
1322 if ((state->
curr_tx == NULL && (state->
tx_cnt == 0 || !no_new_tx)) ||
1323 (SMTPTransactionRequestIsComplete(state->
curr_tx) && !no_new_tx)) {
1324 tx = SMTPTransactionCreate(state);
1336 if (frame != NULL && state->
curr_tx) {
1357 const bool is_rset = SCMemcmpLowercase(
"rset", line->
buf, 4) == 0;
1361 }
else if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1363 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1390 if (data_frame == NULL) {
1391 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1400 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1402 r = SMTPParseCommandBDAT(state, line, &last);
1415 SMTPTransactionCompleteTS(tx);
1418 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1419 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1420 r = SMTPParseCommandHELO(state, line);
1435 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1436 r = SMTPParseCommandMAILFROM(state, line);
1441 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1442 r = SMTPParseCommandRCPTTO(state, line);
1447 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1451 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1459 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1468 return SMTPProcessCommandDATA(state, tx, f, line);
1472 return SMTPProcessCommandBDAT(state, tx, line);
1481 static inline void ResetLine(
SMTPLine *line)
1490 static int SMTPPreProcessCommandBDAT(
1501 uint32_t consumed =
MIN((uint32_t)input->
len, remaining);
1503 line->
len = consumed;
1505 input->
len -= consumed;
1506 int ret = SMTPProcessRequest(state, f, input, line, slice);
1531 static int SMTPPreProcessCommands(
1540 return SMTPPreProcessCommandBDAT(state, f, slice, input, line);
1548 bool line_complete =
false;
1549 const int32_t input_len = input->
len;
1551 for (int32_t i = 0; i < input_len; i++) {
1553 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1559 line_complete =
true;
1560 }
else if (input->
buf[
offset + i] == 0x0a) {
1563 line_complete =
true;
1566 if (line_complete || (i == input_len - 1)) {
1573 SCLogDebug(
"Possible boundary, yield to GetLine");
1577 int32_t total_consumed =
offset + i + 1;
1578 int32_t current_line_consumed = total_consumed - input->
consumed;
1583 if (line->
len < 0) {
1588 input->
len -= current_line_consumed;
1590 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1593 line_complete =
false;
1616 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1617 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1619 if (input_buf == NULL &&
1624 }
else if (input_buf == NULL || input_len == 0) {
1628 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1629 SMTPLine line = { NULL, 0, 0,
false };
1632 if (direction == 0) {
1637 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1641 }
else if (ret < 0) {
1645 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1646 while (res.
status == 0) {
1647 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1667 if ((input.
len > 0) &&
1672 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1676 }
else if (ret < 0) {
1680 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1686 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1687 while (res.
status == 0) {
1688 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1698 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1713 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1722 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1737 if (smtp_state->
cmds == NULL) {
1772 static void *SMTPLocalStorageAlloc(
void)
1781 if (td->
pmq == NULL) {
1794 static void SMTPLocalStorageFree(
void *ptr)
1798 if (td->
pmq != NULL) {
1826 SMTPStringFree(
str);
1837 static void SMTPStateFree(
void *
p)
1841 if (smtp_state->
cmds != NULL) {
1848 if (smtp_state->
helo) {
1853 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1855 SMTPTransactionFree(tx, smtp_state);
1861 static void SMTPSetMpmState(
void)
1864 if (
unlikely(smtp_mpm_ctx == NULL)) {
1880 static void SMTPFreeMpmState(
void)
1882 if (smtp_mpm_ctx != NULL) {
1885 smtp_mpm_ctx = NULL;
1889 static int SMTPStateGetEventInfo(
1899 static int SMTPStateGetEventInfoById(
1903 if (*event_name == NULL) {
1905 "smtp's enum map table.",
1918 static AppProto SMTPClientProbingParserCheckPort(
1919 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1927 static AppProto SMTPServerProbingParser(
1928 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1935 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1939 if (input[3] !=
' ' && input[3] !=
'-') {
1945 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1956 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1967 static int SMTPRegisterPatternsForProtocolDetection(
void)
1970 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1974 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1978 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1983 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1986 NULL, SMTPServerProbingParser);
1992 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1997 if (tx_id < tx->tx_id)
1999 else if (tx_id > tx->
tx_id)
2002 if (tx == smtp_state->
curr_tx)
2005 SMTPTransactionFree(tx, state);
2013 static uint64_t SMTPStateGetTxCnt(
void *state)
2024 static void *SMTPStateGetTx(
void *state, uint64_t
id)
2030 if (smtp_state->
curr_tx == NULL)
2036 if (tx->
tx_id ==
id)
2043 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
2046 if (direction & STREAM_TOSERVER) {
2057 if (direction & STREAM_TOSERVER) {
2086 if (state->
un.
ptr == NULL) {
2092 while (tx_ptr->
tx_id < min_tx_id) {
2098 if (tx_ptr->
tx_id >= max_tx_id) {
2105 .has_next = (state->
un.
ptr != NULL),
2118 const char *proto_name =
"smtp";
2122 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
2125 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
2134 SMTPParseClientRecord);
2136 SMTPParseServerRecord);
2142 SMTPLocalStorageFree);
2155 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
2157 IPPROTO_TCP,
ALPROTO_SMTP, SMTPStateGetStateIdByName, SMTPStateGetStateNameById);
2159 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2184 static void SMTPTestInitConfig(
void)
2198 static int SMTPParserTest01(
void)
2205 uint8_t welcome_reply[] = {
2206 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2207 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2208 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2209 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2210 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2213 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2216 uint8_t request1[] = {
2217 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
2218 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
2219 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
2221 uint32_t request1_len =
sizeof(request1);
2228 uint8_t reply1[] = {
2229 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
2230 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2231 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
2232 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
2233 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
2234 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
2235 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
2236 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
2237 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
2238 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
2239 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2240 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2241 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2242 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2243 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2244 0x44, 0x45, 0x53, 0x0d, 0x0a
2246 uint32_t reply1_len =
sizeof(reply1);
2249 uint8_t request2[] = {
2250 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2253 uint32_t request2_len =
sizeof(request2);
2255 uint8_t reply2[] = {
2256 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2257 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2258 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2259 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2261 uint32_t reply2_len =
sizeof(reply2);
2266 memset(&f, 0,
sizeof(f));
2267 memset(&ssn, 0,
sizeof(ssn));
2271 f.
proto = IPPROTO_TCP;
2275 SMTPTestInitConfig();
2278 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2280 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2284 if (smtp_state == NULL) {
2285 printf(
"no smtp state: ");
2290 printf(
"smtp parser in inconsistent state\n");
2295 STREAM_TOSERVER, request1, request1_len);
2297 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2303 printf(
"smtp parser in inconsistent state\n");
2308 STREAM_TOCLIENT, reply1, reply1_len);
2310 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2315 printf(
"smtp parser in inconsistent state\n");
2320 STREAM_TOSERVER, request2, request2_len);
2322 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2328 printf(
"smtp parser in inconsistent state\n");
2333 STREAM_TOCLIENT, reply2, reply2_len);
2335 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2341 printf(
"smtp parser in inconsistent state\n");
2361 static int SMTPParserTest02(
void)
2368 uint8_t welcome_reply[] = {
2369 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2370 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2371 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2372 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2373 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2376 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2379 uint8_t request1[] = {
2380 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2381 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2383 uint32_t request1_len =
sizeof(request1);
2390 uint8_t reply1[] = {
2391 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2392 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2393 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2394 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2395 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2396 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2397 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2398 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2399 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2400 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2401 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2402 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2403 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2404 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2405 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2407 uint32_t reply1_len =
sizeof(reply1);
2410 uint8_t request2[] = {
2411 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2412 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2413 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2416 uint32_t request2_len =
sizeof(request2);
2418 uint8_t reply2[] = {
2419 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2420 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2422 uint32_t reply2_len =
sizeof(reply2);
2425 uint8_t request3[] = {
2426 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2427 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2428 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2431 uint32_t request3_len =
sizeof(request3);
2433 uint8_t reply3[] = {
2434 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2435 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2437 uint32_t reply3_len =
sizeof(reply3);
2440 uint8_t request4[] = {
2441 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2443 uint32_t request4_len =
sizeof(request4);
2445 uint8_t reply4[] = {
2446 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2447 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2448 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2449 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2450 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2452 uint32_t reply4_len =
sizeof(reply4);
2455 uint8_t request5_1[] = {
2456 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2457 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2458 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2460 uint32_t request5_1_len =
sizeof(request5_1);
2462 uint8_t request5_2[] = {
2463 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2464 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2465 0x6f, 0x6d, 0x0d, 0x0a
2467 uint32_t request5_2_len =
sizeof(request5_2);
2469 uint8_t request5_3[] = {
2472 uint32_t request5_3_len =
sizeof(request5_3);
2474 uint8_t request5_4[] = {
2475 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2476 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2477 0x6c, 0x31, 0x0d, 0x0a
2479 uint32_t request5_4_len =
sizeof(request5_4);
2481 uint8_t request5_5[] = {
2484 uint32_t request5_5_len =
sizeof(request5_5);
2486 uint8_t reply5[] = {
2487 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2488 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2489 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2490 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2491 0x46, 0x32, 0x0d, 0x0a
2493 uint32_t reply5_len =
sizeof(reply5);
2496 uint8_t request6[] = {
2497 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2498 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2499 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2502 uint32_t request6_len =
sizeof(request6);
2504 uint8_t reply6[] = {
2505 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2506 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2508 uint32_t reply6_len =
sizeof(reply6);
2511 uint8_t request7[] = {
2512 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2513 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2514 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2517 uint32_t request7_len =
sizeof(request7);
2519 uint8_t reply7[] = {
2520 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2521 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2523 uint32_t reply7_len =
sizeof(reply7);
2526 uint8_t request8[] = {
2527 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2529 uint32_t request8_len =
sizeof(request8);
2531 uint8_t reply8[] = {
2532 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2533 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2534 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2535 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2536 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2538 uint32_t reply8_len =
sizeof(reply8);
2541 uint8_t request9_1[] = {
2542 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2543 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2544 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2546 uint32_t request9_1_len =
sizeof(request9_1);
2548 uint8_t request9_2[] = {
2549 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2550 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2551 0x6f, 0x6d, 0x0d, 0x0a
2553 uint32_t request9_2_len =
sizeof(request9_2);
2555 uint8_t request9_3[] = {
2558 uint32_t request9_3_len =
sizeof(request9_3);
2560 uint8_t request9_4[] = {
2561 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2562 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2563 0x6c, 0x32, 0x0d, 0x0a
2565 uint32_t request9_4_len =
sizeof(request9_4);
2567 uint8_t request9_5[] = {
2570 uint32_t request9_5_len =
sizeof(request9_5);
2572 uint8_t reply9[] = {
2573 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2574 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2575 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2576 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2577 0x46, 0x32, 0x0d, 0x0a
2579 uint32_t reply9_len =
sizeof(reply9);
2582 uint8_t request10[] = {
2583 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2585 uint32_t request10_len =
sizeof(request10);
2587 uint8_t reply10[] = {
2588 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2589 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2591 uint32_t reply10_len =
sizeof(reply10);
2596 memset(&f, 0,
sizeof(f));
2597 memset(&ssn, 0,
sizeof(ssn));
2601 f.
proto = IPPROTO_TCP;
2605 SMTPTestInitConfig();
2608 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2610 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2614 if (smtp_state == NULL) {
2615 printf(
"no smtp state: ");
2620 printf(
"smtp parser in inconsistent state\n");
2625 STREAM_TOSERVER, request1, request1_len);
2627 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2633 printf(
"smtp parser in inconsistent state\n");
2638 STREAM_TOCLIENT, reply1, reply1_len);
2640 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2645 printf(
"smtp parser in inconsistent state\n");
2650 STREAM_TOSERVER, request2, request2_len);
2652 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2658 printf(
"smtp parser in inconsistent state\n");
2663 STREAM_TOCLIENT, reply2, reply2_len);
2665 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2670 printf(
"smtp parser in inconsistent state\n");
2675 STREAM_TOSERVER, request3, request3_len);
2677 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2683 printf(
"smtp parser in inconsistent state\n");
2688 STREAM_TOCLIENT, reply3, reply3_len);
2690 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2695 printf(
"smtp parser in inconsistent state\n");
2700 STREAM_TOSERVER, request4, request4_len);
2702 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2708 printf(
"smtp parser in inconsistent state\n");
2713 STREAM_TOCLIENT, reply4, reply4_len);
2715 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2721 printf(
"smtp parser in inconsistent state\n");
2726 STREAM_TOSERVER, request5_1, request5_1_len);
2728 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2735 printf(
"smtp parser in inconsistent state\n");
2740 STREAM_TOSERVER, request5_2, request5_2_len);
2742 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2749 printf(
"smtp parser in inconsistent state\n");
2754 STREAM_TOSERVER, request5_3, request5_3_len);
2756 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2763 printf(
"smtp parser in inconsistent state\n");
2768 STREAM_TOSERVER, request5_4, request5_4_len);
2770 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2777 printf(
"smtp parser in inconsistent state\n");
2782 STREAM_TOSERVER, request5_5, request5_5_len);
2784 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2790 printf(
"smtp parser in inconsistent state\n");
2795 STREAM_TOCLIENT, reply5, reply5_len);
2797 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2802 printf(
"smtp parser in inconsistent state\n");
2807 STREAM_TOSERVER, request6, request6_len);
2809 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2815 printf(
"smtp parser in inconsistent state\n");
2820 STREAM_TOCLIENT, reply6, reply6_len);
2822 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2827 printf(
"smtp parser in inconsistent state\n");
2832 STREAM_TOSERVER, request7, request7_len);
2834 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2840 printf(
"smtp parser in inconsistent state\n");
2845 STREAM_TOCLIENT, reply7, reply7_len);
2847 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2852 printf(
"smtp parser in inconsistent state\n");
2857 STREAM_TOSERVER, request8, request8_len);
2859 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2865 printf(
"smtp parser in inconsistent state\n");
2870 STREAM_TOCLIENT, reply8, reply8_len);
2872 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2878 printf(
"smtp parser in inconsistent state\n");
2883 STREAM_TOSERVER, request9_1, request9_1_len);
2885 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2892 printf(
"smtp parser in inconsistent state\n");
2897 STREAM_TOSERVER, request9_2, request9_2_len);
2899 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2906 printf(
"smtp parser in inconsistent state\n");
2911 STREAM_TOSERVER, request9_3, request9_3_len);
2913 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2920 printf(
"smtp parser in inconsistent state\n");
2925 STREAM_TOSERVER, request9_4, request9_4_len);
2927 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2934 printf(
"smtp parser in inconsistent state\n");
2939 STREAM_TOSERVER, request9_5, request9_5_len);
2941 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2947 printf(
"smtp parser in inconsistent state\n");
2952 STREAM_TOCLIENT, reply9, reply9_len);
2954 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2959 printf(
"smtp parser in inconsistent state\n");
2964 STREAM_TOSERVER, request10, request10_len);
2966 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2972 printf(
"smtp parser in inconsistent state\n");
2977 STREAM_TOCLIENT, reply10, reply10_len);
2979 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2984 printf(
"smtp parser in inconsistent state\n");
3000 static int SMTPParserTest03(
void)
3007 uint8_t welcome_reply[] = {
3008 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3009 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3010 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3011 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3012 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3013 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3015 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3018 uint8_t request1[] = {
3019 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3020 0x2e, 0x63, 0x6f, 0x6d, 0x0a
3022 uint32_t request1_len =
sizeof(request1);
3032 uint8_t reply1[] = {
3033 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3034 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3035 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3036 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3037 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3038 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3039 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3040 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3041 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3042 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3043 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3044 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3045 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3046 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3047 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3048 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3049 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3051 uint32_t reply1_len =
sizeof(reply1);
3058 uint8_t request2[] = {
3059 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3060 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3061 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3062 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3063 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3064 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3065 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3066 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
3067 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
3069 uint32_t request2_len =
sizeof(request2);
3074 uint8_t reply2[] = {
3075 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3076 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
3077 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
3078 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
3079 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
3080 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
3081 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
3082 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
3085 uint32_t reply2_len =
sizeof(reply2);
3090 memset(&f, 0,
sizeof(f));
3091 memset(&ssn, 0,
sizeof(ssn));
3095 f.
proto = IPPROTO_TCP;
3099 SMTPTestInitConfig();
3102 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3104 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3108 if (smtp_state == NULL) {
3109 printf(
"no smtp state: ");
3114 printf(
"smtp parser in inconsistent state\n");
3119 STREAM_TOSERVER, request1, request1_len);
3121 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3127 printf(
"smtp parser in inconsistent state\n");
3132 STREAM_TOCLIENT, reply1, reply1_len);
3134 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3140 printf(
"smtp parser in inconsistent state\n");
3145 STREAM_TOSERVER, request2, request2_len);
3147 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3157 printf(
"smtp parser in inconsistent state\n");
3162 STREAM_TOCLIENT, reply2, reply2_len);
3164 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3171 printf(
"smtp parser in inconsistent state\n");
3187 static int SMTPParserTest04(
void)
3194 uint8_t welcome_reply[] = {
3195 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3196 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3197 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3198 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3199 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3200 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3202 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3205 uint8_t request1[] = {
3206 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3207 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3208 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3209 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3210 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3211 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3213 uint32_t request1_len =
sizeof(request1);
3218 memset(&f, 0,
sizeof(f));
3219 memset(&ssn, 0,
sizeof(ssn));
3223 f.
proto = IPPROTO_TCP;
3227 SMTPTestInitConfig();
3230 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3232 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3236 if (smtp_state == NULL) {
3237 printf(
"no smtp state: ");
3242 printf(
"smtp parser in inconsistent state\n");
3247 STREAM_TOSERVER, request1, request1_len);
3249 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3255 printf(
"smtp parser in inconsistent state\n");
3271 static int SMTPParserTest05(
void)
3278 uint8_t welcome_reply[] = {
3279 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3280 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3281 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3282 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3283 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3284 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3286 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3289 uint8_t request1[] = {
3290 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3291 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3293 uint32_t request1_len =
sizeof(request1);
3303 uint8_t reply1[] = {
3304 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3305 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3306 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3307 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3308 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3309 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3310 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3311 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3312 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3313 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3314 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3315 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3316 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3317 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3318 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3319 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3320 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3322 uint32_t reply1_len =
sizeof(reply1);
3325 uint8_t request2[] = {
3326 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3329 uint32_t request2_len =
sizeof(request2);
3331 uint8_t reply2[] = {
3332 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3333 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3334 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3335 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3336 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3339 uint32_t reply2_len =
sizeof(reply2);
3342 uint8_t request3[] = {
3343 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3346 uint32_t request3_len =
sizeof(request3);
3348 uint8_t reply3[] = {
3349 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3350 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3352 uint32_t reply3_len =
sizeof(reply3);
3357 memset(&f, 0,
sizeof(f));
3358 memset(&ssn, 0,
sizeof(ssn));
3362 f.
proto = IPPROTO_TCP;
3366 SMTPTestInitConfig();
3369 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3371 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3375 if (smtp_state == NULL) {
3376 printf(
"no smtp state: ");
3381 printf(
"smtp parser in inconsistent state\n");
3386 STREAM_TOSERVER, request1, request1_len);
3388 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3394 printf(
"smtp parser in inconsistent state\n");
3399 STREAM_TOCLIENT, reply1, reply1_len);
3401 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3407 printf(
"smtp parser in inconsistent state\n");
3412 STREAM_TOSERVER, request2, request2_len);
3414 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3421 printf(
"smtp parser in inconsistent state\n");
3426 STREAM_TOCLIENT, reply2, reply2_len);
3428 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3434 printf(
"smtp parser in inconsistent state\n");
3446 STREAM_TOSERVER, request3, request3_len);
3448 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3455 printf(
"smtp parser in inconsistent state\n");
3460 STREAM_TOCLIENT, reply3, reply3_len);
3462 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3468 printf(
"smtp parser in inconsistent state\n");
3484 static int SMTPParserTest06(
void)
3490 uint8_t welcome_reply[] = {
3491 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3492 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3493 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3494 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3495 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3496 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3497 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3498 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3499 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3500 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3501 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3502 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3503 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3504 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3505 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3506 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3507 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3508 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3509 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3510 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3511 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3512 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3513 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3514 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3515 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3516 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3517 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3518 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3519 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3520 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3521 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3522 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3523 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3524 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3525 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3526 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3527 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3528 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3529 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3531 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3533 uint8_t request1[] = {
3534 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3535 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3536 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3537 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3540 uint32_t request1_len =
sizeof(request1);
3542 uint8_t reply1[] = {
3543 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3544 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3545 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3546 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3547 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3548 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3549 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3550 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3551 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3552 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3553 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3554 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3555 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3556 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3557 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3558 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3559 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3560 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3561 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3562 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3563 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3566 uint32_t reply1_len =
sizeof(reply1);
3569 uint8_t request2[] = {
3570 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3571 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3572 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3575 uint32_t request2_len =
sizeof(request2);
3577 uint8_t reply2[] = {
3578 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3579 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3581 uint32_t reply2_len =
sizeof(reply2);
3584 uint8_t request3[] = {
3585 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3586 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3587 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3590 uint32_t request3_len =
sizeof(request3);
3592 uint8_t reply3[] = {
3593 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3594 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3596 uint32_t reply3_len =
sizeof(reply3);
3599 uint8_t request4[] = {
3600 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3603 uint32_t request4_len =
sizeof(request4);
3605 uint8_t request5[] = {
3606 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3607 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3608 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3609 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3611 uint32_t request5_len =
sizeof(request5);
3613 uint8_t request6[] = {
3614 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3615 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3618 uint32_t request6_len =
sizeof(request6);
3623 memset(&f, 0,
sizeof(f));
3624 memset(&ssn, 0,
sizeof(ssn));
3628 f.
proto = IPPROTO_TCP;
3632 SMTPTestInitConfig();
3635 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3637 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3641 if (smtp_state == NULL) {
3642 printf(
"no smtp state: ");
3647 printf(
"smtp parser in inconsistent state\n");
3652 STREAM_TOSERVER, request1, request1_len);
3654 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3660 printf(
"smtp parser in inconsistent state\n");
3665 STREAM_TOCLIENT, reply1, reply1_len);
3667 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3672 printf(
"smtp parser in inconsistent state\n");
3677 STREAM_TOSERVER, request2, request2_len);
3679 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3685 printf(
"smtp parser in inconsistent state\n");
3690 STREAM_TOCLIENT, reply2, reply2_len);
3692 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3697 printf(
"smtp parser in inconsistent state\n");
3702 STREAM_TOSERVER, request3, request3_len);
3704 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3710 printf(
"smtp parser in inconsistent state\n");
3715 STREAM_TOCLIENT, reply3, reply3_len);
3717 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3722 printf(
"smtp parser in inconsistent state\n");
3727 STREAM_TOSERVER, request4, request4_len);
3729 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3737 printf(
"smtp parser in inconsistent state\n");
3742 STREAM_TOSERVER, request5, request5_len);
3744 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3751 printf(
"smtp parser in inconsistent state\n");
3756 STREAM_TOSERVER, request6, request6_len);
3758 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3764 printf(
"smtp parser in inconsistent state\n");
3777 static int SMTPParserTest12(
void)
3791 uint8_t request1[] = {
3792 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3793 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3795 int32_t request1_len =
sizeof(request1);
3799 uint8_t reply1[] = {
3800 0x31, 0x38, 0x38, 0x0d, 0x0a,
3802 uint32_t reply1_len =
sizeof(reply1);
3808 memset(&f, 0,
sizeof(f));
3809 memset(&ssn, 0,
sizeof(ssn));
3815 f.
proto = IPPROTO_TCP;
3824 SMTPTestInitConfig();
3833 "(msg:\"SMTP event handling\"; "
3834 "app-layer-event: smtp.invalid_reply; "
3843 STREAM_TOSERVER | STREAM_START, request1,
3846 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3851 if (smtp_state == NULL) {
3852 printf(
"no smtp state: ");
3860 printf(
"sid 1 matched. It shouldn't match: ");
3865 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3868 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3876 printf(
"sid 1 didn't match. Should have matched: ");
3894 static int SMTPParserTest13(
void)
3908 uint8_t request1[] = {
3909 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3910 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3912 int32_t request1_len =
sizeof(request1);
3916 uint8_t reply1[] = {
3917 0x32, 0x35, 0x30, 0x0d, 0x0a,
3919 uint32_t reply1_len =
sizeof(reply1);
3926 uint8_t request2[] = {
3927 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3928 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3929 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3930 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3931 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3932 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3933 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3934 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3937 uint32_t request2_len =
sizeof(request2);
3943 memset(&f, 0,
sizeof(f));
3944 memset(&ssn, 0,
sizeof(ssn));
3950 f.
proto = IPPROTO_TCP;
3959 SMTPTestInitConfig();
3968 "(msg:\"SMTP event handling\"; "
3970 "smtp.invalid_pipelined_sequence; "
3979 STREAM_TOSERVER | STREAM_START, request1,
3982 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3987 if (smtp_state == NULL) {
3988 printf(
"no smtp state: ");
3996 printf(
"sid 1 matched. It shouldn't match: ");
4001 STREAM_TOCLIENT, reply1, reply1_len);
4003 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4011 printf(
"sid 1 matched. It shouldn't match: ");
4016 STREAM_TOSERVER, request2, request2_len);
4018 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4026 printf(
"sid 1 didn't match. Should have matched: ");
4046 static int SMTPParserTest14(
void)
4053 static uint8_t welcome_reply[] = {
4054 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
4055 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
4056 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
4057 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
4058 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
4061 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
4064 static uint8_t request1[] = {
4065 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
4066 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
4068 static uint32_t request1_len =
sizeof(request1);
4075 static uint8_t reply1[] = {
4076 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
4077 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
4078 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
4079 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
4080 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
4081 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
4082 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
4083 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
4084 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
4085 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
4086 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
4087 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
4088 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
4089 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
4090 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
4092 static uint32_t reply1_len =
sizeof(reply1);
4095 static uint8_t request2[] = {
4096 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
4097 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
4098 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
4101 static uint32_t request2_len =
sizeof(request2);
4103 static uint8_t reply2[] = {
4104 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4105 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4107 static uint32_t reply2_len =
sizeof(reply2);
4110 static uint8_t request3[] = {
4111 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
4112 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
4113 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
4116 static uint32_t request3_len =
sizeof(request3);
4118 static uint8_t reply3[] = {
4119 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4120 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4122 static uint32_t reply3_len =
sizeof(reply3);
4125 static uint8_t request4[] = {
4126 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
4128 static uint32_t request4_len =
sizeof(request4);
4130 static uint8_t reply4[] = {
4131 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
4132 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
4133 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
4134 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
4135 0x4c, 0x46, 0x3e, 0x0d, 0x0a
4137 static uint32_t reply4_len =
sizeof(reply4);
4140 static uint64_t filesize = 133;
4141 static uint8_t request4_msg[] = {
4142 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
4143 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
4144 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4145 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
4146 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
4147 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
4148 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
4149 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4150 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
4151 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
4152 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
4153 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
4154 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
4155 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
4156 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
4157 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
4158 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
4159 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
4160 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
4161 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
4162 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
4163 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
4164 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4165 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
4166 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
4167 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
4168 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
4169 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
4170 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
4171 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4172 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
4173 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4174 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4175 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
4176 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4177 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4178 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4179 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4180 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
4181 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
4182 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
4183 0x41, 0x3D, 0x3D, 0x0D,0x0A };
4184 static uint32_t request4_msg_len =
sizeof(request4_msg);
4187 static uint8_t request4_end[] = {
4188 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4190 static uint32_t request4_end_len =
sizeof(request4_end);
4192 static uint8_t reply4_end[] = {
4193 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4194 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
4195 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
4196 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
4197 0x46, 0x32, 0x0d, 0x0a
4199 static uint32_t reply4_end_len =
sizeof(reply4_end);
4202 static uint8_t request5[] = {
4203 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
4205 static uint32_t request5_len =
sizeof(request5);
4207 static uint8_t reply5[] = {
4208 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4209 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
4211 static uint32_t reply5_len =
sizeof(reply5);
4216 memset(&f, 0,
sizeof(f));
4217 memset(&ssn, 0,
sizeof(ssn));
4221 f.
proto = IPPROTO_TCP;
4225 SMTPTestInitConfig();
4229 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
4231 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4235 if (smtp_state == NULL) {
4236 printf(
"no smtp state: ");
4241 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4246 STREAM_TOSERVER, request1, request1_len);
4248 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4254 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4260 STREAM_TOCLIENT, reply1, reply1_len);
4262 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4266 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4267 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4273 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4279 STREAM_TOSERVER, request2, request2_len);
4281 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4287 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4293 STREAM_TOCLIENT, reply2, reply2_len);
4295 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4301 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4309 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4315 STREAM_TOSERVER, request3, request3_len);
4317 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4323 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4329 STREAM_TOCLIENT, reply3, reply3_len);
4331 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4336 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4342 SCMimeSmtpConfigDecodeBase64(1);
4343 SCMimeSmtpConfigDecodeQuoted(1);
4347 STREAM_TOSERVER, request4, request4_len);
4349 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4356 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4362 STREAM_TOCLIENT, reply4, reply4_len);
4364 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4370 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4376 STREAM_TOSERVER, request4_msg, request4_msg_len);
4378 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4386 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4392 STREAM_TOSERVER, request4_end, request4_end_len);
4394 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4402 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4411 if (files != NULL && files->
head != NULL) {
4414 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4415 printf(
"smtp-mime file name is incorrect");
4419 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4422 static uint8_t org_binary[] = {
4423 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4424 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4426 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4427 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4428 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4429 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4430 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4431 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4432 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4433 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4434 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4435 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4437 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4438 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4439 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4442 org_binary,
sizeof(org_binary)) != 1)
4444 printf(
"smtp-mime file data incorrect\n");
4451 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4453 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4458 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4464 STREAM_TOSERVER, request5, request5_len);
4466 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4472 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4478 STREAM_TOCLIENT, reply5, reply5_len);
4480 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4485 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);