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-content-inspection.h
"
42
#include "
detect-content.h
"
43
44
#include "
flow.h
"
45
#include "
flow-util.h
"
46
47
#include "
util-unittest.h
"
48
#include "
util-unittest-helper.h
"
49
#include "
util-profiling.h
"
50
51
#include "
app-layer.h
"
52
#include "
app-layer-parser.h
"
53
54
#include "
app-layer-htp.h
"
55
#include "
detect-http-server-body.h
"
56
#include "
stream-tcp.h
"
57
58
static
int
DetectHttpServerBodySetup(
DetectEngineCtx
*,
Signature
*,
const
char
*);
59
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
);
60
#ifdef UNITTESTS
61
static
void
DetectHttpServerBodyRegisterTests
(
void
);
62
#endif
63
static
int
g_buffer_id = 0;
64
65
/**
66
* \brief Registers the keyword handlers for the "http_server_body" keyword.
67
*/
68
void
DetectHttpServerBodyRegister
(
void
)
69
{
70
/* http_server_body content modifier */
71
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
name
=
"http_server_body"
;
72
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
desc
=
73
"content modifier to match on the HTTP response-body"
;
74
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
url
=
"/rules/http-keywords.html#http-server-body"
;
75
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
Setup
= DetectHttpServerBodySetup;
76
#ifdef UNITTESTS
77
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
RegisterTests
=
DetectHttpServerBodyRegisterTests
;
78
#endif
79
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_NOOPT
;
80
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_INFO_CONTENT_MODIFIER
;
81
sigmatch_table
[
DETECT_HTTP_SERVER_BODY
].
alternative
=
DETECT_HTTP_RESPONSE_BODY
;
82
83
/* http.request_body sticky buffer */
84
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
name
=
"http.response_body"
;
85
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
desc
=
"sticky buffer to match the HTTP response body buffer"
;
86
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
url
=
"/rules/http-keywords.html#http-server-body"
;
87
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
Setup
= DetectHttpServerBodySetupSticky;
88
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_NOOPT
;
89
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_INFO_STICKY_BUFFER
;
90
91
g_buffer_id =
DetectBufferTypeRegister
(
"file_data"
);
92
}
93
94
/**
95
* \brief The setup function for the http_server_body keyword for a signature.
96
*
97
* \param de_ctx Pointer to the detection engine context.
98
* \param s Pointer to signature for the current Signature being parsed
99
* from the rules.
100
* \param m Pointer to the head of the SigMatchs for the current rule
101
* being parsed.
102
* \param arg Pointer to the string holding the keyword value.
103
*
104
* \retval 0 On success
105
* \retval -1 On failure
106
*/
107
int
DetectHttpServerBodySetup(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*arg)
108
{
109
return
DetectEngineContentModifierBufferSetup
(
110
de_ctx
, s, arg,
DETECT_HTTP_SERVER_BODY
, g_buffer_id,
ALPROTO_HTTP1
);
111
}
112
113
/**
114
* \brief this function setup the http.response_body keyword used in the rule
115
*
116
* \param de_ctx Pointer to the Detection Engine Context
117
* \param s Pointer to the Signature to which the current keyword belongs
118
* \param str Should hold an empty string always
119
*
120
* \retval 0 On success
121
*/
122
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
)
123
{
124
if
(
DetectBufferSetActiveList
(
de_ctx
, s, g_buffer_id) < 0)
125
return
-1;
126
if
(
DetectSignatureSetAppProto
(s,
ALPROTO_HTTP
) < 0)
127
return
-1;
128
// file data is on both directions, but we only take the one to client here
129
s->
flags
|=
SIG_FLAG_TOCLIENT
;
130
s->
flags
&= ~
SIG_FLAG_TOSERVER
;
131
return
0;
132
}
133
134
/************************************Unittests*********************************/
135
136
#ifdef UNITTESTS
137
#include "
tests/detect-http-server-body.c
"
138
#endif
/* UNITTESTS */
139
140
/**
141
* @}
142
*/
SigTableElmt_::url
const char * url
Definition:
detect.h:1322
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition:
detect-parse.c:1770
detect-content.h
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition:
detect.h:1527
SigTableElmt_::desc
const char * desc
Definition:
detect.h:1321
sigmatch_table
SigTableElmt * sigmatch_table
Definition:
detect-parse.c:153
flow-util.h
SIGMATCH_INFO_CONTENT_MODIFIER
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition:
detect.h:1525
SigTableElmt_::name
const char * name
Definition:
detect.h:1319
stream-tcp.h
DetectHttpServerBodyRegister
void DetectHttpServerBodyRegister(void)
Registers the keyword handlers for the "http_server_body" keyword.
Definition:
detect-http-server-body.c:68
DetectBufferSetActiveList
int DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition:
detect-engine.c:1359
threads.h
SigTableElmt_::flags
uint16_t flags
Definition:
detect.h:1313
DetectEngineCtx_
main detection engine ctx
Definition:
detect.h:854
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition:
detect.h:270
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition:
detect.h:1304
util-unittest.h
util-unittest-helper.h
DETECT_HTTP_SERVER_BODY
@ DETECT_HTTP_SERVER_BODY
Definition:
detect-engine-register.h:159
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition:
detect.h:269
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:1317
app-layer-parser.h
util-profiling.h
Signature_::flags
uint32_t flags
Definition:
detect.h:615
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition:
detect-parse.c:220
DETECT_HTTP_RESPONSE_BODY
@ DETECT_HTTP_RESPONSE_BODY
Definition:
detect-engine-register.h:160
detect-engine-content-inspection.h
detect-http-server-body.h
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition:
detect-engine.c:1032
suricata-common.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition:
app-layer-protos.h:36
str
#define str(s)
Definition:
suricata-common.h:300
detect-http-server-body.c
detect-parse.h
Signature_
Signature container.
Definition:
detect.h:614
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition:
app-layer-protos.h:76
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition:
detect.h:1503
flow.h
DetectHttpServerBodyRegisterTests
void DetectHttpServerBodyRegisterTests(void)
Definition:
detect-http-server-body.c:3097
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition:
detect.h:1311
app-layer.h
src
detect-http-server-body.c
Generated on Thu Feb 20 2025 23:30:33 for suricata by
1.8.18