Go to the documentation of this file.
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;
65 {
"direct_operate", 5},
66 {
"direct_operate_nr", 6},
68 {
"immed_freeze_nr", 8},
70 {
"freeze_clear_nr", 10},
71 {
"freeze_at_time", 11},
72 {
"freeze_at_time_nr", 12},
75 {
"initialize_data", 15},
76 {
"initialize_appl", 16},
80 {
"enable_unsolicited", 20},
81 {
"disable_unsolicited", 21},
83 {
"delay_measure", 23},
84 {
"record_current_time", 24},
88 {
"get_file_info", 28},
89 {
"authenticate_file", 29},
91 {
"activate_config", 31},
92 {
"authenticate_req", 32},
93 {
"authenticate_err", 33},
95 {
"unsolicited_response", 130},
96 {
"authenticate_resp", 131}
100 static void DetectDNP3FuncRegisterTests(
void);
101 static void DetectDNP3ObjRegisterTests(
void);
106 Flow *_f,
const uint8_t flow_flags,
107 void *txv,
const int list_id)
115 if ((flow_flags & STREAM_TOSERVER && !tx->
is_request) ||
116 (flow_flags & STREAM_TOCLIENT && tx->
is_request)) {
142 static int DetectDNP3FuncParseFunctionCode(
const char *
str, uint8_t *fc)
170 SCLogError(
"Invalid argument \"%s\" supplied to dnp3_func keyword.",
str);
195 SCDetectU16Free(ptr);
206 if (detect == NULL) {
207 SCLogError(
"Invalid argument \"%s\" supplied to dnp3.ind keyword.",
str);
218 if (detect != NULL) {
219 DetectDNP3IndFree(NULL, detect);
233 static int DetectDNP3ObjParse(
const char *
str, uint8_t *
group, uint8_t *var)
235 size_t size = strlen(
str) + 1;
236 char groupstr[size], *varstr, *sep;
239 sep = strchr(groupstr,
',');
271 detect =
SCCalloc(1,
sizeof(*detect));
285 if (detect != NULL) {
323 DNP3ObjectList *objects = NULL;
331 if (objects != NULL) {
354 static void DetectDNP3FuncRegister(
void)
361 "match on the application function code found in DNP3 request and responses";
373 static void DetectDNP3IndRegister(
void)
380 "match on the DNP3 internal indicator flags in the response application header";
390 static void DetectDNP3ObjRegister(
void)
420 static void DetectDNP3DataRegister(
void)
427 "make the following content options to match on the re-assembled application buffer";
448 DetectDNP3DataRegister();
450 DetectDNP3FuncRegister();
451 DetectDNP3IndRegister();
452 DetectDNP3ObjRegister();
475 static int DetectDNP3FuncParseFunctionCodeTest(
void)
480 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"0", &fc));
483 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"1", &fc));
486 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"254", &fc));
489 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"255", &fc));
492 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"confirm", &fc));
495 FAIL_IF_NOT(DetectDNP3FuncParseFunctionCode(
"CONFIRM", &fc));
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));
508 static int DetectDNP3FuncTest01(
void)
514 "(msg:\"SURICATA DNP3 Write request\"; "
515 "dnp3_func:2; sid:5000009; rev:1;)");
529 static int DetectDNP3ObjSetupTest(
void)
535 "(msg:\"SURICATA DNP3 Object Test\"; "
536 "dnp3_obj:99,99; sid:1; rev:1;)");
551 static int DetectDNP3ObjParseTest(
void)
569 static void DetectDNP3FuncRegisterTests(
void)
572 DetectDNP3FuncParseFunctionCodeTest);
576 static void DetectDNP3ObjRegisterTests(
void)
#define SIGMATCH_INFO_UINT16
#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 *)
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
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.
main detection engine ctx
#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 *)
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
#define SIG_FLAG_TOCLIENT
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#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)
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
#define SIG_FLAG_TOSERVER
#define PASS
Pass the test.
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
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
#define SIGMATCH_INFO_BITFLAGS_UINT
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)
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
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.
a single match condition for a signature
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
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
DetectUintData_u16 DetectU16Data
DNP3Mapping DNP3FunctionNameMap[]
void(* RegisterTests)(void)