suricata
detect-parse.h File Reference
Include dependency graph for detect-parse.h:

Go to the source code of this file.

Data Structures

struct  DetectParseRegex
 

Typedefs

typedef struct DetectEngineCtx_ DetectEngineCtx
 
typedef struct Signature_ Signature
 
typedef struct SigMatchCtx_ SigMatchCtx
 
typedef struct SigMatch_ SigMatch
 
typedef struct SigMatchData_ SigMatchData
 
typedef struct DetectParseRegex DetectParseRegex
 

Enumerations

enum  { SIG_DIREC_NORMAL , SIG_DIREC_SWITCHED }
 
enum  { SIG_DIREC_SRC , SIG_DIREC_DST }
 

Functions

int SignatureInitDataBufferCheckExpand (Signature *s)
 check if buffers array still has space left, expand if not
 
SignatureSigAlloc (void)
 
void SigFree (DetectEngineCtx *de_ctx, Signature *s)
 
SignatureSigInit (DetectEngineCtx *, const char *sigstr)
 Parses a signature and adds it to the Detection Engine Context.
 
SigMatchDataSigMatchList2DataArray (SigMatch *head)
 convert SigMatch list to SigMatchData array
 
void SigParseRegisterTests (void)
 
SignatureDetectEngineAppendSig (DetectEngineCtx *, const char *)
 Parse and append a Signature into the Detection Engine Context signature list.
 
SignatureDetectFirewallRuleAppendNew (DetectEngineCtx *, const char *)
 Parse and append a Signature into the Detection Engine Context signature list.
 
SigMatchSCSigMatchAppendSMToList (DetectEngineCtx *, Signature *, uint16_t, SigMatchCtx *, int)
 Append a SigMatch to the list type.
 
void SigMatchRemoveSMFromList (Signature *, SigMatch *, int)
 
int SigMatchListSMBelongsTo (const Signature *, const SigMatch *)
 
int DetectParseDupSigHashInit (DetectEngineCtx *)
 Initializes the hash table that is used to cull duplicate sigs.
 
void DetectParseDupSigHashFree (DetectEngineCtx *)
 Frees the hash table that is used to cull duplicate sigs.
 
