suricata
app-layer-ftp.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2026 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;
72  uint8_t *request;
74 
75  /* for the command description */
77 
78  uint16_t dyn_port; /* dynamic port, if applicable */
79  bool done; /* transaction complete? */
80  bool active; /* active or passive mode */
81 
82  uint8_t direction;
83 
84  /* Handle multiple responses */
85  TAILQ_HEAD(, FTPResponseWrapper_) response_list;
86 
89 
90 /** FTP State for app layer parser */
91 typedef struct FtpState_ {
92  bool active;
93 
95  TAILQ_HEAD(, FTPTransaction_) tx_list; /**< transaction list */
96  uint64_t tx_cnt;
97 
100 
101  FtpRequestCommand command;
103  uint32_t port_line_len;
104  uint32_t port_line_size;
105  uint8_t *port_line;
106 
107  uint16_t dyn_port;
108 
111 
112 /** FTP Data State for app layer parser */
113 typedef struct FtpDataState_ {
114  uint8_t *input;
115  uint8_t *file_name;
117  int32_t input_len;
118  int16_t file_len;
119  FtpRequestCommand command;
120  uint8_t state;
121  uint8_t direction;
126 
127 void RegisterFTPParsers(void);
128 void FTPParserRegisterTests(void);
129 void FTPParserCleanup(void);
130 int FTPSetMemcap(uint64_t size);
131 uint64_t FTPMemuseGlobalCounter(void);
132 uint64_t FTPMemcapGlobalCounter(void);
133 
134 uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len);
135 bool EveFTPDataAddMetadata(const void *vtx, void *jb);
136 
137 #endif /* SURICATA_APP_LAYER_FTP_H */
FTPTransaction_::request_truncated
bool request_truncated
Definition: app-layer-ftp.h:73
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:72
EveFTPDataAddMetadata
bool EveFTPDataAddMetadata(const void *vtx, void *jb)
Definition: app-layer-ftp.c:1515
FtpDataState_::input_len
int32_t input_len
Definition: app-layer-ftp.h:117
RegisterFTPParsers
void RegisterFTPParsers(void)
Definition: app-layer-ftp.c:1404
FtpState_::active
bool active
Definition: app-layer-ftp.h:92
FtpDataState_::state
uint8_t state
Definition: app-layer-ftp.h:120
FtpState
struct FtpState_ FtpState
FtpDataState_::input
uint8_t * input
Definition: app-layer-ftp.h:114
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:101
FtpState_::TAILQ_HEAD
TAILQ_HEAD(, FTPTransaction_) tx_list
AppLayerStateData
Definition: app-layer-parser.h:155
FTPTransaction_::done
bool done
Definition: app-layer-ftp.h:79
FtpState_::current_line_truncated_tc
bool current_line_truncated_tc
Definition: app-layer-ftp.h:99
FTPTransaction_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ftp.h:67
FtpDataState_::command
FtpRequestCommand command
Definition: app-layer-ftp.h:119
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:118
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:121
FtpState_
Definition: app-layer-ftp.h:91
FtpState_::port_line
uint8_t * port_line
Definition: app-layer-ftp.h:105
AppLayerTxData
Definition: app-layer-parser.h:172
FtpDataState_::initialized
bool initialized
Definition: app-layer-ftp.h:124
FtpState_::curr_tx
FTPTransaction * curr_tx
Definition: app-layer-ftp.h:94
FtpDataState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:123
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:1505
FtpState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:109
FTPTransaction_::command_descriptor
FtpCommandInfo command_descriptor
Definition: app-layer-ftp.h:76
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:102
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:122
FTPMemuseGlobalCounter
uint64_t FTPMemuseGlobalCounter(void)
Definition: app-layer-ftp.c:92
FTPTransaction_::direction
uint8_t direction
Definition: app-layer-ftp.h:82
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:103
FtpState_::dyn_port
uint16_t dyn_port
Definition: app-layer-ftp.h:107
FtpDataState_
Definition: app-layer-ftp.h:113
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:96
FtpState_::current_line_truncated_ts
bool current_line_truncated_ts
Definition: app-layer-ftp.h:98
FTPSetMemcap
int FTPSetMemcap(uint64_t size)
Definition: app-layer-ftp.c:104
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:104
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:78
FTPMemcapGlobalCounter
uint64_t FTPMemcapGlobalCounter(void)
Definition: app-layer-ftp.c:98
FTPTransaction_::active
bool active
Definition: app-layer-ftp.h:80
FtpDataState_::files
FileContainer * files
Definition: app-layer-ftp.h:116
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:1555
FTPTransaction_::preliminary_response_cnt
uint32_t preliminary_response_cnt
Definition: app-layer-ftp.h:71
FtpDataState_::file_name
uint8_t * file_name
Definition: app-layer-ftp.h:115
FTPParserRegisterTests
void FTPParserRegisterTests(void)
Definition: app-layer-ftp.c:1995