suricata
detect-parse.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef SURICATA_DETECT_PARSE_H
25 #define SURICATA_DETECT_PARSE_H
26 
27 #include "action-globals.h"
28 #include "app-layer-protos.h"
29 #include "detect-engine-register.h"
30 // types from detect.h with only forward declarations for bindgen
31 typedef struct DetectEngineCtx_ DetectEngineCtx;
32 typedef struct Signature_ Signature;
33 typedef struct SigMatchCtx_ SigMatchCtx;
34 typedef struct SigMatch_ SigMatch;
35 typedef struct SigMatchData_ SigMatchData;
37 
38 /** Flags to indicate if the Signature parsing must be done
39 * switching the source and dest (for ip addresses and ports)
40 * or otherwise as normal */
41 enum {
44 };
45 
46 /** Flags to indicate if are referencing the source of the Signature
47 * or the destination (for ip addresses and ports)*/
48 enum {
51 };
52 
53 /* prototypes */
55 Signature *SigAlloc(void);
57 Signature *SigInit(DetectEngineCtx *, const char *sigstr);
59 void SigParseRegisterTests(void);
62 
65 int SigMatchListSMBelongsTo(const Signature *, const SigMatch *);
66 
69 
71  Signature *s, const char *arg, int sm_type, int sm_list,
72  AppProto alproto);
73 
74 bool SCSigMatchSilentErrorEnabled(const DetectEngineCtx *de_ctx, uint16_t id);
75 bool SigMatchStrictEnabled(const enum DetectKeywordId id);
76 
77 const char *DetectListToHumanString(int list);
78 const char *DetectListToString(int list);
79 
81 
85 SigMatch *DetectGetLastSMByListPtr(const Signature *s, SigMatch *sm_list, ...);
86 SigMatch *DetectGetLastSMByListId(const Signature *s, int list_id, ...);
87 
90 
91 /* parse regex setup and free util funcs */
92 
93 #ifndef SURICATA_BINDGEN_H
94 typedef struct DetectParseRegex {
95  pcre2_code *regex;
96  pcre2_match_context *context;
99 
100 DetectParseRegex *DetectSetupPCRE2(const char *parse_str, int opts);
101 bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts);
102 void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex);
104 void DetectParseFreeRegexes(void);
106 
107 /* parse regex exec */
108 int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str,
109  int start_offset, int options);
111  pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen);
112 int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr,
113  PCRE2_SIZE *bufflen);
114 #endif
115 
118 
119 const char *ActionScopeToString(enum ActionScope s);
120 
121 struct DetectFirewallPolicy;
122 void DetectFirewallPolicyToString(const struct DetectFirewallPolicy *p, char *out, size_t out_size);
126  const AppProto alproto, const int direction, const uint8_t hook);
127 
128 #endif /* SURICATA_DETECT_PARSE_H */
SigMatchRemoveSMFromList
void SigMatchRemoveSMFromList(Signature *, SigMatch *, int)
Definition: detect-parse.c:486
DetectFirewallPolicies
Definition: detect.h:937
DetectSetupPCRE2
DetectParseRegex * DetectSetupPCRE2(const char *parse_str, int opts)
Definition: detect-parse.c:3710
DetectFirewallGetPolicySignature
Signature * DetectFirewallGetPolicySignature(struct DetectFirewallPolicies *fw_policies, const AppProto alproto, const int direction, const uint8_t hook)
Definition: detect-parse.c:4138
DetectParseRegex
Definition: detect-parse.h:94
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *, Signature *, uint16_t, SigMatchCtx *, int)
Append a SigMatch to the list type.
Definition: detect-parse.c:387
DetectFirewallRuleAppendNew
Signature * DetectFirewallRuleAppendNew(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3508
DetectParseRegex::context
pcre2_match_context * context
Definition: detect-parse.h:96
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:87
action-globals.h
DetectParseFreeRegex
void DetectParseFreeRegex(DetectParseRegex *r)
Definition: detect-parse.c:3644
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:973
DetectParseRegexAddToFreeList
void DetectParseRegexAddToFreeList(DetectParseRegex *parse_regex)
add regex and/or study to at exit free list
Definition: detect-parse.c:3670
detect-engine-register.h
SCSigMatchSilentErrorEnabled
bool SCSigMatchSilentErrorEnabled(const DetectEngineCtx *de_ctx, uint16_t id)
Definition: detect-parse.c:330
SIG_DIREC_SRC
@ SIG_DIREC_SRC
Definition: detect-parse.h:49
SigTableApplyStrictCommandLineOption
void SigTableApplyStrictCommandLineOption(const char *str)
Definition: detect-parse.c:343
DetectParseRegex::regex
pcre2_code * regex
Definition: detect-parse.h:95
DetectKeywordId
DetectKeywordId
Definition: detect-engine-register.h:27
DetectParseDupSigHashInit
int DetectParseDupSigHashInit(DetectEngineCtx *)
Initializes the hash table that is used to cull duplicate sigs.
Definition: detect-parse.c:3313
p
Packet * p
Definition: fuzz_iprep.c:21
SigMatchData_
Data needed for Match()
Definition: detect.h:365
DetectParseFreeRegexes
void DetectParseFreeRegexes(void)
Definition: detect-parse.c:3654
DetectParseRegex::next
struct DetectParseRegex * next
Definition: detect-parse.h:97
SC_Pcre2SubstringCopy
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:3736
ActionScopeToString
const char * ActionScopeToString(enum ActionScope s)
Definition: detect-parse.c:3796
DetectGetLastSMByListId
SigMatch * DetectGetLastSMByListId(const Signature *s, int list_id,...)
Returns the sm with the largest index (added last) from the list passed to us as an id.
Definition: detect-parse.c:657
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex)
Definition: detect-parse.c:3760
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectGetLastSM
SigMatch * DetectGetLastSM(const Signature *)
Returns the sm with the largest index (added latest) from this sig.
Definition: detect-parse.c:708
DetectListToHumanString
const char * DetectListToHumanString(int list)
Definition: detect-parse.c:112
DetectParseRegex
struct DetectParseRegex DetectParseRegex
SCDetectGetLastSMFromLists
SigMatch * SCDetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:563
SigMatchStrictEnabled
bool SigMatchStrictEnabled(const enum DetectKeywordId id)
Definition: detect-parse.c:335
DetectFirewallPolicyToString
void DetectFirewallPolicyToString(const struct DetectFirewallPolicy *p, char *out, size_t out_size)
Definition: detect-parse.c:3814
SigFree
void SigFree(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-parse.c:2126
DetectGetLastSMFromMpmLists
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
Definition: detect-parse.c:526
SigInit
Signature * SigInit(DetectEngineCtx *, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3238
DetectSignatureSetMultiAppProto
int WARN_UNUSED DetectSignatureSetMultiAppProto(Signature *s, const AppProto *alprotos)
this function is used to set multiple possible app-layer protos
Definition: detect-parse.c:2223
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:3634
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *, const SigMatch *)
Definition: detect-parse.c:762
SigMatchList2DataArray
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
Definition: detect-parse.c:2437
DetectFirewallLoadDefaultPolicies
int DetectFirewallLoadDefaultPolicies(DetectEngineCtx *)
Definition: detect-parse.c:4057
DetectFirewallInitDefaultPolicies
int DetectFirewallInitDefaultPolicies(DetectEngineCtx *)
allocate and initialize to default values the policies table
Definition: detect-parse.c:4018
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:351
SIG_DIREC_DST
@ SIG_DIREC_DST
Definition: detect-parse.h:50
DetectSetupParseRegexesOpts
bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts)
Definition: detect-parse.c:3681
DetectGetLastSMByListPtr
SigMatch * DetectGetLastSMByListPtr(const Signature *s, SigMatch *sm_list,...)
Returns the sm with the largest index (added last) from the list passed to us as a pointer.
Definition: detect-parse.c:625
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition: detect-parse.c:146
ActionScope
ActionScope
Definition: action-globals.h:42
SignatureInitDataBufferCheckExpand
int SignatureInitDataBufferCheckExpand(Signature *s)
check if buffers array still has space left, expand if not
Definition: detect-parse.c:1986
SIG_DIREC_SWITCHED
@ SIG_DIREC_SWITCHED
Definition: detect-parse.h:43
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:2006
str
#define str(s)
Definition: suricata-common.h:316
DetectFirewallPolicy
Definition: detect.h:924
head
Flow * head
Definition: flow-hash.h:1
SigParseRegisterTests
void SigParseRegisterTests(void)
Definition: detect-parse.c:5920
Signature_
Signature container.
Definition: detect.h:675
SigMatch_
a single match condition for a signature
Definition: detect.h:356
SC_Pcre2SubstringGet
int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:3748
WARN_UNUSED
#define WARN_UNUSED
Definition: bindgen.h:33
app-layer-protos.h
DetectListToString
const char * DetectListToString(int list)
Definition: detect-parse.c:130
DetectListSupportedProtocols
void DetectListSupportedProtocols(void)
Definition: detect-parse.c:1373
DetectParseDupSigHashFree
void DetectParseDupSigHashFree(DetectEngineCtx *)
Frees the hash table that is used to cull duplicate sigs.
Definition: detect-parse.c:3330
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3580
DetectRegisterAppLayerHookLists
void DetectRegisterAppLayerHookLists(void)
register app hooks as generic lists
Definition: detect-parse.c:1156
SIG_DIREC_NORMAL
@ SIG_DIREC_NORMAL
Definition: detect-parse.h:42
SCDetectSignatureSetAppProto
int WARN_UNUSED SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2301