suricata
detect-rawbytes.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 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 *
23 * Implements rawbytes keyword support
24 *
25 * \todo Provide un-normalized telnet dce/rpc buffers to match on
26 */
27
28#include "suricata-common.h"
29
30#include "decode.h"
31#include "detect.h"
32#include "detect-parse.h"
33#include "detect-rawbytes.h"
34#include "detect-engine.h"
35
36#include "detect-content.h"
37#include "detect-pcre.h"
38
39#include "util-debug.h"
40
41static int DetectRawbytesSetup(DetectEngineCtx *, Signature *, const char *);
42
44{
47 "dummy keyword to be compatible with snort signatures without effect";
48 sigmatch_table[DETECT_RAWBYTES].url = "/rules/payload-keywords.html#rawbytes";
49 sigmatch_table[DETECT_RAWBYTES].Setup = DetectRawbytesSetup;
51}
52
53static int DetectRawbytesSetup(DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
54{
55 SCEnter();
56
57 if (nullstr != NULL) {
58 SCLogError("rawbytes has no value");
59 SCReturnInt(-1);
60 }
61
63 SCLogError("\"rawbytes\" cannot be combined "
64 "with the \"%s\" sticky buffer",
66 SCReturnInt(-1);
67 }
68
70 if (pm == NULL) {
71 SCLogError("\"rawbytes\" needs a preceding content option");
72 SCReturnInt(-1);
73 }
74
75 switch (pm->type) {
76 case DETECT_CONTENT: {
78 if (cd->flags & DETECT_CONTENT_RAWBYTES) {
79 SCLogError("can't use multiple rawbytes modifiers for the same content. ");
80 SCReturnInt(-1);
81 }
82 cd->flags |= DETECT_CONTENT_RAWBYTES;
83 break;
84 }
85 default:
86 SCLogError("\"rawbytes\" needs a preceding content option");
87 SCReturnInt(-1);
88 }
89
90 SCReturnInt(0);
91}
#define DETECT_CONTENT_RAWBYTES
@ DETECT_RAWBYTES
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
SigMatch * DetectGetLastSMByListId(const Signature *s, int list_id,...)
Returns the sm with the largest index (added last) from the list passed to us as an id.
SigTableElmt * sigmatch_table
void DetectRawbytesRegister(void)
#define SIGMATCH_NOOPT
Definition detect.h:1651
#define DETECT_SM_LIST_NOTSET
Definition detect.h:144
@ DETECT_SM_LIST_PMATCH
Definition detect.h:119
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
a single match condition for a signature
Definition detect.h:356
uint16_t type
Definition detect.h:357
SigMatchCtx * ctx
Definition detect.h:359
const char * url
Definition detect.h:1462
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
SignatureInitData * init_data
Definition detect.h:747
#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