suricata
detect-uricontent.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2022 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 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
23 *
24 * Simple uricontent match part of the detection engine.
25 */
26
27#include "suricata-common.h"
28#include "decode.h"
29#include "detect.h"
30#include "detect-content.h"
31#include "detect-http-uri.h"
32#include "detect-uricontent.h"
33#include "detect-engine-mpm.h"
34#include "detect-parse.h"
35#include "detect-engine.h"
36#include "detect-engine-state.h"
37#include "flow.h"
38#include "detect-flow.h"
39#include "flow-var.h"
40#include "flow-util.h"
41#include "threads.h"
42
43#include "stream-tcp.h"
44#include "stream.h"
45#include "app-layer.h"
46#include "app-layer-parser.h"
47#include "app-layer-protos.h"
48#include "app-layer-htp.h"
49
50#include "util-mpm.h"
51#include "util-print.h"
52#include "util-debug.h"
53#include "util-unittest.h"
55#include "util-spm.h"
56#include "conf.h"
57
58/* prototypes */
59static int DetectUricontentSetup(DetectEngineCtx *, Signature *, const char *);
60static void DetectUricontentFree(DetectEngineCtx *de_ctx, void *);
61
62static int g_http_uri_buffer_id = 0;
63
64/**
65 * \brief Registration function for uricontent: keyword
66 */
68{
70 sigmatch_table[DETECT_URICONTENT].desc = "legacy keyword to match on the request URI buffer";
71 sigmatch_table[DETECT_URICONTENT].url = "/rules/http-keywords.html#uricontent";
73 sigmatch_table[DETECT_URICONTENT].Setup = DetectUricontentSetup;
74 sigmatch_table[DETECT_URICONTENT].Free = DetectUricontentFree;
77
78 g_http_uri_buffer_id = DetectBufferTypeRegister("http_uri");
79}
80
81/**
82 * \brief this function will Free memory associated with DetectContentData
83 *
84 * \param cd pointer to DetectUricontentData
85 */
86void DetectUricontentFree(DetectEngineCtx *de_ctx, void *ptr)
87{
88 SCEnter();
90
91 if (cd == NULL)
93
95 SCFree(cd);
96
98}
99
100/**
101 * \brief Creates a SigMatch for the uricontent keyword being sent as argument,
102 * and appends it to the Signature(s).
103 *
104 * \param de_ctx Pointer to the detection engine context
105 * \param s Pointer to signature for the current Signature being parsed
106 * from the rules
107 * \param contentstr Pointer to the string holding the keyword value
108 *
109 * \retval 0 on success, -1 on failure
110 */
111int DetectUricontentSetup(DetectEngineCtx *de_ctx, Signature *s, const char *contentstr)
112{
113 SCEnter();
114
115 const char *legacy = NULL;
116 if (SCConfGet("legacy.uricontent", &legacy) == 1) {
117 if (strcasecmp("disabled", legacy) == 0) {
118 SCLogError("uricontent deprecated. To "
119 "use a rule with \"uricontent\", either set the "
120 "option - \"legacy.uricontent\" in the conf to "
121 "\"enabled\" OR replace uricontent with "
122 "\'content:%s; http_uri;\'.",
123 contentstr);
124 goto error;
125 } else if (strcasecmp("enabled", legacy) == 0) {
126 ;
127 } else {
128 SCLogError("Invalid value found "
129 "for legacy.uricontent - \"%s\". Valid values are "
130 "\"enabled\" OR \"disabled\".",
131 legacy);
132 goto error;
133 }
134 }
135
136 if (DetectContentSetup(de_ctx, s, contentstr) < 0)
137 goto error;
138
139 if (DetectHttpUriSetup(de_ctx, s, NULL) < 0)
140 goto error;
141
142 SCReturnInt(0);
143error:
144 SCReturnInt(-1);
145}
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition conf.c:350
int DetectContentSetup(DetectEngineCtx *de_ctx, Signature *s, const char *contentstr)
Function to setup a content pattern.
@ DETECT_URICONTENT
Data structures and function prototypes for keeping state for the detection engine.
int DetectBufferTypeRegister(const char *name)
int DetectHttpUriSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
this function setups the http_uri modifier keyword used in the rule
SigTableElmt * sigmatch_table
void DetectUricontentRegister(void)
Registration function for uricontent: keyword.
#define SIGMATCH_QUOTES_MANDATORY
Definition detect.h:1668
#define SIGMATCH_HANDLE_NEGATION
Definition detect.h:1672
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
void(* Free)(DetectEngineCtx *, void *)
Definition detect.h:1446
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition detect.h:1421
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
#define SCEnter(...)
Definition util-debug.h:277
#define SCReturnInt(x)
Definition util-debug.h:281
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
#define SCReturn
Definition util-debug.h:279
#define SCFree(p)
Definition util-mem.h:61
void SpmDestroyCtx(SpmCtx *ctx)
Definition util-spm.c:183