suricata
detect-http-server-body.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2023 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 * \ingroup httplayer
20 *
21 * @{
22 */
23
24
25/**
26 * \file
27 *
28 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
29 * \author Victor Julien <victor@inliniac.net>
30 *
31 * Implements support for the http_server_body keyword
32 */
33
34#include "suricata-common.h"
35#include "threads.h"
36#include "decode.h"
37
38#include "detect.h"
39#include "detect-parse.h"
40#include "detect-engine.h"
43#include "detect-content.h"
44
45#include "flow.h"
46#include "flow-util.h"
47
48#include "util-unittest.h"
50#include "util-profiling.h"
51
52#include "app-layer.h"
53#include "app-layer-parser.h"
54
55#include "app-layer-htp.h"
57#include "stream-tcp.h"
58
59static int DetectHttpServerBodySetup(DetectEngineCtx *, Signature *, const char *);
60static int DetectHttpServerBodySetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
61#ifdef UNITTESTS
62static void DetectHttpServerBodyRegisterTests(void);
63#endif
64static int g_buffer_id = 0;
65
66/**
67 * \brief Registers the keyword handlers for the "http_server_body" keyword.
68 */
70{
71 /* http_server_body content modifier */
72 sigmatch_table[DETECT_HTTP_SERVER_BODY].name = "http_server_body";
74 "content modifier to match on the HTTP response-body";
75 sigmatch_table[DETECT_HTTP_SERVER_BODY].url = "/rules/http-keywords.html#http-server-body";
76 sigmatch_table[DETECT_HTTP_SERVER_BODY].Setup = DetectHttpServerBodySetup;
77#ifdef UNITTESTS
79#endif
83
84 /* http.request_body sticky buffer */
85 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].name = "http.response_body";
86 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].desc = "sticky buffer to match the HTTP response body buffer";
87 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].url = "/rules/http-keywords.html#http-server-body";
88 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].Setup = DetectHttpServerBodySetupSticky;
91
92 g_buffer_id = DetectBufferTypeRegister("file_data");
93}
94
95/**
96 * \brief The setup function for the http_server_body keyword for a signature.
97 *
98 * \param de_ctx Pointer to the detection engine context.
99 * \param s Pointer to signature for the current Signature being parsed
100 * from the rules.
101 * \param m Pointer to the head of the SigMatchs for the current rule
102 * being parsed.
103 * \param arg Pointer to the string holding the keyword value.
104 *
105 * \retval 0 On success
106 * \retval -1 On failure
107 */
108int DetectHttpServerBodySetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
109{
111 de_ctx, s, arg, DETECT_HTTP_SERVER_BODY, g_buffer_id, ALPROTO_HTTP1);
112}
113
114/**
115 * \brief this function setup the http.response_body keyword used in the rule
116 *
117 * \param de_ctx Pointer to the Detection Engine Context
118 * \param s Pointer to the Signature to which the current keyword belongs
119 * \param str Should hold an empty string always
120 *
121 * \retval 0 On success
122 */
123static int DetectHttpServerBodySetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
124{
125 if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
126 return -1;
128 return -1;
129 // file data is on both directions, but we only take the one to client here
131 s->flags &= ~SIG_FLAG_TOSERVER;
132 return 0;
133}
134
135/************************************Unittests*********************************/
136
137#ifdef UNITTESTS
139#endif /* UNITTESTS */
140
141/**
142 * @}
143 */
@ ALPROTO_HTTP
@ ALPROTO_HTTP1
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
@ DETECT_HTTP_RESPONSE_BODY
@ DETECT_HTTP_SERVER_BODY
int DetectBufferTypeRegister(const char *name)
void DetectHttpServerBodyRegister(void)
Registers the keyword handlers for the "http_server_body" keyword.
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
SigTableElmt * sigmatch_table
#define SIGMATCH_NOOPT
Definition detect.h:1651
#define SIG_FLAG_TOCLIENT
Definition detect.h:272
#define SIGMATCH_INFO_STICKY_BUFFER
Definition detect.h:1676
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition detect.h:1674
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
const char * url
Definition detect.h:1462
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
uint16_t alternative
Definition detect.h:1457
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
void(* RegisterTests)(void)
Definition detect.h:1448
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
uint32_t flags
Definition detect.h:669
#define str(s)
void DetectHttpServerBodyRegisterTests(void)