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  bool lf_found;
44 
45 typedef struct FTPResponseWrapper_ {
46  FTPResponseLine *response;
49 
50 /*
51  * These are the values for the table index value and the FTP command
52  * enum value. These *should* be the same if the enum and command insertion
53  * order remain the same. However, we store each value to protect against
54  * drift between enum and insertion order.
55  */
56 typedef struct FtpCommandInfo_ {
57  uint8_t command_index;
58  FtpRequestCommand command_code;
60 
61 typedef struct FTPTransaction_ {
62  /** id of this tx, starting at 0 */
63  uint64_t tx_id;
64 
66 
67  /* for the request */
68  uint32_t request_length;
69  uint8_t *request;
71 
72  /* for the command description */
74 
75  uint16_t dyn_port; /* dynamic port, if applicable */
76  bool done; /* transaction complete? */
77  bool active; /* active or passive mode */
78 
79  uint8_t direction;
80 
81  /* Handle multiple responses */
82  TAILQ_HEAD(, FTPResponseWrapper_) response_list;
83 
86 
87 /** FTP State for app layer parser */
88 typedef struct FtpState_ {
89  bool active;
90 
92  TAILQ_HEAD(, FTPTransaction_) tx_list; /**< transaction list */
93  uint64_t tx_cnt;
94 
97 
98  FtpRequestCommand command;
100  uint32_t port_line_len;
101  uint32_t port_line_size;
102  uint8_t *port_line;
103 
104  uint16_t dyn_port;
105 
108 
109 /** FTP Data State for app layer parser */
110 typedef struct FtpDataState_ {
111  uint8_t *input;
112  uint8_t *file_name;
114  int32_t input_len;
115  int16_t file_len;
116  FtpRequestCommand command;
117  uint8_t state;
118  uint8_t direction;
122 
123 void RegisterFTPParsers(void);
124 void FTPParserRegisterTests(void);
125 void FTPParserCleanup(void);
126 int FTPSetMemcap(uint64_t size);
127 uint64_t FTPMemuseGlobalCounter(void);
128 uint64_t FTPMemcapGlobalCounter(void);
129 
130 uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len);
131 bool EveFTPDataAddMetadata(void *vtx, SCJsonBuilder *jb);
132 
133 #endif /* SURICATA_APP_LAYER_FTP_H */
FTPTransaction_::request_truncated
bool request_truncated
Definition: app-layer-ftp.h:70
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:69
FtpDataState_::input_len
int32_t input_len
Definition: app-layer-ftp.h:114
RegisterFTPParsers
void RegisterFTPParsers(void)
Definition: app-layer-ftp.c:1287
FtpState_::active
bool active
Definition: app-layer-ftp.h:89
FtpDataState_::state
uint8_t state
Definition: app-layer-ftp.h:117
FtpState
struct FtpState_ FtpState
FtpDataState_::input
uint8_t * input
Definition: app-layer-ftp.h:111
FtpLineState
struct FtpLineState_ FtpLineState
FtpCommandInfo_
Definition: app-layer-ftp.h:56
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
FtpState_::command
FtpRequestCommand command
Definition: app-layer-ftp.h:98
FtpState_::TAILQ_HEAD
TAILQ_HEAD(, FTPTransaction_) tx_list
AppLayerStateData
Definition: app-layer-parser.h:160
FTPTransaction_::done
bool done
Definition: app-layer-ftp.h:76
FtpState_::current_line_truncated_tc
bool current_line_truncated_tc
Definition: app-layer-ftp.h:96
FTPTransaction_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ftp.h:65
FtpDataState_::command
FtpRequestCommand command
Definition: app-layer-ftp.h:116
EveFTPDataAddMetadata
bool EveFTPDataAddMetadata(void *vtx, SCJsonBuilder *jb)
Definition: app-layer-ftp.c:1398
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:115
FTPTransaction
struct FTPTransaction_ FTPTransaction
FtpCommandInfo
struct FtpCommandInfo_ FtpCommandInfo
FTPResponseWrapper_
Definition: app-layer-ftp.h:45
FtpDataState_::direction
uint8_t direction
Definition: app-layer-ftp.h:118
FtpState_
Definition: app-layer-ftp.h:88
FtpState_::port_line
uint8_t * port_line
Definition: app-layer-ftp.h:102
AppLayerTxData
Definition: app-layer-parser.h:177
FtpState_::curr_tx
FTPTransaction * curr_tx
Definition: app-layer-ftp.h:91
FtpDataState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:120
FTPTransaction_::TAILQ_ENTRY
TAILQ_ENTRY(FTPTransaction_) next
FtpLineState_::lf_found
bool lf_found
Definition: app-layer-ftp.h:42
app-layer-parser.h
JsonGetNextLineFromBuffer
uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len)
Definition: app-layer-ftp.c:1388
FtpState_::state_data
AppLayerStateData state_data
Definition: app-layer-ftp.h:106
FTPTransaction_::command_descriptor
FtpCommandInfo command_descriptor
Definition: app-layer-ftp.h:73
FTPResponseWrapper
struct FTPResponseWrapper_ FTPResponseWrapper
FtpCommandInfo_::command_code
FtpRequestCommand command_code
Definition: app-layer-ftp.h:58
FtpState_::arg_offset
FtpRequestCommandArgOfs arg_offset
Definition: app-layer-ftp.h:99
FTPResponseWrapper_::TAILQ_ENTRY
TAILQ_ENTRY(FTPResponseWrapper_) next
FTPResponseWrapper_::response
FTPResponseLine * response
Definition: app-layer-ftp.h:46
FtpDataState
struct FtpDataState_ FtpDataState
FtpDataState_::tx_data
AppLayerTxData tx_data
Definition: app-layer-ftp.h:119
FTPMemuseGlobalCounter
uint64_t FTPMemuseGlobalCounter(void)
Definition: app-layer-ftp.c:79
FTPTransaction_::direction
uint8_t direction
Definition: app-layer-ftp.h:79
FTPTransaction_::request_length
uint32_t request_length
Definition: app-layer-ftp.h:68
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:100
FtpState_::dyn_port
uint16_t dyn_port
Definition: app-layer-ftp.h:104
FtpDataState_
Definition: app-layer-ftp.h:110
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:57
FtpState_::tx_cnt
uint64_t tx_cnt
Definition: app-layer-ftp.h:93
FtpState_::current_line_truncated_ts
bool current_line_truncated_ts
Definition: app-layer-ftp.h:95
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:101
FTPTransaction_::tx_id
uint64_t tx_id
Definition: app-layer-ftp.h:63
FTPTransaction_::dyn_port
uint16_t dyn_port
Definition: app-layer-ftp.h:75
FTPMemcapGlobalCounter
uint64_t FTPMemcapGlobalCounter(void)
Definition: app-layer-ftp.c:85
FTPTransaction_::active
bool active
Definition: app-layer-ftp.h:77
FtpDataState_::files
FileContainer * files
Definition: app-layer-ftp.h:113
FTPTransaction_
Definition: app-layer-ftp.h:61
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:1423
FtpDataState_::file_name
uint8_t * file_name
Definition: app-layer-ftp.h:112
FTPParserRegisterTests
void FTPParserRegisterTests(void)
Definition: app-layer-ftp.c:1562