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 
41 static int DetectRawbytesSetup (DetectEngineCtx *, Signature *, const char *);
42 
44 {
45  sigmatch_table[DETECT_RAWBYTES].name = "rawbytes";
46  sigmatch_table[DETECT_RAWBYTES].Setup = DetectRawbytesSetup;
48 }
49 
50 static int DetectRawbytesSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
51 {
52  SCEnter();
53 
54  if (nullstr != NULL) {
55  SCLogError(SC_ERR_INVALID_VALUE, "rawbytes has no value");
56  SCReturnInt(-1);
57  }
58 
60  SCLogError(SC_ERR_RAWBYTES_BUFFER, "\"rawbytes\" cannot be combined "
61  "with the \"%s\" sticky buffer",
63  SCReturnInt(-1);
64  }
65 
67  DETECT_CONTENT, -1);
68  if (pm == NULL) {
69  SCLogError(SC_ERR_RAWBYTES_MISSING_CONTENT, "\"rawbytes\" needs a preceding content option");
70  SCReturnInt(-1);
71  }
72 
73  switch (pm->type) {
74  case DETECT_CONTENT:
75  {
77  if (cd->flags & DETECT_CONTENT_RAWBYTES) {
78  SCLogError(SC_ERR_INVALID_SIGNATURE, "can't use multiple rawbytes modifiers for the same content. ");
79  SCReturnInt(-1);
80  }
82  break;
83  }
84  default:
85  SCLogError(SC_ERR_RAWBYTES_MISSING_CONTENT, "\"rawbytes\" needs a preceding content option");
86  SCReturnInt(-1);
87  }
88 
89  SCReturnInt(0);
90 }
91 
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:90
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
SigTableElmt_::name
const char * name
Definition: detect.h:1211
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:59
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1205
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
DETECT_CONTENT_RAWBYTES
#define DETECT_CONTENT_RAWBYTES
Definition: detect-content.h:38
SC_ERR_INVALID_SIGNATURE
@ SC_ERR_INVALID_SIGNATURE
Definition: util-error.h:69
SC_ERR_RAWBYTES_MISSING_CONTENT
@ SC_ERR_RAWBYTES_MISSING_CONTENT
Definition: util-error.h:142
DetectContentData_
Definition: detect-content.h:86
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1196
detect-pcre.h
DetectGetLastSMByListId
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.
Definition: detect-parse.c:540
decode.h
SC_ERR_RAWBYTES_BUFFER
@ SC_ERR_RAWBYTES_BUFFER
Definition: util-error.h:231
util-debug.h
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
detect-rawbytes.h
SignatureInitData_::list
int list
Definition: detect.h:505
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:97
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:597
SigMatch_::type
uint8_t type
Definition: detect.h:321
DETECT_SM_LIST_NOTSET
#define DETECT_SM_LIST_NOTSET
Definition: detect.h:115
suricata-common.h
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
DETECT_RAWBYTES
@ DETECT_RAWBYTES
Definition: detect-engine-register.h:71
DetectRawbytesRegister
void DetectRawbytesRegister(void)
Definition: detect-rawbytes.c:43
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
SigMatch_
a single match condition for a signature
Definition: detect.h:320
DetectBufferTypeGetNameById
const char * DetectBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:889
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1380
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304