53 #define FILEDATA_CONTENT_LIMIT 100000
55 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
57 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
60 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
62 #define SMTP_COMMAND_BUFFER_STEPS 5
69 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
71 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
73 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
75 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
81 #define SMTP_COMMAND_STARTTLS 1
82 #define SMTP_COMMAND_DATA 2
83 #define SMTP_COMMAND_BDAT 3
88 #define SMTP_COMMAND_DATA_MODE 4
90 #define SMTP_COMMAND_OTHER_CMD 5
91 #define SMTP_COMMAND_RSET 6
92 #define SMTP_COMMAND_QUIT 7
94 #define SMTP_COMMAND_BDAT_LAST 8
96 #define SMTP_DEFAULT_MAX_TX 256
99 #define SMTP_NO_TX_ID UINT64_MAX
175 static int SMTPGetFrameIdByName(
const char *frame_name)
184 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
204 static int SMTPStateGetStateIdByName(
const char *
name,
const uint8_t direction)
207 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
215 static const char *SMTPStateGetStateNameById(
const int id,
const uint8_t direction)
218 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
222 static inline void SMTPSetProgressTS(
SMTPTransaction *tx, uint8_t progress)
229 static inline void SMTPSetProgressTC(
SMTPTransaction *tx, uint8_t progress)
255 static bool SMTPTransactionRequestIsComplete(
const SMTPTransaction *tx)
265 #define SMTP_MPM mpm_default_matcher
267 static MpmCtx *smtp_mpm_ctx = NULL;
375 #define SCHEME_SUFFIX_LEN 3
383 static void SMTPConfigure(
void) {
387 uint32_t content_limit = 0;
388 uint32_t content_inspect_min_size = 0;
389 uint32_t content_inspect_window = 0;
392 if (config != NULL) {
403 SCMimeSmtpConfigDecodeBase64(val);
408 SCMimeSmtpConfigDecodeQuoted(val);
413 if (imval < 0 || imval > UINT32_MAX) {
414 FatalError(
"Invalid value for header-value-depth");
416 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
421 SCMimeSmtpConfigExtractUrls(val);
428 if (extract_urls_schemes) {
432 size_t scheme_len = strlen(scheme->
val);
434 FatalError(
"extract-urls-schemes entry '%s' is too long", scheme->
val);
436 if (scheme->
val[scheme_len - 1] !=
'/') {
439 int r = snprintf(tmp,
sizeof(tmp),
"%s://", scheme->
val);
440 if (r != (
int)scheme_len) {
441 FatalError(
"snprintf failure for SMTP url extraction scheme.");
445 FatalError(
"extract-urls-schemes entry SCStrdup failure.");
448 scheme->
val = new_val;
450 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
452 FatalError(
"Failed to add smtp extract url scheme");
458 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
463 SCMimeSmtpConfigLogUrlScheme(val);
470 SCMimeSmtpConfigBodyMd5(
false);
472 SCMimeSmtpConfigBodyMd5(
true);
473 }
else if (strcmp(strval,
"auto") != 0) {
484 if (strcasecmp(
"content-limit",
p->name) == 0) {
492 if (strcasecmp(
"content-inspect-min-size",
p->name) == 0) {
494 SCLogWarning(
"parsing content-inspect-min-size %s failed",
p->val);
500 if (strcasecmp(
"content-inspect-window",
p->name) == 0) {
502 SCLogWarning(
"parsing content-inspect-window %s failed",
p->val);
517 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
518 "options can't be enabled at the same time, "
519 "disabling raw extraction");
525 const char *
str = NULL;
538 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
569 if (tx->
tx_id == tx_id) {
572 if (tx->
tx_id > tx_id) {
596 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
598 }
else if (tx == NULL) {
599 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
601 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
611 if (tx == NULL || file == NULL) {
616 FlagDetectStateNewFile(tx);
648 if (direction == 0 &&
655 }
else if (direction == 1) {
659 if (frame != NULL && reply_tx != NULL) {
666 const uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
669 if (lf_idx == NULL) {
682 uint32_t o_consumed = input->
consumed;
683 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
691 line->
buf = input->
buf + o_consumed;
694 frame->
len = (int64_t)line->
len;
702 if (discard_till_lf) {
704 if (direction == 0) {
724 static int SMTPInsertCommandIntoCommandBuffer(
772 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
797 SMTPTransactionCompleteTS(tx);
804 static void SetMimeEvents(
SMTPState *state, uint32_t events)
810 if (events & MIME_ANOM_INVALID_BASE64) {
813 if (events & MIME_ANOM_INVALID_QP) {
816 if (events & MIME_ANOM_LONG_LINE) {
819 if (events & MIME_ANOM_LONG_ENC_LINE) {
822 if (events & MIME_ANOM_LONG_HEADER_NAME) {
825 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
828 if (events & MIME_ANOM_LONG_BOUNDARY) {
831 if (events & MIME_ANOM_LONG_FILENAME) {
849 static int SMTPProcessCommandDATA(
861 if (line->
len == 1 && line->
buf[0] ==
'.') {
879 SMTPTransactionCompleteTS(tx);
893 const uint8_t *filename = NULL;
894 uint16_t filename_len = 0;
899 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
901 SetMimeEvents(state, events);
903 case MimeSmtpFileOpen:
907 if (filename_len == 0) {
914 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
930 case MimeSmtpFileChunk:
939 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
950 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
955 case MimeSmtpFileClose:
958 SCLogDebug(
"FileCloseFile() failed: %d", ret);
966 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
975 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
980 static int SMTPProcessReply(
991 if (reply_tx != NULL) {
1002 if (line->
len >= 4) {
1004 if (line->
buf[3] !=
'-') {
1008 if (line->
buf[3] ==
'-') {
1026 SCLogDebug(
"invalid reply code %02x %02x %02x", line->
buf[0], line->
buf[1], line->
buf[2]);
1030 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
1049 SCLogDebug(
"unable to match reply with request");
1064 SMTPTransactionComplete(reply_tx);
1099 SMTPTransactionCompleteTC(reply_tx);
1103 SMTPTransactionCompleteTC(reply_tx);
1108 SMTPTransactionComplete(reply_tx);
1113 SMTPTransactionComplete(reply_tx);
1127 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1142 static int SMTPParseCommandBDAT(
SMTPState *state,
const SMTPLine *line,
bool *last)
1149 while (i < line->
len) {
1150 if (line->
buf[i] !=
' ') {
1159 if (i == line->
len) {
1166 if (line->
len - i <
len) {
1169 memcpy(strbuf, line->
buf + i,
len);
1179 if (i < line->
len && line->
buf[i] !=
' ') {
1182 while (i < line->
len && line->
buf[i] ==
' ') {
1185 if (line->
len - i == 4 && SCMemcmpLowercase(
"last", line->
buf + i, 4) == 0) {
1187 }
else if (i != line->
len) {
1194 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1195 uint8_t **target, uint16_t *target_len)
1197 int i = prefix_len + 1;
1199 while (i < line->
len) {
1200 if (line->
buf[i] !=
' ') {
1209 while (spc_i < line->
len) {
1210 if (line->
buf[spc_i] ==
' ') {
1217 if (*target == NULL)
1219 memcpy(*target, line->
buf + i, spc_i - i);
1220 (*target)[spc_i - i] =
'\0';
1221 if (spc_i - i > UINT16_MAX) {
1222 *target_len = UINT16_MAX;
1225 *target_len = (uint16_t)(spc_i - i);
1237 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1246 return SMTPParseCommandWithParam(
1253 uint16_t rcptto_len;
1255 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1258 rcptto_str->
str = rcptto;
1259 rcptto_str->
len = rcptto_len;
1275 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1277 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1285 #define rawmsgname "rawmsg"
1304 static int SMTPProcessRequest(
1312 frame->
len = (int64_t)line->
len;
1328 const bool no_new_tx = NoNewTx(state, line);
1329 if ((state->
curr_tx == NULL && (state->
tx_cnt == 0 || !no_new_tx)) ||
1330 (SMTPTransactionRequestIsComplete(state->
curr_tx) && !no_new_tx)) {
1331 tx = SMTPTransactionCreate(state);
1344 if (frame != NULL && state->
curr_tx) {
1365 const bool is_rset = SCMemcmpLowercase(
"rset", line->
buf, 4) == 0;
1369 }
else if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1371 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1398 if (data_frame == NULL) {
1399 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1408 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1410 r = SMTPParseCommandBDAT(state, line, &last);
1423 SMTPTransactionCompleteTS(tx);
1426 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1427 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1428 r = SMTPParseCommandHELO(state, line);
1443 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1444 r = SMTPParseCommandMAILFROM(state, line);
1449 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1450 r = SMTPParseCommandRCPTTO(state, line);
1455 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1459 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1467 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1476 return SMTPProcessCommandDATA(state, tx,
f, line);
1480 return SMTPProcessCommandBDAT(state, tx, line);
1489 static inline void ResetLine(
SMTPLine *line)
1498 static int SMTPPreProcessCommandBDAT(
1509 uint32_t consumed =
MIN((uint32_t)input->
len, remaining);
1511 line->
len = consumed;
1513 input->
len -= consumed;
1514 int ret = SMTPProcessRequest(state,
f, input, line, slice);
1539 static int SMTPPreProcessCommands(
1548 return SMTPPreProcessCommandBDAT(state,
f, slice, input, line);
1556 bool line_complete =
false;
1557 const int32_t input_len = input->
len;
1559 for (int32_t i = 0; i < input_len; i++) {
1561 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1567 line_complete =
true;
1568 }
else if (input->
buf[
offset + i] == 0x0a) {
1571 line_complete =
true;
1574 if (line_complete || (i == input_len - 1)) {
1581 SCLogDebug(
"Possible boundary, yield to GetLine");
1585 int32_t total_consumed =
offset + i + 1;
1586 int32_t current_line_consumed = total_consumed - input->
consumed;
1591 if (line->
len < 0) {
1596 input->
len -= current_line_consumed;
1598 if (SMTPProcessRequest(state,
f, input, line, slice) == -1) {
1601 line_complete =
false;
1624 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1625 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1627 if (input_buf == NULL &&
1632 }
else if (input_buf == NULL || input_len == 0) {
1636 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1637 SMTPLine line = { NULL, 0, 0,
false };
1640 if (direction == 0) {
1645 int ret = SMTPPreProcessCommands(state,
f, &stream_slice, &input, &line);
1649 }
else if (ret < 0) {
1653 AppLayerResult res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1654 while (res.
status == 0) {
1655 int retval = SMTPProcessRequest(state,
f, &input, &line, &stream_slice);
1675 if ((input.
len > 0) &&
1680 int ret = SMTPPreProcessCommands(state,
f, &stream_slice, &input, &line);
1684 }
else if (ret < 0) {
1688 res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1694 AppLayerResult res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1695 while (res.
status == 0) {
1696 if (SMTPProcessReply(state,
f, thread_data, &input, &line) != 0)
1706 res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1721 return SMTPParse(0,
f, alstate, pstate, stream_slice, local_data);
1730 return SMTPParse(1,
f, alstate, pstate, stream_slice, local_data);
1745 if (smtp_state->
cmds == NULL) {
1780 static void *SMTPLocalStorageAlloc(
void)
1789 if (td->
pmq == NULL) {
1802 static void SMTPLocalStorageFree(
void *ptr)
1806 if (td->
pmq != NULL) {
1834 SMTPStringFree(
str);
1845 static void SMTPStateFree(
void *
p)
1849 if (smtp_state->
cmds != NULL) {
1856 if (smtp_state->
helo) {
1861 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1863 SMTPTransactionFree(tx, smtp_state);
1869 static void SMTPSetMpmState(
void)
1872 if (
unlikely(smtp_mpm_ctx == NULL)) {
1888 static void SMTPFreeMpmState(
void)
1890 if (smtp_mpm_ctx != NULL) {
1893 smtp_mpm_ctx = NULL;
1897 static int SMTPStateGetEventInfo(
1907 static int SMTPStateGetEventInfoById(
1911 if (*event_name == NULL) {
1913 "smtp's enum map table.",
1926 static AppProto SMTPClientProbingParserCheckPort(
1927 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1935 static AppProto SMTPServerProbingParser(
1936 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1943 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1947 if (input[3] !=
' ' && input[3] !=
'-') {
1953 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1964 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1975 static int SMTPRegisterPatternsForProtocolDetection(
void)
1978 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1982 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1986 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1991 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1994 NULL, SMTPServerProbingParser);
2000 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
2005 if (tx_id < tx->tx_id)
2007 else if (tx_id > tx->
tx_id)
2010 if (tx == smtp_state->
curr_tx)
2014 SMTPTransactionFree(tx, state);
2022 static uint64_t SMTPStateGetTxCnt(
void *state)
2033 static void *SMTPStateGetTx(
void *state, uint64_t
id)
2039 if (smtp_state->
curr_tx == NULL)
2045 if (tx->
tx_id ==
id)
2052 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
2055 if (direction & STREAM_TOSERVER) {
2066 if (direction & STREAM_TOSERVER) {
2095 if (state->
un.
ptr == NULL) {
2101 while (tx_ptr->
tx_id < min_tx_id) {
2107 if (tx_ptr->
tx_id >= max_tx_id) {
2114 .has_next = (state->
un.
ptr != NULL),
2127 const char *proto_name =
"smtp";
2131 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
2134 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
2143 SMTPParseClientRecord);
2145 SMTPParseServerRecord);
2151 SMTPLocalStorageFree);
2164 IPPROTO_TCP,
ALPROTO_SMTP, SMTPGetFrameIdByName, SMTPGetFrameNameById);
2166 IPPROTO_TCP,
ALPROTO_SMTP, SMTPStateGetStateIdByName, SMTPStateGetStateNameById);
2168 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2201 static void SMTPTestInitConfig(
void)
2215 static int SMTPParserTest01(
void)
2222 uint8_t welcome_reply[] = {
2223 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2224 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2225 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2226 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2227 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2230 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2233 uint8_t request1[] = {
2234 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
2235 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
2236 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
2238 uint32_t request1_len =
sizeof(request1);
2245 uint8_t reply1[] = {
2246 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
2247 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2248 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
2249 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
2250 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
2251 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
2252 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
2253 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
2254 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
2255 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
2256 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
2257 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
2258 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
2259 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
2260 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
2261 0x44, 0x45, 0x53, 0x0d, 0x0a
2263 uint32_t reply1_len =
sizeof(reply1);
2266 uint8_t request2[] = {
2267 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2270 uint32_t request2_len =
sizeof(request2);
2272 uint8_t reply2[] = {
2273 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2274 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
2275 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
2276 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
2278 uint32_t reply2_len =
sizeof(reply2);
2283 memset(&
f, 0,
sizeof(
f));
2284 memset(&
ssn, 0,
sizeof(
ssn));
2292 SMTPTestInitConfig();
2295 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2297 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2301 if (smtp_state == NULL) {
2302 printf(
"no smtp state: ");
2307 printf(
"smtp parser in inconsistent state\n");
2312 STREAM_TOSERVER, request1, request1_len);
2314 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2320 printf(
"smtp parser in inconsistent state\n");
2325 STREAM_TOCLIENT, reply1, reply1_len);
2327 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2332 printf(
"smtp parser in inconsistent state\n");
2337 STREAM_TOSERVER, request2, request2_len);
2339 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2345 printf(
"smtp parser in inconsistent state\n");
2350 STREAM_TOCLIENT, reply2, reply2_len);
2352 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2358 printf(
"smtp parser in inconsistent state\n");
2378 static int SMTPParserTest02(
void)
2385 uint8_t welcome_reply[] = {
2386 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2387 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2388 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2389 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2390 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2393 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2396 uint8_t request1[] = {
2397 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2398 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2400 uint32_t request1_len =
sizeof(request1);
2407 uint8_t reply1[] = {
2408 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2409 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2410 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2411 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2412 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2413 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2414 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2415 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2416 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2417 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2418 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2419 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2420 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2421 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2422 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2424 uint32_t reply1_len =
sizeof(reply1);
2427 uint8_t request2[] = {
2428 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2429 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2430 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2433 uint32_t request2_len =
sizeof(request2);
2435 uint8_t reply2[] = {
2436 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2437 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2439 uint32_t reply2_len =
sizeof(reply2);
2442 uint8_t request3[] = {
2443 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2444 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2445 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2448 uint32_t request3_len =
sizeof(request3);
2450 uint8_t reply3[] = {
2451 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2452 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2454 uint32_t reply3_len =
sizeof(reply3);
2457 uint8_t request4[] = {
2458 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2460 uint32_t request4_len =
sizeof(request4);
2462 uint8_t reply4[] = {
2463 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2464 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2465 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2466 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2467 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2469 uint32_t reply4_len =
sizeof(reply4);
2472 uint8_t request5_1[] = {
2473 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2474 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2475 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2477 uint32_t request5_1_len =
sizeof(request5_1);
2479 uint8_t request5_2[] = {
2480 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2481 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2482 0x6f, 0x6d, 0x0d, 0x0a
2484 uint32_t request5_2_len =
sizeof(request5_2);
2486 uint8_t request5_3[] = {
2489 uint32_t request5_3_len =
sizeof(request5_3);
2491 uint8_t request5_4[] = {
2492 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2493 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2494 0x6c, 0x31, 0x0d, 0x0a
2496 uint32_t request5_4_len =
sizeof(request5_4);
2498 uint8_t request5_5[] = {
2501 uint32_t request5_5_len =
sizeof(request5_5);
2503 uint8_t reply5[] = {
2504 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2505 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2506 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2507 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2508 0x46, 0x32, 0x0d, 0x0a
2510 uint32_t reply5_len =
sizeof(reply5);
2513 uint8_t request6[] = {
2514 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2515 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2516 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2519 uint32_t request6_len =
sizeof(request6);
2521 uint8_t reply6[] = {
2522 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2523 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2525 uint32_t reply6_len =
sizeof(reply6);
2528 uint8_t request7[] = {
2529 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2530 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2531 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2534 uint32_t request7_len =
sizeof(request7);
2536 uint8_t reply7[] = {
2537 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2538 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2540 uint32_t reply7_len =
sizeof(reply7);
2543 uint8_t request8[] = {
2544 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2546 uint32_t request8_len =
sizeof(request8);
2548 uint8_t reply8[] = {
2549 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2550 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2551 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2552 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2553 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2555 uint32_t reply8_len =
sizeof(reply8);
2558 uint8_t request9_1[] = {
2559 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2560 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2561 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2563 uint32_t request9_1_len =
sizeof(request9_1);
2565 uint8_t request9_2[] = {
2566 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2567 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2568 0x6f, 0x6d, 0x0d, 0x0a
2570 uint32_t request9_2_len =
sizeof(request9_2);
2572 uint8_t request9_3[] = {
2575 uint32_t request9_3_len =
sizeof(request9_3);
2577 uint8_t request9_4[] = {
2578 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2579 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2580 0x6c, 0x32, 0x0d, 0x0a
2582 uint32_t request9_4_len =
sizeof(request9_4);
2584 uint8_t request9_5[] = {
2587 uint32_t request9_5_len =
sizeof(request9_5);
2589 uint8_t reply9[] = {
2590 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2591 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2592 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2593 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2594 0x46, 0x32, 0x0d, 0x0a
2596 uint32_t reply9_len =
sizeof(reply9);
2599 uint8_t request10[] = {
2600 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2602 uint32_t request10_len =
sizeof(request10);
2604 uint8_t reply10[] = {
2605 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2606 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2608 uint32_t reply10_len =
sizeof(reply10);
2613 memset(&
f, 0,
sizeof(
f));
2614 memset(&
ssn, 0,
sizeof(
ssn));
2622 SMTPTestInitConfig();
2625 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2627 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2631 if (smtp_state == NULL) {
2632 printf(
"no smtp state: ");
2637 printf(
"smtp parser in inconsistent state\n");
2642 STREAM_TOSERVER, request1, request1_len);
2644 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2650 printf(
"smtp parser in inconsistent state\n");
2655 STREAM_TOCLIENT, reply1, reply1_len);
2657 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2662 printf(
"smtp parser in inconsistent state\n");
2667 STREAM_TOSERVER, request2, request2_len);
2669 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2675 printf(
"smtp parser in inconsistent state\n");
2680 STREAM_TOCLIENT, reply2, reply2_len);
2682 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2687 printf(
"smtp parser in inconsistent state\n");
2692 STREAM_TOSERVER, request3, request3_len);
2694 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2700 printf(
"smtp parser in inconsistent state\n");
2705 STREAM_TOCLIENT, reply3, reply3_len);
2707 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2712 printf(
"smtp parser in inconsistent state\n");
2717 STREAM_TOSERVER, request4, request4_len);
2719 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2725 printf(
"smtp parser in inconsistent state\n");
2730 STREAM_TOCLIENT, reply4, reply4_len);
2732 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2738 printf(
"smtp parser in inconsistent state\n");
2743 STREAM_TOSERVER, request5_1, request5_1_len);
2745 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2752 printf(
"smtp parser in inconsistent state\n");
2757 STREAM_TOSERVER, request5_2, request5_2_len);
2759 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2766 printf(
"smtp parser in inconsistent state\n");
2771 STREAM_TOSERVER, request5_3, request5_3_len);
2773 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2780 printf(
"smtp parser in inconsistent state\n");
2785 STREAM_TOSERVER, request5_4, request5_4_len);
2787 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2794 printf(
"smtp parser in inconsistent state\n");
2799 STREAM_TOSERVER, request5_5, request5_5_len);
2801 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2807 printf(
"smtp parser in inconsistent state\n");
2812 STREAM_TOCLIENT, reply5, reply5_len);
2814 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2819 printf(
"smtp parser in inconsistent state\n");
2824 STREAM_TOSERVER, request6, request6_len);
2826 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2832 printf(
"smtp parser in inconsistent state\n");
2837 STREAM_TOCLIENT, reply6, reply6_len);
2839 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2844 printf(
"smtp parser in inconsistent state\n");
2849 STREAM_TOSERVER, request7, request7_len);
2851 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2857 printf(
"smtp parser in inconsistent state\n");
2862 STREAM_TOCLIENT, reply7, reply7_len);
2864 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2869 printf(
"smtp parser in inconsistent state\n");
2874 STREAM_TOSERVER, request8, request8_len);
2876 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2882 printf(
"smtp parser in inconsistent state\n");
2887 STREAM_TOCLIENT, reply8, reply8_len);
2889 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2895 printf(
"smtp parser in inconsistent state\n");
2900 STREAM_TOSERVER, request9_1, request9_1_len);
2902 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2909 printf(
"smtp parser in inconsistent state\n");
2914 STREAM_TOSERVER, request9_2, request9_2_len);
2916 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2923 printf(
"smtp parser in inconsistent state\n");
2928 STREAM_TOSERVER, request9_3, request9_3_len);
2930 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2937 printf(
"smtp parser in inconsistent state\n");
2942 STREAM_TOSERVER, request9_4, request9_4_len);
2944 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2951 printf(
"smtp parser in inconsistent state\n");
2956 STREAM_TOSERVER, request9_5, request9_5_len);
2958 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2964 printf(
"smtp parser in inconsistent state\n");
2969 STREAM_TOCLIENT, reply9, reply9_len);
2971 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2976 printf(
"smtp parser in inconsistent state\n");
2981 STREAM_TOSERVER, request10, request10_len);
2983 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2989 printf(
"smtp parser in inconsistent state\n");
2994 STREAM_TOCLIENT, reply10, reply10_len);
2996 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3001 printf(
"smtp parser in inconsistent state\n");
3017 static int SMTPParserTest03(
void)
3024 uint8_t welcome_reply[] = {
3025 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3026 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3027 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3028 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3029 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3030 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3032 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3035 uint8_t request1[] = {
3036 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3037 0x2e, 0x63, 0x6f, 0x6d, 0x0a
3039 uint32_t request1_len =
sizeof(request1);
3049 uint8_t reply1[] = {
3050 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3051 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3052 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3053 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3054 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3055 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3056 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3057 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3058 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3059 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3060 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3061 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3062 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3063 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3064 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3065 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3066 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3068 uint32_t reply1_len =
sizeof(reply1);
3075 uint8_t request2[] = {
3076 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3077 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3078 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3079 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3080 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3081 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3082 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3083 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
3084 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
3086 uint32_t request2_len =
sizeof(request2);
3091 uint8_t reply2[] = {
3092 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3093 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
3094 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
3095 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
3096 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
3097 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
3098 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
3099 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
3102 uint32_t reply2_len =
sizeof(reply2);
3107 memset(&
f, 0,
sizeof(
f));
3108 memset(&
ssn, 0,
sizeof(
ssn));
3116 SMTPTestInitConfig();
3119 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3121 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3125 if (smtp_state == NULL) {
3126 printf(
"no smtp state: ");
3131 printf(
"smtp parser in inconsistent state\n");
3136 STREAM_TOSERVER, request1, request1_len);
3138 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3144 printf(
"smtp parser in inconsistent state\n");
3149 STREAM_TOCLIENT, reply1, reply1_len);
3151 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3157 printf(
"smtp parser in inconsistent state\n");
3162 STREAM_TOSERVER, request2, request2_len);
3164 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3174 printf(
"smtp parser in inconsistent state\n");
3179 STREAM_TOCLIENT, reply2, reply2_len);
3181 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3188 printf(
"smtp parser in inconsistent state\n");
3204 static int SMTPParserTest04(
void)
3211 uint8_t welcome_reply[] = {
3212 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3213 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3214 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3215 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3216 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3217 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3219 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3222 uint8_t request1[] = {
3223 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3224 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3225 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3226 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3227 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3228 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3230 uint32_t request1_len =
sizeof(request1);
3235 memset(&
f, 0,
sizeof(
f));
3236 memset(&
ssn, 0,
sizeof(
ssn));
3244 SMTPTestInitConfig();
3247 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3249 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3253 if (smtp_state == NULL) {
3254 printf(
"no smtp state: ");
3259 printf(
"smtp parser in inconsistent state\n");
3264 STREAM_TOSERVER, request1, request1_len);
3266 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3272 printf(
"smtp parser in inconsistent state\n");
3288 static int SMTPParserTest05(
void)
3295 uint8_t welcome_reply[] = {
3296 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
3297 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3298 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3299 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
3300 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
3301 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
3303 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3306 uint8_t request1[] = {
3307 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3308 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3310 uint32_t request1_len =
sizeof(request1);
3320 uint8_t reply1[] = {
3321 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3322 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3323 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3324 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3325 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
3326 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
3327 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3328 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3329 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3330 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3331 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3332 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3333 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3334 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3335 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3336 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3337 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3339 uint32_t reply1_len =
sizeof(reply1);
3342 uint8_t request2[] = {
3343 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3346 uint32_t request2_len =
sizeof(request2);
3348 uint8_t reply2[] = {
3349 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
3350 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
3351 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
3352 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
3353 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3356 uint32_t reply2_len =
sizeof(reply2);
3359 uint8_t request3[] = {
3360 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3363 uint32_t request3_len =
sizeof(request3);
3365 uint8_t reply3[] = {
3366 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3367 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3369 uint32_t reply3_len =
sizeof(reply3);
3374 memset(&
f, 0,
sizeof(
f));
3375 memset(&
ssn, 0,
sizeof(
ssn));
3383 SMTPTestInitConfig();
3386 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3388 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3392 if (smtp_state == NULL) {
3393 printf(
"no smtp state: ");
3398 printf(
"smtp parser in inconsistent state\n");
3403 STREAM_TOSERVER, request1, request1_len);
3405 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3411 printf(
"smtp parser in inconsistent state\n");
3416 STREAM_TOCLIENT, reply1, reply1_len);
3418 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3424 printf(
"smtp parser in inconsistent state\n");
3429 STREAM_TOSERVER, request2, request2_len);
3431 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3438 printf(
"smtp parser in inconsistent state\n");
3443 STREAM_TOCLIENT, reply2, reply2_len);
3445 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3451 printf(
"smtp parser in inconsistent state\n");
3463 STREAM_TOSERVER, request3, request3_len);
3465 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3472 printf(
"smtp parser in inconsistent state\n");
3477 STREAM_TOCLIENT, reply3, reply3_len);
3479 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3485 printf(
"smtp parser in inconsistent state\n");
3501 static int SMTPParserTest06(
void)
3507 uint8_t welcome_reply[] = {
3508 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3509 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3510 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3511 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3512 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3513 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3514 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3515 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3516 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3517 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3518 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3519 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3520 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3521 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3522 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3523 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3524 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3525 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3526 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3527 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3528 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3529 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3530 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3531 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3532 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3533 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3534 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3535 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3536 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3537 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3538 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3539 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3540 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3541 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3542 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3543 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3544 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3545 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3546 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3548 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3550 uint8_t request1[] = {
3551 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3552 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3553 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3554 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3557 uint32_t request1_len =
sizeof(request1);
3559 uint8_t reply1[] = {
3560 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3561 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3562 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3563 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3564 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3565 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3566 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3567 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3568 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3569 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3570 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3571 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3572 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3573 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3574 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3575 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3576 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3577 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3578 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3579 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3580 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3583 uint32_t reply1_len =
sizeof(reply1);
3586 uint8_t request2[] = {
3587 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3588 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3589 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3592 uint32_t request2_len =
sizeof(request2);
3594 uint8_t reply2[] = {
3595 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3596 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3598 uint32_t reply2_len =
sizeof(reply2);
3601 uint8_t request3[] = {
3602 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3603 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3604 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3607 uint32_t request3_len =
sizeof(request3);
3609 uint8_t reply3[] = {
3610 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3611 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3613 uint32_t reply3_len =
sizeof(reply3);
3616 uint8_t request4[] = {
3617 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3620 uint32_t request4_len =
sizeof(request4);
3622 uint8_t request5[] = {
3623 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3624 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3625 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3626 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3628 uint32_t request5_len =
sizeof(request5);
3630 uint8_t request6[] = {
3631 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3632 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3635 uint32_t request6_len =
sizeof(request6);
3640 memset(&
f, 0,
sizeof(
f));
3641 memset(&
ssn, 0,
sizeof(
ssn));
3649 SMTPTestInitConfig();
3652 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3654 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3658 if (smtp_state == NULL) {
3659 printf(
"no smtp state: ");
3664 printf(
"smtp parser in inconsistent state\n");
3669 STREAM_TOSERVER, request1, request1_len);
3671 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3677 printf(
"smtp parser in inconsistent state\n");
3682 STREAM_TOCLIENT, reply1, reply1_len);
3684 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3689 printf(
"smtp parser in inconsistent state\n");
3694 STREAM_TOSERVER, request2, request2_len);
3696 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3702 printf(
"smtp parser in inconsistent state\n");
3707 STREAM_TOCLIENT, reply2, reply2_len);
3709 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3714 printf(
"smtp parser in inconsistent state\n");
3719 STREAM_TOSERVER, request3, request3_len);
3721 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3727 printf(
"smtp parser in inconsistent state\n");
3732 STREAM_TOCLIENT, reply3, reply3_len);
3734 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3739 printf(
"smtp parser in inconsistent state\n");
3744 STREAM_TOSERVER, request4, request4_len);
3746 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3754 printf(
"smtp parser in inconsistent state\n");
3759 STREAM_TOSERVER, request5, request5_len);
3761 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3768 printf(
"smtp parser in inconsistent state\n");
3773 STREAM_TOSERVER, request6, request6_len);
3775 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3781 printf(
"smtp parser in inconsistent state\n");
3794 static int SMTPParserTest12(
void)
3808 uint8_t request1[] = {
3809 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3810 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3812 int32_t request1_len =
sizeof(request1);
3816 uint8_t reply1[] = {
3817 0x31, 0x38, 0x38, 0x0d, 0x0a,
3819 uint32_t reply1_len =
sizeof(reply1);
3825 memset(&
f, 0,
sizeof(
f));
3826 memset(&
ssn, 0,
sizeof(
ssn));
3841 SMTPTestInitConfig();
3850 "(msg:\"SMTP event handling\"; "
3851 "app-layer-event: smtp.invalid_reply; "
3860 STREAM_TOSERVER | STREAM_START, request1,
3863 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3868 if (smtp_state == NULL) {
3869 printf(
"no smtp state: ");
3877 printf(
"sid 1 matched. It shouldn't match: ");
3882 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3885 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3893 printf(
"sid 1 didn't match. Should have matched: ");
3911 static int SMTPParserTest13(
void)
3925 uint8_t request1[] = {
3926 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3927 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3929 int32_t request1_len =
sizeof(request1);
3933 uint8_t reply1[] = {
3934 0x32, 0x35, 0x30, 0x0d, 0x0a,
3936 uint32_t reply1_len =
sizeof(reply1);
3943 uint8_t request2[] = {
3944 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3945 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3946 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3947 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3948 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3949 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3950 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3951 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3954 uint32_t request2_len =
sizeof(request2);
3960 memset(&
f, 0,
sizeof(
f));
3961 memset(&
ssn, 0,
sizeof(
ssn));
3976 SMTPTestInitConfig();
3985 "(msg:\"SMTP event handling\"; "
3987 "smtp.invalid_pipelined_sequence; "
3996 STREAM_TOSERVER | STREAM_START, request1,
3999 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4004 if (smtp_state == NULL) {
4005 printf(
"no smtp state: ");
4013 printf(
"sid 1 matched. It shouldn't match: ");
4018 STREAM_TOCLIENT, reply1, reply1_len);
4020 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4028 printf(
"sid 1 matched. It shouldn't match: ");
4033 STREAM_TOSERVER, request2, request2_len);
4035 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
4043 printf(
"sid 1 didn't match. Should have matched: ");
4063 static int SMTPParserTest14(
void)
4070 static uint8_t welcome_reply[] = {
4071 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
4072 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
4073 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
4074 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
4075 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
4078 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
4081 static uint8_t request1[] = {
4082 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
4083 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
4085 static uint32_t request1_len =
sizeof(request1);
4092 static uint8_t reply1[] = {
4093 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
4094 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
4095 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
4096 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
4097 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
4098 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
4099 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
4100 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
4101 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
4102 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
4103 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
4104 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
4105 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
4106 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
4107 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
4109 static uint32_t reply1_len =
sizeof(reply1);
4112 static uint8_t request2[] = {
4113 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
4114 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
4115 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
4118 static uint32_t request2_len =
sizeof(request2);
4120 static uint8_t reply2[] = {
4121 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4122 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4124 static uint32_t reply2_len =
sizeof(reply2);
4127 static uint8_t request3[] = {
4128 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
4129 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
4130 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
4133 static uint32_t request3_len =
sizeof(request3);
4135 static uint8_t reply3[] = {
4136 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
4137 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
4139 static uint32_t reply3_len =
sizeof(reply3);
4142 static uint8_t request4[] = {
4143 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
4145 static uint32_t request4_len =
sizeof(request4);
4147 static uint8_t reply4[] = {
4148 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
4149 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
4150 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
4151 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
4152 0x4c, 0x46, 0x3e, 0x0d, 0x0a
4154 static uint32_t reply4_len =
sizeof(reply4);
4157 static uint64_t filesize = 133;
4158 static uint8_t request4_msg[] = {
4159 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
4160 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
4161 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4162 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
4163 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
4164 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
4165 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
4166 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
4167 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
4168 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
4169 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
4170 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
4171 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
4172 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
4173 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
4174 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
4175 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
4176 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
4177 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
4178 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
4179 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
4180 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
4181 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4182 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
4183 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
4184 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
4185 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
4186 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
4187 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
4188 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4189 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
4190 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
4191 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
4192 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
4193 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4194 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4195 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4196 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
4197 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
4198 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
4199 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
4200 0x41, 0x3D, 0x3D, 0x0D,0x0A };
4201 static uint32_t request4_msg_len =
sizeof(request4_msg);
4204 static uint8_t request4_end[] = {
4205 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4207 static uint32_t request4_end_len =
sizeof(request4_end);
4209 static uint8_t reply4_end[] = {
4210 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4211 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
4212 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
4213 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
4214 0x46, 0x32, 0x0d, 0x0a
4216 static uint32_t reply4_end_len =
sizeof(reply4_end);
4219 static uint8_t request5[] = {
4220 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
4222 static uint32_t request5_len =
sizeof(request5);
4224 static uint8_t reply5[] = {
4225 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
4226 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
4228 static uint32_t reply5_len =
sizeof(reply5);
4233 memset(&
f, 0,
sizeof(
f));
4234 memset(&
ssn, 0,
sizeof(
ssn));
4242 SMTPTestInitConfig();
4246 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
4248 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4252 if (smtp_state == NULL) {
4253 printf(
"no smtp state: ");
4258 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4263 STREAM_TOSERVER, request1, request1_len);
4265 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4271 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4277 STREAM_TOCLIENT, reply1, reply1_len);
4279 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4283 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
4284 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
4290 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4296 STREAM_TOSERVER, request2, request2_len);
4298 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4304 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4310 STREAM_TOCLIENT, reply2, reply2_len);
4312 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4318 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
4326 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4332 STREAM_TOSERVER, request3, request3_len);
4334 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4340 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4346 STREAM_TOCLIENT, reply3, reply3_len);
4348 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4353 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4359 SCMimeSmtpConfigDecodeBase64(1);
4360 SCMimeSmtpConfigDecodeQuoted(1);
4364 STREAM_TOSERVER, request4, request4_len);
4366 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4373 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4379 STREAM_TOCLIENT, reply4, reply4_len);
4381 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4387 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4393 STREAM_TOSERVER, request4_msg, request4_msg_len);
4395 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4403 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4409 STREAM_TOSERVER, request4_end, request4_end_len);
4411 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4419 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4428 if (files != NULL && files->
head != NULL) {
4431 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4432 printf(
"smtp-mime file name is incorrect");
4436 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4439 static uint8_t org_binary[] = {
4440 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4441 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4443 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4444 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4445 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4446 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4447 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4448 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4449 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4450 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4451 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4452 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4454 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4455 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4456 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4459 org_binary,
sizeof(org_binary)) != 1)
4461 printf(
"smtp-mime file data incorrect\n");
4468 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4470 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4475 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4481 STREAM_TOSERVER, request5, request5_len);
4483 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4489 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4495 STREAM_TOCLIENT, reply5, reply5_len);
4497 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4502 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);