suricata
app-layer-ftp.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2025 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 Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
22  * \author Jeff Lucovsky <jeff@lucovsky.org>
23  */
24 
25 #ifndef SURICATA_APP_LAYER_FTP_H
26 #define SURICATA_APP_LAYER_FTP_H
27 
28 #include "rust.h"
29 #include "app-layer-parser.h"
30 
31 struct FtpCommand;
32 
33 typedef uint32_t FtpRequestCommandArgOfs;
34 
35 /** used to hold the line state when we have fragmentation. */
36 typedef struct FtpLineState_ {
37  /** used to indicate if the current_line buffer is a malloced buffer. We
38  * use a malloced buffer, if a line is fragmented */
39  const uint8_t *buf;
40  uint32_t len;
41  uint8_t delim_len;
42  /** the line was longer than the configured maximum and buf holds only
43  * what fit; set by the line getter for the line it hands back */
44  bool truncated;
46 
47 typedef struct FTPResponseWrapper_ {
48  FTPResponseLine *response;
51 
52 /*
53  * These are the values for the table index value and the FTP command
54  * enum value. These *should* be the same if the enum and command insertion
55  * order remain the same. However, we store each value to protect against
56  * drift between enum and insertion order.
57  */
58 typedef struct FtpCommandInfo_ {
59  uint8_t command_index;
60  FtpRequestCommand command_code;
62 
63 typedef struct FTPTransaction_ {
64  /** id of this tx, starting at 0 */
65  uint64_t tx_id;
66 
68 
69  /* for the request */
70  uint32_t request_length;
71  uint8_t *request;
73 
74  /* for the command description */
76 
77  uint16_t dyn_port; /* dynamic port, if applicable */
78  bool done; /* transaction complete? */
79  bool active; /* active or passive mode */
80 
81  uint8_t direction;
82 
83  /* Handle multiple responses */
84  TAILQ_HEAD(, FTPResponseWrapper_) response_list;
85 
88 
89 /** FTP State for app layer parser */
90 typedef struct FtpState_ {
91  bool active;
92 
94  TAILQ_HEAD(, FTPTransaction_) tx_list; /**< transaction list */
95  uint64_t tx_cnt;
96 
99 
100  FtpRequestCommand command;
102  uint32_t port_line_len;
103  uint32_t port_line_size;
104  uint8_t *port_line;
105 
106  uint16_t dyn_port;
107 
110 
111 /** FTP Data State for app layer parser */
112 typedef struct FtpDataState_ {
113  uint8_t *input;
114  uint8_t *file_name;
116  int32_t input_len;
117  int16_t file_len;
118  FtpRequestCommand command;
119  uint8_t state;
120  uint8_t direction;
125 
126 void RegisterFTPParsers(void);
127 void FTPParserRegisterTests(void);
128 void FTPParserCleanup(void);
129 int FTPSetMemcap(uint64_t size);
130 uint64_t FTPMemuseGlobalCounter(void);
131 uint64_t FTPMemcapGlobalCounter(void);
132 
133 uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len);
134 bool EveFTPDataAddMetadata(void *vtx, SCJsonBuilder *jb);
135 
136 #endif /* SURICATA_APP_LAYER_FTP_H */
FTPTransaction_::request_truncated
bool request_truncated
Definition: app-layer-ftp.h:72
FileContainer_
Definition: util-file.h:37
len
uint8_t len
Definition: app-layer-dnp3.h:2
FTPTransaction_::request
uint8_t * request
Definition: app-layer-ftp.h:71
FtpDataState_::input_len
int32_t input_len
Definition: app-layer-ftp.h:116
RegisterFTPParsers
void RegisterFTPParsers(void)
Definition: app-layer-ftp.c:1371
FtpState_::active
bool active
Definition: app-layer-ftp.h:91
FtpDataState_::state
uint8_t state
Definition: app-layer-ftp.h:119
FtpState
struct FtpState_ FtpState
FtpDataState_::input
uint8_t * input
Definition: app-layer-ftp.h:113
FtpLineState
struct FtpLineState_ FtpLineState
FtpCommandInfo_
Definition: app-layer-ftp.h:58
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
FtpState_::command
FtpRequestCommand command
Definition: app-layer-ftp.h:100
FtpState_::TAILQ_HEAD
TAILQ_HEAD(, FTPTransaction_) tx_list
AppLayerStateData
Definition: app-layer-parser.h:149
FTPTransaction_::done
bool done
Definition: app-layer-ftp.h:78
FtpState_::current_line_truncated_tc
bool current_line_truncated_tc
Definition: app-layer-ftp.h:98
FTPTransaction_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ftp.h:67
FtpDataState_::command
FtpRequestCommand command
Definition: app-layer-ftp.h:118
EveFTPDataAddMetadata
bool EveFTPDataAddMetadata(void *vtx, SCJsonBuilder *jb)
Definition: app-layer-ftp.c:1482
rust.h
FtpLineState_::buf
const uint8_t * buf
Definition: app-layer-ftp.h:39
FtpDataState_::file_len
int16_t file_len
Definition: app-layer-ftp.h:117
FTPTransaction
struct FTPTransaction_ FTPTransaction
FtpCommandInfo
struct FtpCommandInfo_ FtpCommandInfo
FTPResponseWrapper_
Definition: app-layer-ftp.h:47
FtpDataState_::direction
uint8_t direction
Definition: app-layer-ftp.h:120
FtpState_
Definition: app-layer-ftp.h:90
FtpState_::port_line
uint8_t * port_line
Definition: app-layer-ftp.h:104
AppLayerTxData
Definition: app-layer-parser.h:166
FtpDataState_::initialized
bool initialized
Definition: app-layer-ftp.h:123
FtpState_::curr_tx
FTPTransaction * curr_tx
Definition: app-layer-ftp.h:93
FtpDataState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:122
FTPTransaction_::TAILQ_ENTRY
TAILQ_ENTRY(FTPTransaction_) next
app-layer-parser.h
JsonGetNextLineFromBuffer
uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len)
Definition: app-layer-ftp.c:1472
FtpState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:108
FTPTransaction_::command_descriptor
FtpCommandInfo command_descriptor
Definition: app-layer-ftp.h:75
FTPResponseWrapper
struct FTPResponseWrapper_ FTPResponseWrapper
FtpCommandInfo_::command_code
FtpRequestCommand command_code
Definition: app-layer-ftp.h:60
FtpState_::arg_offset
FtpRequestCommandArgOfs arg_offset
Definition: app-layer-ftp.h:101
FtpLineState_::truncated
bool truncated
Definition: app-layer-ftp.h:44
FTPResponseWrapper_::TAILQ_ENTRY
TAILQ_ENTRY(FTPResponseWrapper_) next
FTPResponseWrapper_::response
FTPResponseLine * response
Definition: app-layer-ftp.h:48
FtpDataState
struct FtpDataState_ FtpDataState
FtpDataState_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ftp.h:121
FTPMemuseGlobalCounter
uint64_t FTPMemuseGlobalCounter(void)
Definition: app-layer-ftp.c:79
FTPTransaction_::direction
uint8_t direction
Definition: app-layer-ftp.h:81
FTPTransaction_::request_length
uint32_t request_length
Definition: app-layer-ftp.h:70
FtpLineState_
Definition: app-layer-ftp.h:36
FtpRequestCommandArgOfs
uint32_t FtpRequestCommandArgOfs
Definition: app-layer-ftp.h:31
FtpState_::port_line_len
uint32_t port_line_len
Definition: app-layer-ftp.h:102
FtpState_::dyn_port
uint16_t dyn_port
Definition: app-layer-ftp.h:106
FtpDataState_
Definition: app-layer-ftp.h:112
FtpLineState_::delim_len
uint8_t delim_len
Definition: app-layer-ftp.h:41
FtpCommandInfo_::command_index
uint8_t command_index
Definition: app-layer-ftp.h:59
FtpState_::tx_cnt
uint64_t tx_cnt
Definition: app-layer-ftp.h:95
FtpState_::current_line_truncated_ts
bool current_line_truncated_ts
Definition: app-layer-ftp.h:97
FTPSetMemcap
int FTPSetMemcap(uint64_t size)
Definition: app-layer-ftp.c:91
FtpLineState_::len
uint32_t len
Definition: app-layer-ftp.h:40
FtpState_::port_line_size
uint32_t port_line_size
Definition: app-layer-ftp.h:103
FTPTransaction_::tx_id
uint64_t tx_id
Definition: app-layer-ftp.h:65
FTPTransaction_::dyn_port
uint16_t dyn_port
Definition: app-layer-ftp.h:77
FTPMemcapGlobalCounter
uint64_t FTPMemcapGlobalCounter(void)
Definition: app-layer-ftp.c:85
FTPTransaction_::active
bool active
Definition: app-layer-ftp.h:79
FtpDataState_::files
FileContainer * files
Definition: app-layer-ftp.h:115
FTPTransaction_
Definition: app-layer-ftp.h:63
FTPTransaction_::TAILQ_HEAD
TAILQ_HEAD(, FTPResponseWrapper_) response_list
FTPParserCleanup
void FTPParserCleanup(void)
Free memory allocated for global FTP parser state.
Definition: app-layer-ftp.c:1522
FtpDataState_::file_name
uint8_t * file_name
Definition: app-layer-ftp.h:114
FTPParserRegisterTests
void FTPParserRegisterTests(void)
Definition: app-layer-ftp.c:1753