55 #define FILEDATA_CONTENT_LIMIT 100000
57 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
59 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
62 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
64 #define SMTP_COMMAND_BUFFER_STEPS 5
71 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
73 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
75 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
77 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
83 #define SMTP_COMMAND_STARTTLS 1
84 #define SMTP_COMMAND_DATA 2
85 #define SMTP_COMMAND_BDAT 3
90 #define SMTP_COMMAND_DATA_MODE 4
92 #define SMTP_COMMAND_OTHER_CMD 5
93 #define SMTP_COMMAND_RSET 6
94 #define SMTP_COMMAND_QUIT 7
96 #define SMTP_COMMAND_BDAT_LAST 8
98 #define SMTP_DEFAULT_MAX_TX 256
101 #define SMTP_NO_TX_ID UINT64_MAX
177 static int SMTPGetFrameIdByName(
const char *frame_name)
186 static const char *SMTPGetFrameNameById(
const uint8_t frame_id)
206 static int SMTPStateGetStateIdByName(
const char *
name,
const uint8_t direction)
209 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
217 static const char *SMTPStateGetStateNameById(
const int id,
const uint8_t direction)
220 direction == STREAM_TOSERVER ? smtp_state_client_table : smtp_state_server_table;
224 static inline void SMTPSetProgressTS(
SMTPTransaction *tx, uint8_t progress)
231 static inline void SMTPSetProgressTC(
SMTPTransaction *tx, uint8_t progress)
257 static bool SMTPTransactionRequestIsComplete(
const SMTPTransaction *tx)
267 #define SMTP_MPM mpm_default_matcher
269 static MpmCtx *smtp_mpm_ctx = NULL;
377 #define SCHEME_SUFFIX_LEN 3
385 static void SMTPConfigure(
void) {
389 uint32_t content_limit = 0;
390 uint32_t content_inspect_min_size = 0;
391 uint32_t content_inspect_window = 0;
394 if (config != NULL) {
405 SCMimeSmtpConfigDecodeBase64(val);
410 SCMimeSmtpConfigDecodeQuoted(val);
415 if (imval < 0 || imval > UINT32_MAX) {
416 FatalError(
"Invalid value for header-value-depth");
418 SCMimeSmtpConfigHeaderValueDepth((uint32_t)imval);
423 SCMimeSmtpConfigExtractUrls(val);
430 if (extract_urls_schemes) {
434 size_t scheme_len = strlen(scheme->
val);
436 FatalError(
"extract-urls-schemes entry '%s' is too long", scheme->
val);
438 if (scheme->
val[scheme_len - 1] !=
'/') {
441 int r = snprintf(tmp,
sizeof(tmp),
"%s://", scheme->
val);
442 if (r != (
int)scheme_len) {
443 FatalError(
"snprintf failure for SMTP url extraction scheme.");
447 FatalError(
"extract-urls-schemes entry SCStrdup failure.");
450 scheme->
val = new_val;
452 int r = SCMimeSmtpConfigExtractUrlsSchemeAdd(scheme->
val);
454 FatalError(
"Failed to add smtp extract url scheme");
460 SCMimeSmtpConfigExtractUrlsSchemeAdd(
"http://");
465 SCMimeSmtpConfigLogUrlScheme(val);
472 SCMimeSmtpConfigBodyMd5(
false);
474 SCMimeSmtpConfigBodyMd5(
true);
475 }
else if (strcmp(strval,
"auto") != 0) {
486 if (strcasecmp(
"content-limit",
p->name) == 0) {
494 if (strcasecmp(
"content-inspect-min-size",
p->name) == 0) {
496 SCLogWarning(
"parsing content-inspect-min-size %s failed",
p->val);
502 if (strcasecmp(
"content-inspect-window",
p->name) == 0) {
504 SCLogWarning(
"parsing content-inspect-window %s failed",
p->val);
519 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
520 "options can't be enabled at the same time, "
521 "disabling raw extraction");
527 const char *
str = NULL;
540 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
571 if (tx->
tx_id == tx_id) {
574 if (tx->
tx_id > tx_id) {
598 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
600 }
else if (tx == NULL) {
601 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
603 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
613 if (tx == NULL || file == NULL) {
618 FlagDetectStateNewFile(tx);
650 if (direction == 0 &&
657 }
else if (direction == 1) {
661 if (frame != NULL && reply_tx != NULL) {
668 const uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
671 if (lf_idx == NULL) {
684 uint32_t o_consumed = input->
consumed;
685 input->
consumed = (uint32_t)(lf_idx - input->
buf + 1);
693 line->
buf = input->
buf + o_consumed;
696 frame->
len = (int64_t)line->
len;
704 if (discard_till_lf) {
706 if (direction == 0) {
726 static int SMTPInsertCommandIntoCommandBuffer(
774 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
799 SMTPTransactionCompleteTS(tx);
806 static void SetMimeEvents(
SMTPState *state, uint32_t events)
812 if (events & MIME_ANOM_INVALID_BASE64) {
815 if (events & MIME_ANOM_INVALID_QP) {
818 if (events & MIME_ANOM_LONG_LINE) {
821 if (events & MIME_ANOM_LONG_ENC_LINE) {
824 if (events & MIME_ANOM_LONG_HEADER_NAME) {
827 if (events & MIME_ANOM_LONG_HEADER_VALUE) {
830 if (events & MIME_ANOM_LONG_BOUNDARY) {
833 if (events & MIME_ANOM_LONG_FILENAME) {
851 static int SMTPProcessCommandDATA(
863 if (line->
len == 1 && line->
buf[0] ==
'.') {
881 SMTPTransactionCompleteTS(tx);
895 const uint8_t *filename = NULL;
896 uint16_t filename_len = 0;
901 MimeSmtpParserResult ret = SCSmtpMimeParseLine(
903 SetMimeEvents(state, events);
905 case MimeSmtpFileOpen:
909 if (filename_len == 0) {
916 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
932 case MimeSmtpFileChunk:
941 "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
952 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32,
957 case MimeSmtpFileClose:
960 SCLogDebug(
"FileCloseFile() failed: %d", ret);
968 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth);
977 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
982 static int SMTPProcessReply(
993 if (reply_tx != NULL) {
1004 if (line->
len >= 4) {
1006 if (line->
buf[3] !=
'-') {
1010 if (line->
buf[3] ==
'-') {
1028 SCLogDebug(
"invalid reply code %02x %02x %02x", line->
buf[0], line->
buf[1], line->
buf[2]);
1032 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
1051 SCLogDebug(
"unable to match reply with request");
1066 SMTPTransactionComplete(reply_tx);
1101 SMTPTransactionCompleteTC(reply_tx);
1105 SMTPTransactionCompleteTC(reply_tx);
1110 SMTPTransactionComplete(reply_tx);
1115 SMTPTransactionComplete(reply_tx);
1129 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1144 static int SMTPParseCommandBDAT(
SMTPState *state,
const SMTPLine *line,
bool *last)
1151 while (i < line->
len) {
1152 if (line->
buf[i] !=
' ') {
1161 if (i == line->
len) {
1168 if (line->
len - i <
len) {
1171 memcpy(strbuf, line->
buf + i,
len);
1181 if (i < line->
len && line->
buf[i] !=
' ') {
1184 while (i < line->
len && line->
buf[i] ==
' ') {
1187 if (line->
len - i == 4 && SCMemcmpLowercase(
"last", line->
buf + i, 4) == 0) {
1189 }
else if (i != line->
len) {
1196 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1197 uint8_t **target, uint16_t *target_len)
1199 int i = prefix_len + 1;
1201 while (i < line->
len) {
1202 if (line->
buf[i] !=
' ') {
1211 while (spc_i < line->
len) {
1212 if (line->
buf[spc_i] ==
' ') {
1219 if (*target == NULL)
1221 memcpy(*target, line->
buf + i, spc_i - i);
1222 (*target)[spc_i - i] =
'\0';
1223 if (spc_i - i > UINT16_MAX) {
1224 *target_len = UINT16_MAX;
1227 *target_len = (uint16_t)(spc_i - i);
1239 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1248 return SMTPParseCommandWithParam(
1255 uint16_t rcptto_len;
1257 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1260 rcptto_str->
str = rcptto;
1261 rcptto_str->
len = rcptto_len;
1277 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1279 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1287 #define rawmsgname "rawmsg"
1306 static int SMTPProcessRequest(
1314 frame->
len = (int64_t)line->
len;
1330 const bool no_new_tx = NoNewTx(state, line);
1331 if ((state->
curr_tx == NULL && (state->
tx_cnt == 0 || !no_new_tx)) ||
1332 (SMTPTransactionRequestIsComplete(state->
curr_tx) && !no_new_tx)) {
1333 tx = SMTPTransactionCreate(state);
1345 if (frame != NULL && state->
curr_tx) {
1366 const bool is_rset = SCMemcmpLowercase(
"rset", line->
buf, 4) == 0;
1370 }
else if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1372 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1399 if (data_frame == NULL) {
1400 SCLogDebug(
"data_frame %p - no data frame set up", data_frame);
1409 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1411 r = SMTPParseCommandBDAT(state, line, &last);
1424 SMTPTransactionCompleteTS(tx);
1427 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1428 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1429 r = SMTPParseCommandHELO(state, line);
1444 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1445 r = SMTPParseCommandMAILFROM(state, line);
1450 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1451 r = SMTPParseCommandRCPTTO(state, line);
1456 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1460 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1468 if (SMTPInsertCommandIntoCommandBuffer(state, state->
current_command, tx) == -1) {
1477 return SMTPProcessCommandDATA(state, tx,
f, line);
1481 return SMTPProcessCommandBDAT(state, tx, line);
1490 static inline void ResetLine(
SMTPLine *line)
1499 static int SMTPPreProcessCommandBDAT(
1510 uint32_t consumed =
MIN((uint32_t)input->
len, remaining);
1512 line->
len = consumed;
1514 input->
len -= consumed;
1515 int ret = SMTPProcessRequest(state,
f, input, line, slice);
1540 static int SMTPPreProcessCommands(
1549 return SMTPPreProcessCommandBDAT(state,
f, slice, input, line);
1557 bool line_complete =
false;
1558 const int32_t input_len = input->
len;
1560 for (int32_t i = 0; i < input_len; i++) {
1562 if (i < input_len - 1 && input->buf[
offset + i + 1] == 0x0a) {
1568 line_complete =
true;
1569 }
else if (input->
buf[
offset + i] == 0x0a) {
1572 line_complete =
true;
1575 if (line_complete || (i == input_len - 1)) {
1582 SCLogDebug(
"Possible boundary, yield to GetLine");
1586 int32_t total_consumed =
offset + i + 1;
1587 int32_t current_line_consumed = total_consumed - input->
consumed;
1592 if (line->
len < 0) {
1597 input->
len -= current_line_consumed;
1599 if (SMTPProcessRequest(state,
f, input, line, slice) == -1) {
1602 line_complete =
false;
1625 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1626 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1628 if (input_buf == NULL &&
1633 }
else if (input_buf == NULL || input_len == 0) {
1637 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1638 SMTPLine line = { NULL, 0, 0,
false };
1641 if (direction == 0) {
1646 int ret = SMTPPreProcessCommands(state,
f, &stream_slice, &input, &line);
1650 }
else if (ret < 0) {
1654 AppLayerResult res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1655 while (res.
status == 0) {
1656 int retval = SMTPProcessRequest(state,
f, &input, &line, &stream_slice);
1676 if ((input.
len > 0) &&
1681 int ret = SMTPPreProcessCommands(state,
f, &stream_slice, &input, &line);
1685 }
else if (ret < 0) {
1689 res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1695 AppLayerResult res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1696 while (res.
status == 0) {
1697 if (SMTPProcessReply(state,
f, thread_data, &input, &line) != 0)
1707 res = SMTPGetLine(
f, &stream_slice, state, &input, &line, direction);
1722 return SMTPParse(0,
f, alstate, pstate, stream_slice, local_data);
1731 return SMTPParse(1,
f, alstate, pstate, stream_slice, local_data);
1746 if (smtp_state->
cmds == NULL) {
1781 static void *SMTPLocalStorageAlloc(
void)
1790 if (td->
pmq == NULL) {
1803 static void SMTPLocalStorageFree(
void *ptr)
1807 if (td->
pmq != NULL) {
1835 SMTPStringFree(
str);
1846 static void SMTPStateFree(
void *
p)
1850 if (smtp_state->
cmds != NULL) {
1857 if (smtp_state->
helo) {
1862 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1864 SMTPTransactionFree(tx, smtp_state);
1870 static void SMTPSetMpmState(
void)
1873 if (
unlikely(smtp_mpm_ctx == NULL)) {
1889 static void SMTPFreeMpmState(
void)
1891 if (smtp_mpm_ctx != NULL) {
1894 smtp_mpm_ctx = NULL;
1898 static int SMTPStateGetEventInfo(
1908 static int SMTPStateGetEventInfoById(
1912 if (*event_name == NULL) {
1914 "smtp's enum map table.",
1927 static AppProto SMTPClientProbingParserCheckPort(
1928 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1936 static AppProto SMTPServerProbingParser(
1937 const Flow *
f, uint8_t direction,
const uint8_t *input, uint32_t
len, uint8_t *rdir)
1944 if (input[0] !=
'2' || input[1] !=
'2' || input[2] !=
'0') {
1948 if (input[3] !=
' ' && input[3] !=
'-') {
1954 if (memchr(input + 4,
'\n',
len - 4) != NULL) {
1965 uint32_t
offset = SCValidateDomain(input + 4,
len - 4);
1976 static int SMTPRegisterPatternsForProtocolDetection(
void)
1979 IPPROTO_TCP,
ALPROTO_SMTP,
"EHLO", 4, 0, STREAM_TOSERVER) < 0) {
1983 IPPROTO_TCP,
ALPROTO_SMTP,
"HELO", 4, 0, STREAM_TOSERVER) < 0) {
1987 STREAM_TOSERVER, SMTPClientProbingParserCheckPort, 4, 4) < 0) {
1992 "tcp", IPPROTO_TCP,
"smtp",
ALPROTO_SMTP, 0, 5, NULL, SMTPServerProbingParser)) {
1995 NULL, SMTPServerProbingParser);
2001 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
2006 if (tx_id < tx->tx_id)
2008 else if (tx_id > tx->
tx_id)
2011 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__);