/src/suricata7/src/detect-pkt-data.c
Line | Count | Source |
1 | | /* Copyright (C) 2012-2020 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 Xavier Lange <xrlange@gmail.com> |
22 | | * |
23 | | */ |
24 | | |
25 | | #include "suricata-common.h" |
26 | | #include "threads.h" |
27 | | #include "decode.h" |
28 | | |
29 | | #include "detect.h" |
30 | | #include "detect-parse.h" |
31 | | #include "detect-pkt-data.h" |
32 | | #include "detect-engine.h" |
33 | | #include "detect-engine-mpm.h" |
34 | | #include "detect-engine-state.h" |
35 | | |
36 | | #include "flow.h" |
37 | | #include "flow-var.h" |
38 | | #include "flow-util.h" |
39 | | |
40 | | #include "util-debug.h" |
41 | | #include "util-spm-bm.h" |
42 | | #include "util-unittest.h" |
43 | | #include "util-unittest-helper.h" |
44 | | |
45 | | static int DetectPktDataSetup (DetectEngineCtx *, Signature *, const char *); |
46 | | #ifdef UNITTESTS |
47 | | static void DetectPktDataTestRegister(void); |
48 | | #endif |
49 | | |
50 | | /** |
51 | | * \brief Registration function for keyword: file_data |
52 | | */ |
53 | | void DetectPktDataRegister(void) |
54 | 74 | { |
55 | 74 | sigmatch_table[DETECT_PKT_DATA].name = "pkt_data"; |
56 | 74 | sigmatch_table[DETECT_PKT_DATA].Setup = DetectPktDataSetup; |
57 | | #ifdef UNITTESTS |
58 | | sigmatch_table[DETECT_PKT_DATA].RegisterTests = DetectPktDataTestRegister; |
59 | | #endif |
60 | 74 | sigmatch_table[DETECT_PKT_DATA].flags = SIGMATCH_NOOPT; |
61 | 74 | } |
62 | | |
63 | | /** |
64 | | * \brief this function is used to parse pkt_data options |
65 | | * \brief into the current signature |
66 | | * |
67 | | * \param de_ctx pointer to the Detection Engine Context |
68 | | * \param s pointer to the current signature |
69 | | * \param unused unused for keyword with SIGMATCH_NOOPT set |
70 | | * |
71 | | * \retval 0 on Success |
72 | | * \retval -1 on Failure |
73 | | */ |
74 | | static int DetectPktDataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *unused) |
75 | 586 | { |
76 | 586 | SCEnter(); |
77 | 586 | if (s->init_data->transforms.cnt) { |
78 | 2 | SCLogError("previous transforms not consumed before 'pkt_data'"); |
79 | 2 | SCReturnInt(-1); |
80 | 2 | } |
81 | 584 | s->init_data->list = DETECT_SM_LIST_NOTSET; |
82 | 584 | SCReturnInt(0); |
83 | 586 | } |
84 | | |
85 | | #ifdef UNITTESTS |
86 | | |
87 | | /************************************Unittests*********************************/ |
88 | | static int DetectPktDataTest02(void) |
89 | | { |
90 | | DetectEngineCtx *de_ctx = DetectEngineCtxInit(); |
91 | | FAIL_IF_NULL(de_ctx); |
92 | | de_ctx->flags |= DE_QUIET; |
93 | | |
94 | | Signature *sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any " |
95 | | "(file_data; compress_whitespace; " |
96 | | " pkt_data; content:\"in pkt data\"; sid:1;)"); |
97 | | FAIL_IF_NOT_NULL(sig); |
98 | | DetectEngineCtxFree(de_ctx); |
99 | | PASS; |
100 | | } |
101 | | |
102 | | static void DetectPktDataTestRegister(void) |
103 | | { |
104 | | UtRegisterTest("DetectPktDataTest02", DetectPktDataTest02); |
105 | | } |
106 | | #endif |