parser

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: Apache-2.0, BSD-3-Clause, MIT, + 2 more Imports: 8 Imported by: 0

Documentation

Overview

Package parser 实现了指纹规则的解析和评估功能。 该包提供了将YAML格式的指纹规则转换为可执行规则对象的功能, 并支持对HTTP请求响应进行指纹匹配评估。

Package parser 实现栈结构

Package parser 实现栈结构

Package parser 实现词法分析

Package parser 实现词法分析栈结构

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckBalance

func CheckBalance(tokens []Token) error

CheckBalance verifies if parentheses in token sequence are balanced Returns error if unbalanced, nil otherwise 主要功能:检查token序列中的括号是否匹配 不匹配时返回error,匹配时返回nil

func Eval

func Eval(config *Config, dsl *Rule) bool

Eval 评估配置是否匹配规则 参数:

  • config: 配置对象,包含请求体、请求头和图标信息
  • dsl: 要评估的规则对象

返回:

  • bool: 是否匹配规则

Types

type AdvisoryConfig

type AdvisoryConfig struct {
	Version    string
	IsInternal bool
}

AdvisoryConfig 提供漏洞配置信息

type Config

type Config struct {
	Body   string
	Header string
	Icon   int32
}

Config 定义了进行指纹匹配时需要的配置信息

type Exp

type Exp interface {
	Name() string
}

Exp 定义了表达式接口 所有表达式类型都需要实现 Name() 方法

type Extractor

type Extractor struct {
	Part  string `yaml:"part"`
	Group string `yaml:"group"`
	Regex string `yaml:"regex"`
}

Extractor 定义了从响应中提取信息的规则

type FingerPrint

type FingerPrint struct {
	Info    FingerPrintInfo `yaml:"info"`
	Http    []HttpRule      `yaml:"http"`
	Version []HttpRule      `yaml:"version,omitempty"`
}

FingerPrint 定义了完整的指纹规则结构

func InitFingerPrintFromData

func InitFingerPrintFromData(reader []byte) (*FingerPrint, error)

InitFingerPrintFromData 从字节数据初始化指纹配置 参数:

  • reader: 包含YAML格式指纹配置的字节数据

返回:

  • *FingerPrint: 解析后的指纹对象
  • error: 解析过程中的错误

type FingerPrintInfo

type FingerPrintInfo struct {
	Name     string            `yaml:"name"`
	Author   string            `yaml:"author"`
	Example  []string          `yaml:"example,omitempty"`
	Desc     string            `yaml:"desc,omitempty"`
	Severity string            `yaml:"severity"`
	Metadata map[string]string `yaml:"metadata"`
}

FingerPrintInfo 定义了指纹的基本信息

type FingerPrints

type FingerPrints []FingerPrint

FingerPrints 表示多个指纹规则的集合

type FpResult

type FpResult struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

FpResult 指纹结构体

type HttpRule

type HttpRule struct {
	Method   string   `yaml:"method"`
	Path     string   `yaml:"path"`
	Matchers []string `yaml:"matchers"`
	Data     string   `yaml:"data,omitempty"`

	Extractor Extractor `yaml:"extractor,omitempty"`
	// contains filtered or unexported fields
}

HttpRule 定义了HTTP请求匹配规则

func (*HttpRule) GetDsl

func (h *HttpRule) GetDsl() []*Rule

GetDsl 返回解析后的DSL规则列表

type Rule

type Rule struct {
	// contains filtered or unexported fields
}

Rule 表示一个规则,包含多个表达式

func TransFormExp

func TransFormExp(tokens []Token) (*Rule, error)

TransFormExp 将token序列转换为表达式规则 输入tokens切片,返回Rule对象和error 主要功能:解析tokens并构建DSL表达式、逻辑表达式和括号表达式

func (*Rule) AdvisoryEval

func (r *Rule) AdvisoryEval(config *AdvisoryConfig) bool

AdvisoryEval 评估建议规则是否匹配 输入建议配置对象,返回布尔值表示是否匹配 主要用于版本号比较的规则评估

func (*Rule) Eval

func (r *Rule) Eval(config *Config) bool

Eval 评估规则是否匹配 输入配置对象,返回布尔值表示是否匹配 使用栈实现后缀表达式求值

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack represents a LIFO (Last In First Out) data structure 使用Go标准库中的list实现栈结构

func NewStack

func NewStack() *Stack

NewStack creates and initializes a new Stack 创建并初始化一个新的栈

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token represents a lexical unit in the expression parsing 表示表达式解析中的词法单元

func ParseAdvisorTokens

func ParseAdvisorTokens(s1 string) ([]Token, error)

ParseAdvisorTokens parses advisor expressions, similar to ParseTokens but supports version keyword

func ParseTokens

func ParseTokens(s1 string) ([]Token, error)

ParseTokens converts input string to token sequence, supporting text content(quoted), comparison ops(=,==,!=,~=), logical ops(&&,||), parentheses and keywords(body,header,icon)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL