Go to the documentation of this file.
46 #define PARSE_REGEX "^\\s*([0-9]{0,10})\\s*(?:,\\s*([0-9]{0,10}|[*])\\s*(?:,\\s*([0-9]{0,10}|[*]))?)?\\s*$"
54 static void DetectRpcRegisterTests(
void);
97 char *rpcmsg = (
char *)p->
payload;
106 }
else if (PacketIsUDP(p)) {
113 SCLogDebug(
"No valid proto for the rpc message");
151 char *args[3] = {NULL,NULL,NULL};
155 pcre2_match_data *match = NULL;
157 if (ret < 1 || ret > 4) {
158 SCLogError(
"parse error, ret %" PRId32
", string %s", ret, rpcstr);
164 res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
166 SCLogError(
"pcre2_substring_get_bynumber failed");
169 args[0] = (
char *)str_ptr;
172 res = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
174 SCLogError(
"pcre2_substring_get_bynumber failed");
177 args[1] = (
char *)str_ptr;
180 res = pcre2_substring_get_bynumber(match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
182 SCLogError(
"pcre2_substring_get_bynumber failed");
185 args[2] = (
char *)str_ptr;
198 for (i = 0; i < (ret - 1); i++) {
203 SCLogError(
"Invalid size specified for the rpc program:\"%s\"", args[i]);
209 if (args[i][0] !=
'*') {
212 "Invalid size specified for the rpc version:\"%s\"", args[i]);
219 if (args[i][0] !=
'*') {
222 "Invalid size specified for the rpc procedure:\"%s\"", args[i]);
234 for (i = 0; i < (ret -1); i++){
236 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
238 pcre2_match_data_free(match);
243 pcre2_match_data_free(match);
245 for (i = 0; i < (ret -1) && i < 3; i++){
247 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
270 rd = DetectRpcParse(
de_ctx, rpcstr);
271 if (rd == NULL)
goto error;
313 static int DetectRpcTestParse01 (
void)
325 static int DetectRpcTestParse02 (
void)
328 rd = DetectRpcParse(NULL,
"111,222,333");
346 static int DetectRpcTestParse03 (
void)
350 rd = DetectRpcParse(NULL,
"111,*,333");
362 rd = DetectRpcParse(NULL,
"111,222,*");
374 rd = DetectRpcParse(NULL,
"111,*,*");
386 rd = DetectRpcParse(NULL,
"111,222");
398 rd = DetectRpcParse(NULL,
"111");
415 static int DetectRpcTestParse04 (
void)
418 rd = DetectRpcParse(NULL,
"");
429 static int DetectRpcTestParse05 (
void)
432 rd = DetectRpcParse(NULL,
"111,aaa,*");
443 static int DetectRpcTestSig01(
void)
474 0x00,0x00,0x00,0x00 };
475 uint16_t buflen =
sizeof(buf);
481 memset(&th_v, 0,
sizeof(th_v));
491 "alert udp any any -> any any (msg:\"RPC Get Port Call\"; rpc:100000, 2, 3; sid:1;)");
495 "alert udp any any -> any any (msg:\"RPC Get Port Call\"; rpc:100000, 2, *; sid:2;)");
499 "alert udp any any -> any any (msg:\"RPC Get Port Call\"; rpc:100000, *, 3; sid:3;)");
503 "alert udp any any -> any any (msg:\"RPC Get Port Call\"; rpc:100000, *, *; sid:4;)");
507 "match\"; rpc:123456, *, 3; sid:5;)");
531 static void DetectRpcRegisterTests(
void)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define PARSE_REGEX
Regex for parsing our rpc options.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
void DetectRpcRegister(void)
Registration function for rpc keyword.
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
#define DETECT_RPC_CHECK_PROCEDURE
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define PASS
Pass the test.
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Per thread variable structure.
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
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.
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
void DetectRpcFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectRpcData
#define SCLogError(...)
Macro used to log ERROR messages.
DetectEngineCtx * DetectEngineCtxInit(void)
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
#define DETECT_RPC_CHECK_PROGRAM
#define DETECT_RPC_CHECK_VERSION
void(* RegisterTests)(void)
#define SIG_FLAG_REQUIRE_PACKET
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.