finger

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 39 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: cert.go @Date: 2025/9/1 下午4:00*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: eval.go @Date: 2025/2/21 下午3:01*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: icon.go @Date: 2025/2/21 下午3:06*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: req.go @Date: 2025/2/21 下午3:06*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: runner.go @Date: 2025/2/20 下午3:37*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: server.go @Date: 2025/4/3 上午10:10*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: title.go @Date: 2025/4/3 上午9:47*
  • Package fingerYaml @Author: zhizhuo @IDE:GoLand @File: yaml.go @Date: 2025/2/21 下午2:36*

Index

Constants

View Source
const (
	CodePolicyType     = "policy-type"
	CodePolicyRaw      = "policy-raw"
	CodePolicyReverse  = "policy-reverse"
	CodePolicySleep    = "policy-sleep"
	CodePolicySubRules = "policy-sub-rules"
	CodePolicyRules    = "policy-rules"
)

规则策略的检查代码。

View Source
const (
	RedirectHTTP       = "http"
	RedirectRefresh    = "refresh"
	RedirectJavaScript = "javascript"
)

跳转类型,写入扫描结果。

View Source
const (
	SeverityError   = "error"
	SeverityWarning = "warning"
)

诊断的严重程度。

View Source
const (
	CodeYAML              = "yaml"               // YAML 语法或结构错误,规则无法加载
	CodeUnknownKey        = "unknown-key"        // 未知的键
	CodeMissingID         = "missing-id"         // 缺少 id
	CodeInvalidID         = "invalid-id"         // id 不是小写字母、数字与连字符组成的 3–96 个字符
	CodeMissingName       = "missing-name"       // 缺少 info.name
	CodeMissingRules      = "missing-rules"      // 没有子规则
	CodeMissingExpression = "missing-expression" // 缺少总表达式
	CodeExpression        = "expression-compile" // 表达式无法编译
	CodeMissingProduct    = "missing-product"    // 没有声明 info.product
	CodeInvalidProduct    = "invalid-product"    // info.product 缺少必填项或取值不合规
	CodeMissingServices   = "missing-services"   // TCP/UDP 规则没有声明 info.services
	CodeInvalidService    = "invalid-service"    // info.services 的一项不合规
)

诊断代码。

View Source
const (
	HttpType = "http"
	TcpType  = "tcp"
	UdpType  = "udp"
)
View Source
const FingerFile = "fingerYaml"

FingerFile 配置poc文件目录

Variables

View Source
var (
	ProductCategories = []string{"application", "middleware", "framework", "operating-system", "cms", "database",
		"web-server", "security", "library", "hosting-panel", "device", "network-device", "iot", "other"}
	ProductIdentities = []string{"product", "signal"}
	ProductAssurances = []string{"verified", "inferred"}
)

产品声明的取值范围。

View Source
var ErrRulePolicy = errors.New("规则违反规则策略")

ErrRulePolicy 是规则违反规则策略的错误类别。

Functions

func BuildPageResponseOwned added in v1.5.0

func BuildPageResponseOwned(ctx context.Context, resp *http.Response, body []byte, client *network.HTTPClient, options network.OptionsRequest, pageURL string, icon bool) *proto.Response

BuildPageResponseOwned 构造入口跳转链上一页的响应,接管独占正文。 pageURL 是该页的实际地址,用于解析页面资源;icon 为 false 时不下载图标 (跳转链的中间页只参与规则匹配)。

func BuildProtoRequest

func BuildProtoRequest(resp *http.Response, method, body, path string) *proto.Request

BuildProtoRequest 构造proto.Request结构体 (公开版本)

func BuildProtoResponseOwned

func BuildProtoResponseOwned(ctx context.Context, resp *http.Response, body []byte, latency int64, client *network.HTTPClient, options network.OptionsRequest) *proto.Response

