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 */
53 
54  /* Invalid behavior or content */
57 };
58 
59 typedef struct SMTPString_ {
60  uint8_t *str;
61  uint16_t len;
62 
64 } SMTPString;
65 
66 typedef struct SMTPTransaction_ {
67  /** id of this tx, starting at 0 */
68  uint64_t tx_id;
69 
70  uint64_t detect_flags_ts;
71  uint64_t detect_flags_tc;
72 
73  int done;
74  /** indicates loggers done logging */
75  uint32_t logged;
76  /** the first message contained in the session */
78  /** the last message contained in the session */
80  /** the mime decoding parser state */
82 
83  AppLayerDecoderEvents *decoder_events; /**< per tx events */
85 
86  /* MAIL FROM parameters */
87  uint8_t *mail_from;
88  uint16_t mail_from_len;
89 
90  TAILQ_HEAD(, SMTPString_) rcpt_to_list; /**< rcpt to string list */
91 
92  TAILQ_ENTRY(SMTPTransaction_) next;
94 
95 typedef struct SMTPConfig {
96 
99  uint32_t content_limit;
102 
104 
106 } SMTPConfig;
107 
108 typedef struct SMTPState_ {
110  TAILQ_HEAD(, SMTPTransaction_) tx_list; /**< transaction list */
111  uint64_t tx_cnt;
112  uint64_t toserver_data_count;
113  uint64_t toserver_last_data_stamp;
114 
115  /* current input that is being parsed */
116  const uint8_t *input;
117  int32_t input_len;
118  uint8_t direction;
119 
120  /* --parser details-- */
121  /** current line extracted by the parser from the call to SMTPGetline() */
122  const uint8_t *current_line;
123  /** length of the line in current_line. Doesn't include the delimiter */
124  int32_t current_line_len;
125  uint8_t current_line_delimiter_len;
126 
127  /** used to indicate if the current_line buffer is a malloced buffer. We
128  * use a malloced buffer, if a line is fragmented */
129  uint8_t *tc_db;
130  int32_t tc_db_len;
131  uint8_t tc_current_line_db;
132  /** we have see LF for the currently parsed line */
133  uint8_t tc_current_line_lf_seen;
134 
135  /** used to indicate if the current_line buffer is a malloced buffer. We
136  * use a malloced buffer, if a line is fragmented */
137  uint8_t *ts_db;
138  int32_t ts_db_len;
139  uint8_t ts_current_line_db;
140  /** we have see LF for the currently parsed line */
141  uint8_t ts_current_line_lf_seen;
142 
143  /** var to indicate parser state */
144  uint8_t parser_state;
145  /** current command in progress */
146  uint8_t current_command;
147  /** bdat chunk len */
148  uint32_t bdat_chunk_len;
149  /** bdat chunk idx */
150  uint32_t bdat_chunk_idx;
151 
152  /* the request commands are store here and the reply handler uses these
153  * stored command in the buffer to match the reply(ies) with the command */
154  /** the command buffer */
155  uint8_t *cmds;
156  /** the buffer length */
157  uint16_t cmds_buffer_len;
158  /** no of commands stored in the above buffer */
159  uint16_t cmds_cnt;
160  /** index of the command in the buffer, currently in inspection by reply
161  * handler */
162  uint16_t cmds_idx;
163 
164  /* HELO of HELO message content */
165  uint16_t helo_len;
166  uint8_t *helo;
167 
168  /* SMTP Mime decoding and file extraction */
169  /** the list of files sent to the server */
170  FileContainer *files_ts;
171  uint32_t file_track_id;
172 } SMTPState;
173 
174 /* Create SMTP config structure */
175 extern SMTPConfig smtp_config;
176 
177 int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state);
178 void *SMTPStateAlloc(void);
179 void RegisterSMTPParsers(void);
180 void SMTPParserCleanup(void);
181 void SMTPParserRegisterTests(void);
182 
183 #endif /* __APP_LAYER_SMTP_H__ */
uint8_t * mail_from
Structure for containing configuration options.
uint32_t content_limit
struct HtpBodyChunk_ * next
uint16_t mail_from_len
MimeDecEntity * msg_tail
struct SMTPConfig SMTPConfig
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
uint16_t len
TAILQ_ENTRY(SMTPString_) next
AppLayerDecoderEvents * decoder_events
#define TAILQ_HEAD(name, type)
Definition: queue.h:321
DetectEngineState * de_state
MimeDecEntity * msg_head
This represents the MIME Entity (or also top level message) in a child-sibling tree.
uint32_t content_inspect_min_size
Data structure to store app layer decoder events.
SMTPTransaction * curr_tx
uint8_t * str
SMTPConfig smtp_config
MimeDecParseState * mime_state
int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state)
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
uint64_t detect_flags_tc
Structure contains the current state of the MIME parser.
MimeDecConfig mime_config
uint32_t content_inspect_window
uint64_t detect_flags_ts
StreamingBufferConfig sbcfg
void * SMTPStateAlloc(void)
void SMTPParserRegisterTests(void)