suricata
detect-dnp3.c
Go to the documentation of this file.
1 /* Copyright (C) 2015-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 #include "suricata-common.h"
19 
20 #include "stream.h"
21 
22 #include "detect.h"
23 #include "detect-parse.h"
24 #include "detect-dnp3.h"
25 #include "detect-engine.h"
26 #include "detect-engine-buffer.h"
27 #include "detect-engine-mpm.h"
30 #include "detect-engine-uint.h"
31 
32 #include "app-layer-dnp3.h"
33 #include "util-byte.h"
34 
35 static int g_dnp3_match_buffer_id = 0;
36 static int g_dnp3_data_buffer_id = 0;
37 static int g_dnp3_ind_buffer_id = 0;
38 
39 /**
40  * The detection struct.
41  */
42 typedef struct DetectDNP3_ {
43  union {
44  struct {
45  /* Function code for function code detection. */
46  uint8_t function_code;
47  };
48  struct {
49  /* Object info for object detection. */
50  uint8_t obj_group;
51  uint8_t obj_variation;
52  };
53  };
55 
56 /**
57  * Application function code name to code mappings (Snort compatible).
58  */
60  {"confirm", 0},
61  {"read", 1},
62  {"write", 2},
63  {"select", 3},
64  {"operate", 4},
65  {"direct_operate", 5},
66  {"direct_operate_nr", 6},
67  {"immed_freeze", 7},
68  {"immed_freeze_nr", 8},
69  {"freeze_clear", 9},
70  {"freeze_clear_nr", 10},
71  {"freeze_at_time", 11},
72  {"freeze_at_time_nr", 12},
73  {"cold_restart", 13},
74  {"warm_restart", 14},
75  {"initialize_data", 15},
76  {"initialize_appl", 16},
77  {"start_appl", 17},
78  {"stop_appl", 18},
79  {"save_config", 19},
80  {"enable_unsolicited", 20},
81  {"disable_unsolicited", 21},
82  {"assign_class", 22},
83  {"delay_measure", 23},
84  {"record_current_time", 24},
85  {"open_file", 25},
86  {"close_file", 26},
87  {"delete_file", 27},
88  {"get_file_info", 28},
89  {"authenticate_file", 29},
90  {"abort_file", 30},
91  {"activate_config", 31},
92  {"authenticate_req", 32},
93  {"authenticate_err", 33},
94  {"response", 129},
95  {"unsolicited_response", 130},
96  {"authenticate_resp", 131}
97 };
98 
99 #ifdef UNITTESTS
100 static void DetectDNP3FuncRegisterTests(void);
101 static void DetectDNP3ObjRegisterTests(void);
102 #endif
103 
104 static InspectionBuffer *GetDNP3Data(DetectEngineThreadCtx *det_ctx,
105  const DetectEngineTransforms *transforms,
106  Flow *_f, const uint8_t flow_flags,
107  void *txv, const int list_id)
108 {
109  SCLogDebug("list_id %d", list_id);
110  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
111  if (buffer->inspect == NULL) {
112  DNP3Transaction *tx = (DNP3Transaction *)txv;
113  SCLogDebug("tx %p", tx);
114 
115  if ((flow_flags & STREAM_TOSERVER && !tx->is_request) ||
116  (flow_flags & STREAM_TOCLIENT && tx->is_request)) {
117  return NULL;
118  }
119 
120  if (tx->buffer == NULL || tx->buffer_len == 0) {
121  return NULL;
122  }
123 
124  SCLogDebug("tx %p data %p data_len %u", tx, tx->buffer, tx->buffer_len);
126  det_ctx, list_id, buffer, tx->buffer, tx->buffer_len, transforms);
127  }
128  return buffer;
129 }
130 
131 /**
132  * \brief Parse the provided function name or code to its integer
133  * value.
134  *
135  * If the value passed is a number, it will be checked that it falls
136  * within the range of valid function codes. If function name is
137  * passed it will be resolved to its function code.
138  *
139  * \retval The function code as an integer if successful, -1 on
140  * failure.
141  */
142 static int DetectDNP3FuncParseFunctionCode(const char *str, uint8_t *fc)
143 {
144  if (StringParseUint8(fc, 10, (uint16_t)strlen(str), str) > 0) {
145  return 1;
146  }
147 
148  /* Lookup by name. */
149  for (size_t i = 0;
150  i < sizeof(DNP3FunctionNameMap) / sizeof(DNP3Mapping); i++) {
151  if (strcasecmp(str, DNP3FunctionNameMap[i].name) == 0) {
152  *fc = (uint8_t)(DNP3FunctionNameMap[i].value);
153  return 1;
154  }
155  }
156 
157  return 0;
158 }
159 
160 static int DetectDNP3FuncSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
161 {
162  SCEnter();
163  DetectDNP3 *dnp3 = NULL;
164  uint8_t function_code;
165 
167  return -1;
168 
169  if (!DetectDNP3FuncParseFunctionCode(str, &function_code)) {
170  SCLogError("Invalid argument \"%s\" supplied to dnp3_func keyword.", str);
171  return -1;
172  }
173 
174  dnp3 = SCCalloc(1, sizeof(DetectDNP3));
175  if (unlikely(dnp3 == NULL)) {
176  goto error;
177  }
179 
181  de_ctx, s, DETECT_DNP3FUNC, (SigMatchCtx *)dnp3, g_dnp3_match_buffer_id) == NULL) {
182  goto error;
183  }
184 
185  SCReturnInt(0);
186 error:
187  if (dnp3 != NULL) {
188  SCFree(dnp3);
189  }
190  SCReturnInt(-1);
191 }
192 
193 static void DetectDNP3IndFree(DetectEngineCtx *de_ctx, void *ptr)
194 {
195  SCDetectU16Free(ptr);
196 }
197 
198 static int DetectDNP3IndSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
199 {
200  SCEnter();
201 
203  return -1;
204 
205  DetectU16Data *detect = SCDnp3DetectIndParse(str);
206  if (detect == NULL) {
207  SCLogError("Invalid argument \"%s\" supplied to dnp3.ind keyword.", str);
208  return -1;
209  }
210 
212  de_ctx, s, DETECT_DNP3IND, (SigMatchCtx *)detect, g_dnp3_ind_buffer_id) == NULL) {
213  goto error;
214  }
215 
216  SCReturnInt(0);
217 error:
218  if (detect != NULL) {
219  DetectDNP3IndFree(NULL, detect);
220  }
221  SCReturnInt(-1);
222 }
223 
224 /**
225  * \brief Parse the value of string of the dnp3_obj keyword.
226  *
227  * \param str the input string
228  * \param gout pointer to variable to store the parsed group integer
229  * \param vout pointer to variable to store the parsed variation integer
230  *
231  * \retval 1 if parsing successful otherwise 0.
232  */
233 static int DetectDNP3ObjParse(const char *str, uint8_t *group, uint8_t *var)
234 {
235  size_t size = strlen(str) + 1;
236  char groupstr[size], *varstr, *sep;
237  strlcpy(groupstr, str, size);
238 
239  sep = strchr(groupstr, ',');
240  if (sep == NULL) {
241  return 0;
242  }
243  *sep = '\0';
244  varstr = sep + 1;
245 
246  if (StringParseUint8(group, 0, (uint16_t)strlen(groupstr), groupstr) <= 0) {
247  return 0;
248  }
249 
250  if (StringParseUint8(var, 0, (uint16_t)strlen(varstr), varstr) <= 0) {
251  return 0;
252  }
253 
254  return 1;
255 }
256 
257 static int DetectDNP3ObjSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
258 {
259  SCEnter();
260  uint8_t group;
261  uint8_t variation;
262  DetectDNP3 *detect = NULL;
263 
265  return -1;
266 
267  if (!DetectDNP3ObjParse(str, &group, &variation)) {
268  goto fail;
269  }
270 
271  detect = SCCalloc(1, sizeof(*detect));
272  if (unlikely(detect == NULL)) {
273  goto fail;
274  }
275  detect->obj_group = group;
276  detect->obj_variation = variation;
277 
279  de_ctx, s, DETECT_DNP3OBJ, (SigMatchCtx *)detect, g_dnp3_match_buffer_id) == NULL) {
280  goto fail;
281  }
282 
283  SCReturnInt(1);
284 fail:
285  if (detect != NULL) {
286  SCFree(detect);
287  }
288  SCReturnInt(0);
289 }
290 
291 static void DetectDNP3Free(DetectEngineCtx *de_ctx, void *ptr)
292 {
293  SCEnter();
294  if (ptr != NULL) {
295  SCFree(ptr);
296  }
297  SCReturn;
298 }
299 
300 static int DetectDNP3FuncMatch(DetectEngineThreadCtx *det_ctx,
301  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
302  const SigMatchCtx *ctx)
303 {
304  DNP3Transaction *tx = (DNP3Transaction *)txv;
305  DetectDNP3 *detect = (DetectDNP3 *)ctx;
306  int match = 0;
307 
308  if (flags & STREAM_TOSERVER && tx->is_request) {
309  match = detect->function_code == tx->ah.function_code;
310  } else if (flags & STREAM_TOCLIENT && !tx->is_request) {
311  match = detect->function_code == tx->ah.function_code;
312  }
313 
314  return match;
315 }
316 
317 static int DetectDNP3ObjMatch(DetectEngineThreadCtx *det_ctx,
318  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
319  const SigMatchCtx *ctx)
320 {
321  DNP3Transaction *tx = (DNP3Transaction *)txv;
322  DetectDNP3 *detect = (DetectDNP3 *)ctx;
323  DNP3ObjectList *objects = NULL;
324 
325  if (flags & STREAM_TOSERVER && tx->is_request) {
326  objects = &tx->objects;
327  } else if (flags & STREAM_TOCLIENT && !tx->is_request) {
328  objects = &tx->objects;
329  }
330 
331  if (objects != NULL) {
332  DNP3Object *object;
333  TAILQ_FOREACH(object, objects, next) {
334  if (object->group == detect->obj_group &&
335  object->variation == detect->obj_variation) {
336  return 1;
337  }
338  }
339  }
340 
341  return 0;
342 }
343 
344 static int DetectDNP3IndMatch(DetectEngineThreadCtx *det_ctx,
345  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
346  const SigMatchCtx *ctx)
347 {
348  DNP3Transaction *tx = (DNP3Transaction *)txv;
349  DetectU16Data *detect = (DetectU16Data *)ctx;
350 
351  return DetectU16Match((uint16_t)((tx->iin.iin1 << 8) | tx->iin.iin2), detect);
352 }
353 
354 static void DetectDNP3FuncRegister(void)
355 {
356  SCEnter();
357 
358  sigmatch_table[DETECT_DNP3FUNC].name = "dnp3_func";
359  sigmatch_table[DETECT_DNP3FUNC].alias = "dnp3.func";
361  "match on the application function code found in DNP3 request and responses";
362  sigmatch_table[DETECT_DNP3FUNC].url = "/rules/dnp3-keywords.html#dnp3-func";
364  sigmatch_table[DETECT_DNP3FUNC].AppLayerTxMatch = DetectDNP3FuncMatch;
365  sigmatch_table[DETECT_DNP3FUNC].Setup = DetectDNP3FuncSetup;
366  sigmatch_table[DETECT_DNP3FUNC].Free = DetectDNP3Free;
367 #ifdef UNITTESTS
368  sigmatch_table[DETECT_DNP3FUNC].RegisterTests = DetectDNP3FuncRegisterTests;
369 #endif
370  SCReturn;
371 }
372 
373 static void DetectDNP3IndRegister(void)
374 {
375  SCEnter();
376 
377  sigmatch_table[DETECT_DNP3IND].name = "dnp3_ind";
378  sigmatch_table[DETECT_DNP3IND].alias = "dnp3.ind";
380  "match on the DNP3 internal indicator flags in the response application header";
381  sigmatch_table[DETECT_DNP3IND].url = "/rules/dnp3-keywords.html#dnp3-ind";
383  sigmatch_table[DETECT_DNP3IND].AppLayerTxMatch = DetectDNP3IndMatch;
384  sigmatch_table[DETECT_DNP3IND].Setup = DetectDNP3IndSetup;
385  sigmatch_table[DETECT_DNP3IND].Free = DetectDNP3IndFree;
387  SCReturn;
388 }
389 
390 static void DetectDNP3ObjRegister(void)
391 {
392  SCEnter();
393 
394  sigmatch_table[DETECT_DNP3OBJ].name = "dnp3_obj";
395  sigmatch_table[DETECT_DNP3OBJ].alias = "dnp3.obj";
396  sigmatch_table[DETECT_DNP3OBJ].desc = "match on the DNP3 application data objects";
397  sigmatch_table[DETECT_DNP3OBJ].url = "/rules/dnp3-keywords.html#dnp3-obj";
399  sigmatch_table[DETECT_DNP3OBJ].AppLayerTxMatch = DetectDNP3ObjMatch;
400  sigmatch_table[DETECT_DNP3OBJ].Setup = DetectDNP3ObjSetup;
401  sigmatch_table[DETECT_DNP3OBJ].Free = DetectDNP3Free;
402 #ifdef UNITTESTS
403  sigmatch_table[DETECT_DNP3OBJ].RegisterTests = DetectDNP3ObjRegisterTests;
404 #endif
405  SCReturn;
406 }
407 
408 static int DetectDNP3DataSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
409 {
410  SCEnter();
412  return -1;
413 
414  if (SCDetectBufferSetActiveList(de_ctx, s, g_dnp3_data_buffer_id) != 0)
415  return -1;
416 
417  SCReturnInt(0);
418 }
419 
420 static void DetectDNP3DataRegister(void)
421 {
422  SCEnter();
423 
424  sigmatch_table[DETECT_DNP3DATA].name = "dnp3.data";
425  sigmatch_table[DETECT_DNP3DATA].alias = "dnp3_data";
427  "make the following content options to match on the re-assembled application buffer";
428  sigmatch_table[DETECT_DNP3DATA].url = "/rules/dnp3-keywords.html#dnp3-data";
429  sigmatch_table[DETECT_DNP3DATA].Setup = DetectDNP3DataSetup;
431 
433  DetectEngineInspectBufferGeneric, GetDNP3Data);
435  GetDNP3Data, ALPROTO_DNP3, 0);
436 
438  DetectEngineInspectBufferGeneric, GetDNP3Data);
440  GetDNP3Data, ALPROTO_DNP3, 0);
441 
442  g_dnp3_data_buffer_id = DetectBufferTypeGetByName("dnp3_data");
443  SCReturn;
444 }
445 
447 {
448  DetectDNP3DataRegister();
449 
450  DetectDNP3FuncRegister();
451  DetectDNP3IndRegister();
452  DetectDNP3ObjRegister();
453 
454  /* Register the list of func, ind and obj. */
459 
460  g_dnp3_match_buffer_id = DetectBufferTypeRegister("dnp3");
461 
464  g_dnp3_ind_buffer_id = DetectBufferTypeRegister("dnp3_ind");
465 }
466 
467 #ifdef UNITTESTS
468 
469 #include "util-unittest.h"
470 #include "util-unittest-helper.h"
471 #include "app-layer-parser.h"
472 #include "flow-util.h"
473 #include "stream-tcp.h"
474 
475 static int DetectDNP3FuncParseFunctionCodeTest(void)
476 {
477  uint8_t fc;
478 
479  /* Valid. */
480  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("0", &fc));
481  FAIL_IF(fc != 0);
482 
483  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("1", &fc));
484  FAIL_IF(fc != 1);
485 
486  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("254", &fc));
487  FAIL_IF(fc != 254);
488 
489  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("255", &fc));
490  FAIL_IF(fc != 255);
491 
492  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("confirm", &fc));
493  FAIL_IF(fc != 0);
494 
495  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("CONFIRM", &fc));
496  FAIL_IF(fc != 0);
497 
498  /* Invalid. */
499  FAIL_IF(DetectDNP3FuncParseFunctionCode("", &fc));
500  FAIL_IF(DetectDNP3FuncParseFunctionCode("-1", &fc));
501  FAIL_IF(DetectDNP3FuncParseFunctionCode("-2", &fc));
502  FAIL_IF(DetectDNP3FuncParseFunctionCode("256", &fc));
503  FAIL_IF(DetectDNP3FuncParseFunctionCode("unknown_function_code", &fc));
504 
505  PASS;
506 }
507 
508 static int DetectDNP3FuncTest01(void)
509 {
512 
513  Signature *s = DetectEngineAppendSig(de_ctx, "alert dnp3 any any -> any any "
514  "(msg:\"SURICATA DNP3 Write request\"; "
515  "dnp3_func:2; sid:5000009; rev:1;)");
517 
518  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_dnp3_match_buffer_id);
519  FAIL_IF_NULL(sm);
520  FAIL_IF_NULL(sm->ctx);
521 
522  DetectDNP3 *dnp3func = (DetectDNP3 *)sm->ctx;
523  FAIL_IF(dnp3func->function_code != 2);
524 
526  PASS;
527 }
528 
529 static int DetectDNP3ObjSetupTest(void)
530 {
532  FAIL_IF(de_ctx == NULL);
533 
534  Signature *s = DetectEngineAppendSig(de_ctx, "alert dnp3 any any -> any any "
535  "(msg:\"SURICATA DNP3 Object Test\"; "
536  "dnp3_obj:99,99; sid:1; rev:1;)");
537  FAIL_IF(de_ctx->sig_list == NULL);
538 
539  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_dnp3_match_buffer_id);
540  FAIL_IF_NULL(sm);
541  FAIL_IF_NULL(sm->ctx);
542 
543  DetectDNP3 *detect = (DetectDNP3 *)sm->ctx;
544  FAIL_IF(detect->obj_group != 99);
545  FAIL_IF(detect->obj_variation != 99);
546 
548  PASS;
549 }
550 
551 static int DetectDNP3ObjParseTest(void)
552 {
553  uint8_t group, var;
554 
555  FAIL_IF(!DetectDNP3ObjParse("0,0", &group, &var));
556  FAIL_IF(group != 0 || var != 0);
557 
558  FAIL_IF(!DetectDNP3ObjParse("255,255", &group, &var));
559  FAIL_IF(group != 255 || var != 255);
560 
561  FAIL_IF(DetectDNP3ObjParse("-1,-1", &group, &var));
562  FAIL_IF(DetectDNP3ObjParse("256,256", &group, &var));
563  FAIL_IF(DetectDNP3ObjParse("a,1", &group, &var));
564  FAIL_IF(DetectDNP3ObjParse("1,a", &group, &var));
565 
566  PASS;
567 }
568 
569 static void DetectDNP3FuncRegisterTests(void)
570 {
571  UtRegisterTest("DetectDNP3FuncParseFunctionCodeTest",
572  DetectDNP3FuncParseFunctionCodeTest);
573  UtRegisterTest("DetectDNP3FuncTest01", DetectDNP3FuncTest01);
574 }
575 
576 static void DetectDNP3ObjRegisterTests(void)
577 {
578  UtRegisterTest("DetectDNP3ObjParseTest", DetectDNP3ObjParseTest);
579  UtRegisterTest("DetectDNP3ObjSetupTest", DetectDNP3ObjSetupTest);
580 }
581 #endif
util-byte.h
SIGMATCH_INFO_UINT16
#define SIGMATCH_INFO_UINT16
Definition: detect.h:1688
detect-engine-uint.h
SigTableElmt_::url
const char * url
Definition: detect.h:1460
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1674
SigTableElmt_::desc
const char * desc
Definition: detect.h:1459
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
DetectEngineInspectBufferGeneric
uint8_t DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:2049
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1444
flow-util.h
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:157
SigTableElmt_::name
const char * name
Definition: detect.h:1457
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:391
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1448
DetectDNP3Register
void DetectDNP3Register(void)
Definition: detect-dnp3.c:446
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
DNP3Object_
Struct to hold the list of decoded objects.
Definition: app-layer-dnp3.h:192
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
Flow_
Flow data structure.
Definition: flow.h:348
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2634
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1422
DetectDNP3_
Definition: detect-dnp3.c:42
DNP3Transaction_::objects
DNP3ObjectList objects
Definition: app-layer-dnp3.h:221
detect-dnp3.h
SCDetectBufferSetActiveList
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition: detect-engine-buffer.c:29
SCDetectSignatureSetAppProto
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2229
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3439
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:272
DNP3Transaction_::buffer_len
uint32_t buffer_len
Definition: app-layer-dnp3.h:220
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine-inspect-buffer.c:56
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1439
DETECT_DNP3DATA
@ DETECT_DNP3DATA
Definition: detect-engine-register.h:264
DetectDNP3_::function_code
uint8_t function_code
Definition: detect-dnp3.c:46
detect-engine-prefilter.h
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1278
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
StringParseUint8
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:370
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:271
DNP3Transaction_::ah
DNP3ApplicationHeader ah
Definition: app-layer-dnp3.h:224
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
DETECT_DNP3IND
@ DETECT_DNP3IND
Definition: detect-engine-register.h:266
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
DetectEngineThreadCtx_
Definition: detect.h:1244
DNP3Transaction_::iin
DNP3InternalInd iin
Definition: app-layer-dnp3.h:225
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition: app-layer-protos.h:50
app-layer-dnp3.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:281
detect-engine-mpm.h
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:388
detect.h
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1577
DetectAppLayerMpmRegister
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register an app layer keyword for mpm
Definition: detect-engine-mpm.c:152
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
SCReturn
#define SCReturn
Definition: util-debug.h:283
stream.h
DNP3Object_::group
uint8_t group
Definition: app-layer-dnp3.h:193
variation
uint8_t variation
Definition: app-layer-dnp3.h:1
DETECT_DNP3FUNC
@ DETECT_DNP3FUNC
Definition: detect-engine-register.h:265
SIGMATCH_INFO_BITFLAGS_UINT
#define SIGMATCH_INFO_BITFLAGS_UINT
Definition: detect.h:1698
name
const char * name
Definition: tm-threads.c:2163
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1419
DetectDNP3_::obj_variation
uint8_t obj_variation
Definition: detect-dnp3.c:51
detect-engine-content-inspection.h
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:351
DNP3Transaction_::is_request
bool is_request
Definition: app-layer-dnp3.h:215
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:1214
DetectU16Match
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
Definition: detect-engine-uint.c:107
flags
uint8_t flags
Definition: decode-gre.h:0
SigTableElmt_::alias
const char * alias
Definition: detect.h:1458
group
uint8_t group
Definition: app-layer-dnp3.h:0
suricata-common.h
DetectDNP3_::obj_group
uint8_t obj_group
Definition: detect-dnp3.c:50
detect-engine-buffer.h
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:941
DetectEngineInspectGenericList
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1946
DNP3Mapping_
Definition: detect-dnp3.h:24
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect-engine-inspect-buffer.h:35
str
#define str(s)
Definition: suricata-common.h:308
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:271
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DNP3Object_::variation
uint8_t variation
Definition: app-layer-dnp3.h:194
detect-parse.h
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
InspectionBufferSetupAndApplyTransforms
void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
Definition: detect-engine-inspect-buffer.c:197
function_code
uint8_t function_code
Definition: app-layer-dnp3.h:1
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2595
DETECT_DNP3OBJ
@ DETECT_DNP3OBJ
Definition: detect-engine-register.h:267
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1649
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
Definition: detect-engine.c:273
DetectDNP3
struct DetectDNP3_ DetectDNP3
DetectU16Data
DetectUintData_u16 DetectU16Data
Definition: detect-engine-uint.h:42
DNP3FunctionNameMap
DNP3Mapping DNP3FunctionNameMap[]
Definition: detect-dnp3.c:59
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:285
DNP3Transaction_
DNP3 transaction.
Definition: app-layer-dnp3.h:211
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1446
DNP3Transaction_::buffer
uint8_t * buffer
Definition: app-layer-dnp3.h:219