BuildProtoResponseOwned 接管独占正文,UTF-8 输入直接作为只读消息正文。 调用后不得修改输入;GB18030 回退与字符串入口一致。Raw 与 Body 仍使用 各自的数组,消息发布后可由同次扫描中的规则共享读取。

func CheckLibraryPolicy added in v1.8.0

func CheckLibraryPolicy(fingers []*Finger, policy RulePolicy) error

CheckLibraryPolicy 检查规则库整体:规则数上限与每条规则。返回第一处违反。

func CheckProductDeclarations added in v1.8.0

func CheckProductDeclarations(fingers []*Finger) error

CheckProductDeclarations 检查同一产品标识在全部规则中的声明完全相同,返回第一处不一致。 未声明产品或产品标识为空的规则不参与比较。

func CleanServerString

func CleanServerString(server string) string

CleanServerString 移除服务器信息中没有用的内容

func ClientRedirect added in v1.5.0

func ClientRedirect(page *url.URL, header http.Header, body []byte) (*url.URL, string)

ClientRedirect 返回页面声明的客户端跳转目标与类型;没有可识别的跳转时目标为 nil。

依次检查 Refresh 响应头、<meta http-equiv="refresh"> 和跳转壳中的脚本。 返回的目标已按页面地址及 <base href> 解析为绝对地址,只可能是 http/https, 并且与页面地址不同(忽略片段)。

func CloneMetadata added in v1.8.0

func CloneMetadata(metadata map[string]any) map[string]any

CloneMetadata 深拷贝 info.metadata。解析后的取值只含映射、列表与标量,见 normalizeMetadata。

func EvaluateOutput added in v1.2.0

func EvaluateOutput(args yaml.MapSlice, variables map[string]any, lib *gcel.CustomLib) map[string]string

EvaluateOutput 仅保存成功求值的输出。失败的提取表达式不作为产品版本或证据回传。 执行变量保留完整值,公开结果中的单项输出限制为 512 字节。

func EvaluateOutputReport added in v1.8.0

func EvaluateOutputReport(args yaml.MapSlice, variables map[string]any, lib *gcel.CustomLib, failed func(key string, err error)) map[string]string

EvaluateOutputReport 与 EvaluateOutput 相同,并在提取表达式求值失败时调用 failed。

func ExtractICPRecordFromBody

func ExtractICPRecordFromBody(body []byte) string

ExtractICPRecordFromBody 从只读正文提取备案号,不保留整页引用。

func ExtractServerInfo

func ExtractServerInfo(header http.Header) (string, string)

ExtractServerInfo 从HTTP响应头中提取server信息

func ExtractVersion

func ExtractVersion(server string) string

ExtractVersion 从服务器字符串中提取版本信息

func GetCertInfos

func GetCertInfos(resp *http.Response) []*types.CertInfo

GetCertInfos 返回完整证书信息数组,用于结构化输出

func GetPageIconHash

func GetPageIconHash(ctx context.Context, client *network.HTTPClient, pageURL string, body []byte, options network.OptionsRequest) string

GetPageIconHash 依次验证页面候选,最后回退根路径。所有请求共享一个 时间预算;失败不写长期缓存,签名参数不同的地址保持独立。

func GetServerInfoFromResponse

func GetServerInfoFromResponse(resp *http.Response) *types.ServerInfo

GetServerInfoFromResponse 从HTTP响应中获取并格式化服务器信息 返回ServerInfo结构体指针

func GetTitleFromBody

func GetTitleFromBody(ctx context.Context, urlStr string, resp *http.Response, bodyBytes []byte, client *network.HTTPClient, options network.OptionsRequest) string

GetTitleFromBody 消费已限长的正文,附加资源继承同一次扫描的请求策略。

func IsFuzzSet

func IsFuzzSet(args yaml.MapSlice, variableMap map[string]any, customLib *celPkg.CustomLib)

IsFuzzSet 解析Set中的定义变量。

