suricata
detect-content.h File Reference
#include "util-spm.h"
Include dependency graph for detect-content.h:

Go to the source code of this file.

Data Structures

struct  DetectContentData_
 

Macros

#define DETECT_CONTENT_NOCASE   BIT_U32(0)
 
#define DETECT_CONTENT_DISTANCE   BIT_U32(1)
 
#define DETECT_CONTENT_WITHIN   BIT_U32(2)
 
#define DETECT_CONTENT_OFFSET   BIT_U32(3)
 
#define DETECT_CONTENT_DEPTH   BIT_U32(4)
 
#define DETECT_CONTENT_FAST_PATTERN   BIT_U32(5)
 
#define DETECT_CONTENT_FAST_PATTERN_ONLY   BIT_U32(6)
 
#define DETECT_CONTENT_FAST_PATTERN_CHOP   BIT_U32(7)
 
#define DETECT_CONTENT_RAWBYTES   BIT_U32(8)
 
#define DETECT_CONTENT_NEGATED   BIT_U32(9)
 
#define DETECT_CONTENT_ENDS_WITH   BIT_U32(10)
 
#define DETECT_CONTENT_OFFSET_BE   BIT_U32(11)
 
#define DETECT_CONTENT_DEPTH_BE   BIT_U32(12)
 
#define DETECT_CONTENT_DISTANCE_BE   BIT_U32(13)
 
#define DETECT_CONTENT_WITHIN_BE   BIT_U32(14)
 
#define DETECT_CONTENT_REPLACE   BIT_U32(15)
 
#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED   BIT_U32(16)
 
#define DETECT_CONTENT_WITHIN_NEXT   BIT_U32(17)
 
#define DETECT_CONTENT_DISTANCE_NEXT   BIT_U32(18)
 
#define DETECT_CONTENT_STARTS_WITH   BIT_U32(19)
 
#define DETECT_CONTENT_MPM   BIT_U32(20)
 
#define DETECT_CONTENT_RELATIVE_NEXT   (DETECT_CONTENT_WITHIN_NEXT|DETECT_CONTENT_DISTANCE_NEXT)
 
#define DETECT_CONTENT_IS_SINGLE(c)
 
#define DETECT_CONTENT_MPM_IS_CONCLUSIVE(c)
 

Typedefs

typedef struct DetectContentData_ DetectContentData
 

Functions

void DetectContentRegister (void)
 
uint32_t DetectContentMaxId (DetectEngineCtx *)
 
DetectContentDataDetectContentParse (SpmGlobalThreadCtx *spm_global_thread_ctx, const char *contentstr)
 DetectContentParse . More...
 
int DetectContentDataParse (const char *keyword, const char *contentstr, uint8_t **pstr, uint16_t *plen)
 Parse a content string, ie "abc|DE|fgh". More...
 
DetectContentDataDetectContentParseEncloseQuotes (SpmGlobalThreadCtx *spm_global_thread_ctx, const char *contentstr)
 
int DetectContentSetup (DetectEngineCtx *de_ctx, Signature *s, const char *contentstr)
 Function to setup a content pattern. More...
 
void DetectContentPrint (DetectContentData *)
 Helper function to print a DetectContentData. More...
 
void DetectContentFree (void *)
 this function will SCFree memory associated with DetectContentData More...
 
_Bool DetectContentPMATCHValidateCallback (const Signature *s)
 
void DetectContentPropagateLimits (Signature *s)
 apply depth/offset and distance/within to content matches More...
 

Detailed Description

Macro Definition Documentation

#define DETECT_CONTENT_DEPTH_BE   BIT_U32(12)
#define DETECT_CONTENT_DISTANCE_BE   BIT_U32(13)
#define DETECT_CONTENT_DISTANCE_NEXT   BIT_U32(18)

Definition at line 58 of file detect-content.h.

Referenced by DetectByteExtractRetrieveSMVar(), and DetectDistanceRegister().

#define DETECT_CONTENT_FAST_PATTERN_CHOP   BIT_U32(7)
#define DETECT_CONTENT_IS_SINGLE (   c)
Value:
(!( ((c)->flags & DETECT_CONTENT_DISTANCE) || \
uint16_t flags
#define DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_OFFSET

Definition at line 66 of file detect-content.h.

Referenced by DetectEngineContentInspection().

#define DETECT_CONTENT_MPM   BIT_U32(20)

MPM pattern selected by the engine or forced by fast_pattern keyword

Definition at line 61 of file detect-content.h.

Referenced by EngineAnalysisRulesFailure().

#define DETECT_CONTENT_MPM_IS_CONCLUSIVE (   c)
Value:
uint16_t flags
#define DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_FAST_PATTERN_CHOP
#define DETECT_CONTENT_OFFSET

Definition at line 76 of file detect-content.h.

Referenced by MpmStoreFree().

#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED   BIT_U32(16)

Definition at line 55 of file detect-content.h.

#define DETECT_CONTENT_OFFSET_BE   BIT_U32(11)
#define DETECT_CONTENT_RAWBYTES   BIT_U32(8)

content applies to a "raw"/undecoded field if applicable

Definition at line 38 of file detect-content.h.

Referenced by DetectByteExtractRetrieveSMVar(), DetectEngineContentModifierBufferSetup(), and DetectRawbytesRegister().

#define DETECT_CONTENT_REPLACE   BIT_U32(15)

Definition at line 51 of file detect-content.h.

Referenced by DetectEngineContentInspection(), and DetectReplaceRegister().

#define DETECT_CONTENT_STARTS_WITH   BIT_U32(19)
#define DETECT_CONTENT_WITHIN_BE   BIT_U32(14)
#define DETECT_CONTENT_WITHIN_NEXT   BIT_U32(17)

Typedef Documentation

Function Documentation

int DetectContentDataParse ( const char *  keyword,
const char *  contentstr,
uint8_t **  pstr,
uint16_t *  plen 
)

Parse a content string, ie "abc|DE|fgh".

Parameters
content_strnull terminated string containing the content
resultresult pointer to pass the fully parsed byte array
result_lensize of the resulted data
flagsflags to be set by this parsing function
Return values
-1error
0ok

Definition at line 78 of file detect-content.c.

References SC_ERR_INVALID_SIGNATURE, SCCalloc, SCLogDebug, SCLogError, str, and strlcpy().

Referenced by DetectContentParse(), DetectFileextRegister(), DetectFilemagicRegister(), DetectFilenameRegister(), DetectFlowvarMatch(), DetectPktvarRegister(), and DetectReplaceRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

void DetectContentFree ( void *  ptr)

this function will SCFree memory associated with DetectContentData

Parameters
cdpointer to DetectContentData

Definition at line 359 of file detect-content.c.

References SCEnter, SCFree, SCReturn, DetectContentData_::spm_ctx, and SpmDestroyCtx().

Referenced by DetectContentRegister(), and DetectContentSetup().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t DetectContentMaxId ( DetectEngineCtx )
DetectContentData* DetectContentParse ( SpmGlobalThreadCtx spm_global_thread_ctx,
const char *  contentstr 
)
DetectContentData* DetectContentParseEncloseQuotes ( SpmGlobalThreadCtx spm_global_thread_ctx,
const char *  contentstr 
)

Definition at line 243 of file detect-content.c.

References DetectContentParse().

Here is the call graph for this function:

_Bool DetectContentPMATCHValidateCallback ( const Signature s)
void DetectContentPropagateLimits ( Signature s)

apply depth/offset and distance/within to content matches

The idea is that any limitation we can set is a win, as the mpm can use this to reduce match candidates.

E.g. if we have 'content:"1"; depth:1; content:"2"; distance:0; within:1;' we know that we can add 'offset:1; depth:2;' to the 2nd condition. This will then be used in mpm if the 2nd condition would be selected for mpm.

Another example: 'content:"1"; depth:1; content:"2"; distance:0;'. Here we cannot set a depth, but we can set an offset of 'offset:1;'. This will make the mpm a bit more precise.

Definition at line 425 of file detect-content.c.

References BUG_ON, DetectContentData_::content_len, SigMatch_::ctx, DetectContentData_::depth, DETECT_CONTENT, DETECT_CONTENT_DEPTH, DETECT_CONTENT_DISTANCE, DETECT_CONTENT_ENDS_WITH, DETECT_CONTENT_NEGATED, DETECT_CONTENT_OFFSET, DETECT_CONTENT_WITHIN, DETECT_PCRE, DETECT_PCRE_RELATIVE, DETECT_SM_LIST_PMATCH, DetectContentData_::distance, DetectPcreData_::flags, DetectContentData_::flags, Signature_::init_data, MIN, SigMatch_::next, DetectContentData_::offset, offset, SCLogDebug, SignatureInitData_::smlists, SignatureInitData_::smlists_array_size, SignatureInitData_::smlists_tail, SigMatch_::type, and DetectContentData_::within.

Referenced by SigAddressPrepareStage1().

Here is the caller graph for this function:

int DetectContentSetup ( DetectEngineCtx de_ctx,
Signature s,
const char *  contentstr 
)

Function to setup a content pattern.

Parameters
de_ctxpointer to the current detection_engine
spointer to the current Signature
mpointer to the last parsed SigMatch
contentstrpointer to the current keyword content string
Return values
-1if error
0if all was ok

Definition at line 318 of file detect-content.c.

References SigMatch_::ctx, DETECT_CONTENT, DETECT_CONTENT_NEGATED, DETECT_SM_LIST_NOTSET, DETECT_SM_LIST_PMATCH, DetectBufferGetActiveList(), DetectContentFree(), DetectContentParse(), DetectContentPrint(), DetectContentData_::flags, Signature_::init_data, SignatureInitData_::list, SignatureInitData_::negated, SigMatchAlloc(), SigMatchAppendSMToList(), DetectEngineCtx_::spm_global_thread_ctx, and SigMatch_::type.

Referenced by DetectContentRegister(), and DetectUricontentRegister().

Here is the call graph for this function:

Here is the caller graph for this function: