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
"
41
#include "
detect-engine-buffer.h
"
42
#include "
detect-engine-content-inspection.h
"
43
#include "
detect-content.h
"
44
45
#include "
flow.h
"
46
#include "
flow-util.h
"
47
48
#include "
util-unittest.h
"
49
#include "
util-unittest-helper.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
"
56
#include "
detect-http-server-body.h
"
57
#include "
stream-tcp.h
"
58
59
static
int
DetectHttpServerBodySetup(
DetectEngineCtx
*,
Signature
*,
const
char
*);
60
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
);
61
#ifdef UNITTESTS
62
static
void
DetectHttpServerBodyRegisterTests
(
void
);
63
#endif
64
static
int
g_buffer_id = 0;
65
66
/**
67
* \brief Registers the keyword handlers for the "http_server_body" keyword.
68
*/
69
void
DetectHttpServerBodyRegister
(
void
)
70
{
71
/* http_server_body content modifier */
72
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
name
=
"http_server_body"
;
73
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
desc
=
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
78
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
RegisterTests
=
DetectHttpServerBodyRegisterTests
;
79
#endif
80
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_NOOPT
;
81
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_INFO_CONTENT_MODIFIER
;
82
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
alternative
=
DETECT_HTTP_RESPONSE_BODY
;
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;
89
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_NOOPT
;
90
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_INFO_STICKY_BUFFER
;
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
*/
108
int
DetectHttpServerBodySetup(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*arg)
109
{
110
return
DetectEngineContentModifierBufferSetup
(
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
*/
123
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
)
124
{
125
if
(
SCDetectBufferSetActiveList
(
de_ctx
, s, g_buffer_id) < 0)
126
return
-1;
127
if
(
DetectSignatureSetAppProto
(s,
ALPROTO_HTTP
) < 0)
128
return
-1;
129
// file data is on both directions, but we only take the one to client here
130
s->
flags
|=
SIG_FLAG_TOCLIENT
;
131
s->
flags
&= ~
SIG_FLAG_TOSERVER
;
132
return
0;
133
}
134
135
/************************************Unittests*********************************/
136
137
#ifdef UNITTESTS
138
#include "
tests/detect-http-server-body.c
"
139
#endif
/* UNITTESTS */
140
141
/**
142
* @}
143
*/
SigTableElmt_::url
const char * url
Definition:
detect.h:1431
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition:
detect-parse.c:2313
detect-content.h
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition:
detect.h:1645
SigTableElmt_::desc
const char * desc
Definition:
detect.h:1430
sigmatch_table
SigTableElmt * sigmatch_table
Definition:
detect-parse.c:155
flow-util.h
SIGMATCH_INFO_CONTENT_MODIFIER
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition:
detect.h:1643
SigTableElmt_::name
const char * name
Definition:
detect.h:1428
stream-tcp.h
DetectHttpServerBodyRegister
void DetectHttpServerBodyRegister(void)
Registers the keyword handlers for the "http_server_body" keyword.
Definition:
detect-http-server-body.c:69
threads.h
SigTableElmt_::flags
uint16_t flags
Definition:
detect.h:1422
DetectEngineCtx_
main detection engine ctx
Definition:
detect.h:931
SCDetectBufferSetActiveList
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition:
detect-engine-buffer.c:29
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition:
detect.h:271
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition:
detect.h:1413
util-unittest.h
util-unittest-helper.h
DETECT_HTTP_SERVER_BODY
@ DETECT_HTTP_SERVER_BODY
Definition:
detect-engine-register.h:158
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition:
detect.h:270
app-layer-htp.h
decode.h
de_ctx
DetectEngineCtx * de_ctx
Definition:
fuzz_siginit.c:18
detect.h
SigTableElmt_::alternative
uint16_t alternative
Definition:
detect.h:1426
app-layer-parser.h
util-profiling.h
Signature_::flags
uint32_t flags
Definition:
detect.h:671
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition:
detect-parse.c:222
DETECT_HTTP_RESPONSE_BODY
@ DETECT_HTTP_RESPONSE_BODY
Definition:
detect-engine-register.h:159
detect-engine-content-inspection.h
detect-http-server-body.h
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition:
detect-engine.c:1093
suricata-common.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition:
app-layer-protos.h:36
detect-engine-buffer.h
str
#define str(s)
Definition:
suricata-common.h:308
detect-http-server-body.c
detect-parse.h
Signature_
Signature container.
Definition:
detect.h:670
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition:
app-layer-protos.h:75
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition:
detect.h:1620
flow.h
DetectHttpServerBodyRegisterTests
void DetectHttpServerBodyRegisterTests(void)
Definition:
detect-http-server-body.c:3097
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition:
detect.h:1420
app-layer.h
src
detect-http-server-body.c
Generated on Fri May 9 2025 23:30:33 for suricata by
1.8.18