suricata
detect-ftp-command.c
Go to the documentation of this file.
1/* Copyright (C) 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 *
20 * \author Jeff Lucovsky <jlucovsky@oisf.net>
21 *
22 * Implements the ftp.command sticky buffer
23 *
24 */
25
26#include "suricata-common.h"
27#include "detect.h"
28
29#include "detect-parse.h"
30#include "detect-engine.h"
33
34#include "flow.h"
35
36#include "app-layer.h"
37#include "app-layer-ftp.h"
38
39#include "detect-ftp-command.h"
40
41#define KEYWORD_NAME "ftp.command"
42#define KEYWORD_DOC "ftp-keywords.html#ftp-command"
43#define BUFFER_NAME "ftp.command"
44#define BUFFER_DESC "ftp command"
45
46static int g_ftp_cmd_buffer_id = 0;
47
48static int DetectFtpCommandSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
49{
50 if (SCDetectBufferSetActiveList(de_ctx, s, g_ftp_cmd_buffer_id) < 0)
51 return -1;
52
54 return -1;
55
56 return 0;
57}
58
59static bool DetectFTPCommandGetData(
60 const void *txv, const uint8_t _flow_flags, const uint8_t **buffer, uint32_t *buffer_len)
61{
62 FTPTransaction *tx = (FTPTransaction *)txv;
63
64 if (tx->command_descriptor.command_code == FTP_COMMAND_UNKNOWN)
65 return false;
66
67 uint8_t b_len = 0;
68 if (SCGetFtpCommandInfo(
69 tx->command_descriptor.command_index, (const char **)buffer, NULL, &b_len)) {
70 *buffer_len = b_len;
71 return true;
72 } else {
73 return false;
74 }
75}
76
78{
79 /* ftp.command sticky buffer */
81 sigmatch_table[DETECT_FTP_COMMAND].desc = "sticky buffer to match on the FTP command buffer";
83 sigmatch_table[DETECT_FTP_COMMAND].Setup = DetectFtpCommandSetup;
85
86 g_ftp_cmd_buffer_id = SCDetectHelperBufferMpmRegister(
87 BUFFER_NAME, BUFFER_DESC, ALPROTO_FTP, STREAM_TOSERVER, DetectFTPCommandGetData);
88
89 SCLogDebug("registering " BUFFER_NAME " rule option");
90}
@ ALPROTO_FTP
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
int SCDetectHelperBufferMpmRegister(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionSingleBufferGetDataPtr GetData)
@ DETECT_FTP_COMMAND
#define KEYWORD_DOC
#define BUFFER_DESC
#define BUFFER_NAME
#define KEYWORD_NAME
void DetectFtpCommandRegister(void)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigTableElmt * sigmatch_table
#define SIGMATCH_NOOPT
Definition detect.h:1651
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
FtpCommandInfo command_descriptor
uint8_t command_index
FtpRequestCommand command_code
const char * url
Definition detect.h:1462
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
#define str(s)
#define SCLogDebug(...)
Definition util-debug.h:275