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,
936 case MimeSmtpFileChunk:
945 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
956 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
961 case MimeSmtpFileClose:
964 SCLogDebug(
"FileCloseFile() failed: %d", ret);
972 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
981 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
986 static int SMTPProcessReply(
997 if (reply_tx != NULL) {
1002 if (line->
len < 3) {
1008 if (line->
len >= 4) {
1010 if (line->
buf[3] !=
'-') {
1014 if (line->
buf[3] ==
'-') {
1032 SCLogDebug(
"invalid reply code %02x %02x %02x", line->
buf[0], line->
buf[1], line->
buf[2]);
1036 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
1055 SCLogDebug(
"unable to match reply with request");
1070 SMTPTransactionComplete(reply_tx);
1105 SMTPTransactionCompleteTC(reply_tx);
1109 SMTPTransactionCompleteTC(reply_tx);
1114 SMTPTransactionComplete(reply_tx);
1119 SMTPTransactionComplete(reply_tx);
1133 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1148 static int SMTPParseCommandBDAT(
SMTPState *state,
const SMTPLine *line,
bool *last)
1155 while (i < line->
len) {
1156 if (line->
buf[i] !=
' ') {
1165 if (i == line->
len) {
1172 if (line->
len - i <
len) {
1175 memcpy(strbuf, line->
buf + i,
len);
1185 if (i < line->
len && line->
buf[i] !=
' ') {
1188 while (i < line->
len && line->
buf[i] ==
' ') {
1191 if (line->
len - i == 4 && SCMemcmpLowercase(
"last", line->
buf + i, 4) == 0) {
1193 }
else if (i != line->
len) {
1200 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1201 uint8_t **target, uint16_t *target_len)
1203 int i = prefix_len + 1;
1205 while (i < line->
len) {
1206 if (line->
buf[i] !=
' ') {
1215 while (spc_i < line->
len) {
1216 if (line->
buf[spc_i] ==
' ') {
1223 if (*target == NULL)
1225 memcpy(*target, line->
buf + i, spc_i - i);
1226 (*target)[spc_i - i] =
'\0';
1227 if (spc_i - i > UINT16_MAX) {
1228 *target_len = UINT16_MAX;
1231 *target_len = (uint16_t)(spc_i - i);
1243 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1252 return SMTPParseCommandWithParam(
1259 uint16_t rcptto_len;
1261 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1264 rcptto_str->
str = rcptto;
1265 rcptto_str->
len = rcptto_len;
1281 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1283 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1291 #define rawmsgname "rawmsg"
1310 static int SMTPProcessRequest(
1318 frame->
len = (int64_t)line->
len;
1334 const bool no_new_tx = NoNewTx(state, line);
1335 if ((state->
curr_tx == NULL && (state->
tx_cnt == 0 || !no_new_tx)) ||
1336 (SMTPTransactionRequestIsComplete(state->
curr_tx) && !no_new_tx)) {
1337 tx = SMTPTransactionCreate(state);
1349 if (frame != NULL && state->
curr_tx) {
1370 const bool is_rset = SCMemcmpLowercase(
"rset", line->
buf, 4) == 0;
1374 }
else if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1376 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1403 if (data_frame == NULL) {
1404 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1413 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1415 r = SMTPParseCommandBDAT(state, line, &last);
1428 SMTPTransactionCompleteTS(tx);
1431 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1432 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1433 r = SMTPParseCommandHELO(state, line);
1448 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1449 r = SMTPParseCommandMAILFROM(state, line);
1454 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1455 r = SMTPParseCommandRCPTTO(state, line);
1460 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1464 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1472 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1481 return SMTPProcessCommandDATA(state, tx, f, line);
1485 return SMTPProcessCommandBDAT(state, tx, line);
1494 static inline void ResetLine(
SMTPLine *line)
1503 static int SMTPPreProcessCommandBDAT(
1514 uint32_t consumed =
MIN((uint32_t)input->
len, remaining);
1516 line->
len = consumed;
1518 input->
len -= consumed;
1519 int ret = SMTPProcessRequest(state, f, input, line, slice);
1544 static int SMTPPreProcessCommands(
1553 return SMTPPreProcessCommandBDAT(state, f, slice, input, line);
1561 bool line_complete =
false;
1562 const int32_t input_len = input->
len;
1564 for (int32_t i = 0; i < input_len; i++) {
1566 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1572 line_complete =
true;
1573 }
else if (input->
buf[
offset + i] == 0x0a) {
1576 line_complete =
true;
1579 if (line_complete || (i == input_len - 1)) {
1586 SCLogDebug(
"Possible boundary, yield to GetLine");
1590 int32_t total_consumed =
offset + i + 1;
1591 int32_t current_line_consumed = total_consumed - input->
consumed;
1596 if (line->
len < 0) {
1601 input->
len -= current_line_consumed;
1603 if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
1606 line_complete =
false;
1629 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1630 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1632 if (input_buf == NULL &&
1637 }
else if (input_buf == NULL || input_len == 0) {
1641 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1642 SMTPLine line = { NULL, 0, 0,
false };
1645 if (direction == 0) {
1650 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1654 }
else if (ret < 0) {
1658 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1659 while (res.
status == 0) {
1660 int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
1680 if ((input.
len > 0) &&
1685 int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
1689 }
else if (ret < 0) {
1693 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1699 AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1700 while (res.
status == 0) {
1701 if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
1711 res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
1726 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1735 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1750 if (smtp_state->
cmds == NULL) {
1785 static void *SMTPLocalStorageAlloc(
void)
1794 if (td->
pmq == NULL) {
1807 static void SMTPLocalStorageFree(
void *ptr)
1811 if (td->
pmq != NULL) {
1839 SMTPStringFree(
str);
1850 static void SMTPStateFree(
void *
p)
1854 if (smtp_state->
cmds != NULL) {
1861 if (smtp_state->
helo) {
1866 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1868 SMTPTransactionFree(tx, smtp_state);
1874 static void SMTPSetMpmState(
void)
1877 if (
unlikely(smtp_mpm_ctx == NULL)) {
1893 static void SMTPFreeMpmState(
void)
1895 if (smtp_mpm_ctx != NULL) {
1898 smtp_mpm_ctx = NULL;
1902 static int SMTPStateGetEventInfo(
1912 static int SMTPStateGetEventInfoById(
1916 if (*event_name == NULL) {
1918 "smtp's enum map table.",
1931 static AppProto SMTPClientProbingParserCheckPort(
1932 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1940 static AppProto SMTPServerProbingParser(
1941 const Flow *f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1948 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1952 if (input[3] !=
' ' && input[3] !=
'-') {
1958 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1969 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1980 static int SMTPRegisterPatternsForProtocolDetection(
void)
1983 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1987 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1991 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1996 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1999 NULL, SMTPServerProbingParser);
2005 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
2010 if (tx_id < tx->tx_id)
2012 else if (tx_id > tx->
tx_id)
2015 if (tx == smtp_state->
curr_tx)
2018 SMTPTransactionFree(tx, state);
2026 static uint64_t SMTPStateGetTxCnt(
void *state)
2037 static void *SMTPStateGetTx(
void *state, uint64_t
id)
2043 if (smtp_state->
curr_tx == NULL)
2049 if (tx->
tx_id ==
id)
2056 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
2059 if (direction & STREAM_TOSERVER) {
2070 if (direction & STREAM_TOSERVER) {
2099 if (state->
un.
ptr == NULL) {
2105 while (tx_ptr->
tx_id < min_tx_id) {
2111 if (tx_ptr->
tx_id >= max_tx_id) {
2118 .has_next = (state->
un.
ptr != NULL),
2131 const char *proto_name =
"smtp";
2135 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
2138 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
2147 SMTPParseClientRecord);
2149 SMTPParseServerRecord);
2155 SMTPLocalStorageFree);
2168 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
2170 IPPROTO_TCP,
ALPROTO_SMTP, SMTPStateGetStateIdByName, SMTPStateGetStateNameById);
2172 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2197 static void SMTPTestInitConfig(
void)
2211 static int SMTPParserTest01(
void)
2218 uint8_t welcome_reply[] = {
2219 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2220 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2221 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2222 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2223 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2226 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2229 uint8_t request1[] = {
2230 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
2231 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
2232 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
2234 uint32_t request1_len =
sizeof(request1);
2241 uint8_t reply1[] = {
2242 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
2243 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2244 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
2245 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
2246 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
2247 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
2248 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
2249 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
2250 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
2251 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
2252 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2253 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2254 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2255 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2256 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2257 0x44, 0x45, 0x53, 0x0d, 0x0a
2259 uint32_t reply1_len =
sizeof(reply1);
2262 uint8_t request2[] = {
2263 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2266 uint32_t request2_len =
sizeof(request2);
2268 uint8_t reply2[] = {
2269 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2270 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2271 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2272 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2274 uint32_t reply2_len =
sizeof(reply2);
2279 memset(&f, 0,
sizeof(f));
2280 memset(&ssn, 0,
sizeof(ssn));
2284 f.
proto = IPPROTO_TCP;
2288 SMTPTestInitConfig();
2291 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2293 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2297 if (smtp_state == NULL) {
2298 printf(
"no smtp state: ");
2303 printf(
"smtp parser in inconsistent state\n");
2308 STREAM_TOSERVER, request1, request1_len);
2310 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2316 printf(
"smtp parser in inconsistent state\n");
2321 STREAM_TOCLIENT, reply1, reply1_len);
2323 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2328 printf(
"smtp parser in inconsistent state\n");
2333 STREAM_TOSERVER, request2, request2_len);
2335 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2341 printf(
"smtp parser in inconsistent state\n");
2346 STREAM_TOCLIENT, reply2, reply2_len);
2348 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2354 printf(
"smtp parser in inconsistent state\n");
2374 static int SMTPParserTest02(
void)
2381 uint8_t welcome_reply[] = {
2382 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2383 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2384 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2385 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2386 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2389 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2392 uint8_t request1[] = {
2393 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2394 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2396 uint32_t request1_len =
sizeof(request1);
2403 uint8_t reply1[] = {
2404 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2405 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2406 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2407 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2408 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2409 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2410 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2411 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2412 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2413 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2414 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2415 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2416 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2417 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2418 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2420 uint32_t reply1_len =
sizeof(reply1);
2423 uint8_t request2[] = {
2424 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2425 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2426 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2429 uint32_t request2_len =
sizeof(request2);
2431 uint8_t reply2[] = {
2432 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2433 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2435 uint32_t reply2_len =
sizeof(reply2);
2438 uint8_t request3[] = {
2439 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2440 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2441 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2444 uint32_t request3_len =
sizeof(request3);
2446 uint8_t reply3[] = {
2447 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2448 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2450 uint32_t reply3_len =
sizeof(reply3);
2453 uint8_t request4[] = {
2454 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2456 uint32_t request4_len =
sizeof(request4);
2458 uint8_t reply4[] = {
2459 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2460 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2461 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2462 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2463 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2465 uint32_t reply4_len =
sizeof(reply4);
2468 uint8_t request5_1[] = {
2469 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2470 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2471 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2473 uint32_t request5_1_len =
sizeof(request5_1);
2475 uint8_t request5_2[] = {
2476 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2477 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2478 0x6f, 0x6d, 0x0d, 0x0a
2480 uint32_t request5_2_len =
sizeof(request5_2);
2482 uint8_t request5_3[] = {
2485 uint32_t request5_3_len =
sizeof(request5_3);
2487 uint8_t request5_4[] = {
2488 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2489 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2490 0x6c, 0x31, 0x0d, 0x0a
2492 uint32_t request5_4_len =
sizeof(request5_4);
2494 uint8_t request5_5[] = {
2497 uint32_t request5_5_len =
sizeof(request5_5);
2499 uint8_t reply5[] = {
2500 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2501 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2502 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2503 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2504 0x46, 0x32, 0x0d, 0x0a
2506 uint32_t reply5_len =
sizeof(reply5);
2509 uint8_t request6[] = {
2510 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2511 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2512 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2515 uint32_t request6_len =
sizeof(request6);
2517 uint8_t reply6[] = {
2518 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2519 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2521 uint32_t reply6_len =
sizeof(reply6);
2524 uint8_t request7[] = {
2525 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2526 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2527 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2530 uint32_t request7_len =
sizeof(request7);
2532 uint8_t reply7[] = {
2533 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2534 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2536 uint32_t reply7_len =
sizeof(reply7);
2539 uint8_t request8[] = {
2540 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2542 uint32_t request8_len =
sizeof(request8);
2544 uint8_t reply8[] = {
2545 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2546 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2547 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2548 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2549 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2551 uint32_t reply8_len =
sizeof(reply8);
2554 uint8_t request9_1[] = {
2555 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2556 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2557 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2559 uint32_t request9_1_len =
sizeof(request9_1);
2561 uint8_t request9_2[] = {
2562 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2563 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2564 0x6f, 0x6d, 0x0d, 0x0a
2566 uint32_t request9_2_len =
sizeof(request9_2);
2568 uint8_t request9_3[] = {
2571 uint32_t request9_3_len =
sizeof(request9_3);
2573 uint8_t request9_4[] = {
2574 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2575 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2576 0x6c, 0x32, 0x0d, 0x0a
2578 uint32_t request9_4_len =
sizeof(request9_4);
2580 uint8_t request9_5[] = {
2583 uint32_t request9_5_len =
sizeof(request9_5);
2585 uint8_t reply9[] = {
2586 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2587 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2588 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2589 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2590 0x46, 0x32, 0x0d, 0x0a
2592 uint32_t reply9_len =
sizeof(reply9);
2595 uint8_t request10[] = {
2596 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2598 uint32_t request10_len =
sizeof(request10);
2600 uint8_t reply10[] = {
2601 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2602 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2604 uint32_t reply10_len =
sizeof(reply10);
2609 memset(&f, 0,
sizeof(f));
2610 memset(&ssn, 0,
sizeof(ssn));
2614 f.
proto = IPPROTO_TCP;
2618 SMTPTestInitConfig();
2621 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2623 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2627 if (smtp_state == NULL) {
2628 printf(
"no smtp state: ");
2633 printf(
"smtp parser in inconsistent state\n");
2638 STREAM_TOSERVER, request1, request1_len);
2640 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2646 printf(
"smtp parser in inconsistent state\n");
2651 STREAM_TOCLIENT, reply1, reply1_len);
2653 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2658 printf(
"smtp parser in inconsistent state\n");
2663 STREAM_TOSERVER, request2, request2_len);
2665 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2671 printf(
"smtp parser in inconsistent state\n");
2676 STREAM_TOCLIENT, reply2, reply2_len);
2678 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2683 printf(
"smtp parser in inconsistent state\n");
2688 STREAM_TOSERVER, request3, request3_len);
2690 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2696 printf(
"smtp parser in inconsistent state\n");
2701 STREAM_TOCLIENT, reply3, reply3_len);
2703 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2708 printf(
"smtp parser in inconsistent state\n");
2713 STREAM_TOSERVER, request4, request4_len);
2715 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2721 printf(
"smtp parser in inconsistent state\n");
2726 STREAM_TOCLIENT, reply4, reply4_len);
2728 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2734 printf(
"smtp parser in inconsistent state\n");
2739 STREAM_TOSERVER, request5_1, request5_1_len);
2741 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2748 printf(
"smtp parser in inconsistent state\n");
2753 STREAM_TOSERVER, request5_2, request5_2_len);
2755 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2762 printf(
"smtp parser in inconsistent state\n");
2767 STREAM_TOSERVER, request5_3, request5_3_len);
2769 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2776 printf(
"smtp parser in inconsistent state\n");
2781 STREAM_TOSERVER, request5_4, request5_4_len);
2783 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2790 printf(
"smtp parser in inconsistent state\n");
2795 STREAM_TOSERVER, request5_5, request5_5_len);
2797 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2803 printf(
"smtp parser in inconsistent state\n");
2808 STREAM_TOCLIENT, reply5, reply5_len);
2810 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2815 printf(
"smtp parser in inconsistent state\n");
2820 STREAM_TOSERVER, request6, request6_len);
2822 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2828 printf(
"smtp parser in inconsistent state\n");
2833 STREAM_TOCLIENT, reply6, reply6_len);
2835 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2840 printf(
"smtp parser in inconsistent state\n");
2845 STREAM_TOSERVER, request7, request7_len);
2847 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2853 printf(
"smtp parser in inconsistent state\n");
2858 STREAM_TOCLIENT, reply7, reply7_len);
2860 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2865 printf(
"smtp parser in inconsistent state\n");
2870 STREAM_TOSERVER, request8, request8_len);
2872 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2878 printf(
"smtp parser in inconsistent state\n");
2883 STREAM_TOCLIENT, reply8, reply8_len);
2885 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2891 printf(
"smtp parser in inconsistent state\n");
2896 STREAM_TOSERVER, request9_1, request9_1_len);
2898 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2905 printf(
"smtp parser in inconsistent state\n");
2910 STREAM_TOSERVER, request9_2, request9_2_len);
2912 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2919 printf(
"smtp parser in inconsistent state\n");
2924 STREAM_TOSERVER, request9_3, request9_3_len);
2926 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2933 printf(
"smtp parser in inconsistent state\n");
2938 STREAM_TOSERVER, request9_4, request9_4_len);
2940 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2947 printf(
"smtp parser in inconsistent state\n");
2952 STREAM_TOSERVER, request9_5, request9_5_len);
2954 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2960 printf(
"smtp parser in inconsistent state\n");
2965 STREAM_TOCLIENT, reply9, reply9_len);
2967 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2972 printf(
"smtp parser in inconsistent state\n");
2977 STREAM_TOSERVER, request10, request10_len);
2979 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2985 printf(
"smtp parser in inconsistent state\n");
2990 STREAM_TOCLIENT, reply10, reply10_len);
2992 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2997 printf(
"smtp parser in inconsistent state\n");
3013 static int SMTPParserTest03(
void)
3020 uint8_t welcome_reply[] = {
3021 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3022 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3023 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3024 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3025 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3026 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3028 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3031 uint8_t request1[] = {
3032 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3033 0x2e, 0x63, 0x6f, 0x6d, 0x0a
3035 uint32_t request1_len =
sizeof(request1);
3045 uint8_t reply1[] = {
3046 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3047 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3048 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3049 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3050 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3051 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3052 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3053 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3054 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3055 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3056 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3057 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3058 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3059 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3060 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3061 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3062 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3064 uint32_t reply1_len =
sizeof(reply1);
3071 uint8_t request2[] = {
3072 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3073 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3074 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3075 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3076 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3077 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3078 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3079 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
3080 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
3082 uint32_t request2_len =
sizeof(request2);
3087 uint8_t reply2[] = {
3088 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3089 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
3090 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
3091 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
3092 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
3093 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
3094 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
3095 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
3098 uint32_t reply2_len =
sizeof(reply2);
3103 memset(&f, 0,
sizeof(f));
3104 memset(&ssn, 0,
sizeof(ssn));
3108 f.
proto = IPPROTO_TCP;
3112 SMTPTestInitConfig();
3115 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3117 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3121 if (smtp_state == NULL) {
3122 printf(
"no smtp state: ");
3127 printf(
"smtp parser in inconsistent state\n");
3132 STREAM_TOSERVER, request1, request1_len);
3134 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3140 printf(
"smtp parser in inconsistent state\n");
3145 STREAM_TOCLIENT, reply1, reply1_len);
3147 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3153 printf(
"smtp parser in inconsistent state\n");
3158 STREAM_TOSERVER, request2, request2_len);
3160 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3170 printf(
"smtp parser in inconsistent state\n");
3175 STREAM_TOCLIENT, reply2, reply2_len);
3177 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3184 printf(
"smtp parser in inconsistent state\n");
3200 static int SMTPParserTest04(
void)
3207 uint8_t welcome_reply[] = {
3208 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3209 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3210 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3211 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3212 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3213 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3215 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3218 uint8_t request1[] = {
3219 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3220 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3221 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3222 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3223 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3224 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3226 uint32_t request1_len =
sizeof(request1);
3231 memset(&f, 0,
sizeof(f));
3232 memset(&ssn, 0,
sizeof(ssn));
3236 f.
proto = IPPROTO_TCP;
3240 SMTPTestInitConfig();
3243 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3245 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3249 if (smtp_state == NULL) {
3250 printf(
"no smtp state: ");
3255 printf(
"smtp parser in inconsistent state\n");
3260 STREAM_TOSERVER, request1, request1_len);
3262 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3268 printf(
"smtp parser in inconsistent state\n");
3284 static int SMTPParserTest05(
void)
3291 uint8_t welcome_reply[] = {
3292 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3293 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3294 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3295 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3296 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3297 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3299 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3302 uint8_t request1[] = {
3303 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3304 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3306 uint32_t request1_len =
sizeof(request1);
3316 uint8_t reply1[] = {
3317 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3318 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3319 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3320 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3321 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3322 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3323 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3324 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3325 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3326 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3327 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3328 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3329 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3330 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3331 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3332 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3333 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3335 uint32_t reply1_len =
sizeof(reply1);
3338 uint8_t request2[] = {
3339 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3342 uint32_t request2_len =
sizeof(request2);
3344 uint8_t reply2[] = {
3345 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3346 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3347 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3348 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3349 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3352 uint32_t reply2_len =
sizeof(reply2);
3355 uint8_t request3[] = {
3356 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3359 uint32_t request3_len =
sizeof(request3);
3361 uint8_t reply3[] = {
3362 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3363 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3365 uint32_t reply3_len =
sizeof(reply3);
3370 memset(&f, 0,
sizeof(f));
3371 memset(&ssn, 0,
sizeof(ssn));
3375 f.
proto = IPPROTO_TCP;
3379 SMTPTestInitConfig();
3382 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3384 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3388 if (smtp_state == NULL) {
3389 printf(
"no smtp state: ");
3394 printf(
"smtp parser in inconsistent state\n");
3399 STREAM_TOSERVER, request1, request1_len);
3401 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3407 printf(
"smtp parser in inconsistent state\n");
3412 STREAM_TOCLIENT, reply1, reply1_len);
3414 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3420 printf(
"smtp parser in inconsistent state\n");
3425 STREAM_TOSERVER, request2, request2_len);
3427 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3434 printf(
"smtp parser in inconsistent state\n");
3439 STREAM_TOCLIENT, reply2, reply2_len);
3441 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3447 printf(
"smtp parser in inconsistent state\n");
3459 STREAM_TOSERVER, request3, request3_len);
3461 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3468 printf(
"smtp parser in inconsistent state\n");
3473 STREAM_TOCLIENT, reply3, reply3_len);
3475 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3481 printf(
"smtp parser in inconsistent state\n");
3497 static int SMTPParserTest06(
void)
3503 uint8_t welcome_reply[] = {
3504 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3505 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3506 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3507 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3508 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3509 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3510 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3511 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3512 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3513 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3514 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3515 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3516 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3517 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3518 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3519 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3520 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3521 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3522 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3523 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3524 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3525 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3526 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3527 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3528 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3529 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3530 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3531 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3532 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3533 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3534 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3535 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3536 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3537 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3538 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3539 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3540 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3541 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3542 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3544 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3546 uint8_t request1[] = {
3547 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3548 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3549 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3550 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3553 uint32_t request1_len =
sizeof(request1);
3555 uint8_t reply1[] = {
3556 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3557 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3558 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3559 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3560 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3561 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3562 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3563 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3564 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3565 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3566 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3567 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3568 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3569 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3570 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3571 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3572 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3573 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3574 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3575 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3576 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3579 uint32_t reply1_len =
sizeof(reply1);
3582 uint8_t request2[] = {
3583 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3584 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3585 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3588 uint32_t request2_len =
sizeof(request2);
3590 uint8_t reply2[] = {
3591 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3592 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3594 uint32_t reply2_len =
sizeof(reply2);
3597 uint8_t request3[] = {
3598 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3599 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3600 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3603 uint32_t request3_len =
sizeof(request3);
3605 uint8_t reply3[] = {
3606 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3607 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3609 uint32_t reply3_len =
sizeof(reply3);
3612 uint8_t request4[] = {
3613 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3616 uint32_t request4_len =
sizeof(request4);
3618 uint8_t request5[] = {
3619 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3620 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3621 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3622 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3624 uint32_t request5_len =
sizeof(request5);
3626 uint8_t request6[] = {
3627 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3628 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3631 uint32_t request6_len =
sizeof(request6);
3636 memset(&f, 0,
sizeof(f));
3637 memset(&ssn, 0,
sizeof(ssn));
3641 f.
proto = IPPROTO_TCP;
3645 SMTPTestInitConfig();
3648 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3650 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3654 if (smtp_state == NULL) {
3655 printf(
"no smtp state: ");
3660 printf(
"smtp parser in inconsistent state\n");
3665 STREAM_TOSERVER, request1, request1_len);
3667 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3673 printf(
"smtp parser in inconsistent state\n");
3678 STREAM_TOCLIENT, reply1, reply1_len);
3680 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3685 printf(
"smtp parser in inconsistent state\n");
3690 STREAM_TOSERVER, request2, request2_len);
3692 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3698 printf(
"smtp parser in inconsistent state\n");
3703 STREAM_TOCLIENT, reply2, reply2_len);
3705 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3710 printf(
"smtp parser in inconsistent state\n");
3715 STREAM_TOSERVER, request3, request3_len);
3717 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3723 printf(
"smtp parser in inconsistent state\n");
3728 STREAM_TOCLIENT, reply3, reply3_len);
3730 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3735 printf(
"smtp parser in inconsistent state\n");
3740 STREAM_TOSERVER, request4, request4_len);
3742 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3750 printf(
"smtp parser in inconsistent state\n");
3755 STREAM_TOSERVER, request5, request5_len);
3757 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3764 printf(
"smtp parser in inconsistent state\n");
3769 STREAM_TOSERVER, request6, request6_len);
3771 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3777 printf(
"smtp parser in inconsistent state\n");
3790 static int SMTPParserTest12(
void)
3804 uint8_t request1[] = {
3805 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3806 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3808 int32_t request1_len =
sizeof(request1);
3812 uint8_t reply1[] = {
3813 0x31, 0x38, 0x38, 0x0d, 0x0a,
3815 uint32_t reply1_len =
sizeof(reply1);
3821 memset(&f, 0,
sizeof(f));
3822 memset(&ssn, 0,
sizeof(ssn));
3828 f.
proto = IPPROTO_TCP;
3837 SMTPTestInitConfig();
3846 "(msg:\"SMTP event handling\"; "
3847 "app-layer-event: smtp.invalid_reply; "
3856 STREAM_TOSERVER | STREAM_START, request1,
3859 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3864 if (smtp_state == NULL) {
3865 printf(
"no smtp state: ");
3873 printf(
"sid 1 matched. It shouldn't match: ");
3878 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3881 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3889 printf(
"sid 1 didn't match. Should have matched: ");
3907 static int SMTPParserTest13(
void)
3921 uint8_t request1[] = {
3922 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3923 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3925 int32_t request1_len =
sizeof(request1);
3929 uint8_t reply1[] = {
3930 0x32, 0x35, 0x30, 0x0d, 0x0a,
3932 uint32_t reply1_len =
sizeof(reply1);
3939 uint8_t request2[] = {
3940 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3941 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3942 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3943 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3944 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3945 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3946 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3947 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3950 uint32_t request2_len =
sizeof(request2);
3956 memset(&f, 0,
sizeof(f));
3957 memset(&ssn, 0,
sizeof(ssn));
3963 f.
proto = IPPROTO_TCP;
3972 SMTPTestInitConfig();
3981 "(msg:\"SMTP event handling\"; "
3983 "smtp.invalid_pipelined_sequence; "
3992 STREAM_TOSERVER | STREAM_START, request1,
3995 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4000 if (smtp_state == NULL) {
4001 printf(
"no smtp state: ");
4009 printf(
"sid 1 matched. It shouldn't match: ");
4014 STREAM_TOCLIENT, reply1, reply1_len);
4016 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4024 printf(
"sid 1 matched. It shouldn't match: ");
4029 STREAM_TOSERVER, request2, request2_len);
4031 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4039 printf(
"sid 1 didn't match. Should have matched: ");
4059 static int SMTPParserTest14(
void)
4066 static uint8_t welcome_reply[] = {
4067 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
4068 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
4069 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
4070 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
4071 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
4074 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
4077 static uint8_t request1[] = {
4078 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
4079 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
4081 static uint32_t request1_len =
sizeof(request1);
4088 static uint8_t reply1[] = {
4089 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
4090 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
4091 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
4092 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
4093 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
4094 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
4095 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
4096 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
4097 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
4098 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
4099 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
4100 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
4101 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
4102 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
4103 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
4105 static uint32_t reply1_len =
sizeof(reply1);
4108 static uint8_t request2[] = {
4109 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
4110 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
4111 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
4114 static uint32_t request2_len =
sizeof(request2);
4116 static uint8_t reply2[] = {
4117 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4118 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4120 static uint32_t reply2_len =
sizeof(reply2);
4123 static uint8_t request3[] = {
4124 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
4125 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
4126 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
4129 static uint32_t request3_len =
sizeof(request3);
4131 static uint8_t reply3[] = {
4132 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4133 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4135 static uint32_t reply3_len =
sizeof(reply3);
4138 static uint8_t request4[] = {
4139 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
4141 static uint32_t request4_len =
sizeof(request4);
4143 static uint8_t reply4[] = {
4144 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
4145 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
4146 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
4147 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
4148 0x4c, 0x46, 0x3e, 0x0d, 0x0a
4150 static uint32_t reply4_len =
sizeof(reply4);
4153 static uint64_t filesize = 133;
4154 static uint8_t request4_msg[] = {
4155 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
4156 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
4157 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4158 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
4159 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
4160 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
4161 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
4162 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4163 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
4164 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
4165 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
4166 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
4167 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
4168 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
4169 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
4170 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
4171 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
4172 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
4173 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
4174 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
4175 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
4176 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
4177 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4178 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
4179 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
4180 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
4181 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
4182 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
4183 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
4184 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4185 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
4186 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4187 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4188 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
4189 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4190 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4191 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4192 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4193 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
4194 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
4195 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
4196 0x41, 0x3D, 0x3D, 0x0D,0x0A };
4197 static uint32_t request4_msg_len =
sizeof(request4_msg);
4200 static uint8_t request4_end[] = {
4201 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4203 static uint32_t request4_end_len =
sizeof(request4_end);
4205 static uint8_t reply4_end[] = {
4206 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4207 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
4208 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
4209 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
4210 0x46, 0x32, 0x0d, 0x0a
4212 static uint32_t reply4_end_len =
sizeof(reply4_end);
4215 static uint8_t request5[] = {
4216 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
4218 static uint32_t request5_len =
sizeof(request5);
4220 static uint8_t reply5[] = {
4221 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4222 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
4224 static uint32_t reply5_len =
sizeof(reply5);
4229 memset(&f, 0,
sizeof(f));
4230 memset(&ssn, 0,
sizeof(ssn));
4234 f.
proto = IPPROTO_TCP;
4238 SMTPTestInitConfig();
4242 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
4244 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4248 if (smtp_state == NULL) {
4249 printf(
"no smtp state: ");
4254 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4259 STREAM_TOSERVER, request1, request1_len);
4261 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4267 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4273 STREAM_TOCLIENT, reply1, reply1_len);
4275 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4279 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4280 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4286 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4292 STREAM_TOSERVER, request2, request2_len);
4294 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4300 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4306 STREAM_TOCLIENT, reply2, reply2_len);
4308 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4314 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4322 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4328 STREAM_TOSERVER, request3, request3_len);
4330 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4336 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4342 STREAM_TOCLIENT, reply3, reply3_len);
4344 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4349 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4355 SCMimeSmtpConfigDecodeBase64(1);
4356 SCMimeSmtpConfigDecodeQuoted(1);
4360 STREAM_TOSERVER, request4, request4_len);
4362 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4369 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4375 STREAM_TOCLIENT, reply4, reply4_len);
4377 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4383 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4389 STREAM_TOSERVER, request4_msg, request4_msg_len);
4391 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4399 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4405 STREAM_TOSERVER, request4_end, request4_end_len);
4407 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4415 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4424 if (files != NULL && files->
head != NULL) {
4427 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4428 printf(
"smtp-mime file name is incorrect");
4432 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4435 static uint8_t org_binary[] = {
4436 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4437 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4439 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4440 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4441 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4442 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4443 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4444 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4445 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4446 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4447 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4448 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4449 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4450 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4451 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4452 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4455 org_binary,
sizeof(org_binary)) != 1)
4457 printf(
"smtp-mime file data incorrect\n");
4464 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4466 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4471 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4477 STREAM_TOSERVER, request5, request5_len);
4479 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4485 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4491 STREAM_TOCLIENT, reply5, reply5_len);
4493 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4498 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);