值按 CEL 表达式求值,失败时按原文作为字符串。YAML 中写成数字、布尔等非字符串 标量时按其文本求值(`n: 5` 得到整数 5),不能因类型断言失败而中断整条指纹。

func SendRequest

func SendRequest(parentCtx context.Context, client *network.HTTPClient, target string, req RuleRequest, rule Rule, variableMap map[string]any, options network.OptionsRequest) (map[string]any, error)

SendRequest 使用指定 HTTP 客户端发送 yaml poc 请求。 parentCtx 取消或超时后,请求会尽快结束(与 Scan(ctx) 语义一致)。

func SetVariableMap

func SetVariableMap(find string, variableMap map[string]any) string

SetVariableMap 处理解析set中变量 跳过 proto.Request/Response/Reverse 等不可能出现在模板中的大对象, 避免 fmt.Sprintf("%v") 触发 protobuf 文本序列化(单次数百KB,占总分配64%)。 URL 对象替换为其 URL 文本。

func TargetRequest added in v1.5.0

func TargetRequest(target string) *proto.Request

TargetRequest 用目标地址合成只含 Url 的请求,使 set 块在发出任何请求之前 就能求值 request.url.host、request.url.domain 等变量。未带协议时按 https 解析。

func ValidCPE added in v1.8.0

func ValidCPE(value string) bool

ValidCPE 报告取值是否为结构完整的 CPE 2.3 格式化字符串。属性可包含转义冒号, 只按未转义的分隔符拆分 11 个属性。

func ValidReferenceURL added in v1.8.0

func ValidReferenceURL(reference string) bool

ValidReferenceURL 报告链接能否作为参考资料:http(s)、有主机名、不含账号信息, 且不是 example.com 一类的占位域名。

func WithIconEvidenceSlot added in v1.8.0

func WithIconEvidenceSlot(ctx context.Context) (context.Context, func() *IconEvidence)

WithIconEvidenceSlot 让 ctx 下为页面计算图标时保存证据,返回读取证据的函数。 需要同时在请求选项中开启 IconEvidence。

Types

type Classification

type Classification struct {
	CvssMetrics string  `yaml:"cvss-metrics"`
	CvssScore   float64 `yaml:"cvss-score"`
	CveId       string  `yaml:"cve-id"`
	CweId       string  `yaml:"cwe-id"`
}

type DetectionRule added in v1.2.0

type DetectionRule struct {
	Key        string
	Transport  string
	Method     string
	Path       string
	Expression string
	Output     map[string]string
}

type Diagnostic added in v1.8.0

type Diagnostic struct {
	Code     string
	Field    string
	Message  string
	Severity string
	Line     int
	Column   int
}

Diagnostic 是规则校验发现的一处问题。Severity 为 error 或 warning;Line、Column 从 1 开始,无法定位时为 0。Field 是规则内的字段路径,如 rules.r0.request.raw。

func Validate added in v1.8.0

func Validate(content []byte, opts ValidateOptions) []Diagnostic

Validate 校验一条规则的内容,不发请求。非严格模式下 error 与引擎拒绝加载一一对应: YAML 无法解析(含不支持的请求类型)或违反规则策略;其余问题为 warning。严格模式 把规范性问题也报告为 error,用于入库前检查。库级限制(MaxRules)不适用于单条规则。

type ExpressionError added in v1.7.0

type ExpressionError struct {
	Rule       string
	Expression string
	Err        error
}

ExpressionError 是一条编译不通过的表达式。Rule 为空表示指纹的总表达式。

func CheckExpressions added in v1.7.0

func CheckExpressions(fg *Finger) []ExpressionError

CheckExpressions 编译指纹的每条规则表达式和总表达式,返回编译不通过的各项。 只编译、不发请求也不求值。set、payloads 与 output 定义的变量在运行时才有 确定的类型,这里按任意类型声明,因此只报告语法错误、未定义的函数与变量。

type Finger

