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-mpm.h"
29 
30 #include "app-layer-dnp3.h"
31 #include "util-byte.h"
32 
33 static int g_dnp3_match_buffer_id = 0;
34 static int g_dnp3_data_buffer_id = 0;
35 
36 /**
37  * The detection struct.
38  */
39 typedef struct DetectDNP3_ {
40  union {
41  struct {
42  /* Function code for function code detection. */
43  uint8_t function_code;
44  };
45  struct {
46  /* Internal indicator flags for IIN detection. */
47  uint16_t ind_flags;
48  };
49  struct {
50  /* Object info for object detection. */
51  uint8_t obj_group;
52  uint8_t obj_variation;
53  };
54  };
56 
57 /**
58  * Indicator names to value mappings (Snort compatible).
59  */
61  {"device_restart", 0x8000},
62  {"device_trouble", 0x4000},
63  {"local_control", 0x2000},
64  {"need_time", 0x1000},
65  {"class_3_events", 0x0800},
66  {"class_2_events", 0x0400},
67  {"class_1_events", 0x0200},
68  {"all_stations", 0x0100},
69 
70  {"reserved_1", 0x0080},
71  {"reserved_2", 0x0040},
72  {"config_corrupt", 0x0020},
73  {"already_executing", 0x0010},
74  {"event_buffer_overflow", 0x0008},
75  {"parameter_error", 0x0004},
76  {"object_unknown", 0x0002},
77  {"no_func_code_support", 0x0001},
78 
79  {NULL, 0},
80 };
81 
82 /**
83  * Application function code name to code mappings (Snort compatible).
84  */
86  {"confirm", 0},
87  {"read", 1},
88  {"write", 2},
89  {"select", 3},
90  {"operate", 4},
91  {"direct_operate", 5},
92  {"direct_operate_nr", 6},
93  {"immed_freeze", 7},
94  {"immed_freeze_nr", 8},
95  {"freeze_clear", 9},
96  {"freeze_clear_nr", 10},
97  {"freeze_at_time", 11},
98  {"freeze_at_time_nr", 12},
99  {"cold_restart", 13},
100  {"warm_restart", 14},
101  {"initialize_data", 15},
102  {"initialize_appl", 16},
103  {"start_appl", 17},
104  {"stop_appl", 18},
105  {"save_config", 19},
106  {"enable_unsolicited", 20},
107  {"disable_unsolicited", 21},
108  {"assign_class", 22},
109  {"delay_measure", 23},
110  {"record_current_time", 24},
111  {"open_file", 25},
112  {"close_file", 26},
113  {"delete_file", 27},
114  {"get_file_info", 28},
115  {"authenticate_file", 29},
116  {"abort_file", 30},
117  {"activate_config", 31},
118  {"authenticate_req", 32},
119  {"authenticate_err", 33},
120  {"response", 129},
121  {"unsolicited_response", 130},
122  {"authenticate_resp", 131}
123 };
124 
125 #ifdef UNITTESTS
126 static void DetectDNP3FuncRegisterTests(void);
127 static void DetectDNP3IndRegisterTests(void);
128 static void DetectDNP3ObjRegisterTests(void);
129 #endif
130 
131 /**
132  * \brief Utility function to trim leading and trailing whitespace
133  * from a string.
134  */
135 static char *TrimString(char *str)
136 {
137  char *end = str + strlen(str) - 1;
138  while (isspace(*str)) {
139  str++;
140  }
141  while (end > str && isspace(*end)) {
142  end--;
143  }
144  *(end + 1) = '\0';
145  return str;
146 }
147 
148 static InspectionBuffer *GetDNP3Data(DetectEngineThreadCtx *det_ctx,
149  const DetectEngineTransforms *transforms,
150  Flow *_f, const uint8_t flow_flags,
151  void *txv, const int list_id)
152 {
153  SCLogDebug("list_id %d", list_id);
154  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
155  if (buffer->inspect == NULL) {
156  DNP3Transaction *tx = (DNP3Transaction *)txv;
157  SCLogDebug("tx %p", tx);
158 
159  if ((flow_flags & STREAM_TOSERVER && !tx->is_request) ||
160  (flow_flags & STREAM_TOCLIENT && tx->is_request)) {
161  return NULL;
162  }
163 
164  if (tx->buffer == NULL || tx->buffer_len == 0) {
165  return NULL;
166  }
167 
168  SCLogDebug("tx %p data %p data_len %u", tx, tx->buffer, tx->buffer_len);
169  InspectionBufferSetup(det_ctx, list_id, buffer, tx->buffer, tx->buffer_len);
170  InspectionBufferApplyTransforms(buffer, transforms);
171  }
172  return buffer;
173 }
174 
175 /**
176  * \brief Parse the provided function name or code to its integer
177  * value.
178  *
179  * If the value passed is a number, it will be checked that it falls
180  * within the range of valid function codes. If function name is
181  * passed it will be resolved to its function code.
182  *
183  * \retval The function code as an integer if successful, -1 on
184  * failure.
185  */
186 static int DetectDNP3FuncParseFunctionCode(const char *str, uint8_t *fc)
187 {
188  if (StringParseUint8(fc, 10, (uint16_t)strlen(str), str) >= 0) {
189  return 1;
190  }
191 
192  /* Lookup by name. */
193  for (size_t i = 0;
194  i < sizeof(DNP3FunctionNameMap) / sizeof(DNP3Mapping); i++) {
195  if (strcasecmp(str, DNP3FunctionNameMap[i].name) == 0) {
196  *fc = (uint8_t)(DNP3FunctionNameMap[i].value);
197  return 1;
198  }
199  }
200 
201  return 0;
202 }
203 
204 static int DetectDNP3FuncSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
205 {
206  SCEnter();
207  DetectDNP3 *dnp3 = NULL;
208  uint8_t function_code;
209 
211  return -1;
212 
213  if (!DetectDNP3FuncParseFunctionCode(str, &function_code)) {
214  SCLogError("Invalid argument \"%s\" supplied to dnp3_func keyword.", str);
215  return -1;
216  }
217 
218  dnp3 = SCCalloc(1, sizeof(DetectDNP3));
219  if (unlikely(dnp3 == NULL)) {
220  goto error;
221  }
223 
225  g_dnp3_match_buffer_id) == NULL) {
226  goto error;
227  }
228 
229  SCReturnInt(0);
230 error:
231  if (dnp3 != NULL) {
232  SCFree(dnp3);
233  }
234  SCReturnInt(-1);
235 }
236 
237 static int DetectDNP3IndParseByName(const char *str, uint16_t *flags)
238 {
239  char tmp[strlen(str) + 1];
240  char *p, *last = NULL;
241 
242  strlcpy(tmp, str, sizeof(tmp));
243 
244  for ((p = strtok_r(tmp, ",", &last)); p; (p = strtok_r(NULL, ",", &last))) {
245  p = TrimString(p);
246  int found = 0;
247  int i = 0;
248  while (DNP3IndicatorsMap[i].name != NULL) {
249  if (strcasecmp(p, DNP3IndicatorsMap[i].name) == 0) {
251  found = 1;
252  break;
253  }
254  i++;
255  }
256 
257  if (!found) {
258  SCLogError("Bad argument \"%s\" supplied to dnp3.ind keyword.", p);
259  return 0;
260  }
261  }
262 
263  return 1;
264 }
265 
266 static int DetectDNP3IndParse(const char *str, uint16_t *flags)
267 {
268  *flags = 0;
269 
270  if (StringParseUint16(flags, 0, (uint16_t)strlen(str), str) > 0) {
271  return 1;
272  }
273 
274  /* Parse by name - will log a more specific error message on error. */
275  if (DetectDNP3IndParseByName(str, flags)) {
276  return 1;
277  }
278 
279  return 0;
280 }
281 
282 static int DetectDNP3IndSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
283 {
284  SCEnter();
285  DetectDNP3 *detect = NULL;
286  uint16_t flags;
287 
289  return -1;
290 
291  if (!DetectDNP3IndParse(str, &flags)) {
292  SCLogError("Invalid argument \"%s\" supplied to dnp3.ind keyword.", str);
293  return -1;
294  }
295 
296  detect = SCCalloc(1, sizeof(DetectDNP3));
297  if (unlikely(detect == NULL)) {
298  goto error;
299  }
300  detect->ind_flags = flags;
301 
303  g_dnp3_match_buffer_id) == NULL) {
304  goto error;
305  }
306 
307  SCReturnInt(0);
308 error:
309  if (detect != NULL) {
310  SCFree(detect);
311  }
312  SCReturnInt(-1);
313 }
314 
315 /**
316  * \brief Parse the value of string of the dnp3_obj keyword.
317  *
318  * \param str the input string
319  * \param gout pointer to variable to store the parsed group integer
320  * \param vout pointer to variable to store the parsed variation integer
321  *
322  * \retval 1 if parsing successful otherwise 0.
323  */
324 static int DetectDNP3ObjParse(const char *str, uint8_t *group, uint8_t *var)
325 {
326  size_t size = strlen(str) + 1;
327  char groupstr[size], *varstr, *sep;
328  strlcpy(groupstr, str, size);
329 
330  sep = strchr(groupstr, ',');
331  if (sep == NULL) {
332  return 0;
333  }
334  *sep = '\0';
335  varstr = sep + 1;
336 
337  if (StringParseUint8(group, 0, (uint16_t)strlen(groupstr), groupstr) < 0) {
338  return 0;
339  }
340 
341  if (StringParseUint8(var, 0, (uint16_t)strlen(varstr), varstr) < 0) {
342  return 0;
343  }
344 
345  return 1;
346 }
347 
348 static int DetectDNP3ObjSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
349 {
350  SCEnter();
351  uint8_t group;
352  uint8_t variation;
353  DetectDNP3 *detect = NULL;
354 
356  return -1;
357 
358  if (!DetectDNP3ObjParse(str, &group, &variation)) {
359  goto fail;
360  }
361 
362  detect = SCCalloc(1, sizeof(*detect));
363  if (unlikely(detect == NULL)) {
364  goto fail;
365  }
366  detect->obj_group = group;
367  detect->obj_variation = variation;
368 
370  g_dnp3_match_buffer_id) == NULL) {
371  goto fail;
372  }
373 
374  SCReturnInt(1);
375 fail:
376  if (detect != NULL) {
377  SCFree(detect);
378  }
379  SCReturnInt(0);
380 }
381 
382 static void DetectDNP3Free(DetectEngineCtx *de_ctx, void *ptr)
383 {
384  SCEnter();
385  if (ptr != NULL) {
386  SCFree(ptr);
387  }
388  SCReturn;
389 }
390 
391 static int DetectDNP3FuncMatch(DetectEngineThreadCtx *det_ctx,
392  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
393  const SigMatchCtx *ctx)
394 {
395  DNP3Transaction *tx = (DNP3Transaction *)txv;
396  DetectDNP3 *detect = (DetectDNP3 *)ctx;
397  int match = 0;
398 
399  if (flags & STREAM_TOSERVER && tx->is_request) {
400  match = detect->function_code == tx->ah.function_code;
401  } else if (flags & STREAM_TOCLIENT && !tx->is_request) {
402  match = detect->function_code == tx->ah.function_code;
403  }
404 
405  return match;
406 }
407 
408 static int DetectDNP3ObjMatch(DetectEngineThreadCtx *det_ctx,
409  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
410  const SigMatchCtx *ctx)
411 {
412  DNP3Transaction *tx = (DNP3Transaction *)txv;
413  DetectDNP3 *detect = (DetectDNP3 *)ctx;
414  DNP3ObjectList *objects = NULL;
415 
416  if (flags & STREAM_TOSERVER && tx->is_request) {
417  objects = &tx->objects;
418  } else if (flags & STREAM_TOCLIENT && !tx->is_request) {
419  objects = &tx->objects;
420  }
421 
422  if (objects != NULL) {
423  DNP3Object *object;
424  TAILQ_FOREACH(object, objects, next) {
425  if (object->group == detect->obj_group &&
426  object->variation == detect->obj_variation) {
427  return 1;
428  }
429  }
430  }
431 
432  return 0;
433 }
434 
435 static int DetectDNP3IndMatch(DetectEngineThreadCtx *det_ctx,
436  Flow *f, uint8_t flags, void *state, void *txv, const Signature *s,
437  const SigMatchCtx *ctx)
438 {
439  DNP3Transaction *tx = (DNP3Transaction *)txv;
440  DetectDNP3 *detect = (DetectDNP3 *)ctx;
441 
442  if (flags & STREAM_TOCLIENT) {
443  if ((tx->iin.iin1 & (detect->ind_flags >> 8)) ||
444  (tx->iin.iin2 & (detect->ind_flags & 0xf))) {
445  return 1;
446  }
447  }
448 
449  return 0;
450 }
451 
452 static void DetectDNP3FuncRegister(void)
453 {
454  SCEnter();
455 
456  sigmatch_table[DETECT_AL_DNP3FUNC].name = "dnp3_func";
457  sigmatch_table[DETECT_AL_DNP3FUNC].alias = "dnp3.func";
458  sigmatch_table[DETECT_AL_DNP3FUNC].desc = "match on the application function code found in DNP3 request and responses";
459  sigmatch_table[DETECT_AL_DNP3FUNC].url = "/rules/dnp3-keywords.html#dnp3-func";
461  sigmatch_table[DETECT_AL_DNP3FUNC].AppLayerTxMatch = DetectDNP3FuncMatch;
462  sigmatch_table[DETECT_AL_DNP3FUNC].Setup = DetectDNP3FuncSetup;
463  sigmatch_table[DETECT_AL_DNP3FUNC].Free = DetectDNP3Free;
464 #ifdef UNITTESTS
466  DetectDNP3FuncRegisterTests;
467 #endif
468  SCReturn;
469 }
470 
471 static void DetectDNP3IndRegister(void)
472 {
473  SCEnter();
474 
475  sigmatch_table[DETECT_AL_DNP3IND].name = "dnp3_ind";
476  sigmatch_table[DETECT_AL_DNP3IND].alias = "dnp3.ind";
477  sigmatch_table[DETECT_AL_DNP3IND].desc = "match on the DNP3 internal indicator flags in the response application header";
478  sigmatch_table[DETECT_AL_DNP3IND].url = "/rules/dnp3-keywords.html#dnp3-ind";
480  sigmatch_table[DETECT_AL_DNP3IND].AppLayerTxMatch = DetectDNP3IndMatch;
481  sigmatch_table[DETECT_AL_DNP3IND].Setup = DetectDNP3IndSetup;
482  sigmatch_table[DETECT_AL_DNP3IND].Free = DetectDNP3Free;
483 #ifdef UNITTESTS
485  DetectDNP3IndRegisterTests;
486 #endif
487  SCReturn;
488 }
489 
490 static void DetectDNP3ObjRegister(void)
491 {
492  SCEnter();
493 
494  sigmatch_table[DETECT_AL_DNP3OBJ].name = "dnp3_obj";
495  sigmatch_table[DETECT_AL_DNP3OBJ].alias = "dnp3.obj";
496  sigmatch_table[DETECT_AL_DNP3OBJ].desc = "match on the DNP3 application data objects";
497  sigmatch_table[DETECT_AL_DNP3OBJ].url = "/rules/dnp3-keywords.html#dnp3-obj";
499  sigmatch_table[DETECT_AL_DNP3OBJ].AppLayerTxMatch = DetectDNP3ObjMatch;
500  sigmatch_table[DETECT_AL_DNP3OBJ].Setup = DetectDNP3ObjSetup;
501  sigmatch_table[DETECT_AL_DNP3OBJ].Free = DetectDNP3Free;
502 #ifdef UNITTESTS
504  DetectDNP3ObjRegisterTests;
505 #endif
506  SCReturn;
507 }
508 
509 static int DetectDNP3DataSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
510 {
511  SCEnter();
513  return -1;
514 
515  if (DetectBufferSetActiveList(de_ctx, s, g_dnp3_data_buffer_id) != 0)
516  return -1;
517 
518  SCReturnInt(0);
519 }
520 
521 static void DetectDNP3DataRegister(void)
522 {
523  SCEnter();
524 
525  sigmatch_table[DETECT_AL_DNP3DATA].name = "dnp3.data";
526  sigmatch_table[DETECT_AL_DNP3DATA].alias = "dnp3_data";
527  sigmatch_table[DETECT_AL_DNP3DATA].desc = "make the following content options to match on the re-assembled application buffer";
528  sigmatch_table[DETECT_AL_DNP3DATA].url = "/rules/dnp3-keywords.html#dnp3-data";
529  sigmatch_table[DETECT_AL_DNP3DATA].Setup = DetectDNP3DataSetup;
531 
533  DetectEngineInspectBufferGeneric, GetDNP3Data);
535  GetDNP3Data, ALPROTO_DNP3, 0);
536 
538  DetectEngineInspectBufferGeneric, GetDNP3Data);
540  GetDNP3Data, ALPROTO_DNP3, 0);
541 
542  g_dnp3_data_buffer_id = DetectBufferTypeGetByName("dnp3_data");
543  SCReturn;
544 }
545 
547 {
548  DetectDNP3DataRegister();
549 
550  DetectDNP3FuncRegister();
551  DetectDNP3IndRegister();
552  DetectDNP3ObjRegister();
553 
554  /* Register the list of func, ind and obj. */
559 
560  g_dnp3_match_buffer_id = DetectBufferTypeRegister("dnp3");
561 
562 }
563 
564 #ifdef UNITTESTS
565 
566 #include "util-unittest.h"
567 #include "util-unittest-helper.h"
568 #include "app-layer-parser.h"
569 #include "flow-util.h"
570 #include "stream-tcp.h"
571 
572 static int DetectDNP3FuncParseFunctionCodeTest(void)
573 {
574  uint8_t fc;
575 
576  /* Valid. */
577  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("0", &fc));
578  FAIL_IF(fc != 0);
579 
580  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("1", &fc));
581  FAIL_IF(fc != 1);
582 
583  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("254", &fc));
584  FAIL_IF(fc != 254);
585 
586  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("255", &fc));
587  FAIL_IF(fc != 255);
588 
589  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("confirm", &fc));
590  FAIL_IF(fc != 0);
591 
592  FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode("CONFIRM", &fc));
593  FAIL_IF(fc != 0);
594 
595  /* Invalid. */
596  FAIL_IF(DetectDNP3FuncParseFunctionCode("", &fc));
597  FAIL_IF(DetectDNP3FuncParseFunctionCode("-1", &fc));
598  FAIL_IF(DetectDNP3FuncParseFunctionCode("-2", &fc));
599  FAIL_IF(DetectDNP3FuncParseFunctionCode("256", &fc));
600  FAIL_IF(DetectDNP3FuncParseFunctionCode("unknown_function_code", &fc));
601 
602  PASS;
603 }
604 
605 static int DetectDNP3FuncTest01(void)
606 {
609 
610  Signature *s = DetectEngineAppendSig(de_ctx, "alert dnp3 any any -> any any "
611  "(msg:\"SURICATA DNP3 Write request\"; "
612  "dnp3_func:2; sid:5000009; rev:1;)");
614 
615  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_dnp3_match_buffer_id);
616  FAIL_IF_NULL(sm);
617  FAIL_IF_NULL(sm->ctx);
618 
619  DetectDNP3 *dnp3func = (DetectDNP3 *)sm->ctx;
620  FAIL_IF(dnp3func->function_code != 2);
621 
623  PASS;
624 }
625 
626 static int DetectDNP3IndTestParseAsInteger(void)
627 {
628  uint16_t flags = 0;
629 
630  FAIL_IF(!DetectDNP3IndParse("0", &flags));
631  FAIL_IF(flags != 0);
632  FAIL_IF(!DetectDNP3IndParse("1", &flags));
633  FAIL_IF(flags != 0x0001);
634 
635  FAIL_IF(!DetectDNP3IndParse("0x0", &flags));
636  FAIL_IF(flags != 0);
637  FAIL_IF(!DetectDNP3IndParse("0x0000", &flags));
638  FAIL_IF(flags != 0);
639  FAIL_IF(!DetectDNP3IndParse("0x0001", &flags));
640  FAIL_IF(flags != 0x0001);
641 
642  FAIL_IF(!DetectDNP3IndParse("0x8421", &flags));
643  FAIL_IF(flags != 0x8421);
644 
645  FAIL_IF(DetectDNP3IndParse("a", &flags));
646 
647  PASS;
648 }
649 
650 static int DetectDNP3IndTestParseByName(void)
651 {
652  uint16_t flags = 0;
653 
654  FAIL_IF(!DetectDNP3IndParse("all_stations", &flags));
655  FAIL_IF(!(flags & 0x0100));
656  FAIL_IF(!DetectDNP3IndParse("class_1_events , class_2_events", &flags));
657  FAIL_IF(!(flags & 0x0200));
658  FAIL_IF(!(flags & 0x0400));
659  FAIL_IF((flags & 0xf9ff));
660 
661  FAIL_IF(DetectDNP3IndParse("something", &flags));
662 
663  PASS;
664 }
665 
666 static int DetectDNP3ObjSetupTest(void)
667 {
669  FAIL_IF(de_ctx == NULL);
670 
671  Signature *s = DetectEngineAppendSig(de_ctx, "alert dnp3 any any -> any any "
672  "(msg:\"SURICATA DNP3 Object Test\"; "
673  "dnp3_obj:99,99; sid:1; rev:1;)");
674  FAIL_IF(de_ctx->sig_list == NULL);
675 
676  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_dnp3_match_buffer_id);
677  FAIL_IF_NULL(sm);
678  FAIL_IF_NULL(sm->ctx);
679 
680  DetectDNP3 *detect = (DetectDNP3 *)sm->ctx;
681  FAIL_IF(detect->obj_group != 99);
682  FAIL_IF(detect->obj_variation != 99);
683 
685  PASS;
686 }
687 
688 static int DetectDNP3ObjParseTest(void)
689 {
690  uint8_t group, var;
691 
692  FAIL_IF(!DetectDNP3ObjParse("0,0", &group, &var));
693  FAIL_IF(group != 0 || var != 0);
694 
695  FAIL_IF(!DetectDNP3ObjParse("255,255", &group, &var));
696  FAIL_IF(group != 255 || var != 255);
697 
698  FAIL_IF(DetectDNP3ObjParse("-1,-1", &group, &var));
699  FAIL_IF(DetectDNP3ObjParse("256,256", &group, &var));
700  FAIL_IF(DetectDNP3ObjParse("a,1", &group, &var));
701  FAIL_IF(DetectDNP3ObjParse("1,a", &group, &var));
702 
703  PASS;
704 }
705 
706 static void DetectDNP3FuncRegisterTests(void)
707 {
708  UtRegisterTest("DetectDNP3FuncParseFunctionCodeTest",
709  DetectDNP3FuncParseFunctionCodeTest);
710  UtRegisterTest("DetectDNP3FuncTest01", DetectDNP3FuncTest01);
711 }
712 
713 static void DetectDNP3IndRegisterTests(void)
714 {
715  UtRegisterTest("DetectDNP3IndTestParseAsInteger",
716  DetectDNP3IndTestParseAsInteger);
717  UtRegisterTest("DetectDNP3IndTestParseByName",
718  DetectDNP3IndTestParseByName);
719 }
720 
721 static void DetectDNP3ObjRegisterTests(void)
722 {
723  UtRegisterTest("DetectDNP3ObjParseTest", DetectDNP3ObjParseTest);
724  UtRegisterTest("DetectDNP3ObjSetupTest", DetectDNP3ObjSetupTest);
725 }
726 #endif
util-byte.h
DETECT_AL_DNP3IND
@ DETECT_AL_DNP3IND
Definition: detect-engine-register.h:258
SigTableElmt_::url
const char * url
Definition: detect.h:1299
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1753
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:1500
SigTableElmt_::desc
const char * desc
Definition: detect.h:1298
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:2122
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1286
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1296
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:409
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectDNP3Register
void DetectDNP3Register(void)
Definition: detect-dnp3.c:546
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
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
DetectBufferSetActiveList
int DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition: detect-engine.c:1335
InspectionBuffer
Definition: detect.h:374
Flow_
Flow data structure.
Definition: flow.h:351
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1290
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:839
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:337
DETECT_AL_DNP3FUNC
@ DETECT_AL_DNP3FUNC
Definition: detect-engine-register.h:257
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2533
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1267
DetectDNP3_
Definition: detect-dnp3.c:39
DNP3Transaction_::objects
DNP3ObjectList objects
Definition: app-layer-dnp3.h:221
detect-dnp3.h
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2620
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:267
DNP3Transaction_::buffer_len
uint32_t buffer_len
Definition: app-layer-dnp3.h:220
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1281
DetectDNP3_::function_code
uint8_t function_code
Definition: detect-dnp3.c:43
detect-engine-prefilter.h
util-unittest.h
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1479
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:1072
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
DNP3IndicatorsMap
DNP3Mapping DNP3IndicatorsMap[]
Definition: detect-dnp3.c:60
StringParseUint8
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:361
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:266
DNP3Transaction_::ah
DNP3ApplicationHeader ah
Definition: app-layer-dnp3.h:224
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectDNP3_::ind_flags
uint16_t ind_flags
Definition: detect-dnp3.c:47
DetectEngineThreadCtx_
Definition: detect.h:1095
DNP3Transaction_::iin
DNP3InternalInd iin
Definition: app-layer-dnp3.h:225
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition: app-layer-protos.h:44
app-layer-dnp3.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
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:745
DetectAppLayerMpmRegister
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register a MPM engine
Definition: detect-engine-mpm.c:89
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:353
SCReturn
#define SCReturn
Definition: util-debug.h:273
stream.h
DNP3Object_::group
uint8_t group
Definition: app-layer-dnp3.h:193
variation
uint8_t variation
Definition: app-layer-dnp3.h:1
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1264
DetectDNP3_::obj_variation
uint8_t obj_variation
Definition: detect-dnp3.c:52
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:345
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:1008
flags
uint8_t flags
Definition: decode-gre.h:0
SigTableElmt_::alias
const char * alias
Definition: detect.h:1297
group
uint8_t group
Definition: app-layer-dnp3.h:0
suricata-common.h
DetectDNP3_::obj_group
uint8_t obj_group
Definition: detect-dnp3.c:51
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1678
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:127
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine.c:1304
DNP3Mapping_::value
uint16_t value
Definition: detect-dnp3.h:26
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:847
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:2079
DNP3Mapping_
Definition: detect-dnp3.h:24
DETECT_AL_DNP3DATA
@ DETECT_AL_DNP3DATA
Definition: detect-engine-register.h:256
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect.h:375
str
#define str(s)
Definition: suricata-common.h:291
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
InspectionBufferSetup
void InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1574
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:596
SigMatch_
a single match condition for a signature
Definition: detect.h:350
function_code
uint8_t function_code
Definition: app-layer-dnp3.h:1
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2494
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1476
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:169
DetectDNP3
struct DetectDNP3_ DetectDNP3
SigMatchAppendSMToList
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:447
DNP3FunctionNameMap
DNP3Mapping DNP3FunctionNameMap[]
Definition: detect-dnp3.c:85
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
DNP3Transaction_
DNP3 transaction.
Definition: app-layer-dnp3.h:211
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1288
DETECT_AL_DNP3OBJ
@ DETECT_AL_DNP3OBJ
Definition: detect-engine-register.h:259
DNP3Transaction_::buffer
uint8_t * buffer
Definition: app-layer-dnp3.h:219