Go to the documentation of this file.
33 static int g_dnp3_match_buffer_id = 0;
34 static int g_dnp3_data_buffer_id = 0;
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},
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},
91 {
"direct_operate", 5},
92 {
"direct_operate_nr", 6},
94 {
"immed_freeze_nr", 8},
96 {
"freeze_clear_nr", 10},
97 {
"freeze_at_time", 11},
98 {
"freeze_at_time_nr", 12},
100 {
"warm_restart", 14},
101 {
"initialize_data", 15},
102 {
"initialize_appl", 16},
106 {
"enable_unsolicited", 20},
107 {
"disable_unsolicited", 21},
108 {
"assign_class", 22},
109 {
"delay_measure", 23},
110 {
"record_current_time", 24},
114 {
"get_file_info", 28},
115 {
"authenticate_file", 29},
117 {
"activate_config", 31},
118 {
"authenticate_req", 32},
119 {
"authenticate_err", 33},
121 {
"unsolicited_response", 130},
122 {
"authenticate_resp", 131}
126 static void DetectDNP3FuncRegisterTests(
void);
127 static void DetectDNP3IndRegisterTests(
void);
128 static void DetectDNP3ObjRegisterTests(
void);
135 static char *TrimString(
char *
str)
137 char *end =
str + strlen(
str) - 1;
138 while (isspace(*
str)) {
141 while (end >
str && isspace(*end)) {
150 Flow *_f,
const uint8_t flow_flags,
151 void *txv,
const int list_id)
159 if ((flow_flags & STREAM_TOSERVER && !tx->
is_request) ||
160 (flow_flags & STREAM_TOCLIENT && tx->
is_request)) {
186 static int DetectDNP3FuncParseFunctionCode(
const char *
str, uint8_t *fc)
214 SCLogError(
"Invalid argument \"%s\" supplied to dnp3_func keyword.",
str);
225 g_dnp3_match_buffer_id) == NULL) {
237 static int DetectDNP3IndParseByName(
const char *
str, uint16_t *
flags)
239 char tmp[strlen(
str) + 1];
240 char *p, *last = NULL;
244 for ((p = strtok_r(tmp,
",", &last)); p; (p = strtok_r(NULL,
",", &last))) {
258 SCLogError(
"Bad argument \"%s\" supplied to dnp3.ind keyword.", p);
266 static int DetectDNP3IndParse(
const char *
str, uint16_t *
flags)
275 if (DetectDNP3IndParseByName(
str,
flags)) {
291 if (!DetectDNP3IndParse(
str, &
flags)) {
292 SCLogError(
"Invalid argument \"%s\" supplied to dnp3.ind keyword.",
str);
303 g_dnp3_match_buffer_id) == NULL) {
309 if (detect != NULL) {
324 static int DetectDNP3ObjParse(
const char *
str, uint8_t *
group, uint8_t *var)
326 size_t size = strlen(
str) + 1;
327 char groupstr[size], *varstr, *sep;
330 sep = strchr(groupstr,
',');
362 detect =
SCCalloc(1,
sizeof(*detect));
370 g_dnp3_match_buffer_id) == NULL) {
376 if (detect != NULL) {
414 DNP3ObjectList *objects = NULL;
422 if (objects != NULL) {
442 if (
flags & STREAM_TOCLIENT) {
452 static void DetectDNP3FuncRegister(
void)
466 DetectDNP3FuncRegisterTests;
471 static void DetectDNP3IndRegister(
void)
485 DetectDNP3IndRegisterTests;
490 static void DetectDNP3ObjRegister(
void)
504 DetectDNP3ObjRegisterTests;
521 static void DetectDNP3DataRegister(
void)
548 DetectDNP3DataRegister();
550 DetectDNP3FuncRegister();
551 DetectDNP3IndRegister();
552 DetectDNP3ObjRegister();
572 static int DetectDNP3FuncParseFunctionCodeTest(
void)
577 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"0", &fc));
580 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"1", &fc));
583 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"254", &fc));
586 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"255", &fc));
589 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"confirm", &fc));
592 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"CONFIRM", &fc));
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));
605 static int DetectDNP3FuncTest01(
void)
611 "(msg:\"SURICATA DNP3 Write request\"; "
612 "dnp3_func:2; sid:5000009; rev:1;)");
626 static int DetectDNP3IndTestParseAsInteger(
void)
650 static int DetectDNP3IndTestParseByName(
void)
656 FAIL_IF(!DetectDNP3IndParse(
"class_1_events , class_2_events", &
flags));
666 static int DetectDNP3ObjSetupTest(
void)
672 "(msg:\"SURICATA DNP3 Object Test\"; "
673 "dnp3_obj:99,99; sid:1; rev:1;)");
688 static int DetectDNP3ObjParseTest(
void)
706 static void DetectDNP3FuncRegisterTests(
void)
709 DetectDNP3FuncParseFunctionCodeTest);
713 static void DetectDNP3IndRegisterTests(
void)
716 DetectDNP3IndTestParseAsInteger);
718 DetectDNP3IndTestParseByName);
721 static void DetectDNP3ObjRegisterTests(
void)
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
#define SIGMATCH_INFO_STICKY_BUFFER
SigTableElmt * sigmatch_table
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.
void(* Free)(DetectEngineCtx *, void *)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void DetectDNP3Register(void)
struct HtpBodyChunk_ * next
Struct to hold the list of decoded objects.
int DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
#define TAILQ_FOREACH(var, head, field)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
#define SIG_FLAG_TOCLIENT
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
int DetectBufferTypeGetByName(const char *name)
size_t strlcpy(char *dst, const char *src, size_t siz)
DNP3Mapping DNP3IndicatorsMap[]
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
#define SIG_FLAG_TOSERVER
#define PASS
Pass the test.
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
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
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
int DetectBufferTypeRegister(const char *name)
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
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.
#define SCLogError(...)
Macro used to log ERROR messages.
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
a single match condition for a signature
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
struct DetectDNP3_ DetectDNP3
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
DNP3Mapping DNP3FunctionNameMap[]
void(* RegisterTests)(void)