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) {
1355 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1357 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1384 if (data_frame == NULL) {
1385 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1394 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1396 r = SMTPParseCommandBDAT(state, line, &last);
1409 SMTPTransactionCompleteTS(tx);
1412 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1413 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1414 r = SMTPParseCommandHELO(state, line);
1419 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1420 r = SMTPParseCommandMAILFROM(state, line);
1425 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1426 r = SMTPParseCommandRCPTTO(state, line);
1431 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1435 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1443 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1452 return SMTPProcessCommandDATA(state, tx, f, line);
1456 return SMTPProcessCommandBDAT(state, tx, line);
1465 static inline void ResetLine(
SMTPLine *line)
1474 static int SMTPPreProcessCommandBDAT(
1485 uint32_t consumed =
MIN((uint32_t)input->
len, remaining);
1487 line->
len = consumed;
1489 input->
len -= consumed;
1490 int ret = SMTPProcessRequest(state, f, input, line, slice);
1515 static int SMTPPreProcessCommands(
1524 return SMTPPreProcessCommandBDAT(state, f, slice, input, line);
1532 bool line_complete =
false;
1533 const int32_t input_len = input->
len;
1535 for (int32_t i = 0; i < input_len; i++) {
1537 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1543 line_complete =
true;
1544 }
else if (input->
buf[
offset + i] == 0x0a) {
1547 line_complete =
true;
1550 if (line_complete || (i == input_len - 1)) {
1557 SCLogDebug(
"Possible boundary, yield to GetLine");
1561 int32_t total_consumed =
offset + i + 1;
1562 int32_t current_line_consumed = total_consumed - input->
consumed;
1567 if (line->
len < 0) {
1572 input->
len -= current_line_consumed;
1574 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1577 line_complete =
false;
1600 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1601 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1603 if (input_buf == NULL &&
1608 }
else if (input_buf == NULL || input_len == 0) {
1612 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1613 SMTPLine line = { NULL, 0, 0,
false };
1616 if (direction == 0) {
1621 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1625 }
else if (ret < 0) {
1629 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1630 while (res.
status == 0) {
1631 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1651 if ((input.
len > 0) &&
1656 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1660 }
else if (ret < 0) {
1664 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1670 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1671 while (res.
status == 0) {
1672 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1682 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1697 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1706 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1721 if (smtp_state->
cmds == NULL) {
1756 static void *SMTPLocalStorageAlloc(
void)
1765 if (td->
pmq == NULL) {
1778 static void SMTPLocalStorageFree(
void *ptr)
1782 if (td->
pmq != NULL) {
1810 SMTPStringFree(
str);
1821 static void SMTPStateFree(
void *
p)
1825 if (smtp_state->
cmds != NULL) {
1832 if (smtp_state->
helo) {
1837 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1839 SMTPTransactionFree(tx, smtp_state);
1845 static void SMTPSetMpmState(
void)
1848 if (
unlikely(smtp_mpm_ctx == NULL)) {
1864 static void SMTPFreeMpmState(
void)
1866 if (smtp_mpm_ctx != NULL) {
1869 smtp_mpm_ctx = NULL;
1873 static int SMTPStateGetEventInfo(
1883 static int SMTPStateGetEventInfoById(
1887 if (*event_name == NULL) {
1889 "smtp's enum map table.",
1902 static AppProto SMTPClientProbingParserCheckPort(
1903 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1911 static AppProto SMTPServerProbingParser(
1912 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1919 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1923 if (input[3] !=
' ' && input[3] !=
'-') {
1929 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1940 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1951 static int SMTPRegisterPatternsForProtocolDetection(
void)
1954 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1958 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1962 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1967 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1970 NULL, SMTPServerProbingParser);
1976 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1981 if (tx_id < tx->tx_id)
1983 else if (tx_id > tx->
tx_id)
1986 if (tx == smtp_state->
curr_tx)
1989 SMTPTransactionFree(tx, state);
1997 static uint64_t SMTPStateGetTxCnt(
void *state)
2008 static void *SMTPStateGetTx(
void *state, uint64_t
id)
2014 if (smtp_state->
curr_tx == NULL)
2020 if (tx->
tx_id ==
id)
2027 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
2030 if (direction & STREAM_TOSERVER) {
2041 if (direction & STREAM_TOSERVER) {
2070 if (state->
un.
ptr == NULL) {
2076 while (tx_ptr->
tx_id < min_tx_id) {
2082 if (tx_ptr->
tx_id >= max_tx_id) {
2089 .has_next = (state->
un.
ptr != NULL),
2102 const char *proto_name =
"smtp";
2106 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
2109 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
2118 SMTPParseClientRecord);
2120 SMTPParseServerRecord);
2126 SMTPLocalStorageFree);
2139 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
2141 IPPROTO_TCP,
ALPROTO_SMTP, SMTPStateGetStateIdByName, SMTPStateGetStateNameById);
2143 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2168 static void SMTPTestInitConfig(
void)
2182 static int SMTPParserTest01(
void)
2189 uint8_t welcome_reply[] = {
2190 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2191 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2192 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2193 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2194 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2197 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2200 uint8_t request1[] = {
2201 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
2202 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
2203 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
2205 uint32_t request1_len =
sizeof(request1);
2212 uint8_t reply1[] = {
2213 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
2214 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2215 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
2216 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
2217 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
2218 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
2219 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
2220 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
2221 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
2222 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
2223 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2224 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2225 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2226 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2227 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2228 0x44, 0x45, 0x53, 0x0d, 0x0a
2230 uint32_t reply1_len =
sizeof(reply1);
2233 uint8_t request2[] = {
2234 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2237 uint32_t request2_len =
sizeof(request2);
2239 uint8_t reply2[] = {
2240 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2241 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2242 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2243 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2245 uint32_t reply2_len =
sizeof(reply2);
2250 memset(&f, 0,
sizeof(f));
2251 memset(&ssn, 0,
sizeof(ssn));
2255 f.
proto = IPPROTO_TCP;
2259 SMTPTestInitConfig();
2262 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2264 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2268 if (smtp_state == NULL) {
2269 printf(
"no smtp state: ");
2274 printf(
"smtp parser in inconsistent state\n");
2279 STREAM_TOSERVER, request1, request1_len);
2281 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2287 printf(
"smtp parser in inconsistent state\n");
2292 STREAM_TOCLIENT, reply1, reply1_len);
2294 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2299 printf(
"smtp parser in inconsistent state\n");
2304 STREAM_TOSERVER, request2, request2_len);
2306 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2312 printf(
"smtp parser in inconsistent state\n");
2317 STREAM_TOCLIENT, reply2, reply2_len);
2319 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2325 printf(
"smtp parser in inconsistent state\n");
2345 static int SMTPParserTest02(
void)
2352 uint8_t welcome_reply[] = {
2353 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2354 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2355 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2356 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2357 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2360 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2363 uint8_t request1[] = {
2364 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2365 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2367 uint32_t request1_len =
sizeof(request1);
2374 uint8_t reply1[] = {
2375 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2376 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2377 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2378 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2379 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2380 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2381 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2382 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2383 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2384 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2385 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2386 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2387 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2388 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2389 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2391 uint32_t reply1_len =
sizeof(reply1);
2394 uint8_t request2[] = {
2395 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2396 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2397 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2400 uint32_t request2_len =
sizeof(request2);
2402 uint8_t reply2[] = {
2403 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2404 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2406 uint32_t reply2_len =
sizeof(reply2);
2409 uint8_t request3[] = {
2410 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2411 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2412 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2415 uint32_t request3_len =
sizeof(request3);
2417 uint8_t reply3[] = {
2418 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2419 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2421 uint32_t reply3_len =
sizeof(reply3);
2424 uint8_t request4[] = {
2425 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2427 uint32_t request4_len =
sizeof(request4);
2429 uint8_t reply4[] = {
2430 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2431 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2432 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2433 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2434 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2436 uint32_t reply4_len =
sizeof(reply4);
2439 uint8_t request5_1[] = {
2440 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2441 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2442 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2444 uint32_t request5_1_len =
sizeof(request5_1);
2446 uint8_t request5_2[] = {
2447 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2448 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2449 0x6f, 0x6d, 0x0d, 0x0a
2451 uint32_t request5_2_len =
sizeof(request5_2);
2453 uint8_t request5_3[] = {
2456 uint32_t request5_3_len =
sizeof(request5_3);
2458 uint8_t request5_4[] = {
2459 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2460 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2461 0x6c, 0x31, 0x0d, 0x0a
2463 uint32_t request5_4_len =
sizeof(request5_4);
2465 uint8_t request5_5[] = {
2468 uint32_t request5_5_len =
sizeof(request5_5);
2470 uint8_t reply5[] = {
2471 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2472 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2473 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2474 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2475 0x46, 0x32, 0x0d, 0x0a
2477 uint32_t reply5_len =
sizeof(reply5);
2480 uint8_t request6[] = {
2481 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2482 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2483 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2486 uint32_t request6_len =
sizeof(request6);
2488 uint8_t reply6[] = {
2489 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2490 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2492 uint32_t reply6_len =
sizeof(reply6);
2495 uint8_t request7[] = {
2496 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2497 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2498 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2501 uint32_t request7_len =
sizeof(request7);
2503 uint8_t reply7[] = {
2504 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2505 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2507 uint32_t reply7_len =
sizeof(reply7);
2510 uint8_t request8[] = {
2511 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2513 uint32_t request8_len =
sizeof(request8);
2515 uint8_t reply8[] = {
2516 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2517 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2518 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2519 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2520 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2522 uint32_t reply8_len =
sizeof(reply8);
2525 uint8_t request9_1[] = {
2526 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2527 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2528 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2530 uint32_t request9_1_len =
sizeof(request9_1);
2532 uint8_t request9_2[] = {
2533 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2534 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2535 0x6f, 0x6d, 0x0d, 0x0a
2537 uint32_t request9_2_len =
sizeof(request9_2);
2539 uint8_t request9_3[] = {
2542 uint32_t request9_3_len =
sizeof(request9_3);
2544 uint8_t request9_4[] = {
2545 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2546 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2547 0x6c, 0x32, 0x0d, 0x0a
2549 uint32_t request9_4_len =
sizeof(request9_4);
2551 uint8_t request9_5[] = {
2554 uint32_t request9_5_len =
sizeof(request9_5);
2556 uint8_t reply9[] = {
2557 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2558 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2559 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2560 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2561 0x46, 0x32, 0x0d, 0x0a
2563 uint32_t reply9_len =
sizeof(reply9);
2566 uint8_t request10[] = {
2567 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2569 uint32_t request10_len =
sizeof(request10);
2571 uint8_t reply10[] = {
2572 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2573 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2575 uint32_t reply10_len =
sizeof(reply10);
2580 memset(&f, 0,
sizeof(f));
2581 memset(&ssn, 0,
sizeof(ssn));
2585 f.
proto = IPPROTO_TCP;
2589 SMTPTestInitConfig();
2592 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2594 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2598 if (smtp_state == NULL) {
2599 printf(
"no smtp state: ");
2604 printf(
"smtp parser in inconsistent state\n");
2609 STREAM_TOSERVER, request1, request1_len);
2611 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2617 printf(
"smtp parser in inconsistent state\n");
2622 STREAM_TOCLIENT, reply1, reply1_len);
2624 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2629 printf(
"smtp parser in inconsistent state\n");
2634 STREAM_TOSERVER, request2, request2_len);
2636 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2642 printf(
"smtp parser in inconsistent state\n");
2647 STREAM_TOCLIENT, reply2, reply2_len);
2649 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2654 printf(
"smtp parser in inconsistent state\n");
2659 STREAM_TOSERVER, request3, request3_len);
2661 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2667 printf(
"smtp parser in inconsistent state\n");
2672 STREAM_TOCLIENT, reply3, reply3_len);
2674 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2679 printf(
"smtp parser in inconsistent state\n");
2684 STREAM_TOSERVER, request4, request4_len);
2686 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2692 printf(
"smtp parser in inconsistent state\n");
2697 STREAM_TOCLIENT, reply4, reply4_len);
2699 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2705 printf(
"smtp parser in inconsistent state\n");
2710 STREAM_TOSERVER, request5_1, request5_1_len);
2712 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2719 printf(
"smtp parser in inconsistent state\n");
2724 STREAM_TOSERVER, request5_2, request5_2_len);
2726 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2733 printf(
"smtp parser in inconsistent state\n");
2738 STREAM_TOSERVER, request5_3, request5_3_len);
2740 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2747 printf(
"smtp parser in inconsistent state\n");
2752 STREAM_TOSERVER, request5_4, request5_4_len);
2754 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2761 printf(
"smtp parser in inconsistent state\n");
2766 STREAM_TOSERVER, request5_5, request5_5_len);
2768 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2774 printf(
"smtp parser in inconsistent state\n");
2779 STREAM_TOCLIENT, reply5, reply5_len);
2781 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2786 printf(
"smtp parser in inconsistent state\n");
2791 STREAM_TOSERVER, request6, request6_len);
2793 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2799 printf(
"smtp parser in inconsistent state\n");
2804 STREAM_TOCLIENT, reply6, reply6_len);
2806 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2811 printf(
"smtp parser in inconsistent state\n");
2816 STREAM_TOSERVER, request7, request7_len);
2818 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2824 printf(
"smtp parser in inconsistent state\n");
2829 STREAM_TOCLIENT, reply7, reply7_len);
2831 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2836 printf(
"smtp parser in inconsistent state\n");
2841 STREAM_TOSERVER, request8, request8_len);
2843 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2849 printf(
"smtp parser in inconsistent state\n");
2854 STREAM_TOCLIENT, reply8, reply8_len);
2856 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2862 printf(
"smtp parser in inconsistent state\n");
2867 STREAM_TOSERVER, request9_1, request9_1_len);
2869 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2876 printf(
"smtp parser in inconsistent state\n");
2881 STREAM_TOSERVER, request9_2, request9_2_len);
2883 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2890 printf(
"smtp parser in inconsistent state\n");
2895 STREAM_TOSERVER, request9_3, request9_3_len);
2897 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2904 printf(
"smtp parser in inconsistent state\n");
2909 STREAM_TOSERVER, request9_4, request9_4_len);
2911 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2918 printf(
"smtp parser in inconsistent state\n");
2923 STREAM_TOSERVER, request9_5, request9_5_len);
2925 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2931 printf(
"smtp parser in inconsistent state\n");
2936 STREAM_TOCLIENT, reply9, reply9_len);
2938 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2943 printf(
"smtp parser in inconsistent state\n");
2948 STREAM_TOSERVER, request10, request10_len);
2950 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2956 printf(
"smtp parser in inconsistent state\n");
2961 STREAM_TOCLIENT, reply10, reply10_len);
2963 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2968 printf(
"smtp parser in inconsistent state\n");
2984 static int SMTPParserTest03(
void)
2991 uint8_t welcome_reply[] = {
2992 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2993 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2994 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2995 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2996 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2997 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2999 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3002 uint8_t request1[] = {
3003 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3004 0x2e, 0x63, 0x6f, 0x6d, 0x0a
3006 uint32_t request1_len =
sizeof(request1);
3016 uint8_t reply1[] = {
3017 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3018 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3019 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3020 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3021 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3022 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3023 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3024 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3025 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3026 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3027 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3028 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3029 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3030 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3031 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3032 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3033 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3035 uint32_t reply1_len =
sizeof(reply1);
3042 uint8_t request2[] = {
3043 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3044 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3045 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3046 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3047 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3048 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3049 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3050 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
3051 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
3053 uint32_t request2_len =
sizeof(request2);
3058 uint8_t reply2[] = {
3059 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3060 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
3061 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
3062 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
3063 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
3064 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
3065 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
3066 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
3069 uint32_t reply2_len =
sizeof(reply2);
3074 memset(&f, 0,
sizeof(f));
3075 memset(&ssn, 0,
sizeof(ssn));
3079 f.
proto = IPPROTO_TCP;
3083 SMTPTestInitConfig();
3086 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3088 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3092 if (smtp_state == NULL) {
3093 printf(
"no smtp state: ");
3098 printf(
"smtp parser in inconsistent state\n");
3103 STREAM_TOSERVER, request1, request1_len);
3105 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3111 printf(
"smtp parser in inconsistent state\n");
3116 STREAM_TOCLIENT, reply1, reply1_len);
3118 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3124 printf(
"smtp parser in inconsistent state\n");
3129 STREAM_TOSERVER, request2, request2_len);
3131 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3141 printf(
"smtp parser in inconsistent state\n");
3146 STREAM_TOCLIENT, reply2, reply2_len);
3148 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3155 printf(
"smtp parser in inconsistent state\n");
3171 static int SMTPParserTest04(
void)
3178 uint8_t welcome_reply[] = {
3179 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3180 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3181 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3182 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3183 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3184 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3186 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3189 uint8_t request1[] = {
3190 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3191 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3192 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3193 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3194 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3195 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3197 uint32_t request1_len =
sizeof(request1);
3202 memset(&f, 0,
sizeof(f));
3203 memset(&ssn, 0,
sizeof(ssn));
3207 f.
proto = IPPROTO_TCP;
3211 SMTPTestInitConfig();
3214 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3216 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3220 if (smtp_state == NULL) {
3221 printf(
"no smtp state: ");
3226 printf(
"smtp parser in inconsistent state\n");
3231 STREAM_TOSERVER, request1, request1_len);
3233 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3239 printf(
"smtp parser in inconsistent state\n");
3255 static int SMTPParserTest05(
void)
3262 uint8_t welcome_reply[] = {
3263 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3264 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3265 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3266 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3267 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3268 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3270 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3273 uint8_t request1[] = {
3274 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3275 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3277 uint32_t request1_len =
sizeof(request1);
3287 uint8_t reply1[] = {
3288 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3289 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3290 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3291 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3292 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3293 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3294 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3295 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3296 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3297 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3298 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3299 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3300 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3301 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3302 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3303 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3304 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3306 uint32_t reply1_len =
sizeof(reply1);
3309 uint8_t request2[] = {
3310 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3313 uint32_t request2_len =
sizeof(request2);
3315 uint8_t reply2[] = {
3316 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3317 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3318 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3319 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3320 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3323 uint32_t reply2_len =
sizeof(reply2);
3326 uint8_t request3[] = {
3327 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3330 uint32_t request3_len =
sizeof(request3);
3332 uint8_t reply3[] = {
3333 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3334 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3336 uint32_t reply3_len =
sizeof(reply3);
3341 memset(&f, 0,
sizeof(f));
3342 memset(&ssn, 0,
sizeof(ssn));
3346 f.
proto = IPPROTO_TCP;
3350 SMTPTestInitConfig();
3353 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3355 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3359 if (smtp_state == NULL) {
3360 printf(
"no smtp state: ");
3365 printf(
"smtp parser in inconsistent state\n");
3370 STREAM_TOSERVER, request1, request1_len);
3372 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3378 printf(
"smtp parser in inconsistent state\n");
3383 STREAM_TOCLIENT, reply1, reply1_len);
3385 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3391 printf(
"smtp parser in inconsistent state\n");
3396 STREAM_TOSERVER, request2, request2_len);
3398 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3405 printf(
"smtp parser in inconsistent state\n");
3410 STREAM_TOCLIENT, reply2, reply2_len);
3412 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3418 printf(
"smtp parser in inconsistent state\n");
3430 STREAM_TOSERVER, request3, request3_len);
3432 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3439 printf(
"smtp parser in inconsistent state\n");
3444 STREAM_TOCLIENT, reply3, reply3_len);
3446 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3452 printf(
"smtp parser in inconsistent state\n");
3468 static int SMTPParserTest06(
void)
3474 uint8_t welcome_reply[] = {
3475 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3476 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3477 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3478 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3479 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3480 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3481 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3482 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3483 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3484 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3485 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3486 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3487 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3488 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3489 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3490 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3491 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3492 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3493 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3494 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3495 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3496 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3497 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3498 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3499 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3500 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3501 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3502 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3503 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3504 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3505 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3506 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3507 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3508 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3509 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3510 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3511 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3512 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3513 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3515 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3517 uint8_t request1[] = {
3518 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3519 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3520 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3521 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3524 uint32_t request1_len =
sizeof(request1);
3526 uint8_t reply1[] = {
3527 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3528 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3529 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3530 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3531 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3532 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3533 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3534 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3535 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3536 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3537 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3538 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3539 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3540 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3541 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3542 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3543 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3544 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3545 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3546 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3547 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3550 uint32_t reply1_len =
sizeof(reply1);
3553 uint8_t request2[] = {
3554 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3555 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3556 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3559 uint32_t request2_len =
sizeof(request2);
3561 uint8_t reply2[] = {
3562 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3563 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3565 uint32_t reply2_len =
sizeof(reply2);
3568 uint8_t request3[] = {
3569 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3570 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3571 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3574 uint32_t request3_len =
sizeof(request3);
3576 uint8_t reply3[] = {
3577 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3578 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3580 uint32_t reply3_len =
sizeof(reply3);
3583 uint8_t request4[] = {
3584 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3587 uint32_t request4_len =
sizeof(request4);
3589 uint8_t request5[] = {
3590 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3591 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3592 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3593 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3595 uint32_t request5_len =
sizeof(request5);
3597 uint8_t request6[] = {
3598 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3599 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3602 uint32_t request6_len =
sizeof(request6);
3607 memset(&f, 0,
sizeof(f));
3608 memset(&ssn, 0,
sizeof(ssn));
3612 f.
proto = IPPROTO_TCP;
3616 SMTPTestInitConfig();
3619 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3621 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3625 if (smtp_state == NULL) {
3626 printf(
"no smtp state: ");
3631 printf(
"smtp parser in inconsistent state\n");
3636 STREAM_TOSERVER, request1, request1_len);
3638 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3644 printf(
"smtp parser in inconsistent state\n");
3649 STREAM_TOCLIENT, reply1, reply1_len);
3651 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3656 printf(
"smtp parser in inconsistent state\n");
3661 STREAM_TOSERVER, request2, request2_len);
3663 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3669 printf(
"smtp parser in inconsistent state\n");
3674 STREAM_TOCLIENT, reply2, reply2_len);
3676 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3681 printf(
"smtp parser in inconsistent state\n");
3686 STREAM_TOSERVER, request3, request3_len);
3688 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3694 printf(
"smtp parser in inconsistent state\n");
3699 STREAM_TOCLIENT, reply3, reply3_len);
3701 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3706 printf(
"smtp parser in inconsistent state\n");
3711 STREAM_TOSERVER, request4, request4_len);
3713 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3721 printf(
"smtp parser in inconsistent state\n");
3726 STREAM_TOSERVER, request5, request5_len);
3728 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3735 printf(
"smtp parser in inconsistent state\n");
3740 STREAM_TOSERVER, request6, request6_len);
3742 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3748 printf(
"smtp parser in inconsistent state\n");
3761 static int SMTPParserTest12(
void)
3775 uint8_t request1[] = {
3776 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3777 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3779 int32_t request1_len =
sizeof(request1);
3783 uint8_t reply1[] = {
3784 0x31, 0x38, 0x38, 0x0d, 0x0a,
3786 uint32_t reply1_len =
sizeof(reply1);
3792 memset(&f, 0,
sizeof(f));
3793 memset(&ssn, 0,
sizeof(ssn));
3799 f.
proto = IPPROTO_TCP;
3808 SMTPTestInitConfig();
3817 "(msg:\"SMTP event handling\"; "
3818 "app-layer-event: smtp.invalid_reply; "
3827 STREAM_TOSERVER | STREAM_START, request1,
3830 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3835 if (smtp_state == NULL) {
3836 printf(
"no smtp state: ");
3844 printf(
"sid 1 matched. It shouldn't match: ");
3849 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3852 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3860 printf(
"sid 1 didn't match. Should have matched: ");
3878 static int SMTPParserTest13(
void)
3892 uint8_t request1[] = {
3893 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3894 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3896 int32_t request1_len =
sizeof(request1);
3900 uint8_t reply1[] = {
3901 0x32, 0x35, 0x30, 0x0d, 0x0a,
3903 uint32_t reply1_len =
sizeof(reply1);
3910 uint8_t request2[] = {
3911 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3912 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3913 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3914 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3915 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3916 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3917 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3918 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3921 uint32_t request2_len =
sizeof(request2);
3927 memset(&f, 0,
sizeof(f));
3928 memset(&ssn, 0,
sizeof(ssn));
3934 f.
proto = IPPROTO_TCP;
3943 SMTPTestInitConfig();
3952 "(msg:\"SMTP event handling\"; "
3954 "smtp.invalid_pipelined_sequence; "
3963 STREAM_TOSERVER | STREAM_START, request1,
3966 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3971 if (smtp_state == NULL) {
3972 printf(
"no smtp state: ");
3980 printf(
"sid 1 matched. It shouldn't match: ");
3985 STREAM_TOCLIENT, reply1, reply1_len);
3987 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3995 printf(
"sid 1 matched. It shouldn't match: ");
4000 STREAM_TOSERVER, request2, request2_len);
4002 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4010 printf(
"sid 1 didn't match. Should have matched: ");
4030 static int SMTPParserTest14(
void)
4037 static uint8_t welcome_reply[] = {
4038 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
4039 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
4040 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
4041 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
4042 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
4045 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
4048 static uint8_t request1[] = {
4049 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
4050 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
4052 static uint32_t request1_len =
sizeof(request1);
4059 static uint8_t reply1[] = {
4060 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
4061 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
4062 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
4063 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
4064 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
4065 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
4066 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
4067 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
4068 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
4069 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
4070 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
4071 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
4072 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
4073 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
4074 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
4076 static uint32_t reply1_len =
sizeof(reply1);
4079 static uint8_t request2[] = {
4080 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
4081 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
4082 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
4085 static uint32_t request2_len =
sizeof(request2);
4087 static uint8_t reply2[] = {
4088 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4089 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4091 static uint32_t reply2_len =
sizeof(reply2);
4094 static uint8_t request3[] = {
4095 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
4096 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
4097 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
4100 static uint32_t request3_len =
sizeof(request3);
4102 static uint8_t reply3[] = {
4103 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4104 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4106 static uint32_t reply3_len =
sizeof(reply3);
4109 static uint8_t request4[] = {
4110 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
4112 static uint32_t request4_len =
sizeof(request4);
4114 static uint8_t reply4[] = {
4115 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
4116 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
4117 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
4118 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
4119 0x4c, 0x46, 0x3e, 0x0d, 0x0a
4121 static uint32_t reply4_len =
sizeof(reply4);
4124 static uint64_t filesize = 133;
4125 static uint8_t request4_msg[] = {
4126 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
4127 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
4128 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4129 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
4130 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
4131 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
4132 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
4133 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4134 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
4135 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
4136 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
4137 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
4138 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
4139 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
4140 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
4141 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
4142 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
4143 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
4144 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
4145 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
4146 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
4147 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
4148 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4149 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
4150 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
4151 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
4152 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
4153 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
4154 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
4155 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4156 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
4157 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4158 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4159 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
4160 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4161 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4162 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4163 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4164 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
4165 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
4166 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
4167 0x41, 0x3D, 0x3D, 0x0D,0x0A };
4168 static uint32_t request4_msg_len =
sizeof(request4_msg);
4171 static uint8_t request4_end[] = {
4172 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4174 static uint32_t request4_end_len =
sizeof(request4_end);
4176 static uint8_t reply4_end[] = {
4177 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4178 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
4179 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
4180 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
4181 0x46, 0x32, 0x0d, 0x0a
4183 static uint32_t reply4_end_len =
sizeof(reply4_end);
4186 static uint8_t request5[] = {
4187 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
4189 static uint32_t request5_len =
sizeof(request5);
4191 static uint8_t reply5[] = {
4192 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4193 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
4195 static uint32_t reply5_len =
sizeof(reply5);
4200 memset(&f, 0,
sizeof(f));
4201 memset(&ssn, 0,
sizeof(ssn));
4205 f.
proto = IPPROTO_TCP;
4209 SMTPTestInitConfig();
4213 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
4215 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4219 if (smtp_state == NULL) {
4220 printf(
"no smtp state: ");
4225 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4230 STREAM_TOSERVER, request1, request1_len);
4232 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4238 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4244 STREAM_TOCLIENT, reply1, reply1_len);
4246 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4250 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4251 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4257 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4263 STREAM_TOSERVER, request2, request2_len);
4265 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4271 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4277 STREAM_TOCLIENT, reply2, reply2_len);
4279 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4285 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4293 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4299 STREAM_TOSERVER, request3, request3_len);
4301 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4307 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4313 STREAM_TOCLIENT, reply3, reply3_len);
4315 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4320 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4326 SCMimeSmtpConfigDecodeBase64(1);
4327 SCMimeSmtpConfigDecodeQuoted(1);
4331 STREAM_TOSERVER, request4, request4_len);
4333 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4340 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4346 STREAM_TOCLIENT, reply4, reply4_len);
4348 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4354 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4360 STREAM_TOSERVER, request4_msg, request4_msg_len);
4362 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4370 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4376 STREAM_TOSERVER, request4_end, request4_end_len);
4378 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4386 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4395 if (files != NULL && files->
head != NULL) {
4398 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4399 printf(
"smtp-mime file name is incorrect");
4403 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4406 static uint8_t org_binary[] = {
4407 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4408 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4410 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4411 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4412 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4413 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4414 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4415 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4416 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4417 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4418 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4419 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4421 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4422 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4423 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4426 org_binary,
sizeof(org_binary)) != 1)
4428 printf(
"smtp-mime file data incorrect\n");
4435 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4437 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4442 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4448 STREAM_TOSERVER, request5, request5_len);
4450 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4456 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4462 STREAM_TOCLIENT, reply5, reply5_len);
4464 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4469 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);