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 __APP_LAYER_SMTP_H__
25 #define __APP_LAYER_SMTP_H__
26 
27 #include "util-decode-mime.h"
28 #include "util-streaming-buffer.h"
29 #include "rust.h"
30 
31 enum {
42 
43  /* MIME Events */
54 
55  /* Invalid behavior or content */
58  /* For line >= 4KB */
60 };
61 
62 typedef struct SMTPString_ {
63  uint8_t *str;
64  uint16_t len;
65 
68 
69 typedef struct SMTPTransaction_ {
70  /** id of this tx, starting at 0 */
71  uint64_t tx_id;
72 
74 
75  int done;
76  /** the first message contained in the session */
78  /** the last message contained in the session */
80  /** the mime decoding parser state */
82 
83  /* MAIL FROM parameters */
84  uint8_t *mail_from;
85  uint16_t mail_from_len;
86 
87  TAILQ_HEAD(, SMTPString_) rcpt_to_list; /**< rcpt to string list */
88 
90 
93 
94 typedef struct SMTPConfig {
95 
98  uint32_t content_limit;
101 
103 
106 
107 typedef struct SMTPState_ {
108  AppLayerStateData state_data;
110  TAILQ_HEAD(, SMTPTransaction_) tx_list; /**< transaction list */
111  uint64_t tx_cnt;
114 
115  /* If rest of the bytes should be discarded in case of long line w/o LF */
117 
118  /** var to indicate parser state */
119  uint8_t parser_state;
120  /** current command in progress */
122  /** bdat chunk len */
123  uint32_t bdat_chunk_len;
124  /** bdat chunk idx */
125  uint32_t bdat_chunk_idx;
126 
127  /* the request commands are store here and the reply handler uses these
128  * stored command in the buffer to match the reply(ies) with the command */
129  /** the command buffer */
130  uint8_t *cmds;
131  /** the buffer length */
132  uint16_t cmds_buffer_len;
133  /** no of commands stored in the above buffer */
134  uint16_t cmds_cnt;
135  /** index of the command in the buffer, currently in inspection by reply
136  * handler */
137  uint16_t cmds_idx;
138 
139  /* HELO of HELO message content */
140  uint16_t helo_len;
141  uint8_t *helo;
142 
143  /* SMTP Mime decoding and file extraction */
144  /** the list of files sent to the server */
145  uint32_t file_track_id;
147 
148 /* Create SMTP config structure */
149 extern SMTPConfig smtp_config;
150 
151 int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state);
152 void *SMTPStateAlloc(void *orig_state, AppProto proto_orig);
153 void RegisterSMTPParsers(void);
154 void SMTPParserCleanup(void);
155 void SMTPParserRegisterTests(void);
156 
157 #endif /* __APP_LAYER_SMTP_H__ */
SMTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
@ SMTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
Definition: app-layer-smtp.h:41
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:98
SMTPState_
Definition: app-layer-smtp.h:107
FileContainer_
Definition: util-file.h:113
len
uint8_t len
Definition: app-layer-dnp3.h:2
SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
@ SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
Definition: app-layer-smtp.h:45
SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
@ SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
Definition: app-layer-smtp.h:36
SMTPState_::cmds_cnt
uint16_t cmds_cnt
Definition: app-layer-smtp.h:134
SMTPProcessDataChunk
int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state)
Definition: app-layer-smtp.c:486
SMTPTransaction_::msg_tail
MimeDecEntity * msg_tail
Definition: app-layer-smtp.h:79
SMTPState_::bdat_chunk_idx
uint32_t bdat_chunk_idx
Definition: app-layer-smtp.h:125
SMTPTransaction_::mime_state
MimeDecParseState * mime_state
Definition: app-layer-smtp.h:81
SMTPParserRegisterTests
void SMTPParserRegisterTests(void)
Definition: app-layer-smtp.c:4157
SMTPConfig
Definition: app-layer-smtp.h:94
SMTPTransaction_::msg_head
MimeDecEntity * msg_head
Definition: app-layer-smtp.h:77
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:80
SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:34
SMTPConfig::decode_mime
bool decode_mime
Definition: app-layer-smtp.h:96
SMTPState_::toserver_last_data_stamp
uint64_t toserver_last_data_stamp
Definition: app-layer-smtp.h:113
SMTPStateAlloc
void * SMTPStateAlloc(void *orig_state, AppProto proto_orig)
Definition: app-layer-smtp.c:1426
SMTPState_::tx_cnt
uint64_t tx_cnt
Definition: app-layer-smtp.h:111
SMTP_DECODER_EVENT_INVALID_REPLY
@ SMTP_DECODER_EVENT_INVALID_REPLY
Definition: app-layer-smtp.h:32
SMTPState_::cmds_idx
uint16_t cmds_idx
Definition: app-layer-smtp.h:137
SMTPString
struct SMTPString_ SMTPString
rust.h
SMTP_DECODER_EVENT_MIME_INVALID_QP
@ SMTP_DECODER_EVENT_MIME_INVALID_QP
Definition: app-layer-smtp.h:47
SMTPTransaction_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPTransaction_) next
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:99
SMTPConfig::raw_extraction
bool raw_extraction
Definition: app-layer-smtp.h:102
SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
@ SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
Definition: app-layer-smtp.h:57
SMTP_DECODER_EVENT_MIME_LONG_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_LINE
Definition: app-layer-smtp.h:48
SMTPParserCleanup
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
Definition: app-layer-smtp.c:1824
SMTP_DECODER_EVENT_TLS_REJECTED
@ SMTP_DECODER_EVENT_TLS_REJECTED
Definition: app-layer-smtp.h:39
SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
Definition: app-layer-smtp.h:50
SMTPState_::state_data
AppLayerStateData state_data
Definition: app-layer-smtp.h:108
RegisterSMTPParsers
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
Definition: app-layer-smtp.c:1769
SMTPState_::helo
uint8_t * helo
Definition: app-layer-smtp.h:141
SMTP_DECODER_EVENT_MIME_PARSE_FAILED
@ SMTP_DECODER_EVENT_MIME_PARSE_FAILED
Definition: app-layer-smtp.h:44
SMTPTransaction_::done
int done
Definition: app-layer-smtp.h:75
SMTPTransaction_::tx_data
AppLayerTxData tx_data
Definition: app-layer-smtp.h:73
SMTPState_::parser_state
uint8_t parser_state
Definition: app-layer-smtp.h:119
SMTPTransaction_::mail_from
uint8_t * mail_from
Definition: app-layer-smtp.h:84
SMTPState_::curr_tx
SMTPTransaction * curr_tx
Definition: app-layer-smtp.h:109
SMTPConfig
struct SMTPConfig SMTPConfig
SMTPTransaction_
Definition: app-layer-smtp.h:69
SMTPState_::current_command
uint8_t current_command
Definition: app-layer-smtp.h:121
SMTPTransaction_::files_ts
FileContainer files_ts
Definition: app-layer-smtp.h:89
SMTPState
struct SMTPState_ SMTPState
SMTPTransaction_::mail_from_len
uint16_t mail_from_len
Definition: app-layer-smtp.h:85
SMTP_DECODER_EVENT_MIME_INVALID_BASE64
@ SMTP_DECODER_EVENT_MIME_INVALID_BASE64
Definition: app-layer-smtp.h:46
MimeDecConfig
Structure for containing configuration options.
Definition: util-decode-mime.h:91
SMTPString_::len
uint16_t len
Definition: app-layer-smtp.h:64
SMTPState_::helo_len
uint16_t helo_len
Definition: app-layer-smtp.h:140
SMTPState_::toserver_data_count
uint64_t toserver_data_count
Definition: app-layer-smtp.h:112
AppLayerTxData
struct AppLayerTxData AppLayerTxData
Definition: detect.h:1305
SMTPState_::cmds
uint8_t * cmds
Definition: app-layer-smtp.h:130
SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
@ SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
Definition: app-layer-smtp.h:49
SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
Definition: app-layer-smtp.h:35
SMTPTransaction_::tx_id
uint64_t tx_id
Definition: app-layer-smtp.h:71
util-streaming-buffer.h
SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
Definition: app-layer-smtp.h:37
util-decode-mime.h
SMTPState_::bdat_chunk_len
uint32_t bdat_chunk_len
Definition: app-layer-smtp.h:123
SMTP_DECODER_EVENT_DUPLICATE_FIELDS
@ SMTP_DECODER_EVENT_DUPLICATE_FIELDS
Definition: app-layer-smtp.h:56
SMTPString_
Definition: app-layer-smtp.h:62
smtp_config
SMTPConfig smtp_config
Definition: app-layer-smtp.c:245
StreamingBufferConfig_
Definition: util-streaming-buffer.h:66
MimeDecParseState
Structure contains the current state of the MIME parser.
Definition: util-decode-mime.h:185
SMTPConfig::mime_config
MimeDecConfig mime_config
Definition: app-layer-smtp.h:97
SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
@ SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
Definition: app-layer-smtp.h:38
SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
@ SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
Definition: app-layer-smtp.h:33
SMTPString_::TAILQ_ENTRY
TAILQ_ENTRY(SMTPString_) next
SMTPTransaction_::TAILQ_HEAD
TAILQ_HEAD(, SMTPString_) rcpt_to_list
SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
@ SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
Definition: app-layer-smtp.h:40
SMTPConfig::sbcfg
StreamingBufferConfig sbcfg
Definition: app-layer-smtp.h:104
SMTPState_::TAILQ_HEAD
TAILQ_HEAD(, SMTPTransaction_) tx_list
SMTP_DECODER_EVENT_MIME_LONG_FILENAME
@ SMTP_DECODER_EVENT_MIME_LONG_FILENAME
Definition: app-layer-smtp.h:53
SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
@ SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
Definition: app-layer-smtp.h:52
SMTPString_::str
uint8_t * str
Definition: app-layer-smtp.h:63
SMTPState_::file_track_id
uint32_t file_track_id
Definition: app-layer-smtp.h:145
SMTPTransaction
struct SMTPTransaction_ SMTPTransaction
SMTP_DECODER_EVENT_TRUNCATED_LINE
@ SMTP_DECODER_EVENT_TRUNCATED_LINE
Definition: app-layer-smtp.h:59
SMTPState_::cmds_buffer_len
uint16_t cmds_buffer_len
Definition: app-layer-smtp.h:132
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:100
SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
Definition: app-layer-smtp.h:51
SMTPState_::discard_till_lf
bool discard_till_lf
Definition: app-layer-smtp.h:116