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 
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect.h:1406
SignatureInitData * init_data
Definition: detect.h:563
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1149
void DetectRawbytesRegister(void)
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:479
const char * name
Definition: detect.h:1163
Signature container.
Definition: detect.h:495
main detection engine ctx
Definition: detect.h:723
#define DETECT_CONTENT_RAWBYTES
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
#define SCEnter(...)
Definition: util-debug.h:337
#define DETECT_SM_LIST_NOTSET
Definition: detect.h:118
uint8_t type
Definition: detect.h:323
#define SCReturnInt(x)
Definition: util-debug.h:341
SigMatchCtx * ctx
Definition: detect.h:325
#define SIGMATCH_NOOPT
Definition: detect.h:1331
uint16_t flags
Definition: detect.h:1157
const char * DetectBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
a single match condition for a signature
Definition: detect.h:322