type Finger struct {
	Id         string        `yaml:"id"`        //  脚本名称
	Transport  string        `yaml:"transport"` // 传输方式,该字段用于指定发送数据包的协议,该字段用于指定发送数据包的协议:①tcp ②udp ③http
	Set        yaml.MapSlice `yaml:"set"`       // 全局变量定义,该字段用于定义全局变量。比如随机数,反连平台等
	Payloads   Payloads      `yaml:"payloads"`
	Rules      RuleMapSlice  `yaml:"rules"`
	Expression string        `yaml:"expression"`
	Info       Info          `yaml:"info"`
	Source     Source        `yaml:"-"`
}

func Load

func Load(fileName string, Fingers embed.FS) (*Finger, error)

Load 加载yaml文件

func Parse added in v1.8.0

func Parse(content []byte, path string) (*Finger, error)

Parse 解析规则内容;path 记为规则来源,摘要按内容计算。

func Read

func Read(fileName string) (*Finger, error)

Read 获取yaml文件内容

func (*Finger) IsHTTPType

func (finger *Finger) IsHTTPType() bool

IsHTTPType 报告指纹是否包含 HTTP 规则。YAML 加载时类型已归一化为小写; 比较时仍忽略大小写与空白,使不经 YAML 直接构造的规则得到相同结论。

type GetIconHash

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

GetIconHash 获取 icon hash。

func NewGetIconHash

func NewGetIconHash(iconURL string, proxy string) *GetIconHash

NewGetIconHash 初始化 GetIconHash

func (*GetIconHash) WithEvidence added in v1.8.0

func (g *GetIconHash) WithEvidence(limit int) *GetIconHash

WithEvidence 在计算哈希的同一次读取中记录证据,原始字节最多保留 limit 字节。

func (*GetIconHash) WithHTTPClient

func (g *GetIconHash) WithHTTPClient(client *network.HTTPClient) *GetIconHash

WithHTTPClient 绑定 Runner/Engine 持有的 HTTP 客户端(nil 时回退 DefaultHTTPClient)。

func (*GetIconHash) WithHeaders

func (g *GetIconHash) WithHeaders(headers map[string]string) *GetIconHash

WithHeaders 复制页面请求头,支持需要认证或 Referer 的图标资源。

func (*GetIconHash) WithTimeout

func (g *GetIconHash) WithTimeout(timeout time.Duration) *GetIconHash

WithTimeout 设置 favicon 请求超时。

type IconEvidence added in v1.8.0

type IconEvidence struct {
	URL         string
	ContentType string
	Bytes       int64
	SHA256      string
	MMH3        string
	Data        []byte
	TooLarge    bool
	CrossOrigin bool
}

IconEvidence 是页面图标的证据,来自计算图标哈希的同一次读取,不另发请求。 Data 是图标原始字节,超过上限时为空并置 TooLarge;CrossOrigin 表示图标与页面不属于 同一资产(协议、主机、端口)。

type Info

type Info struct {
	Name             string         `yaml:"name"`
	Author           string         `yaml:"author"`
	Severity         string         `yaml:"severity"`
	Verified         bool           `yaml:"verified"`
	VerifiedDeclared bool           `yaml:"-"`
	Description      string         `yaml:"description"`
	Reference        []string       `yaml:"reference"`
	Affected         string         `yaml:"affected"`  // 影响版本
	Solutions        string         `yaml:"solutions"` // 解决方案
	Tags             string         `yaml:"tags"`      // 标签
	Classification   Classification `yaml:"classification"`
	Created          string         `yaml:"created"` // create time
	// Product 是规则声明的产品信息,未声明时为 nil;调用方自有规则可以不声明。
	Product *Product `yaml:"product"`
	// Services 是 TCP/UDP 规则识别的服务;HTTP 规则可以省略。
	Services []Service `yaml:"services"`
	// Metadata 是任意附加信息,引擎只透传,不参与匹配。
	Metadata map[string]any `yaml:"metadata"`
}

