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 "app-layer-frames.h"
29#include "rust.h"
30
31/* Limit till the data would be buffered in current line */
32#define SMTP_LINE_BUFFER_LIMIT 4096
33
34enum {
45
46 /* MIME Events */
57
58 /* Invalid behavior or content */
61 /* For line >= 4KB */
63};
64
65typedef struct SMTPString_ {
66 uint8_t *str;
67 uint16_t len;
68
71
72typedef struct SMTPTransaction_ {
73 /** id of this tx, starting at 0 */
74 uint64_t tx_id;
75
77
78 /** the tx is complete and can be logged and cleaned */
79 bool done;
80 /** the tx has seen a DATA command */
81 // another DATA command within the same context
82 // will trigger an app-layer event.
83 bool is_data;
84 /** the mime decoding parser state */
85 MimeStateSMTP *mime_state;
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
94
97
98/**
99 * \brief Structure for containing configuration options
100 *
101 */
102
115
116typedef struct SMTPState_ {
119 TAILQ_HEAD(, SMTPTransaction_) tx_list; /**< transaction list */
120 uint64_t tx_cnt;
123
124 /* If rest of the bytes should be discarded in case of long line w/o LF */
127
128 /** var to indicate parser state */
130 /** current command in progress */
132 /** bdat chunk len */
134 /** bdat chunk idx */
136
137 /* the request commands are store here and the reply handler uses these
138 * stored command in the buffer to match the reply(ies) with the command */
139 /** the command buffer */
140 uint8_t *cmds;
141 /** the buffer length */
143 /** no of commands stored in the above buffer */
144 uint16_t cmds_cnt;
145 /** index of the command in the buffer, currently in inspection by reply
146 * handler */
147 uint16_t cmds_idx;
148
149 /* HELO of HELO message content */
150 uint16_t helo_len;
151 uint8_t *helo;
152
153 /* SMTP Mime decoding and file extraction */
154 /** the list of files sent to the server */
157
158/* Create SMTP config structure */
160
161void *SMTPStateAlloc(void *orig_state, AppProto proto_orig);
162void RegisterSMTPParsers(void);
163void SMTPParserCleanup(void);
164void SMTPParserRegisterTests(void);
165
166#endif /* SURICATA_APP_LAYER_SMTP_H */
struct HtpBodyChunk_ * next
struct AppLayerTxData AppLayerTxData
struct AppLayerStateData AppLayerStateData
uint16_t AppProto
struct SMTPString_ SMTPString
void * SMTPStateAlloc(void *orig_state, AppProto proto_orig)
struct SMTPTransaction_ SMTPTransaction
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
struct SMTPState_ SMTPState
void SMTPParserRegisterTests(void)
SMTPConfig smtp_config
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
@ SMTP_DECODER_EVENT_UNABLE_TO_MATCH_REPLY_WITH_REQUEST
@ SMTP_DECODER_EVENT_MIME_MALFORMED_MSG
@ SMTP_DECODER_EVENT_MAX_REPLY_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_MIME_INVALID_BASE64
@ SMTP_DECODER_EVENT_TRUNCATED_LINE
@ SMTP_DECODER_EVENT_INVALID_REPLY
@ SMTP_DECODER_EVENT_BDAT_CHUNK_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_TLS_REJECTED
@ SMTP_DECODER_EVENT_MIME_PARSE_FAILED
@ SMTP_DECODER_EVENT_MAX_COMMAND_LINE_LEN_EXCEEDED
@ SMTP_DECODER_EVENT_UNPARSABLE_CONTENT
@ SMTP_DECODER_EVENT_MIME_LONG_FILENAME
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME
@ SMTP_DECODER_EVENT_INVALID_PIPELINED_SEQUENCE
@ SMTP_DECODER_EVENT_MIME_LONG_ENC_LINE
@ SMTP_DECODER_EVENT_NO_SERVER_WELCOME_MESSAGE
@ SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED
@ SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE
@ SMTP_DECODER_EVENT_DUPLICATE_FIELDS
@ SMTP_DECODER_EVENT_MIME_INVALID_QP
@ SMTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
@ SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG
@ SMTP_DECODER_EVENT_MIME_LONG_LINE
Structure for containing configuration options.
StreamingBufferConfig sbcfg
uint32_t content_inspect_min_size
uint64_t max_tx
uint32_t content_inspect_window
uint32_t content_limit
uint16_t helo_len
AppLayerStateData state_data
uint8_t * helo
uint8_t current_command
uint32_t bdat_chunk_len
uint16_t cmds_buffer_len
uint64_t toserver_data_count
uint16_t cmds_idx
uint16_t cmds_cnt
bool discard_till_lf_tc
uint32_t bdat_chunk_idx
uint8_t parser_state
TAILQ_HEAD(, SMTPTransaction_) tx_list
bool discard_till_lf_ts
uint64_t toserver_last_data_stamp
uint64_t tx_cnt
SMTPTransaction * curr_tx
uint8_t * cmds
uint32_t file_track_id
uint8_t * str
TAILQ_ENTRY(SMTPString_) next
AppLayerTxData tx_data
TAILQ_ENTRY(SMTPTransaction_) next
MimeStateSMTP * mime_state
TAILQ_HEAD(, SMTPString_) rcpt_to_list
FileContainer files_ts