63 #define FILEDATA_CONTENT_LIMIT 100000
65 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
67 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
70 #define SMTP_RAW_EXTRACTION_DEFAULT_VALUE false
71 #define SMTP_MAX_REQUEST_AND_REPLY_LINE_LENGTH 510
73 #define SMTP_COMMAND_BUFFER_STEPS 5
77 #define SMTP_PARSER_STATE_COMMAND_MODE 0x00
80 #define SMTP_PARSER_STATE_COMMAND_DATA_MODE 0x01
84 #define SMTP_PARSER_STATE_PARSING_SERVER_RESPONSE 0x02
86 #define SMTP_PARSER_STATE_FIRST_REPLY_SEEN 0x04
88 #define SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY 0x08
90 #define SMTP_PARSER_STATE_PIPELINING_SERVER 0x10
96 #define SMTP_COMMAND_STARTTLS 1
97 #define SMTP_COMMAND_DATA 2
98 #define SMTP_COMMAND_BDAT 3
103 #define SMTP_COMMAND_DATA_MODE 4
105 #define SMTP_COMMAND_OTHER_CMD 5
106 #define SMTP_COMMAND_RSET 6
109 #define SMTP_EHLO_EXTENSION_PIPELINING
110 #define SMTP_EHLO_EXTENSION_SIZE
111 #define SMTP_EHLO_EXTENSION_DSN
112 #define SMTP_EHLO_EXTENSION_STARTTLS
113 #define SMTP_EHLO_EXTENSION_8BITMIME
171 #define SMTP_MPM mpm_default_matcher
173 static MpmCtx *smtp_mpm_ctx = NULL;
246 .decode_base64 =
true,
247 .decode_quoted_printable =
true,
248 .extract_urls =
true,
249 .extract_urls_schemes = NULL,
250 .log_url_scheme =
false,
252 .header_value_depth = 0,
269 static void SMTPConfigure(
void) {
273 uint32_t content_limit = 0;
274 uint32_t content_inspect_min_size = 0;
275 uint32_t content_inspect_window = 0;
278 if (config != NULL) {
279 ConfNode *extract_urls_schemes = NULL;
311 if (extract_urls_schemes) {
316 size_t new_val_len = strlen(scheme->
val) + 3 + 1;
317 if (new_val_len > UINT16_MAX) {
318 FatalError(
"Too long value for extract-urls-schemes");
320 char *new_val =
SCMalloc(new_val_len);
325 int r = snprintf(new_val, new_val_len,
"%s://", scheme->
val);
326 if (r < 0 || r >= (
int)new_val_len) {
333 scheme->
val = new_val;
384 if (strcasecmp(
"content-limit", p->
name) == 0) {
392 if (strcasecmp(
"content-inspect-min-size", p->
name) == 0) {
400 if (strcasecmp(
"content-inspect-window", p->
name) == 0) {
412 if (
ConfGetBool(
"app-layer.protocols.smtp.raw-extraction",
417 SCLogError(
"\"decode-mime\" and \"raw-extraction\" "
418 "options can't be enabled at the same time, "
419 "disabling raw extraction");
426 static void SMTPSetEvent(
SMTPState *s, uint8_t e)
447 tx->
tx_data.file_tx = STREAM_TOSERVER;
453 if (tx && tx->
tx_data.de_state) {
454 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
456 }
else if (tx == NULL) {
457 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX");
458 }
else if (tx->
tx_data.de_state == NULL) {
459 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW NOT set, no TX DESTATE");
469 if (tx == NULL || file == NULL) {
474 FlagDetectStateNewFile(tx);
519 if (files->head != NULL && (files->head->flags &
FILE_STORE)) {
524 (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp);
525 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %"PRIu32, depth);
538 SMTPNewFile(tx, files->tail);
549 SCLogDebug(
"FileCloseFile() failed: %d", ret);
555 depth = smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp;
558 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u",
570 SCLogDebug(
"FileCloseFile() failed: %d", ret);
576 uint32_t depth = smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp;
578 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u",
581 STREAM_TOSERVER, depth);
589 SCLogDebug(
"FileAppendData() - file no longer being extracted");
590 }
else if (ret < 0) {
591 SCLogDebug(
"FileAppendData() failed: %d", ret);
595 if (files->tail && files->tail->content_inspected == 0 &&
598 (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp);
600 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u",
603 STREAM_TOSERVER, depth);
606 }
else if (files->tail && files->tail->content_inspected > 0) {
614 (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp);
615 SCLogDebug(
"StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %"PRIu32,
618 STREAM_TOSERVER, depth);
623 SCLogDebug(
"Successfully processed file data!");
649 uint8_t *lf_idx = memchr(input->
buf + input->
consumed, 0x0a, input->
len);
651 if (lf_idx == NULL) {
664 uint32_t o_consumed = input->
consumed;
672 line->
buf = input->
buf + o_consumed;
696 static int SMTPInsertCommandIntoCommandBuffer(uint8_t command,
SMTPState *state,
Flow *f)
729 if ((
int)(state->
cmds_cnt + 1) > (
int)USHRT_MAX) {
740 static int SMTPProcessCommandBDAT(
758 static void SetMimeEvents(
SMTPState *state)
795 static inline void SMTPTransactionComplete(
SMTPState *state)
817 if (line->
len == 1 && line->
buf[0] ==
'.') {
832 SCLogDebug(
"MimeDecParseComplete() function failed");
836 SetMimeEvents(state);
838 SMTPTransactionComplete(state);
855 SetMimeEvents(state);
857 SCLogDebug(
"MimeDecParseLine() function returned an error code: %d", ret);
869 static int SMTPProcessCommandSTARTTLS(
SMTPState *state,
Flow *f,
875 static inline bool IsReplyToCommand(
const SMTPState *state,
const uint8_t cmd)
899 if (line->
len >= 4) {
901 if (line->
buf[3] !=
'-') {
905 if (line->
buf[3] ==
'-') {
927 SCLogDebug(
"REPLY: reply_code %u / %s", reply_code,
946 SCLogDebug(
"unable to match reply with request");
961 SMTPTransactionComplete(state);
978 SMTPTransactionComplete(state);
992 SCMemcmpLowercase(
"pipelining", line->
buf + 4, 10) == 0) {
1011 while (i < line->
len) {
1012 if (line->
buf[i] !=
' ') {
1021 if (i == line->
len) {
1025 char *endptr = NULL;
1029 if (line->
len - i <
len) {
1032 memcpy(strbuf, line->
buf + i,
len);
1034 state->
bdat_chunk_len = strtoul((
const char *)strbuf, (
char **)&endptr, 10);
1035 if ((uint8_t *)endptr == line->
buf + i) {
1043 static int SMTPParseCommandWithParam(
SMTPState *state,
const SMTPLine *line, uint8_t prefix_len,
1044 uint8_t **target, uint16_t *target_len)
1046 int i = prefix_len + 1;
1048 while (i < line->
len) {
1049 if (line->
buf[i] !=
' ') {
1058 while (spc_i < line->
len) {
1059 if (line->
buf[spc_i] ==
' ') {
1066 if (*target == NULL)
1068 memcpy(*target, line->
buf + i, spc_i - i);
1069 (*target)[spc_i - i] =
'\0';
1070 if (spc_i - i > UINT16_MAX) {
1071 *target_len = UINT16_MAX;
1074 *target_len = (uint16_t)(spc_i - i);
1086 return SMTPParseCommandWithParam(state, line, 4, &state->
helo, &state->
helo_len);
1095 return SMTPParseCommandWithParam(
1102 uint16_t rcptto_len;
1104 if (SMTPParseCommandWithParam(state, line, 7, &rcptto, &rcptto_len) == 0) {
1107 rcptto_str->
str = rcptto;
1108 rcptto_str->
len = rcptto_len;
1124 if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1126 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"quit", line->
buf, 4) == 0) {
1134 #define rawmsgname "rawmsg"
1150 tx = SMTPTransactionCreate();
1174 if (line->
len >= 8 && SCMemcmpLowercase(
"starttls", line->
buf, 8) == 0) {
1176 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"data", line->
buf, 4) == 0) {
1183 tx = SMTPTransactionCreate();
1201 tx = SMTPTransactionCreate();
1227 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"bdat", line->
buf, 4) == 0) {
1228 r = SMTPParseCommandBDAT(state, line);
1234 }
else if (line->
len >= 4 && ((SCMemcmpLowercase(
"helo", line->
buf, 4) == 0) ||
1235 SCMemcmpLowercase(
"ehlo", line->
buf, 4) == 0)) {
1236 r = SMTPParseCommandHELO(state, line);
1241 }
else if (line->
len >= 9 && SCMemcmpLowercase(
"mail from", line->
buf, 9) == 0) {
1242 r = SMTPParseCommandMAILFROM(state, line);
1247 }
else if (line->
len >= 7 && SCMemcmpLowercase(
"rcpt to", line->
buf, 7) == 0) {
1248 r = SMTPParseCommandRCPTTO(state, line);
1253 }
else if (line->
len >= 4 && SCMemcmpLowercase(
"rset", line->
buf, 4) == 0) {
1273 return SMTPProcessCommandSTARTTLS(state, f, pstate);
1276 return SMTPProcessCommandDATA(state, tx, f, pstate, line);
1279 return SMTPProcessCommandBDAT(state, f, pstate, line);
1288 static int SMTPPreProcessCommands(
1300 bool line_complete =
false;
1301 const int32_t input_len = input->
len;
1302 for (int32_t i = 0; i < input_len; i++) {
1303 if (input->
buf[i] == 0x0d) {
1304 if (i < input_len - 1 && input->buf[i + 1] == 0x0a) {
1310 line_complete =
true;
1311 }
else if (input->
buf[i] == 0x0a) {
1314 line_complete =
true;
1317 if (line_complete || (i == input_len - 1)) {
1324 SCLogDebug(
"Possible boundary, yield to GetLine");
1327 int32_t total_consumed = i + 1;
1328 int32_t current_line_consumed = total_consumed - input->
consumed;
1333 input->
len -= current_line_consumed;
1335 if (SMTPProcessRequest(state, f, pstate, input, line) == -1) {
1338 line_complete =
false;
1351 static AppLayerResult SMTPParse(uint8_t direction,
Flow *f,
SMTPState *state,
1356 const uint8_t *input_buf = StreamSliceGetData(&stream_slice);
1357 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
1359 if (input_buf == NULL &&
1364 }
else if (input_buf == NULL || input_len == 0) {
1368 SMTPInput input = { .
buf = input_buf, .len = input_len, .orig_len = input_len, .consumed = 0 };
1372 if (direction == 0) {
1376 int ret = SMTPPreProcessCommands(state, f, pstate, &input, &line);
1381 AppLayerResult res = SMTPGetLine(state, &input, &line);
1382 while (res.status == 0) {
1383 int retval = SMTPProcessRequest(state, f, pstate, &input, &line);
1392 res = SMTPGetLine(state, &input, &line);
1394 if (res.status == 1)
1398 AppLayerResult res = SMTPGetLine(state, &input, &line);
1399 while (res.status == 0) {
1400 if (SMTPProcessReply(state, f, pstate, thread_data, &input, &line) != 0)
1408 res = SMTPGetLine(state, &input, &line);
1410 if (res.status == 1)
1418 StreamSlice stream_slice,
void *local_data)
1423 return SMTPParse(0, f, alstate, pstate, stream_slice, local_data);
1427 StreamSlice stream_slice,
void *local_data)
1432 return SMTPParse(1, f, alstate, pstate, stream_slice, local_data);
1444 memset(smtp_state, 0,
sizeof(
SMTPState));
1448 if (smtp_state->
cmds == NULL) {
1478 static void *SMTPLocalStorageAlloc(
void)
1487 if (td->
pmq == NULL) {
1500 static void SMTPLocalStorageFree(
void *ptr)
1504 if (td->
pmq != NULL) {
1528 if (tx->
tx_data.events != NULL)
1531 if (tx->
tx_data.de_state != NULL)
1540 SMTPStringFree(
str);
1551 static void SMTPStateFree(
void *p)
1555 if (smtp_state->
cmds != NULL) {
1559 if (smtp_state->
helo) {
1564 while ((tx =
TAILQ_FIRST(&smtp_state->tx_list))) {
1566 SMTPTransactionFree(tx, smtp_state);
1574 static void SMTPSetMpmState(
void)
1577 if (
unlikely(smtp_mpm_ctx == NULL)) {
1580 memset(smtp_mpm_ctx, 0,
sizeof(
MpmCtx));
1596 static void SMTPFreeMpmState(
void)
1598 if (smtp_mpm_ctx != NULL) {
1601 smtp_mpm_ctx = NULL;
1605 static int SMTPStateGetEventInfo(
const char *event_name,
1609 if (*event_id == -1) {
1611 "smtp's enum map table.",
1622 static int SMTPStateGetEventInfoById(
int event_id,
const char **event_name,
1626 if (*event_name == NULL) {
1628 "smtp's enum map table.",
1639 static int SMTPRegisterPatternsForProtocolDetection(
void)
1642 "EHLO", 4, 0, STREAM_TOSERVER) < 0)
1647 "HELO", 4, 0, STREAM_TOSERVER) < 0)
1652 "QUIT", 4, 0, STREAM_TOSERVER) < 0)
1660 static void SMTPStateTransactionFree (
void *state, uint64_t tx_id)
1665 if (tx_id < tx->tx_id)
1667 else if (tx_id > tx->
tx_id)
1670 if (tx == smtp_state->
curr_tx)
1673 SMTPTransactionFree(tx, state);
1681 static uint64_t SMTPStateGetTxCnt(
void *state)
1686 cnt = smtp_state->
tx_cnt;
1692 static void *SMTPStateGetTx(
void *state, uint64_t
id)
1698 if (smtp_state->
curr_tx == NULL)
1704 if (tx->
tx_id ==
id)
1712 static int SMTPStateGetAlstateProgress(
void *vtx, uint8_t direction)
1718 static AppLayerGetFileState SMTPGetTxFiles(
void *state,
void *txv, uint8_t direction)
1723 if (direction & STREAM_TOSERVER) {
1735 static AppLayerStateData *SMTPGetStateData(
void *vstate)
1745 static AppLayerGetTxIterTuple SMTPGetTxIterator(
const uint8_t ipproto,
const AppProto alproto,
1749 AppLayerGetTxIterTuple no_tuple = { NULL, 0,
false };
1752 if (state->
un.
ptr == NULL) {
1758 while (tx_ptr->
tx_id < min_tx_id) {
1764 if (tx_ptr->
tx_id >= max_tx_id) {
1768 AppLayerGetTxIterTuple tuple = {
1771 .has_next = (state->
un.
ptr != NULL),
1784 const char *proto_name =
"smtp";
1788 if (SMTPRegisterPatternsForProtocolDetection() < 0 )
1791 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
1800 SMTPParseClientRecord);
1802 SMTPParseServerRecord);
1808 SMTPLocalStorageFree);
1820 SCLogInfo(
"Parsed disabled for %s protocol. Protocol detection"
1821 "still on.", proto_name);
1847 static void SMTPTestInitConfig(
void)
1861 static int SMTPParserTest01(
void)
1868 uint8_t welcome_reply[] = {
1869 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
1870 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1871 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
1872 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
1873 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
1876 uint32_t welcome_reply_len =
sizeof(welcome_reply);
1879 uint8_t request1[] = {
1880 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x5b, 0x31, 0x39,
1881 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e,
1882 0x31, 0x35, 0x38, 0x5d, 0x0d, 0x0a
1884 uint32_t request1_len =
sizeof(request1);
1891 uint8_t reply1[] = {
1892 0x32, 0x35, 0x30, 0x2d, 0x6d, 0x78, 0x2e, 0x67,
1893 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
1894 0x6d, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75,
1895 0x72, 0x20, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
1896 0x65, 0x2c, 0x20, 0x5b, 0x31, 0x31, 0x37, 0x2e,
1897 0x31, 0x39, 0x38, 0x2e, 0x31, 0x31, 0x35, 0x2e,
1898 0x35, 0x30, 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30,
1899 0x2d, 0x53, 0x49, 0x5a, 0x45, 0x20, 0x33, 0x35,
1900 0x38, 0x38, 0x32, 0x35, 0x37, 0x37, 0x0d, 0x0a,
1901 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49, 0x54,
1902 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35,
1903 0x30, 0x2d, 0x53, 0x54, 0x41, 0x52, 0x54, 0x54,
1904 0x4c, 0x53, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20,
1905 0x45, 0x4e, 0x48, 0x41, 0x4e, 0x43, 0x45, 0x44,
1906 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x43, 0x4f,
1907 0x44, 0x45, 0x53, 0x0d, 0x0a
1909 uint32_t reply1_len =
sizeof(reply1);
1912 uint8_t request2[] = {
1913 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
1916 uint32_t request2_len =
sizeof(request2);
1918 uint8_t reply2[] = {
1919 0x32, 0x32, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
1920 0x30, 0x20, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20,
1921 0x74, 0x6f, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
1922 0x20, 0x54, 0x4c, 0x53, 0x0d, 0x0a
1924 uint32_t reply2_len =
sizeof(reply2);
1929 memset(&f, 0,
sizeof(f));
1930 memset(&ssn, 0,
sizeof(ssn));
1934 f.
proto = IPPROTO_TCP;
1938 SMTPTestInitConfig();
1941 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
1943 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
1947 if (smtp_state == NULL) {
1948 printf(
"no smtp state: ");
1953 printf(
"smtp parser in inconsistent state\n");
1958 STREAM_TOSERVER, request1, request1_len);
1960 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
1966 printf(
"smtp parser in inconsistent state\n");
1971 STREAM_TOCLIENT, reply1, reply1_len);
1973 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
1978 printf(
"smtp parser in inconsistent state\n");
1983 STREAM_TOSERVER, request2, request2_len);
1985 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
1991 printf(
"smtp parser in inconsistent state\n");
1996 STREAM_TOCLIENT, reply2, reply2_len);
1998 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2004 printf(
"smtp parser in inconsistent state\n");
2024 static int SMTPParserTest02(
void)
2031 uint8_t welcome_reply[] = {
2032 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
2033 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2034 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
2035 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
2036 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
2039 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2042 uint8_t request1[] = {
2043 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2044 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2046 uint32_t request1_len =
sizeof(request1);
2053 uint8_t reply1[] = {
2054 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2055 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2056 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2057 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2058 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2059 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2060 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2061 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2062 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2063 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2064 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2065 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2066 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2067 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2068 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2070 uint32_t reply1_len =
sizeof(reply1);
2073 uint8_t request2[] = {
2074 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2075 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
2076 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2079 uint32_t request2_len =
sizeof(request2);
2081 uint8_t reply2[] = {
2082 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2083 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2085 uint32_t reply2_len =
sizeof(reply2);
2088 uint8_t request3[] = {
2089 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2090 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2091 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2094 uint32_t request3_len =
sizeof(request3);
2096 uint8_t reply3[] = {
2097 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2098 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2100 uint32_t reply3_len =
sizeof(reply3);
2103 uint8_t request4[] = {
2104 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2106 uint32_t request4_len =
sizeof(request4);
2108 uint8_t reply4[] = {
2109 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2110 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2111 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2112 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2113 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2115 uint32_t reply4_len =
sizeof(reply4);
2118 uint8_t request5_1[] = {
2119 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2120 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
2121 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2123 uint32_t request5_1_len =
sizeof(request5_1);
2125 uint8_t request5_2[] = {
2126 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2127 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2128 0x6f, 0x6d, 0x0d, 0x0a
2130 uint32_t request5_2_len =
sizeof(request5_2);
2132 uint8_t request5_3[] = {
2135 uint32_t request5_3_len =
sizeof(request5_3);
2137 uint8_t request5_4[] = {
2138 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2139 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2140 0x6c, 0x31, 0x0d, 0x0a
2142 uint32_t request5_4_len =
sizeof(request5_4);
2144 uint8_t request5_5[] = {
2147 uint32_t request5_5_len =
sizeof(request5_5);
2149 uint8_t reply5[] = {
2150 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2151 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2152 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2153 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
2154 0x46, 0x32, 0x0d, 0x0a
2156 uint32_t reply5_len =
sizeof(reply5);
2159 uint8_t request6[] = {
2160 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2161 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x67, 0x40,
2162 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
2165 uint32_t request6_len =
sizeof(request6);
2167 uint8_t reply6[] = {
2168 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2169 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2171 uint32_t reply6_len =
sizeof(reply6);
2174 uint8_t request7[] = {
2175 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
2176 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
2177 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
2180 uint32_t request7_len =
sizeof(request7);
2182 uint8_t reply7[] = {
2183 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2184 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
2186 uint32_t reply7_len =
sizeof(reply7);
2189 uint8_t request8[] = {
2190 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
2192 uint32_t request8_len =
sizeof(request8);
2194 uint8_t reply8[] = {
2195 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
2196 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
2197 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
2198 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
2199 0x4c, 0x46, 0x3e, 0x0d, 0x0a
2201 uint32_t reply8_len =
sizeof(reply8);
2204 uint8_t request9_1[] = {
2205 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
2206 0x66, 0x67, 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c,
2207 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2209 uint32_t request9_1_len =
sizeof(request9_1);
2211 uint8_t request9_2[] = {
2212 0x54, 0x4f, 0x3a, 0x62, 0x69, 0x6d, 0x62, 0x73,
2213 0x40, 0x67, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
2214 0x6f, 0x6d, 0x0d, 0x0a
2216 uint32_t request9_2_len =
sizeof(request9_2);
2218 uint8_t request9_3[] = {
2221 uint32_t request9_3_len =
sizeof(request9_3);
2223 uint8_t request9_4[] = {
2224 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
2225 0x74, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x61, 0x69,
2226 0x6c, 0x32, 0x0d, 0x0a
2228 uint32_t request9_4_len =
sizeof(request9_4);
2230 uint8_t request9_5[] = {
2233 uint32_t request9_5_len =
sizeof(request9_5);
2235 uint8_t reply9[] = {
2236 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2237 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
2238 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
2239 0x32, 0x38, 0x43, 0x46, 0x46, 0x32, 0x30, 0x42,
2240 0x46, 0x32, 0x0d, 0x0a
2242 uint32_t reply9_len =
sizeof(reply9);
2245 uint8_t request10[] = {
2246 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
2248 uint32_t request10_len =
sizeof(request10);
2250 uint8_t reply10[] = {
2251 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
2252 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
2254 uint32_t reply10_len =
sizeof(reply10);
2259 memset(&f, 0,
sizeof(f));
2260 memset(&ssn, 0,
sizeof(ssn));
2264 f.
proto = IPPROTO_TCP;
2268 SMTPTestInitConfig();
2271 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2273 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2277 if (smtp_state == NULL) {
2278 printf(
"no smtp state: ");
2283 printf(
"smtp parser in inconsistent state\n");
2288 STREAM_TOSERVER, request1, request1_len);
2290 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2296 printf(
"smtp parser in inconsistent state\n");
2301 STREAM_TOCLIENT, reply1, reply1_len);
2303 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2308 printf(
"smtp parser in inconsistent state\n");
2313 STREAM_TOSERVER, request2, request2_len);
2315 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2321 printf(
"smtp parser in inconsistent state\n");
2326 STREAM_TOCLIENT, reply2, reply2_len);
2328 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2333 printf(
"smtp parser in inconsistent state\n");
2338 STREAM_TOSERVER, request3, request3_len);
2340 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2346 printf(
"smtp parser in inconsistent state\n");
2351 STREAM_TOCLIENT, reply3, reply3_len);
2353 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2358 printf(
"smtp parser in inconsistent state\n");
2363 STREAM_TOSERVER, request4, request4_len);
2365 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2371 printf(
"smtp parser in inconsistent state\n");
2376 STREAM_TOCLIENT, reply4, reply4_len);
2378 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2384 printf(
"smtp parser in inconsistent state\n");
2389 STREAM_TOSERVER, request5_1, request5_1_len);
2391 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2398 printf(
"smtp parser in inconsistent state\n");
2403 STREAM_TOSERVER, request5_2, request5_2_len);
2405 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2412 printf(
"smtp parser in inconsistent state\n");
2417 STREAM_TOSERVER, request5_3, request5_3_len);
2419 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2426 printf(
"smtp parser in inconsistent state\n");
2431 STREAM_TOSERVER, request5_4, request5_4_len);
2433 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2440 printf(
"smtp parser in inconsistent state\n");
2445 STREAM_TOSERVER, request5_5, request5_5_len);
2447 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2453 printf(
"smtp parser in inconsistent state\n");
2458 STREAM_TOCLIENT, reply5, reply5_len);
2460 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2465 printf(
"smtp parser in inconsistent state\n");
2470 STREAM_TOSERVER, request6, request6_len);
2472 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2478 printf(
"smtp parser in inconsistent state\n");
2483 STREAM_TOCLIENT, reply6, reply6_len);
2485 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2490 printf(
"smtp parser in inconsistent state\n");
2495 STREAM_TOSERVER, request7, request7_len);
2497 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2503 printf(
"smtp parser in inconsistent state\n");
2508 STREAM_TOCLIENT, reply7, reply7_len);
2510 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2515 printf(
"smtp parser in inconsistent state\n");
2520 STREAM_TOSERVER, request8, request8_len);
2522 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2528 printf(
"smtp parser in inconsistent state\n");
2533 STREAM_TOCLIENT, reply8, reply8_len);
2535 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2541 printf(
"smtp parser in inconsistent state\n");
2546 STREAM_TOSERVER, request9_1, request9_1_len);
2548 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2555 printf(
"smtp parser in inconsistent state\n");
2560 STREAM_TOSERVER, request9_2, request9_2_len);
2562 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2569 printf(
"smtp parser in inconsistent state\n");
2574 STREAM_TOSERVER, request9_3, request9_3_len);
2576 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2583 printf(
"smtp parser in inconsistent state\n");
2588 STREAM_TOSERVER, request9_4, request9_4_len);
2590 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2597 printf(
"smtp parser in inconsistent state\n");
2602 STREAM_TOSERVER, request9_5, request9_5_len);
2604 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2610 printf(
"smtp parser in inconsistent state\n");
2615 STREAM_TOCLIENT, reply9, reply9_len);
2617 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2622 printf(
"smtp parser in inconsistent state\n");
2627 STREAM_TOSERVER, request10, request10_len);
2629 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2635 printf(
"smtp parser in inconsistent state\n");
2640 STREAM_TOCLIENT, reply10, reply10_len);
2642 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2647 printf(
"smtp parser in inconsistent state\n");
2663 static int SMTPParserTest03(
void)
2670 uint8_t welcome_reply[] = {
2671 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2672 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2673 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2674 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2675 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2676 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2678 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2681 uint8_t request1[] = {
2682 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2683 0x2e, 0x63, 0x6f, 0x6d, 0x0a
2685 uint32_t request1_len =
sizeof(request1);
2695 uint8_t reply1[] = {
2696 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2697 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2698 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2699 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2700 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2701 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2702 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2703 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2704 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2705 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2706 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2707 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2708 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2709 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2710 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2711 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2712 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2714 uint32_t reply1_len =
sizeof(reply1);
2721 uint8_t request2[] = {
2722 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
2723 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2724 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2725 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
2726 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
2727 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
2728 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
2729 0x49, 0x6d, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
2730 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a,
2732 uint32_t request2_len =
sizeof(request2);
2737 uint8_t reply2[] = {
2738 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
2739 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a, 0x32, 0x35,
2740 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e, 0x35, 0x20,
2741 0x4f, 0x6b, 0x0d, 0x0a, 0x33, 0x35, 0x34, 0x20,
2742 0x45, 0x6e, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61,
2743 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x3c, 0x43,
2744 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x2e, 0x3c,
2745 0x43, 0x52, 0x3e, 0x3c, 0x4c, 0x46, 0x3e, 0x0d,
2748 uint32_t reply2_len =
sizeof(reply2);
2753 memset(&f, 0,
sizeof(f));
2754 memset(&ssn, 0,
sizeof(ssn));
2758 f.
proto = IPPROTO_TCP;
2762 SMTPTestInitConfig();
2765 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2767 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2771 if (smtp_state == NULL) {
2772 printf(
"no smtp state: ");
2777 printf(
"smtp parser in inconsistent state\n");
2782 STREAM_TOSERVER, request1, request1_len);
2784 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2790 printf(
"smtp parser in inconsistent state\n");
2795 STREAM_TOCLIENT, reply1, reply1_len);
2797 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2803 printf(
"smtp parser in inconsistent state\n");
2808 STREAM_TOSERVER, request2, request2_len);
2810 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2820 printf(
"smtp parser in inconsistent state\n");
2825 STREAM_TOCLIENT, reply2, reply2_len);
2827 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2834 printf(
"smtp parser in inconsistent state\n");
2850 static int SMTPParserTest04(
void)
2857 uint8_t welcome_reply[] = {
2858 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2859 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2860 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2861 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2862 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2863 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2865 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2868 uint8_t request1[] = {
2869 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2870 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2871 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2872 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2873 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2874 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2876 uint32_t request1_len =
sizeof(request1);
2881 memset(&f, 0,
sizeof(f));
2882 memset(&ssn, 0,
sizeof(ssn));
2886 f.
proto = IPPROTO_TCP;
2890 SMTPTestInitConfig();
2893 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
2895 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2899 if (smtp_state == NULL) {
2900 printf(
"no smtp state: ");
2905 printf(
"smtp parser in inconsistent state\n");
2910 STREAM_TOSERVER, request1, request1_len);
2912 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
2918 printf(
"smtp parser in inconsistent state\n");
2934 static int SMTPParserTest05(
void)
2941 uint8_t welcome_reply[] = {
2942 0x32, 0x32, 0x30, 0x20, 0x70, 0x6f, 0x6f, 0x6e,
2943 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2944 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2945 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x20,
2946 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20, 0x50, 0x6f,
2947 0x73, 0x74, 0x66, 0x69, 0x78, 0x0d, 0x0a
2949 uint32_t welcome_reply_len =
sizeof(welcome_reply);
2952 uint8_t request1[] = {
2953 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
2954 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
2956 uint32_t request1_len =
sizeof(request1);
2966 uint8_t reply1[] = {
2967 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
2968 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
2969 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
2970 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
2971 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x50, 0x49, 0x50,
2972 0x45, 0x4c, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x0d,
2973 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
2974 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
2975 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
2976 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
2977 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
2978 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
2979 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
2980 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
2981 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
2982 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
2983 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
2985 uint32_t reply1_len =
sizeof(reply1);
2988 uint8_t request2[] = {
2989 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
2992 uint32_t request2_len =
sizeof(request2);
2994 uint8_t reply2[] = {
2995 0x35, 0x30, 0x32, 0x20, 0x35, 0x2e, 0x35, 0x2e,
2996 0x32, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x3a,
2997 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
2998 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63,
2999 0x6f, 0x67, 0x6e, 0x69, 0x7a, 0x65, 0x64, 0x0d,
3002 uint32_t reply2_len =
sizeof(reply2);
3005 uint8_t request3[] = {
3006 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3009 uint32_t request3_len =
sizeof(request3);
3011 uint8_t reply3[] = {
3012 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3013 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3015 uint32_t reply3_len =
sizeof(reply3);
3020 memset(&f, 0,
sizeof(f));
3021 memset(&ssn, 0,
sizeof(ssn));
3025 f.
proto = IPPROTO_TCP;
3029 SMTPTestInitConfig();
3032 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3034 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3038 if (smtp_state == NULL) {
3039 printf(
"no smtp state: ");
3044 printf(
"smtp parser in inconsistent state\n");
3049 STREAM_TOSERVER, request1, request1_len);
3051 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3057 printf(
"smtp parser in inconsistent state\n");
3062 STREAM_TOCLIENT, reply1, reply1_len);
3064 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3070 printf(
"smtp parser in inconsistent state\n");
3075 STREAM_TOSERVER, request2, request2_len);
3077 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3084 printf(
"smtp parser in inconsistent state\n");
3089 STREAM_TOCLIENT, reply2, reply2_len);
3091 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3097 printf(
"smtp parser in inconsistent state\n");
3109 STREAM_TOSERVER, request3, request3_len);
3111 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3118 printf(
"smtp parser in inconsistent state\n");
3123 STREAM_TOCLIENT, reply3, reply3_len);
3125 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3131 printf(
"smtp parser in inconsistent state\n");
3147 static int SMTPParserTest06(
void)
3153 uint8_t welcome_reply[] = {
3154 0x32, 0x32, 0x30, 0x20, 0x62, 0x61, 0x79, 0x30,
3155 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3156 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3157 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3158 0x6d, 0x20, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e,
3159 0x67, 0x20, 0x75, 0x6e, 0x73, 0x6f, 0x6c, 0x69,
3160 0x63, 0x69, 0x74, 0x65, 0x64, 0x20, 0x63, 0x6f,
3161 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c,
3162 0x20, 0x6f, 0x72, 0x20, 0x62, 0x75, 0x6c, 0x6b,
3163 0x20, 0x65, 0x2d, 0x6d, 0x61, 0x69, 0x6c, 0x20,
3164 0x74, 0x6f, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x6f,
3165 0x73, 0x6f, 0x66, 0x74, 0x27, 0x73, 0x20, 0x63,
3166 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20,
3167 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
3168 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x68, 0x69,
3169 0x62, 0x69, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x4f,
3170 0x74, 0x68, 0x65, 0x72, 0x20, 0x72, 0x65, 0x73,
3171 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e,
3172 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x6f,
3173 0x75, 0x6e, 0x64, 0x20, 0x61, 0x74, 0x20, 0x68,
3174 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72,
3175 0x69, 0x76, 0x61, 0x63, 0x79, 0x2e, 0x6d, 0x73,
3176 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x6e,
3177 0x74, 0x69, 0x2d, 0x73, 0x70, 0x61, 0x6d, 0x2f,
3178 0x2e, 0x20, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74,
3179 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x6c,
3180 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
3181 0x20, 0x69, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x20,
3182 0x6f, 0x66, 0x20, 0x65, 0x71, 0x75, 0x69, 0x70,
3183 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x63,
3184 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20,
3185 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e,
3186 0x69, 0x61, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6f,
3187 0x74, 0x68, 0x65, 0x72, 0x20, 0x73, 0x74, 0x61,
3188 0x74, 0x65, 0x73, 0x2e, 0x20, 0x46, 0x72, 0x69,
3189 0x2c, 0x20, 0x31, 0x36, 0x20, 0x46, 0x65, 0x62,
3190 0x20, 0x32, 0x30, 0x30, 0x37, 0x20, 0x30, 0x35,
3191 0x3a, 0x30, 0x33, 0x3a, 0x32, 0x33, 0x20, 0x2d,
3192 0x30, 0x38, 0x30, 0x30, 0x20, 0x0d, 0x0a
3194 uint32_t welcome_reply_len =
sizeof(welcome_reply);
3196 uint8_t request1[] = {
3197 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x45, 0x58, 0x43,
3198 0x48, 0x41, 0x4e, 0x47, 0x45, 0x32, 0x2e, 0x63,
3199 0x67, 0x63, 0x65, 0x6e, 0x74, 0x2e, 0x6d, 0x69,
3200 0x61, 0x6d, 0x69, 0x2e, 0x65, 0x64, 0x75, 0x0d,
3203 uint32_t request1_len =
sizeof(request1);
3205 uint8_t reply1[] = {
3206 0x32, 0x35, 0x30, 0x2d, 0x62, 0x61, 0x79, 0x30,
3207 0x2d, 0x6d, 0x63, 0x36, 0x2d, 0x66, 0x31, 0x30,
3208 0x2e, 0x62, 0x61, 0x79, 0x30, 0x2e, 0x68, 0x6f,
3209 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f,
3210 0x6d, 0x20, 0x28, 0x33, 0x2e, 0x33, 0x2e, 0x31,
3211 0x2e, 0x34, 0x29, 0x20, 0x48, 0x65, 0x6c, 0x6c,
3212 0x6f, 0x20, 0x5b, 0x31, 0x32, 0x39, 0x2e, 0x31,
3213 0x37, 0x31, 0x2e, 0x33, 0x32, 0x2e, 0x35, 0x39,
3214 0x5d, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53,
3215 0x49, 0x5a, 0x45, 0x20, 0x32, 0x39, 0x36, 0x39,
3216 0x36, 0x30, 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35,
3217 0x30, 0x2d, 0x38, 0x62, 0x69, 0x74, 0x6d, 0x69,
3218 0x6d, 0x65, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3219 0x42, 0x49, 0x4e, 0x41, 0x52, 0x59, 0x4d, 0x49,
3220 0x4d, 0x45, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3221 0x43, 0x48, 0x55, 0x4e, 0x4b, 0x49, 0x4e, 0x47,
3222 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3223 0x54, 0x48, 0x20, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3224 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x41, 0x55,
3225 0x54, 0x48, 0x3d, 0x4c, 0x4f, 0x47, 0x49, 0x4e,
3226 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x20, 0x4f, 0x4b,
3229 uint32_t reply1_len =
sizeof(reply1);
3232 uint8_t request2[] = {
3233 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3234 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3235 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3238 uint32_t request2_len =
sizeof(request2);
3240 uint8_t reply2[] = {
3241 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3242 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3244 uint32_t reply2_len =
sizeof(reply2);
3247 uint8_t request3[] = {
3248 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3249 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3250 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3253 uint32_t request3_len =
sizeof(request3);
3255 uint8_t reply3[] = {
3256 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3257 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3259 uint32_t reply3_len =
sizeof(reply3);
3262 uint8_t request4[] = {
3263 0x42, 0x44, 0x41, 0x54, 0x20, 0x35, 0x31, 0x0d,
3266 uint32_t request4_len =
sizeof(request4);
3268 uint8_t request5[] = {
3269 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3270 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3271 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3272 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x0d, 0x0a,
3274 uint32_t request5_len =
sizeof(request5);
3276 uint8_t request6[] = {
3277 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x61, 0x73, 0x64,
3278 0x66, 0x66, 0x40, 0x61, 0x73, 0x64, 0x66, 0x2e,
3281 uint32_t request6_len =
sizeof(request6);
3286 memset(&f, 0,
sizeof(f));
3287 memset(&ssn, 0,
sizeof(ssn));
3291 f.
proto = IPPROTO_TCP;
3295 SMTPTestInitConfig();
3298 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3300 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3304 if (smtp_state == NULL) {
3305 printf(
"no smtp state: ");
3310 printf(
"smtp parser in inconsistent state\n");
3315 STREAM_TOSERVER, request1, request1_len);
3317 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3323 printf(
"smtp parser in inconsistent state\n");
3328 STREAM_TOCLIENT, reply1, reply1_len);
3330 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3335 printf(
"smtp parser in inconsistent state\n");
3340 STREAM_TOSERVER, request2, request2_len);
3342 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3348 printf(
"smtp parser in inconsistent state\n");
3353 STREAM_TOCLIENT, reply2, reply2_len);
3355 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3360 printf(
"smtp parser in inconsistent state\n");
3365 STREAM_TOSERVER, request3, request3_len);
3367 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3373 printf(
"smtp parser in inconsistent state\n");
3378 STREAM_TOCLIENT, reply3, reply3_len);
3380 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3385 printf(
"smtp parser in inconsistent state\n");
3390 STREAM_TOSERVER, request4, request4_len);
3392 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3400 printf(
"smtp parser in inconsistent state\n");
3405 STREAM_TOSERVER, request5, request5_len);
3407 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3414 printf(
"smtp parser in inconsistent state\n");
3419 STREAM_TOSERVER, request6, request6_len);
3421 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3427 printf(
"smtp parser in inconsistent state\n");
3440 static int SMTPParserTest12(
void)
3454 uint8_t request1[] = {
3455 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3456 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3458 int32_t request1_len =
sizeof(request1);
3462 uint8_t reply1[] = {
3463 0x31, 0x38, 0x38, 0x0d, 0x0a,
3465 uint32_t reply1_len =
sizeof(reply1);
3469 memset(&th_v, 0,
sizeof(th_v));
3470 memset(&f, 0,
sizeof(f));
3471 memset(&ssn, 0,
sizeof(ssn));
3477 f.
proto = IPPROTO_TCP;
3486 SMTPTestInitConfig();
3495 "(msg:\"SMTP event handling\"; "
3496 "app-layer-event: smtp.invalid_reply; "
3505 STREAM_TOSERVER | STREAM_START, request1,
3508 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3513 if (smtp_state == NULL) {
3514 printf(
"no smtp state: ");
3522 printf(
"sid 1 matched. It shouldn't match: ");
3527 STREAM_TOCLIENT | STREAM_TOCLIENT, reply1,
3530 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3538 printf(
"sid 1 didn't match. Should have matched: ");
3559 static int SMTPParserTest13(
void)
3573 uint8_t request1[] = {
3574 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3575 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a,
3577 int32_t request1_len =
sizeof(request1);
3581 uint8_t reply1[] = {
3582 0x32, 0x35, 0x30, 0x0d, 0x0a,
3584 uint32_t reply1_len =
sizeof(reply1);
3591 uint8_t request2[] = {
3592 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3593 0x4d, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3594 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3595 0x0d, 0x0a, 0x52, 0x43, 0x50, 0x54, 0x20, 0x54,
3596 0x4f, 0x3a, 0x70, 0x62, 0x73, 0x66, 0x40, 0x61,
3597 0x73, 0x64, 0x66, 0x73, 0x2e, 0x63, 0x6f, 0x6d,
3598 0x0d, 0x0a, 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a,
3599 0x53, 0x54, 0x41, 0x52, 0x54, 0x54, 0x4c, 0x53,
3602 uint32_t request2_len =
sizeof(request2);
3606 memset(&th_v, 0,
sizeof(th_v));
3607 memset(&f, 0,
sizeof(f));
3608 memset(&ssn, 0,
sizeof(ssn));
3614 f.
proto = IPPROTO_TCP;
3623 SMTPTestInitConfig();
3632 "(msg:\"SMTP event handling\"; "
3634 "smtp.invalid_pipelined_sequence; "
3643 STREAM_TOSERVER | STREAM_START, request1,
3646 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3651 if (smtp_state == NULL) {
3652 printf(
"no smtp state: ");
3660 printf(
"sid 1 matched. It shouldn't match: ");
3665 STREAM_TOCLIENT, reply1, reply1_len);
3667 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3675 printf(
"sid 1 matched. It shouldn't match: ");
3680 STREAM_TOSERVER, request2, request2_len);
3682 printf(
"AppLayerParse for smtp failed. Returned %" PRId32, r);
3690 printf(
"sid 1 didn't match. Should have matched: ");
3714 static int SMTPParserTest14(
void)
3721 static uint8_t welcome_reply[] = {
3722 0x32, 0x32, 0x30, 0x20, 0x6d, 0x78, 0x2e, 0x67,
3723 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3724 0x6d, 0x20, 0x45, 0x53, 0x4d, 0x54, 0x50, 0x20,
3725 0x64, 0x31, 0x35, 0x73, 0x6d, 0x39, 0x38, 0x36,
3726 0x32, 0x38, 0x33, 0x77, 0x66, 0x6c, 0x2e, 0x36,
3729 static uint32_t welcome_reply_len =
sizeof(welcome_reply);
3732 static uint8_t request1[] = {
3733 0x45, 0x48, 0x4c, 0x4f, 0x20, 0x62, 0x6f, 0x6f,
3734 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a
3736 static uint32_t request1_len =
sizeof(request1);
3743 static uint8_t reply1[] = {
3744 0x32, 0x35, 0x30, 0x2d, 0x70, 0x6f, 0x6f, 0x6e,
3745 0x61, 0x5f, 0x73, 0x6c, 0x61, 0x63, 0x6b, 0x5f,
3746 0x76, 0x6d, 0x31, 0x2e, 0x6c, 0x6f, 0x63, 0x61,
3747 0x6c, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x0d,
3748 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x53, 0x49, 0x5a,
3749 0x45, 0x20, 0x31, 0x30, 0x32, 0x34, 0x30, 0x30,
3750 0x30, 0x30, 0x0d, 0x0a, 0x32, 0x35, 0x30, 0x2d,
3751 0x56, 0x52, 0x46, 0x59, 0x0d, 0x0a, 0x32, 0x35,
3752 0x30, 0x2d, 0x45, 0x54, 0x52, 0x4e, 0x0d, 0x0a,
3753 0x32, 0x35, 0x30, 0x2d, 0x45, 0x4e, 0x48, 0x41,
3754 0x4e, 0x43, 0x45, 0x44, 0x53, 0x54, 0x41, 0x54,
3755 0x55, 0x53, 0x43, 0x4f, 0x44, 0x45, 0x53, 0x0d,
3756 0x0a, 0x32, 0x35, 0x30, 0x2d, 0x38, 0x42, 0x49,
3757 0x54, 0x4d, 0x49, 0x4d, 0x45, 0x0d, 0x0a, 0x32,
3758 0x35, 0x30, 0x20, 0x44, 0x53, 0x4e, 0x0d, 0x0a
3760 static uint32_t reply1_len =
sizeof(reply1);
3763 static uint8_t request2[] = {
3764 0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f,
3765 0x4d, 0x3a, 0x61, 0x73, 0x64, 0x66, 0x66, 0x40,
3766 0x61, 0x73, 0x64, 0x66, 0x2e, 0x63, 0x6f, 0x6d,
3769 static uint32_t request2_len =
sizeof(request2);
3771 static uint8_t reply2[] = {
3772 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3773 0x30, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3775 static uint32_t reply2_len =
sizeof(reply2);
3778 static uint8_t request3[] = {
3779 0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a,
3780 0x62, 0x69, 0x6d, 0x62, 0x73, 0x40, 0x67, 0x6d,
3781 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x0d,
3784 static uint32_t request3_len =
sizeof(request3);
3786 static uint8_t reply3[] = {
3787 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x31, 0x2e,
3788 0x35, 0x20, 0x4f, 0x6b, 0x0d, 0x0a
3790 static uint32_t reply3_len =
sizeof(reply3);
3793 static uint8_t request4[] = {
3794 0x44, 0x41, 0x54, 0x41, 0x0d, 0x0a
3796 static uint32_t request4_len =
sizeof(request4);
3798 static uint8_t reply4[] = {
3799 0x33, 0x35, 0x34, 0x20, 0x45, 0x6e, 0x64, 0x20,
3800 0x64, 0x61, 0x74, 0x61, 0x20, 0x77, 0x69, 0x74,
3801 0x68, 0x20, 0x3c, 0x43, 0x52, 0x3e, 0x3c, 0x4c,
3802 0x46, 0x3e, 0x2e, 0x3c, 0x43, 0x52, 0x3e, 0x3c,
3803 0x4c, 0x46, 0x3e, 0x0d, 0x0a
3805 static uint32_t reply4_len =
sizeof(reply4);
3808 static uint64_t filesize = 133;
3809 static uint8_t request4_msg[] = {
3810 0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72,
3811 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E,
3812 0x30, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3813 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A,
3814 0x20, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
3815 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6F, 0x63, 0x74,
3816 0x65, 0x74, 0x2D, 0x73, 0x74, 0x72, 0x65, 0x61,
3817 0x6D, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65,
3818 0x6E, 0x74, 0x2D, 0x54, 0x72, 0x61, 0x6E, 0x73,
3819 0x66, 0x65, 0x72, 0x2D, 0x45, 0x6E, 0x63, 0x6F,
3820 0x64, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0x62, 0x61,
3821 0x73, 0x65, 0x36, 0x34, 0x0D, 0x0A, 0x43, 0x6F,
3822 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x44, 0x69,
3823 0x73, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F,
3824 0x6E, 0x3A, 0x20, 0x61, 0x74, 0x74, 0x61, 0x63,
3825 0x68, 0x6D, 0x65, 0x6E, 0x74, 0x3B, 0x20, 0x66,
3826 0x69, 0x6C, 0x65, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
3827 0x22, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x65, 0x78,
3828 0x65, 0x22, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x54,
3829 0x56, 0x6F, 0x41, 0x41, 0x46, 0x42, 0x46, 0x41,
3830 0x41, 0x42, 0x4D, 0x41, 0x51, 0x45, 0x41, 0x61,
3831 0x69, 0x70, 0x59, 0x77, 0x77, 0x41, 0x41, 0x41,
3832 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3833 0x41, 0x41, 0x44, 0x41, 0x51, 0x73, 0x42, 0x43,
3834 0x41, 0x41, 0x42, 0x41, 0x41, 0x43, 0x41, 0x41,
3835 0x41, 0x41, 0x41, 0x41, 0x48, 0x6B, 0x41, 0x41,
3836 0x41, 0x41, 0x4D, 0x41, 0x41, 0x41, 0x41, 0x65,
3837 0x51, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
3838 0x41, 0x41, 0x41, 0x41, 0x45, 0x41, 0x41, 0x42,
3839 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3840 0x41, 0x42, 0x30, 0x41, 0x41, 0x41, 0x41, 0x49,
3841 0x41, 0x41, 0x41, 0x41, 0x41, 0x51, 0x41, 0x41,
3842 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42,
3843 0x41, 0x45, 0x41, 0x41, 0x49, 0x67, 0x41, 0x41,
3844 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3845 0x67, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3846 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3847 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
3848 0x41, 0x42, 0x63, 0x58, 0x44, 0x59, 0x32, 0x4C,
3849 0x6A, 0x6B, 0x7A, 0x4C, 0x6A, 0x59, 0x34, 0x4C,
3850 0x6A, 0x5A, 0x63, 0x65, 0x67, 0x41, 0x41, 0x4F,
3851 0x41, 0x3D, 0x3D, 0x0D,0x0A };
3852 static uint32_t request4_msg_len =
sizeof(request4_msg);
3855 static uint8_t request4_end[] = {
3856 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
3858 static uint32_t request4_end_len =
sizeof(request4_end);
3860 static uint8_t reply4_end[] = {
3861 0x32, 0x35, 0x30, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3862 0x30, 0x20, 0x4f, 0x6b, 0x3a, 0x20, 0x71, 0x75,
3863 0x65, 0x75, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20,
3864 0x36, 0x41, 0x31, 0x41, 0x46, 0x32, 0x30, 0x42,
3865 0x46, 0x32, 0x0d, 0x0a
3867 static uint32_t reply4_end_len =
sizeof(reply4_end);
3870 static uint8_t request5[] = {
3871 0x51, 0x55, 0x49, 0x54, 0x0d, 0x0a
3873 static uint32_t request5_len =
sizeof(request5);
3875 static uint8_t reply5[] = {
3876 0x32, 0x32, 0x31, 0x20, 0x32, 0x2e, 0x30, 0x2e,
3877 0x30, 0x20, 0x42, 0x79, 0x65, 0x0d, 0x0a
3879 static uint32_t reply5_len =
sizeof(reply5);
3884 memset(&f, 0,
sizeof(f));
3885 memset(&ssn, 0,
sizeof(ssn));
3889 f.
proto = IPPROTO_TCP;
3893 SMTPTestInitConfig();
3897 STREAM_TOCLIENT, welcome_reply, welcome_reply_len);
3899 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3903 if (smtp_state == NULL) {
3904 printf(
"no smtp state: ");
3909 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3914 STREAM_TOSERVER, request1, request1_len);
3916 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3922 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3928 STREAM_TOCLIENT, reply1, reply1_len);
3930 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3934 if ((smtp_state->
helo_len != 7) || strncmp(
"boo.com", (
char *)smtp_state->
helo, 7)) {
3935 printf(
"incorrect parsing of HELO field '%s' (%d)\n", smtp_state->
helo, smtp_state->
helo_len);
3941 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3947 STREAM_TOSERVER, request2, request2_len);
3949 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3955 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3961 STREAM_TOCLIENT, reply2, reply2_len);
3963 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3969 printf(
"incorrect parsing of MAIL FROM field '%s' (%d)\n",
3977 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3983 STREAM_TOSERVER, request3, request3_len);
3985 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
3991 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
3997 STREAM_TOCLIENT, reply3, reply3_len);
3999 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4004 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4016 STREAM_TOSERVER, request4, request4_len);
4018 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4025 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4031 STREAM_TOCLIENT, reply4, reply4_len);
4033 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4039 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4045 STREAM_TOSERVER, request4_msg, request4_msg_len);
4047 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4056 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4062 STREAM_TOSERVER, request4_end, request4_end_len);
4064 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4073 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4082 if (files != NULL && files->
head != NULL) {
4085 if(strncmp((
const char *)file->
name,
"test.exe", 8) != 0){
4086 printf(
"smtp-mime file name is incorrect");
4090 printf(
"smtp-mime file size %"PRIu64
" is incorrect",
FileDataSize(file));
4093 static uint8_t org_binary[] = {
4094 0x4D, 0x5A, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00,
4095 0x4C, 0x01, 0x01, 0x00, 0x6A, 0x2A, 0x58, 0xC3,
4096 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4097 0x04, 0x00, 0x03, 0x01, 0x0B, 0x01, 0x08, 0x00,
4098 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4099 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4100 0x79, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
4101 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00,
4102 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
4103 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4104 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00,
4105 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4106 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4108 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5C, 0x36, 0x36,
4109 0x2E, 0x39, 0x33, 0x2E, 0x36, 0x38, 0x2E, 0x36,
4110 0x5C, 0x7A, 0x00, 0x00, 0x38,};
4113 org_binary,
sizeof(org_binary)) != 1)
4115 printf(
"smtp-mime file data incorrect\n");
4122 STREAM_TOCLIENT, reply4_end, reply4_end_len);
4124 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4129 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4135 STREAM_TOSERVER, request5, request5_len);
4137 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4143 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);
4149 STREAM_TOCLIENT, reply5, reply5_len);
4151 printf(
"smtp check returned %" PRId32
", expected 0: ", r);
4156 printf(
"smtp parser in inconsistent state l.%d\n", __LINE__);