suricata
app-layer-smtp.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  */
23 
24 #ifndef SURICATA_APP_LAYER_SMTP_H
25 #define SURICATA_APP_LAYER_SMTP_H
26 
27 #include "rust.h"
28 #include "app-layer-parser.h"
29 #include "app-layer-frames.h"
30 #include "util-streaming-buffer.h"
31 
32 /* Limit till the data would be buffered in current line */
33 #define SMTP_LINE_BUFFER_LIMIT 4096
34 
35 enum {
46 
47  /* MIME Events */
58 
59  /* Invalid behavior or content */
62  /* For line >= 4KB */
64 };
65 
66 typedef struct SMTPString_ {
67  uint8_t *str;
68  uint16_t len;
69 
72 
73 typedef struct SMTPTransaction_ {
74  /** id of this tx, starting at 0 */
75  uint64_t tx_id;
76 
78 
79  /** the tx is complete and can be logged and cleaned */
80  bool done;
81  /** the tx has seen a DATA command */
82  // another DATA command within the same context
83  // will trigger an app-layer event.
84  bool is_data;
85  /** the mime decoding parser state */
86  MimeStateSMTP *mime_state;
87 
88  /* MAIL FROM parameters */
89  uint8_t *mail_from;
90  uint16_t mail_from_len;
91 
92  TAILQ_HEAD(, SMTPString_) rcpt_to_list; /**< rcpt to string list */
93 
95 
98 
99 /**
100  * \brief Structure for containing configuration options
101  *
102  */
103 
104 typedef struct SMTPConfig {
105 
107  uint32_t content_limit;
110  uint64_t max_tx;
111 
113 
116 
117 typedef struct SMTPState_ {
120  TAILQ_HEAD(, SMTPTransaction_) tx_list; /**< transaction list */
121  uint64_t tx_cnt;
124 
125  /* If rest of the bytes should be discarded in case of long line w/o LF */
128 
129  /** var to indicate parser state */
130  uint8_t parser_state;
131  /** current command in progress */
133  /** bdat chunk len */
134  uint32_t bdat_chunk_len;
135  /** bdat chunk idx */
136  uint32_t bdat_chunk_idx;
137 
138  /* the request commands are store here and the reply handler uses these
139  * stored command in the buffer to match the reply(ies) with the command */
140  /** the command buffer */
141  uint8_t *cmds;
142  /** the buffer length */
143  uint16_t cmds_buffer_len;
144  /** no of commands stored in the above buffer */
145  uint16_t cmds_cnt;
146  /** index of the command in the buffer, currently in inspection by reply
147  * handler */
148  uint16_t cmds_idx;
149 
150  /* HELO of HELO message content */
151  uint16_t helo_len;
152  uint8_t *helo;
153 
154  /* SMTP Mime decoding and file extraction */
155  /** the list of files sent to the server */
156  uint32_t file_track_id;
158 
159 /* Create SMTP config structure */
160 extern SMTPConfig smtp_config;
161 
162 void *SMTPStateAlloc(void *orig_state, AppProto proto_orig);
163 void RegisterSMTPParsers(void);
164 void SMTPParserCleanup(void);
165 void SMTPParserRegisterTests(void);
166 
167 #endif /* SURICATA_APP_LAYER_SMTP_H */
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:107
SMTPState_
Definition: app-layer-smtp.h:117
FileContainer_
Definition: util-file.h:37
SMTP_DECODER_EVENT_TLS_REJECTED
@ SMTP_DECODER_EVENT_TLS_REJECTED
Definition: app-layer-smtp.h:43
SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:38
SMTPState_::cmds_cnt
uint16_t cmds_cnt
Definition: app-layer-smtp.h:145
SMTP_DECODER_EVENT_MIME_LONG_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_LINE
Definition: app-layer-smtp.h:52
SMTPState_::bdat_chunk_idx
uint32_t bdat_chunk_idx
Definition: app-layer-smtp.h:136
SMTPParserRegisterTests
void SMTPParserRegisterTests(void)
Definition: app-layer-smtp.c:4259
SMTPConfig
Structure for containing configuration options.
Definition: app-layer-smtp.h:104
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
SMTPState_::discard_till_lf_tc
bool discard_till_lf_tc
Definition: app-layer-smtp.h:127
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
SMTPConfig::decode_mime
bool decode_mime
Definition: app-layer-smtp.h:106
AppLayerStateData
Definition: app-layer-parser.h:160
SMTPState_::toserver_last_data_stamp
uint64_t toserver_last_data_stamp
Definition: app-layer-smtp.h:123
SMTPStateAlloc
void * SMTPStateAlloc(void *orig_state, AppProto proto_orig)
Definition: app-layer-smtp.c:1504
SMTPState_::tx_cnt
uint64_t tx_cnt
Definition: app-layer-smtp.h:121
SMTPState_::cmds_idx
uint16_t cmds_idx
Definition: app-layer-smtp.h:148
SMTPString
struct SMTPString_ SMTPString
rust.h
SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:39
SMTPTransaction_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPTransaction_) next
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:108
SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
@ SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
Definition: app-layer-smtp.h:42
SMTPConfig::raw_extraction
bool raw_extraction
Definition: app-layer-smtp.h:112
SMTP_DECODER_EVENT_DUPLICATE_FIELDS
@ SMTP_DECODER_EVENT_DUPLICATE_FIELDS
Definition: app-layer-smtp.h:60
SMTPParserCleanup
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
Definition: app-layer-smtp.c:1934
AppLayerTxData
Definition: app-layer-parser.h:177
SMTPState_::state_data
AppLayerStateData state_data
Definition: app-layer-smtp.h:118
RegisterSMTPParsers
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
Definition: app-layer-smtp.c:1879
SMTPState_::helo
uint8_t * helo
Definition: app-layer-smtp.h:152
SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
@ SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
Definition: app-layer-smtp.h:49
SMTPTransaction_::tx_data
AppLayerTxData tx_data
Definition: app-layer-smtp.h:77
SMTPState_::parser_state
uint8_t parser_state
Definition: app-layer-smtp.h:130
SMTP_DECODER_EVENT_MIME_INVALID_BASE64
@ SMTP_DECODER_EVENT_MIME_INVALID_BASE64
Definition: app-layer-smtp.h:50
SMTPTransaction_::mail_from
uint8_t * mail_from
Definition: app-layer-smtp.h:89
SMTPState_::curr_tx
SMTPTransaction * curr_tx
Definition: app-layer-smtp.h:119
SMTPState_::discard_till_lf_ts
bool discard_till_lf_ts
Definition: app-layer-smtp.h:126
SMTPConfig
struct SMTPConfig SMTPConfig
Structure for containing configuration options.
app-layer-parser.h
SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
@ SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
Definition: app-layer-smtp.h:56
SMTPTransaction_
Definition: app-layer-smtp.h:73
SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
@ SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
Definition: app-layer-smtp.h:44
SMTPState_::current_command
uint8_t current_command
Definition: app-layer-smtp.h:132
SMTPTransaction_::files_ts
FileContainer files_ts
Definition: app-layer-smtp.h:94
SMTPState
struct SMTPState_ SMTPState
SMTPTransaction_::mail_from_len
uint16_t mail_from_len
Definition: app-layer-smtp.h:90
SMTPConfig::max_tx
uint64_t max_tx
Definition: app-layer-smtp.h:110
SMTPString_::len
uint16_t len
Definition: app-layer-smtp.h:68
SMTPState_::helo_len
uint16_t helo_len
Definition: app-layer-smtp.h:151
SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
@ SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
Definition: app-layer-smtp.h:40
SMTPState_::toserver_data_count
uint64_t toserver_data_count
Definition: app-layer-smtp.h:122
app-layer-frames.h
SMTPTransaction_::is_data
bool is_data
Definition: app-layer-smtp.h:84
SMTPState_::cmds
uint8_t * cmds
Definition: app-layer-smtp.h:141
SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
Definition: app-layer-smtp.h:53
SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
@ SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
Definition: app-layer-smtp.h:37
SMTPTransaction_::tx_id
uint64_t tx_id
Definition: app-layer-smtp.h:75
SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
@ SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
Definition: app-layer-smtp.h:61
util-streaming-buffer.h
SMTPState_::bdat_chunk_len
uint32_t bdat_chunk_len
Definition: app-layer-smtp.h:134
SMTP_DECODER_EVENT_MIME_LONG_FILENAME
@ SMTP_DECODER_EVENT_MIME_LONG_FILENAME
Definition: app-layer-smtp.h:57
SMTPString_
Definition: app-layer-smtp.h:66
smtp_config
SMTPConfig smtp_config
Definition: app-layer-smtp.c:293
StreamingBufferConfig_
Definition: util-streaming-buffer.h:65
SMTP_DECODER_EVENT_MIME_INVALID_QP
@ SMTP_DECODER_EVENT_MIME_INVALID_QP
Definition: app-layer-smtp.h:51
SMTPString_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPString_) next
SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
Definition: app-layer-smtp.h:54
SMTPTransaction_::done
bool done
Definition: app-layer-smtp.h:80
SMTPTransaction_::TAILQ_HEAD
TAILQ_HEAD(, SMTPString_) rcpt_to_list
SMTPConfig::sbcfg
StreamingBufferConfig sbcfg
Definition: app-layer-smtp.h:114
SMTP_DECODER_EVENT_MIME_PARSE_FAILED
@ SMTP_DECODER_EVENT_MIME_PARSE_FAILED
Definition: app-layer-smtp.h:48
SMTPState_::TAILQ_HEAD
TAILQ_HEAD(, SMTPTransaction_) tx_list
SMTP_DECODER_EVENT_TRUNCATED_LINE
@ SMTP_DECODER_EVENT_TRUNCATED_LINE
Definition: app-layer-smtp.h:63
SMTPString_::str
uint8_t * str
Definition: app-layer-smtp.h:67
SMTPState_::file_track_id
uint32_t file_track_id
Definition: app-layer-smtp.h:156
SMTPTransaction
struct SMTPTransaction_ SMTPTransaction
SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
Definition: app-layer-smtp.h:41
SMTPState_::cmds_buffer_len
uint16_t cmds_buffer_len
Definition: app-layer-smtp.h:143
SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
Definition: app-layer-smtp.h:55
SMTP_DECODER_EVENT_INVALID_REPLY
@ SMTP_DECODER_EVENT_INVALID_REPLY
Definition: app-layer-smtp.h:36
SMTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
@ SMTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
Definition: app-layer-smtp.h:45
SMTPConfig::content_inspect_window
uint32_t content_inspect_window
Definition: app-layer-smtp.h:109
SMTPTransaction_::mime_state
MimeStateSMTP * mime_state
Definition: app-layer-smtp.h:86