Info 以下开始是 信息部分

func (*Info) UnmarshalYAML added in v1.2.0

func (i *Info) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML 区分未填写 verified 与明确的 false,保留原始声明;附加元数据中的嵌套 映射统一为 map[string]any。

type Metadata added in v1.2.0

type Metadata struct {
	ID         string
	Info       Info
	Source     Source
	Transport  string
	Expression string
	Detection  []DetectionRule
}

Metadata 展示规则来源和检测依据,不暴露表达式树及执行状态。

type Payloads

type Payloads struct {
	Continue bool          `yaml:"continue"`
	Payloads yaml.MapSlice `yaml:"payloads"`
}

type PolicyError added in v1.8.0

type PolicyError struct {
	RuleID  string
	Field   string
	Code    string
	Message string
}

PolicyError 是一处违反规则策略的内容。Field 是规则内的字段路径(如 rules.r0.request.raw)。

func CheckPolicy added in v1.8.0

func CheckPolicy(fg *Finger, policy RulePolicy) []*PolicyError

CheckPolicy 返回规则违反策略的全部内容;策略未生效时返回 nil。表达式按语法解析, 无法解析的表达式不在这里报告(加载后求值失败,按未命中处理)。

func (*PolicyError) Error added in v1.8.0

func (e *PolicyError) Error() string

func (*PolicyError) Unwrap added in v1.8.0

func (e *PolicyError) Unwrap() error

type Product added in v1.8.0

type Product struct {
	ID          string   `yaml:"id"`          // 厂商段.产品段,如 weaver.e-cology
	Name        string   `yaml:"name"`        // 规范产品名
	Vendor      string   `yaml:"vendor"`      // 厂商规范名,不确定时留空
	Category    string   `yaml:"category"`    // 产品分类,取值见 ProductCategories
	Identity    string   `yaml:"identity"`    // product:命中即确认产品;signal:技术线索
	Assurance   string   `yaml:"assurance"`   // verified:厂商与产品已确认;inferred:由规则名称与特征推断
	Tags        []string `yaml:"tags"`        // 产品级用途标签
	Aliases     []string `yaml:"aliases"`     // 别名与旧名
	CPE         []string `yaml:"cpe"`         // CPE 2.3,只在有依据时填写
	References  []string `yaml:"references"`  // 官方主页、文档或仓库
	Description string   `yaml:"description"` // 产品简介
}

Product 是规则声明的产品信息(info.product)。规则自带的声明是产品信息的来源; 同一个产品标识在全部规则中的声明必须完全相同,规则库加载时检查。

func (Product) Clone added in v1.8.0

func (p Product) Clone() Product

Clone 返回不与原值共享切片的副本。

func (Product) DifferentField added in v1.8.0

func (p Product) DifferentField(other Product) string

DifferentField 返回两份声明中第一个不同的字段名(按声明的字段顺序),相同时返回空串。

func (Product) Equal added in v1.8.0

func (p Product) Equal(other Product) bool

Equal 报告两份产品声明是否完全相同;未填写的列表与空列表视为相同。

type ProductConflictError added in v1.8.0

type ProductConflictError struct {
	ProductID string
	RuleIDs   [2]string
	Field     string
}

ProductConflictError 表示同一产品标识在两条规则中的声明不一致。

func (*ProductConflictError) Error added in v1.8.0

func (e *ProductConflictError) Error() string

type Rule

type Rule struct {
	Request    RuleRequest   `yaml:"request"`
	Expression string        `yaml:"expression"`
	Output     yaml.MapSlice `yaml:"output"`
}

type RuleMap

type RuleMap struct {
	Key   string
	Value Rule
}

RuleMap 用于帮助yaml解析,保证Rule有序

type RuleMapSlice

type RuleMapSlice []RuleMap

RuleMapSlice 用于帮助yaml解析,保证Rule有序