int DetectEngineContentModifierBufferSetup (DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
 
bool SigMatchSilentErrorEnabled (const DetectEngineCtx *de_ctx, const enum DetectKeywordId id)
 
bool SigMatchStrictEnabled (const enum DetectKeywordId id)
 
const char * DetectListToHumanString (int list)
 
const char * DetectListToString (int list)
 
void SigTableApplyStrictCommandLineOption (const char *str)
 
SigMatchDetectGetLastSM (const Signature *)
 Returns the sm with the largest index (added latest) from this sig.
 
SigMatchDetectGetLastSMFromMpmLists (const DetectEngineCtx *de_ctx, const Signature *s)
 get the last SigMatch from lists that support MPM.
 
SigMatchDetectGetLastSMFromLists (const Signature *s,...)
 Returns the sm with the largest index (added latest) from the lists passed to us.
 
SigMatchDetectGetLastSMByListPtr (const Signature *s, SigMatch *sm_list,...)
 Returns the sm with the largest index (added last) from the list passed to us as a pointer.
 
SigMatchDetectGetLastSMByListId (const Signature *s, int list_id,...)
 Returns the sm with the largest index (added last) from the list passed to us as an id.
 
int WARN_UNUSED SCDetectSignatureSetAppProto (Signature *s, AppProto alproto)
 
int WARN_UNUSED DetectSignatureSetMultiAppProto (Signature *s, const AppProto *alprotos)
 this function is used to set multiple possible app-layer protos
 
DetectParseRegexDetectSetupPCRE2 (const char *parse_str, int opts)
 
bool DetectSetupParseRegexesOpts (const char *parse_str, DetectParseRegex *parse_regex, int opts)
 
void DetectSetupParseRegexes (const char *parse_str, DetectParseRegex *parse_regex)
 
void DetectParseRegexAddToFreeList (DetectParseRegex *parse_regex)
 add regex and/or study to at exit free list
 
void DetectParseFreeRegexes (void)
 
void DetectParseFreeRegex (DetectParseRegex *r)
 
int DetectParsePcreExec (DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
 
int SC_Pcre2SubstringCopy (pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
 
int SC_Pcre2SubstringGet (pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
 
void DetectRegisterAppLayerHookLists (void)
 register app hooks as generic lists
 

Detailed Description

Typedef Documentation

◆ DetectEngineCtx

Definition at line 30 of file detect-parse.h.

◆ DetectParseRegex

◆ SigMatch

typedef struct SigMatch_ SigMatch

Definition at line 33 of file detect-parse.h.

◆ SigMatchCtx

typedef struct SigMatchCtx_ SigMatchCtx

Definition at line 32 of file detect-parse.h.

◆ SigMatchData

typedef struct SigMatchData_ SigMatchData

Definition at line 34 of file detect-parse.h.

◆ Signature

typedef struct Signature_ Signature

Definition at line 31 of file detect-parse.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Flags to indicate if the Signature parsing must be done switching the source and dest (for ip addresses and ports) or otherwise as normal

Enumerator
SIG_DIREC_NORMAL 
SIG_DIREC_SWITCHED 

Definition at line 39 of file detect-parse.h.

◆ anonymous enum

anonymous enum

Flags to indicate if are referencing the source of the Signature or the destination (for ip addresses and ports)

Enumerator
SIG_DIREC_SRC 
SIG_DIREC_DST 

Definition at line 46 of file detect-parse.h.

Function Documentation

◆ DetectEngineAppendSig()

Signature * DetectEngineAppendSig ( DetectEngineCtx de_ctx,
const char *  sigstr 
)

Parse and append a Signature into the Detection Engine Context signature list.

If the signature is bidirectional it should append two signatures (with the addresses switched) into the list. Also handle duplicate signatures. In case of duplicate sigs, use the ones that have the latest revision. We use the sid and the msg to identify duplicate sigs. If 2 sigs have the same sid and gid, they are duplicates.

Parameters
de_ctxPointer to the Detection Engine Context.
sigstrPointer to a character string containing the signature to be parsed.
sig_filePointer to a character string containing the filename from which signature is read
linenoLine number from where signature is read
Return values
Pointerto the head Signature in the detection engine ctx sig_list on success; NULL on failure.

In DetectEngineAppendSig(), the signatures are prepended and we always return the first one so if the signature is bidirectional, the returned sig will point through "next" ptr to the cloned signatures with the switched addresses

Definition at line 3437 of file detect-parse.c.

◆ DetectEngineContentModifierBufferSetup()

◆ DetectFirewallRuleAppendNew()

Signature * DetectFirewallRuleAppendNew ( DetectEngineCtx de_ctx,
const char *  sigstr 
)

Parse and append a Signature into the Detection Engine Context signature list.

If the signature is bidirectional it should append two signatures (with the addresses switched) into the list. Also handle duplicate signatures. In case of duplicate sigs, use the ones that have the latest revision. We use the sid and the msg to identify duplicate sigs. If 2 sigs have the same sid and gid, they are duplicates.

Parameters
de_ctxPointer to the Detection Engine Context.
sigstrPointer to a character string containing the signature to be parsed.
sig_filePointer to a character string containing the filename from which signature is read
linenoLine number from where signature is read
Return values
Pointerto the head Signature in the detection engine ctx sig_list on success; NULL on failure.

In DetectEngineAppendSig(), the signatures are prepended and we always return the first one so if the signature is bidirectional, the returned sig will point through "next" ptr to the cloned signatures with the switched addresses

Definition at line 3365 of file detect-parse.c.

References de_ctx, Signature_::init_data, SignatureInitData_::init_flags, Signature_::next, SCLogError, SCLogWarning, SIG_FLAG_INIT_BIDIREC, DetectEngineCtx_::sig_list, and SigFree().

Here is the call graph for this function:

◆ DetectGetLastSM()

SigMatch * DetectGetLastSM ( const Signature s)

Returns the sm with the largest index (added latest) from this sig.

Return values
sm_lastPointer to last sm

Definition at line 709 of file detect-parse.c.

References SignatureInitData_::buffer_index, SignatureInitData_::buffers, DETECT_SM_LIST_MAX, SigMatch_::idx, Signature_::init_data, SignatureInitData_::smlists_tail, and SignatureInitDataBuffer_::tail.

◆ 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.

Parameters
list_idid of the list to be searched
va_argslist of keyword types terminated by -1
Return values
sm_lastto last sm.

Definition at line 658 of file detect-parse.c.

References SignatureInitData_::buffer_index, SignatureInitData_::buffers, DETECT_SM_LIST_MAX, SigMatch_::idx, Signature_::init_data, SignatureInitData_::smlists_tail, and SignatureInitDataBuffer_::tail.

Referenced by DetectEngineContentModifierBufferSetup().

Here is the caller graph for this function:

◆ 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.

Parameters
sm_listpointer to the SigMatch we should look before
va_argslist of keyword types terminated by -1
Return values
sm_lastto last sm.

Definition at line 626 of file detect-parse.c.

References SigMatch_::idx.

Referenced by DetectEngineContentModifierBufferSetup(), and DetectGetLastSMFromMpmLists().

Here is the caller graph for this function:

◆ DetectGetLastSMFromLists()

SigMatch * DetectGetLastSMFromLists ( const Signature s,
  ... 
)

Returns the sm with the largest index (added latest) from the lists passed to us.

Return values
Pointerto Last sm.

Definition at line 564 of file detect-parse.c.

References SignatureInitData_::buffer_index, SignatureInitData_::buffers, DETECT_SM_LIST_MAX, DETECT_SM_LIST_NOTSET, SignatureInitDataBuffer_::id, SigMatch_::idx, Signature_::init_data, SignatureInitData_::list, SCLogDebug, SignatureInitData_::smlists, SignatureInitData_::smlists_tail, and SignatureInitDataBuffer_::tail.

Referenced by DetectIsdataatSetup().

Here is the caller graph for this function:

◆ DetectGetLastSMFromMpmLists()

SigMatch * DetectGetLastSMFromMpmLists ( const DetectEngineCtx de_ctx,
const Signature s 
)

◆ DetectListToHumanString()

const char * DetectListToHumanString ( int  list)

◆ DetectListToString()

◆ DetectParseDupSigHashFree()

void DetectParseDupSigHashFree ( DetectEngineCtx de_ctx)

Frees the hash table that is used to cull duplicate sigs.

Parameters
de_ctxPointer to the detection engine context that holds this table.

Definition at line 3187 of file detect-parse.c.

References de_ctx, DetectEngineCtx_::dup_sig_hash_table, and HashListTableFree().

Referenced by DetectEngineCtxFree(), and SigLoadSignatures().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectParseDupSigHashInit()

int DetectParseDupSigHashInit ( DetectEngineCtx de_ctx)

Initializes the hash table that is used to cull duplicate sigs.

Parameters
de_ctxPointer to the detection engine context.
Return values
0On success.
-1On failure.

Definition at line 3170 of file detect-parse.c.

References de_ctx, DetectEngineCtx_::dup_sig_hash_table, and HashListTableInit().

Here is the call graph for this function:

◆ DetectParseFreeRegex()

void DetectParseFreeRegex ( DetectParseRegex r)

Definition at line 3501 of file detect-parse.c.

References DetectParseRegex::context, and DetectParseRegex::regex.

Referenced by DetectParseFreeRegexes().

Here is the caller graph for this function:

◆ DetectParseFreeRegexes()

void DetectParseFreeRegexes ( void  )

Definition at line 3511 of file detect-parse.c.

References DetectParseFreeRegex(), next, DetectParseRegex::next, and SCFree.

Referenced by GlobalsDestroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectParsePcreExec()

int DetectParsePcreExec ( DetectParseRegex parse_regex,
pcre2_match_data **  match,
const char *  str,
int  start_offset,
int  options 
)

Definition at line 3491 of file detect-parse.c.

References DetectParseRegex::context, DetectParseRegex::regex, and str.

◆ DetectParseRegexAddToFreeList()

void DetectParseRegexAddToFreeList ( DetectParseRegex parse_regex)

add regex and/or study to at exit free list

Definition at line 3527 of file detect-parse.c.

References FatalError, DetectParseRegex::next, DetectParseRegex::regex, and SCCalloc.

Referenced by DetectSetupParseRegexesOpts().

Here is the caller graph for this function:

◆ DetectRegisterAppLayerHookLists()

void DetectRegisterAppLayerHookLists ( void  )

register app hooks as generic lists

Register each hook in each app protocol as: <alproto>:<hook name>:generic These lists can be used by lua scripts to hook into.

Todo:
move elsewhere? maybe a detect-engine-hook.c?

Definition at line 1152 of file detect-parse.c.

References ALPROTO_FAILED, AppLayerParserGetStateNameById(), AppLayerParserGetStateProgressCompletionStatus(), AppProtoToString(), DetectAppLayerInspectEngineRegister(), DetectEngineInspectGenericList(), g_alproto_max, name, SCLogDebug, SIG_FLAG_TOCLIENT, and SIG_FLAG_TOSERVER.

Referenced by SigTableSetup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectSetupParseRegexes()

◆ DetectSetupParseRegexesOpts()

bool DetectSetupParseRegexesOpts ( const char *  parse_str,
DetectParseRegex parse_regex,
int  opts 
)

Definition at line 3538 of file detect-parse.c.

References DetectParseRegex::context, DetectParseRegexAddToFreeList(), DetectParseRegex::regex, SC_MATCH_LIMIT_DEFAULT, SC_MATCH_LIMIT_RECURSION_DEFAULT, and SCLogError.

Referenced by DetectSetupParseRegexes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectSetupPCRE2()

DetectParseRegex * DetectSetupPCRE2 ( const char *  parse_str,
int  opts 
)

Definition at line 3567 of file detect-parse.c.

References DetectParseRegex::next, DetectParseRegex::regex, SCCalloc, SCFree, and SCLogError.

Referenced by DetectPcreRegister(), and SCThresholdConfGlobalInit().

Here is the caller graph for this function:

◆ DetectSignatureSetMultiAppProto()

int WARN_UNUSED DetectSignatureSetMultiAppProto ( Signature s,
const AppProto alprotos 
)

this function is used to set multiple possible app-layer protos

into the current signature (for example ja4 for both tls and quic)

Parameters
spointer to the Current Signature
alprotosan array terminated by ALPROTO_UNKNOWN
Return values
0on Success
-1on Failure

Definition at line 2151 of file detect-parse.c.

References Signature_::alproto, ALPROTO_UNKNOWN, SignatureInitData_::alprotos, Signature_::init_data, SCDetectSignatureSetAppProto(), and SIG_ALPROTO_MAX.

Here is the call graph for this function:

◆ SC_Pcre2SubstringCopy()

int SC_Pcre2SubstringCopy ( pcre2_match_data *  match_data,
uint32_t  number,
PCRE2_UCHAR *  buffer,
PCRE2_SIZE *  bufflen 
)

Definition at line 3593 of file detect-parse.c.

◆ SC_Pcre2SubstringGet()

int SC_Pcre2SubstringGet ( pcre2_match_data *  match_data,
uint32_t  number,
PCRE2_UCHAR **  bufferptr,
PCRE2_SIZE *  bufflen 
)

Definition at line 3605 of file detect-parse.c.

◆ SCDetectSignatureSetAppProto()

int WARN_UNUSED SCDetectSignatureSetAppProto ( Signature s,
AppProto  alproto 
)

◆ SCSigMatchAppendSMToList()

◆ SigAlloc()

◆ SigFree()

void SigFree ( DetectEngineCtx de_ctx,
Signature s 
)

Definition at line 2057 of file detect-parse.c.

Referenced by DetectEngineAppendSig(), and DetectFirewallRuleAppendNew().

Here is the caller graph for this function:

◆ SigInit()

Signature * SigInit ( DetectEngineCtx de_ctx,
const char *  sigstr 
)

Parses a signature and adds it to the Detection Engine Context.

Parameters
de_ctxPointer to the Detection Engine Context.
sigstrPointer to a character string containing the signature to be parsed.
Return values
Pointerto the Signature instance on success; NULL on failure.

Definition at line 3095 of file detect-parse.c.

References de_ctx.

Referenced by DetectEngineAppendSig(), LLVMFuzzerTestOneInput(), UTHPacketMatchSig(), and UTHPacketMatchSigMpm().

Here is the caller graph for this function:

◆ SigMatchList2DataArray()

SigMatchData * SigMatchList2DataArray ( SigMatch head)

convert SigMatch list to SigMatchData array

Note
ownership of sm->ctx is transferred to smd->ctx

Definition at line 2365 of file detect-parse.c.

References SigMatch_::ctx, SigMatchData_::ctx, FatalError, head, SigMatchData_::is_last, len, SigMatch_::next, SCCalloc, SigMatch_::type, and SigMatchData_::type.

Referenced by DetectEngineAppInspectionEngine2Signature().

Here is the caller graph for this function:

◆ SigMatchListSMBelongsTo()

◆ SigMatchRemoveSMFromList()

void SigMatchRemoveSMFromList ( Signature s,
SigMatch sm,
int  sm_list 
)

Definition at line 487 of file detect-parse.c.

References Signature_::init_data, SigMatch_::next, SigMatch_::prev, SignatureInitData_::smlists, and SignatureInitData_::smlists_tail.

Referenced by DetectIPProtoRemoveAllSMs().

Here is the caller graph for this function:

◆ SigMatchSilentErrorEnabled()

bool SigMatchSilentErrorEnabled ( const DetectEngineCtx de_ctx,
const enum DetectKeywordId  id 
)

Definition at line 330 of file detect-parse.c.

References de_ctx, id, and DetectEngineCtx_::sm_types_silent_error.

◆ SigMatchStrictEnabled()

bool SigMatchStrictEnabled ( const enum DetectKeywordId  id)

Definition at line 336 of file detect-parse.c.

References DETECT_TBLSIZE, flags, SIGMATCH_STRICT_PARSING, and sigmatch_table.

◆ SignatureInitDataBufferCheckExpand()

int SignatureInitDataBufferCheckExpand ( Signature s)

check if buffers array still has space left, expand if not

Definition at line 1917 of file detect-parse.c.

References SignatureInitData_::buffer_index, SignatureInitData_::buffers, SignatureInitData_::buffers_size, Signature_::init_data, and SCRealloc.

Referenced by DetectBufferGetActiveList(), DetectEngineContentModifierBufferSetup(), SCDetectBufferSetActiveList(), and SCSigMatchAppendSMToList().

Here is the caller graph for this function:

◆ SigParseRegisterTests()

void SigParseRegisterTests ( void  )

Definition at line 5426 of file detect-parse.c.

References DetectParseRegisterTests(), and UtRegisterTest().

Referenced by SigRegisterTests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SigTableApplyStrictCommandLineOption()

void SigTableApplyStrictCommandLineOption ( const char *  str)

Definition at line 344 of file detect-parse.c.

References DETECT_TBLSIZE, FatalError, SigTableElmt_::flags, SCFree, SCLogWarning, SCStrdup, SIGMATCH_STRICT_PARSING, sigmatch_table, and str.

Referenced by PostConfLoadedSetup().

Here is the caller graph for this function: