suricata
detect-engine-analyzer.c File Reference
#include "suricata-common.h"
#include "suricata.h"
#include "rust.h"
#include "detect.h"
#include "detect-parse.h"
#include "detect-engine.h"
#include "detect-engine-analyzer.h"
#include "detect-engine-mpm.h"
#include "conf.h"
#include "detect-content.h"
#include "detect-flow.h"
#include "detect-tcp-flags.h"
#include "feature.h"
#include "util-print.h"
Include dependency graph for detect-engine-analyzer.c:

Go to the source code of this file.

Data Structures

struct  FpPatternStats_
 
struct  DetectEngineAnalyzerItems
 
struct  ExposedItemSeen
 
struct  RuleAnalyzer
 

Macros

#define DETECT_PERCENT_ENCODING_REGEX   "%[0-9|a-f|A-F]{2}"
 
#define MAX_ENCODED_CHARS   240
 
#define CHECK(pat)   if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
 

Typedefs

typedef struct FpPatternStats_ FpPatternStats
 
typedef struct DetectEngineAnalyzerItems DetectEngineAnalyzerItems
 
typedef struct RuleAnalyzer RuleAnalyzer
 

Functions

void EngineAnalysisFP (const DetectEngineCtx *de_ctx, const Signature *s, char *line)
 
int SetupFPAnalyzer (void)
 Sets up the fast pattern analyzer according to the config. More...
 
int SetupRuleAnalyzer (void)
 Sets up the rule analyzer according to the config. More...
 
void CleanupFPAnalyzer (void)
 
void CleanupRuleAnalyzer (void)
 
int PerCentEncodingSetup ()
 Compiles regex for rule analysis. More...
 
int PerCentEncodingMatch (uint8_t *content, uint8_t content_len)
 Checks for % encoding in content. More...
 
void EngineAnalysisRulesFailure (char *line, char *file, int lineno)
 
void EngineAnalysisRules2 (const DetectEngineCtx *de_ctx, const Signature *s)
 
void EngineAnalysisRules (const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
 Prints analysis of loaded rules. More...
 

Variables

DetectEngineAnalyzerItems analyzer_items []
 
int16_t analyzer_item_map [256]
 
struct ExposedItemSeen exposed_item_seen_list []
 
SCMutex g_rules_analyzer_write_m = SCMUTEX_INITIALIZER
 

Detailed Description

Author
Eileen Donlon emdon.nosp@m.lo@g.nosp@m.mail..nosp@m.com
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Rule analyzers for the detection engine

Definition in file detect-engine-analyzer.c.

Macro Definition Documentation

◆ CHECK

#define CHECK (   pat)    if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;

Definition at line 596 of file detect-engine-analyzer.c.

◆ DETECT_PERCENT_ENCODING_REGEX

#define DETECT_PERCENT_ENCODING_REGEX   "%[0-9|a-f|A-F]{2}"

◆ MAX_ENCODED_CHARS

#define MAX_ENCODED_CHARS   240

Typedef Documentation

◆ DetectEngineAnalyzerItems

◆ FpPatternStats

◆ RuleAnalyzer

typedef struct RuleAnalyzer RuleAnalyzer

Function Documentation

◆ CleanupFPAnalyzer()

void CleanupFPAnalyzer ( void  )

Definition at line 389 of file detect-engine-analyzer.c.

◆ CleanupRuleAnalyzer()

void CleanupRuleAnalyzer ( void  )

Definition at line 413 of file detect-engine-analyzer.c.

◆ EngineAnalysisFP()

◆ EngineAnalysisRules()

void EngineAnalysisRules ( const DetectEngineCtx de_ctx,
const Signature s,
const char *  line 
)

Prints analysis of loaded rules.

   Warns if potential rule issues are detected. For example,
   warns if a rule uses a construct that may perform poorly,
   e.g. pcre without content or with http_method content only;
   warns if a rule uses a construct that may not be consistent with intent,
   e.g. client side ports only, http and content without any http_* modifiers, etc.
Parameters
sPointer to the signature.

Definition at line 952 of file detect-engine-analyzer.c.

◆ EngineAnalysisRules2()

◆ EngineAnalysisRulesFailure()

void EngineAnalysisRulesFailure ( char *  line,
char *  file,
int  lineno 
)

Definition at line 546 of file detect-engine-analyzer.c.

◆ PerCentEncodingMatch()

int PerCentEncodingMatch ( uint8_t *  content,
uint8_t  content_len 
)

Checks for % encoding in content.

Parameters
Pointerto content
Return values
numberof matches if content has % encoding
0if it doesn't have % encoding
-1on error

Definition at line 456 of file detect-engine-analyzer.c.

References MAX_ENCODED_CHARS.

◆ PerCentEncodingSetup()

int PerCentEncodingSetup ( )

Compiles regex for rule analysis.

Return values
1if successful
0if on error

Definition at line 427 of file detect-engine-analyzer.c.

◆ SetupFPAnalyzer()

int SetupFPAnalyzer ( void  )

Sets up the fast pattern analyzer according to the config.

Return values
1If rule analyzer successfully enabled.
0If not enabled.

Definition at line 283 of file detect-engine-analyzer.c.

◆ SetupRuleAnalyzer()

int SetupRuleAnalyzer ( void  )

Sets up the rule analyzer according to the config.

Return values
1if rule analyzer successfully enabled
0if not enabled

Definition at line 333 of file detect-engine-analyzer.c.

References ConfGetNode(), ConfNodeLookupChildValue(), and ConfValIsTrue().

Here is the call graph for this function:

Variable Documentation

◆ analyzer_item_map

int16_t analyzer_item_map[256]

Definition at line 119 of file detect-engine-analyzer.c.

◆ analyzer_items

DetectEngineAnalyzerItems analyzer_items[]

Definition at line 72 of file detect-engine-analyzer.c.

◆ exposed_item_seen_list

struct ExposedItemSeen exposed_item_seen_list[]
Initial value:
= {
{ .bufname = "http_method"},
{ .bufname = "file_data"}
}

Definition at line 119 of file detect-engine-analyzer.c.

◆ g_rules_analyzer_write_m

SCMutex g_rules_analyzer_write_m = SCMUTEX_INITIALIZER

Definition at line 675 of file detect-engine-analyzer.c.