suricata
app-layer-smtp.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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 __APP_LAYER_SMTP_H__
25 #define __APP_LAYER_SMTP_H__
26 
27 #include "decode-events.h"
28 #include "util-decode-mime.h"
29 #include "queue.h"
30 #include "util-streaming-buffer.h"
31 
32 enum {
42 
43  /* MIME Events */
54 
55  /* Invalid behavior or content */
58 };
59 
60 typedef struct SMTPString_ {
61  uint8_t *str;
62  uint16_t len;
63 
66 
67 typedef struct SMTPTransaction_ {
68  /** id of this tx, starting at 0 */
69  uint64_t tx_id;
70 
71  uint64_t detect_flags_ts;
72  uint64_t detect_flags_tc;
73 
74  int done;
75  /** indicates loggers done logging */
76  uint32_t logged;
77  /** the first message contained in the session */
79  /** the last message contained in the session */
81  /** the mime decoding parser state */
83 
84  AppLayerDecoderEvents *decoder_events; /**< per tx events */
86 
87  /* MAIL FROM parameters */
88  uint8_t *mail_from;
89  uint16_t mail_from_len;
90 
91  TAILQ_HEAD(, SMTPString_) rcpt_to_list; /**< rcpt to string list */
92 
95 
96 typedef struct SMTPConfig {
97 
100  uint32_t content_limit;
103 
105 
108 
109 typedef struct SMTPState_ {
111  TAILQ_HEAD(, SMTPTransaction_) tx_list; /**< transaction list */
112  uint64_t tx_cnt;
115 
116  /* current input that is being parsed */
117  const uint8_t *input;
118  int32_t input_len;
119  uint8_t direction;
120 
121  /* --parser details-- */
122  /** current line extracted by the parser from the call to SMTPGetline() */
123  const uint8_t *current_line;
124  /** length of the line in current_line. Doesn't include the delimiter */
127 
128  /** used to indicate if the current_line buffer is a malloced buffer. We
129  * use a malloced buffer, if a line is fragmented */
130  uint8_t *tc_db;
131  int32_t tc_db_len;
133  /** we have see LF for the currently parsed line */
135 
136  /** used to indicate if the current_line buffer is a malloced buffer. We
137  * use a malloced buffer, if a line is fragmented */
138  uint8_t *ts_db;
139  int32_t ts_db_len;
141  /** we have see LF for the currently parsed line */
143 
144  /** var to indicate parser state */
145  uint8_t parser_state;
146  /** current command in progress */
148  /** bdat chunk len */
149  uint32_t bdat_chunk_len;
150  /** bdat chunk idx */
151  uint32_t bdat_chunk_idx;
152 
153  /* the request commands are store here and the reply handler uses these
154  * stored command in the buffer to match the reply(ies) with the command */
155  /** the command buffer */
156  uint8_t *cmds;
157  /** the buffer length */
158  uint16_t cmds_buffer_len;
159  /** no of commands stored in the above buffer */
160  uint16_t cmds_cnt;
161  /** index of the command in the buffer, currently in inspection by reply
162  * handler */
163  uint16_t cmds_idx;
164 
165  /* HELO of HELO message content */
166  uint16_t helo_len;
167  uint8_t *helo;
168 
169  /* SMTP Mime decoding and file extraction */
170  /** the list of files sent to the server */
172  uint32_t file_track_id;
174 
175 /* Create SMTP config structure */
176 extern SMTPConfig smtp_config;
177 
178 int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state);
179 void *SMTPStateAlloc(void);
180 void RegisterSMTPParsers(void);
181 void SMTPParserCleanup(void);
182 void SMTPParserRegisterTests(void);
183 
184 #endif /* __APP_LAYER_SMTP_H__ */
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:100
SMTPState_
Definition: app-layer-smtp.h:109
SMTPState_::ts_db_len
int32_t ts_db_len
Definition: app-layer-smtp.h:139
FileContainer_
Definition: util-file.h:100
len
uint8_t len
Definition: app-layer-dnp3.h:2
SMTP_DECODER_EVENT_TLS_REJECTED
@ SMTP_DECODER_EVENT_TLS_REJECTED
Definition: app-layer-smtp.h:40
SMTPState_::cmds_cnt
uint16_t cmds_cnt
Definition: app-layer-smtp.h:160
SMTPProcessDataChunk
int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state)
Definition: app-layer-smtp.c:408
SMTPTransaction_::msg_tail
MimeDecEntity * msg_tail
Definition: app-layer-smtp.h:80
DetectEngineState_
Definition: detect-engine-state.h:92
SMTPState_::bdat_chunk_idx
uint32_t bdat_chunk_idx
Definition: app-layer-smtp.h:151
SMTPStateAlloc
void * SMTPStateAlloc(void)
Definition: app-layer-smtp.c:1433
SMTPState_::current_line_len
int32_t current_line_len
Definition: app-layer-smtp.h:125
SMTPState_::current_line
const uint8_t * current_line
Definition: app-layer-smtp.h:123
SMTPState_::current_line_delimiter_len
uint8_t current_line_delimiter_len
Definition: app-layer-smtp.h:126
SMTPTransaction_::mime_state
MimeDecParseState * mime_state
Definition: app-layer-smtp.h:82
SMTPParserRegisterTests
void SMTPParserRegisterTests(void)
Definition: app-layer-smtp.c:5336
SMTPConfig
Definition: app-layer-smtp.h:96
SMTPState_::tc_current_line_db
uint8_t tc_current_line_db
Definition: app-layer-smtp.h:132
SMTPTransaction_::msg_head
MimeDecEntity * msg_head
Definition: app-layer-smtp.h:78
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
SMTPState_::tc_db
uint8_t * tc_db
Definition: app-layer-smtp.h:130
SMTPState_::input_len
int32_t input_len
Definition: app-layer-smtp.h:118
SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:35
SMTP_DECODER_EVENT_INVALID_REPLY
@ SMTP_DECODER_EVENT_INVALID_REPLY
Definition: app-layer-smtp.h:33
SMTPState_::toserver_last_data_stamp
uint64_t toserver_last_data_stamp
Definition: app-layer-smtp.h:114
SMTPState_::tx_cnt
uint64_t tx_cnt
Definition: app-layer-smtp.h:112
SMTPState_::cmds_idx
uint16_t cmds_idx
Definition: app-layer-smtp.h:163
SMTPString
struct SMTPString_ SMTPString
SMTPTransaction_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPTransaction_) next
SMTPState_::ts_current_line_lf_seen
uint8_t ts_current_line_lf_seen
Definition: app-layer-smtp.h:142
SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
@ SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
Definition: app-layer-smtp.h:37
SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
@ SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
Definition: app-layer-smtp.h:34
SMTPState_::direction
uint8_t direction
Definition: app-layer-smtp.h:119
AppLayerDecoderEvents_
Data structure to store app layer decoder events.
Definition: app-layer-events.h:34
SMTPState_::tc_db_len
int32_t tc_db_len
Definition: app-layer-smtp.h:131
SMTPTransaction_::detect_flags_tc
uint64_t detect_flags_tc
Definition: app-layer-smtp.h:72
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:101
SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
Definition: app-layer-smtp.h:50
SMTPParserCleanup
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
Definition: app-layer-smtp.c:1868
SMTP_DECODER_EVENT_MIME_PARSE_FAILED
@ SMTP_DECODER_EVENT_MIME_PARSE_FAILED
Definition: app-layer-smtp.h:44
SMTP_DECODER_EVENT_MIME_LONG_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_LINE
Definition: app-layer-smtp.h:48
SMTP_DECODER_EVENT_MIME_INVALID_BASE64
@ SMTP_DECODER_EVENT_MIME_INVALID_BASE64
Definition: app-layer-smtp.h:46
RegisterSMTPParsers
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
Definition: app-layer-smtp.c:1806
SMTPState_::helo
uint8_t * helo
Definition: app-layer-smtp.h:167
SMTPConfig::decode_mime
int decode_mime
Definition: app-layer-smtp.h:98
SMTPTransaction_::done
int done
Definition: app-layer-smtp.h:74
SMTPState_::parser_state
uint8_t parser_state
Definition: app-layer-smtp.h:145
SMTPTransaction_::mail_from
uint8_t * mail_from
Definition: app-layer-smtp.h:88
SMTPState_::input
const uint8_t * input
Definition: app-layer-smtp.h:117
SMTPState_::curr_tx
SMTPTransaction * curr_tx
Definition: app-layer-smtp.h:110
SMTPConfig
struct SMTPConfig SMTPConfig
SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:36
SMTPTransaction_
Definition: app-layer-smtp.h:67
SMTPConfig::raw_extraction
int raw_extraction
Definition: app-layer-smtp.h:104
SMTPState_::current_command
uint8_t current_command
Definition: app-layer-smtp.h:147
SMTPState
struct SMTPState_ SMTPState
queue.h
SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
@ SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
Definition: app-layer-smtp.h:57
SMTPTransaction_::mail_from_len
uint16_t mail_from_len
Definition: app-layer-smtp.h:89
SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
Definition: app-layer-smtp.h:38
decode-events.h
MimeDecConfig
Structure for containing configuration options.
Definition: util-decode-mime.h:94
SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
Definition: app-layer-smtp.h:49
SMTPString_::len
uint16_t len
Definition: app-layer-smtp.h:62
SMTPState_::helo_len
uint16_t helo_len
Definition: app-layer-smtp.h:166
SMTP_DECODER_EVENT_MIME_LONG_FILENAME
@ SMTP_DECODER_EVENT_MIME_LONG_FILENAME
Definition: app-layer-smtp.h:53
SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
@ SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
Definition: app-layer-smtp.h:39
SMTPState_::toserver_data_count
uint64_t toserver_data_count
Definition: app-layer-smtp.h:113
SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
@ SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
Definition: app-layer-smtp.h:52
SMTPState_::cmds
uint8_t * cmds
Definition: app-layer-smtp.h:156
SMTPTransaction_::tx_id
uint64_t tx_id
Definition: app-layer-smtp.h:69
util-streaming-buffer.h
SMTPState_::files_ts
FileContainer * files_ts
Definition: app-layer-smtp.h:171
util-decode-mime.h
SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
@ SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
Definition: app-layer-smtp.h:41
SMTPState_::bdat_chunk_len
uint32_t bdat_chunk_len
Definition: app-layer-smtp.h:149
SMTP_DECODER_EVENT_DUPLICATE_FIELDS
@ SMTP_DECODER_EVENT_DUPLICATE_FIELDS
Definition: app-layer-smtp.h:56
SMTPString_
Definition: app-layer-smtp.h:60
SMTPTransaction_::detect_flags_ts
uint64_t detect_flags_ts
Definition: app-layer-smtp.h:71
smtp_config
SMTPConfig smtp_config
Definition: app-layer-smtp.c:240
StreamingBufferConfig_
Definition: util-streaming-buffer.h:67
MimeDecParseState
Structure contains the current state of the MIME parser.
Definition: util-decode-mime.h:187
SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
Definition: app-layer-smtp.h:51
SMTPTransaction_::decoder_events
AppLayerDecoderEvents * decoder_events
Definition: app-layer-smtp.h:84
SMTPState_::ts_db
uint8_t * ts_db
Definition: app-layer-smtp.h:138
SMTPConfig::mime_config
MimeDecConfig mime_config
Definition: app-layer-smtp.h:99
SMTPString_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPString_) next
SMTP_DECODER_EVENT_MIME_INVALID_QP
@ SMTP_DECODER_EVENT_MIME_INVALID_QP
Definition: app-layer-smtp.h:47
SMTPTransaction_::logged
uint32_t logged
Definition: app-layer-smtp.h:76
SMTPTransaction_::TAILQ_HEAD
TAILQ_HEAD(, SMTPString_) rcpt_to_list
SMTPConfig::sbcfg
StreamingBufferConfig sbcfg
Definition: app-layer-smtp.h:106
SMTPState_::TAILQ_HEAD
TAILQ_HEAD(, SMTPTransaction_) tx_list
SMTPTransaction_::de_state
DetectEngineState * de_state
Definition: app-layer-smtp.h:85
SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
@ SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
Definition: app-layer-smtp.h:45
SMTPString_::str
uint8_t * str
Definition: app-layer-smtp.h:61
SMTPState_::file_track_id
uint32_t file_track_id
Definition: app-layer-smtp.h:172
SMTPTransaction
struct SMTPTransaction_ SMTPTransaction
SMTPState_::cmds_buffer_len
uint16_t cmds_buffer_len
Definition: app-layer-smtp.h:158
SMTPState_::ts_current_line_db
uint8_t ts_current_line_db
Definition: app-layer-smtp.h:140
SMTPState_::tc_current_line_lf_seen
uint8_t tc_current_line_lf_seen
Definition: app-layer-smtp.h:134
MimeDecEntity
This represents the MIME Entity (or also top level message) in a child-sibling tree.
Definition: util-decode-mime.h:132
SMTPConfig::content_inspect_window
uint32_t content_inspect_window
Definition: app-layer-smtp.h:102