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 "app-layer-protos.h"
28 #include "detect-engine-register.h"
29 // types from detect.h with only forward declarations for bindgen
30 typedef struct DetectEngineCtx_ DetectEngineCtx;
31 typedef struct Signature_ Signature;
32 typedef struct SigMatchCtx_ SigMatchCtx;
33 typedef struct SigMatch_ SigMatch;
34 typedef struct SigMatchData_ SigMatchData;
35 
36 /** Flags to indicate if the Signature parsing must be done
37 * switching the source and dest (for ip addresses and ports)
38 * or otherwise as normal */
39 enum {
42 };
43 
44 /** Flags to indicate if are referencing the source of the Signature
45 * or the destination (for ip addresses and ports)*/
46 enum {
49 };
50 
51 /* prototypes */
53 Signature *SigAlloc(void);
55 Signature *SigInit(DetectEngineCtx *, const char *sigstr);
57 void SigParseRegisterTests(void);
60 
63 int SigMatchListSMBelongsTo(const Signature *, const SigMatch *);
64 
67 
69  Signature *s, const char *arg, int sm_type, int sm_list,
70  AppProto alproto);
71 
73  const enum DetectKeywordId id);
74 bool SigMatchStrictEnabled(const enum DetectKeywordId id);
75 
76 const char *DetectListToHumanString(int list);
77 const char *DetectListToString(int list);
78 
80 
84 SigMatch *DetectGetLastSMByListPtr(const Signature *s, SigMatch *sm_list, ...);
85 SigMatch *DetectGetLastSMByListId(const Signature *s, int list_id, ...);
86 
89 
90 /* parse regex setup and free util funcs */
91 
92 #ifndef SURICATA_BINDGEN_H
93 typedef struct DetectParseRegex {
94  pcre2_code *regex;
95  pcre2_match_context *context;
98 
99 DetectParseRegex *DetectSetupPCRE2(const char *parse_str, int opts);
100 bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts);
101 void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex);
103 void DetectParseFreeRegexes(void);
105 
106 /* parse regex exec */
107 int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str,
108  int start_offset, int options);
110  pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen);
111 int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr,
112  PCRE2_SIZE *bufflen);
113 #endif
114 
116 
117 #endif /* SURICATA_DETECT_PARSE_H */
SigMatchRemoveSMFromList
void SigMatchRemoveSMFromList(Signature *, SigMatch *, int)
Definition: detect-parse.c:487
DetectSetupPCRE2
DetectParseRegex * DetectSetupPCRE2(const char *parse_str, int opts)
Definition: detect-parse.c:3468
DetectParseRegex
Definition: detect-parse.h:93
SIG_DIREC_NORMAL
@ SIG_DIREC_NORMAL
Definition: detect-parse.h:40
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *, Signature *, uint16_t, SigMatchCtx *, int)
Append a SigMatch to the list type.
Definition: detect-parse.c:388
DetectFirewallRuleAppendNew
Signature * DetectFirewallRuleAppendNew(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3266
DetectParseRegex::context
pcre2_match_context * context
Definition: detect-parse.h:95
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
DetectParseFreeRegex
void DetectParseFreeRegex(DetectParseRegex *r)
Definition: detect-parse.c:3402
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:919
DetectParseRegexAddToFreeList
void DetectParseRegexAddToFreeList(DetectParseRegex *parse_regex)
add regex and/or study to at exit free list
Definition: detect-parse.c:3428
detect-engine-register.h
SIG_DIREC_SWITCHED
@ SIG_DIREC_SWITCHED
Definition: detect-parse.h:41
SigTableApplyStrictCommandLineOption
void SigTableApplyStrictCommandLineOption(const char *str)
Definition: detect-parse.c:344
DetectParseRegex::regex
pcre2_code * regex
Definition: detect-parse.h:94
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:3071
SIG_DIREC_DST
@ SIG_DIREC_DST
Definition: detect-parse.h:48
SigMatchData_
Data needed for Match()
Definition: detect.h:366
DetectParseFreeRegexes
void DetectParseFreeRegexes(void)
Definition: detect-parse.c:3412
DetectParseRegex::next
struct DetectParseRegex * next
Definition: detect-parse.h:96
SC_Pcre2SubstringCopy
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:3494
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:658
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex)
Definition: detect-parse.c:3518
DetectGetLastSMFromLists
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:564
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
DetectGetLastSM
SigMatch * DetectGetLastSM(const Signature *)
Returns the sm with the largest index (added latest) from this sig.
Definition: detect-parse.c:709
DetectListToHumanString
const char * DetectListToHumanString(int list)
Definition: detect-parse.c:112
DetectParseRegex
struct DetectParseRegex DetectParseRegex
SigMatchStrictEnabled
bool SigMatchStrictEnabled(const enum DetectKeywordId id)
Definition: detect-parse.c:336
SigFree
void SigFree(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-parse.c:2040
DetectGetLastSMFromMpmLists
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
Definition: detect-parse.c:527
SigInit
Signature * SigInit(DetectEngineCtx *, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2996
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:2134
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:3392
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *, const SigMatch *)
Definition: detect-parse.c:763
SigMatchList2DataArray
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
Definition: detect-parse.c:2348
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:352
DetectSetupParseRegexesOpts
bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts)
Definition: detect-parse.c:3439
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:626
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition: detect-parse.c:146
SignatureInitDataBufferCheckExpand
int SignatureInitDataBufferCheckExpand(Signature *s)
check if buffers array still has space left, expand if not
Definition: detect-parse.c:1900
SigMatchSilentErrorEnabled
bool SigMatchSilentErrorEnabled(const DetectEngineCtx *de_ctx, const enum DetectKeywordId id)
Definition: detect-parse.c:330
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:1920
SIG_DIREC_SRC
@ SIG_DIREC_SRC
Definition: detect-parse.h:47
str
#define str(s)
Definition: suricata-common.h:308
head
Flow * head
Definition: flow-hash.h:1
SigParseRegisterTests
void SigParseRegisterTests(void)
Definition: detect-parse.c:5327
Signature_
Signature container.
Definition: detect.h:657
SigMatch_
a single match condition for a signature
Definition: detect.h:357
SC_Pcre2SubstringGet
int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:3506
WARN_UNUSED
#define WARN_UNUSED
Definition: bindgen.h:32
app-layer-protos.h
DetectListToString
const char * DetectListToString(int list)
Definition: detect-parse.c:130
DetectParseDupSigHashFree
void DetectParseDupSigHashFree(DetectEngineCtx *)
Frees the hash table that is used to cull duplicate sigs.
Definition: detect-parse.c:3088
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3338
DetectRegisterAppLayerHookLists
void DetectRegisterAppLayerHookLists(void)
register app hooks as generic lists
Definition: detect-parse.c:1152
SCDetectSignatureSetAppProto
int WARN_UNUSED SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2212