func (*RuleMapSlice) UnmarshalYAML

func (m *RuleMapSlice) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML 保持规则在源文件中的顺序,重复名称采用最后一次定义。 所有解析状态属于当前调用;并发加载规则不需要共享计数器或全局锁。

type RulePolicy added in v1.8.0

type RulePolicy struct {
	AllowTypes   []string
	AllowRaw     bool
	AllowReverse bool
	AllowSleep   bool
	MaxRules     int
	MaxSubRules  int
}

RulePolicy 限制可以加载的规则。零值表示不限制;任一字段非零时策略生效,未允许的 能力一律拒绝:AllowTypes 为空时允许 http、tcp、udp 全部类型,否则只允许列出的类型; AllowRaw、AllowReverse、AllowSleep 分别允许 Raw HTTP 请求、反连检测(newReverse、 newJNDI、wait、jndi)与 sleep;MaxRules、MaxSubRules 限制规则数与单条规则的子规则数, 0 表示不限制。

func (RulePolicy) Active added in v1.8.0

func (p RulePolicy) Active() bool

Active 报告策略是否生效。

type RuleRequest

type RuleRequest struct {
	Type            string            `yaml:"type"`         // 传输方式,默认 http,可选 http/tcp/udp;其余值在加载时报错
	Host            string            `yaml:"host"`         // tcp/udp 连接地址,格式见 network.ParseEndpoint;为空时使用扫描目标
	Data            string            `yaml:"data"`         // tcp/udp 发送的内容
	DataType        string            `yaml:"data-type"`    // tcp/udp 发送的数据类型,默认字符串
	ReadSize        int               `yaml:"read-size"`    // tcp/udp 读取内容的长度
	ReadTimeout     int               `yaml:"read-timeout"` // tcp/udp 单次接收的总时长上限(秒)
	ReadIdle        int               `yaml:"read-idle"`    // tcp 收到数据后等待后续分段的空闲时间(毫秒);未设置时自适应
	Raw             string            `yaml:"raw"`          // raw 专用
	Method          string            `yaml:"method"`
	Path            string            `yaml:"path"`
	Headers         map[string]string `yaml:"headers"`
	Body            string            `yaml:"body"`
	FollowRedirects *bool             `yaml:"follow_redirects,omitempty"` // 是否跟随重定向:true 跟随,false 不跟随,未声明时默认跟随
}

func (RuleRequest) ShouldFollowRedirects added in v1.3.0

func (r RuleRequest) ShouldFollowRedirects() bool

ShouldFollowRedirects 返回该请求是否跟随重定向。 未声明 follow_redirects 时默认跟随,与规则格式文档以及 IDE 生成的规则保持一致。

type Service added in v1.8.0

type Service struct {
	Protocol  string `yaml:"protocol"`  // 应用层协议,如 ssh、mysql
	Transport string `yaml:"transport"` // tcp 或 udp
	Ports     []int  `yaml:"ports"`     // 常见端口,1–65535
}

Service 是 TCP/UDP 规则识别的服务(info.services 的一项)。

func CloneServices added in v1.8.0

func CloneServices(services []Service) []Service

CloneServices 返回不与原值共享端口列表的副本。

type Source added in v1.2.0

type Source struct {
	Path    string
	SHA256  string
	Builtin bool
}

Source 记录实际加载的规则文件;摘要只在加载时计算。

type ValidateOptions added in v1.8.0

type ValidateOptions struct {
	// Strict 为 true 时,规范性问题(未知键、缺少必填信息、产品与服务声明不合规、表达式无法编译)报告为 error;
	// 否则报告为 warning,与引擎宽松加载的行为一致。
	Strict bool
	// Policy 与加载时使用的规则策略相同;违反策略总是 error。
	Policy RulePolicy
}

ValidateOptions 是规则校验的选项。

Jump to

Keyboard shortcuts

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