suricata
detect-http-server-body.c
Go to the documentation of this file.
1
/* Copyright (C) 2007-2018 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-mpm.h
"
42
#include "
detect-engine-state.h
"
43
#include "
detect-content.h
"
44
#include "
detect-pcre.h
"
45
46
#include "
flow.h
"
47
#include "
flow-var.h
"
48
#include "
flow-util.h
"
49
50
#include "
util-debug.h
"
51
#include "
util-unittest.h
"
52
#include "
util-unittest-helper.h
"
53
#include "
util-spm.h
"
54
55
#include "
app-layer.h
"
56
#include "
app-layer-parser.h
"
57
58
#include "
app-layer-htp.h
"
59
#include "
detect-http-server-body.h
"
60
#include "
stream-tcp.h
"
61
62
static
int
DetectHttpServerBodySetup(
DetectEngineCtx
*,
Signature
*,
const
char
*);
63
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
);
64
#ifdef UNITTESTS
65
static
void
DetectHttpServerBodyRegisterTests
(
void
);
66
#endif
67
static
int
g_file_data_buffer_id = 0;
68
69
/**
70
* \brief Registers the keyword handlers for the "http_server_body" keyword.
71
*/
72
void
DetectHttpServerBodyRegister
(
void
)
73
{
74
/* http_server_body content modifier */
75
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
name
=
"http_server_body"
;
76
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
desc
=
"content modifier to match on the HTTP response-body"
;
77
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
url
=
"/rules/http-keywords.html#http-server-body"
;
78
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
Setup
= DetectHttpServerBodySetup;
79
#ifdef UNITTESTS
80
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
RegisterTests
=
DetectHttpServerBodyRegisterTests
;
81
#endif
82
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_NOOPT
;
83
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
flags
|=
SIGMATCH_INFO_CONTENT_MODIFIER
;
84
sigmatch_table
[
DETECT_AL_HTTP_SERVER_BODY
].
alternative
=
DETECT_HTTP_RESPONSE_BODY
;
85
86
/* http.request_body sticky buffer */
87
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
name
=
"http.response_body"
;
88
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
desc
=
"sticky buffer to match the HTTP response body buffer"
;
89
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
url
=
"/rules/http-keywords.html#http-server-body"
;
90
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
Setup
= DetectHttpServerBodySetupSticky;
91
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_NOOPT
;
92
sigmatch_table
[
DETECT_HTTP_RESPONSE_BODY
].
flags
|=
SIGMATCH_INFO_STICKY_BUFFER
;
93
94
g_file_data_buffer_id =
DetectBufferTypeRegister
(
"file_data"
);
95
}
96
97
/**
98
* \brief The setup function for the http_server_body keyword for a signature.
99
*
100
* \param de_ctx Pointer to the detection engine context.
101
* \param s Pointer to signature for the current Signature being parsed
102
* from the rules.
103
* \param m Pointer to the head of the SigMatchs for the current rule
104
* being parsed.
105
* \param arg Pointer to the string holding the keyword value.
106
*
107
* \retval 0 On success
108
* \retval -1 On failure
109
*/
110
int
DetectHttpServerBodySetup(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*arg)
111
{
112
return
DetectEngineContentModifierBufferSetup
(
113
de_ctx
, s, arg,
DETECT_AL_HTTP_SERVER_BODY
, g_file_data_buffer_id,
ALPROTO_HTTP1
);
114
}
115
116
/**
117
* \brief this function setup the http.response_body keyword used in the rule
118
*
119
* \param de_ctx Pointer to the Detection Engine Context
120
* \param s Pointer to the Signature to which the current keyword belongs
121
* \param str Should hold an empty string always
122
*
123
* \retval 0 On success
124
*/
125
static
int
DetectHttpServerBodySetupSticky(
DetectEngineCtx
*
de_ctx
,
Signature
*s,
const
char
*
str
)
126
{
127
if
(
DetectBufferSetActiveList
(s, g_file_data_buffer_id) < 0)
128
return
-1;
129
if
(
DetectSignatureSetAppProto
(s,
ALPROTO_HTTP1
) < 0)
130
return
-1;
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:1241
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition:
detect-parse.c:1498
detect-content.h
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition:
detect.h:1447
SigTableElmt_::desc
const char * desc
Definition:
detect.h:1240
flow-util.h
SIGMATCH_INFO_CONTENT_MODIFIER
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition:
detect.h:1445
SigTableElmt_::name
const char * name
Definition:
detect.h:1238
stream-tcp.h
DetectHttpServerBodyRegister
void DetectHttpServerBodyRegister(void)
Registers the keyword handlers for the "http_server_body" keyword.
Definition:
detect-http-server-body.c:72
threads.h
SigTableElmt_::flags
uint16_t flags
Definition:
detect.h:1232
DetectEngineCtx_
main detection engine ctx
Definition:
detect.h:785
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition:
detect.h:1223
detect-pcre.h
util-unittest.h
util-unittest-helper.h
app-layer-htp.h
decode.h
util-debug.h
de_ctx
DetectEngineCtx * de_ctx
Definition:
fuzz_siginit.c:17
detect-engine-mpm.h
detect.h
SigTableElmt_::alternative
uint16_t alternative
Definition:
detect.h:1236
app-layer-parser.h
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition:
detect-parse.c:149
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
DETECT_HTTP_RESPONSE_BODY
@ DETECT_HTTP_RESPONSE_BODY
Definition:
detect-engine-register.h:135
detect-http-server-body.h
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition:
detect-engine.c:1025
suricata-common.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition:
app-layer-protos.h:30
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition:
detect-parse.c:76
util-spm.h
str
#define str(s)
Definition:
suricata-common.h:280
detect-http-server-body.c
detect-parse.h
Signature_
Signature container.
Definition:
detect.h:540
DETECT_AL_HTTP_SERVER_BODY
@ DETECT_AL_HTTP_SERVER_BODY
Definition:
detect-engine-register.h:134
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition:
detect.h:1423
DetectBufferSetActiveList
int DetectBufferSetActiveList(Signature *s, const int list)
Definition:
detect-engine.c:1293
flow.h
DetectHttpServerBodyRegisterTests
void DetectHttpServerBodyRegisterTests(void)
Definition:
detect-http-server-body.c:8721
flow-var.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition:
detect.h:1230
app-layer.h
src
detect-http-server-body.c
Generated on Mon Feb 6 2023 23:30:33 for suricata by
1.8.18