probe

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TCP 协议
	TCP = "tcp"
	// UDP 协议
	UDP = "udp"
)

定义协议类型常量

View Source
const DefaultRegexpTimeout = 500 * time.Millisecond

DefaultRegexpTimeout 默认正则表达式匹配超时时间,防止灾难性回溯

Variables

View Source
var DefaultVersionIntensity = 7

Functions

func FixProtocol

func FixProtocol(oldProtocol string) string

FixProtocol 标准化协议名称

func GetCacheKey

func GetCacheKey(fileName string, versionIntensity int) string

GetCacheKey 根据文件名和版本强度生成缓存键

func GetDefaultProbeFilePath

func GetDefaultProbeFilePath() string

GetDefaultProbeFilePath 获取默认的探针文件路径

func InitDefaultStore

func InitDefaultStore() error

func ParseRegexPattern

func ParseRegexPattern(pattern string) string

ParseRegexPattern 转换正则表达式

func RegexStringUnescape

func RegexStringUnescape(s string) string

Types

type FingerprintOptions

type FingerprintOptions struct {
	// 指纹文件路径(可选,默认使用内置指纹)
	ProbeFilePath string
	// 版本检测强度(0-9)
	VersionIntensity int
}

FingerprintOptions 指纹库配置选项

type Match

type Match struct {
	// 行号
	Line int
	// 是否为软匹配
	Soft bool
	// 服务名称
	Service string
	// 匹配模式
	Pattern string

	// 版本信息
	VersionInfo *VersionInfo
	// contains filtered or unexported fields
}

Match 表示一个匹配规则

type MatchResult

type MatchResult struct {
	// 匹配的探针
	Probe *Probe
	// 匹配的规则
	Match *Match
	// 提取的版本信息
	VersionInfo map[string]interface{}
	// 是否通过fallback匹配
	IsFallback bool
	// fallback链路径(如果是通过fallback匹配的)
	FallbackPath []string
	// 原始响应数据
	Response []byte
}

type Probe

type Probe struct {
	// 探针名称
	Name string
	// 探针适用的默认端口
	Ports []int
	// 探针适用的SSL端口
	SSLPorts []int
	// 探针总等待时间
	TotalWaitMS time.Duration
	// TCP包装等待时间
	TCPWrappedMS time.Duration
	// 探针稀有度(值越小优先级越高)
	Rarity int
	// 使用字符串表示协议类型
	Protocol string
	// 探针发送数据
	SendData []byte
	// 匹配组
	MatchGroup []*Match
	// 回退探针名称
	Fallback []string
	// 回退探针引用
	FallbackProbes []*Probe
	// 探针的匹配超时时间
	MatchTimeout time.Duration
}

Probe 表示一个服务探针

func ParseProbes

func ParseProbes(content string) ([]*Probe, error)

ParseProbes 解析探针文件内容并添加到指定的探针存储中

func (*Probe) HasExactPort

func (p *Probe) HasExactPort(port int) bool

HasExactPort 检查探针是否精确匹配指定端口(单独列出而非端口范围)

func (*Probe) HasExactSSLPort

func (p *Probe) HasExactSSLPort(port int) bool

HasExactSSLPort 检查探针是否精确匹配SSL端口(单独列出而非端口范围)

func (*Probe) HasPort

func (p *Probe) HasPort(port int) bool

HasPort 检查探针是否适用于指定端口

func (*Probe) HasSSLPort

func (p *Probe) HasSSLPort(port int) bool

HasSSLPort 检查探针是否适用于指定SSL端口

func (*Probe) Match

func (p *Probe) Match(response []byte) (*MatchResult, error)

Match 匹配响应数据,返回匹配结果

type Store

type Store struct {

	// 按名称索引的探针映射
	ProbesByName map[string]*Probe
	// TCP探针列表
	TCPProbes []*Probe
	// UDP探针列表
	UDPProbes []*Probe
	// contains filtered or unexported fields
}
var (
	DefaultStore *Store
)

默认探针存储实例

func GetDefaultStore

func GetDefaultStore() *Store

func GetStoreWithOptions

func GetStoreWithOptions(filename string, versionIntensity int, reload bool) (*Store, error)

GetStoreWithOptions GetStoreWithIntensity 获取指定版本强度的探针存储

func NewProbeStore

func NewProbeStore(opts ...StoreOption) *Store

NewProbeStore 创建新的探针存储

func (*Store) AddProbe

func (ps *Store) AddProbe(probe *Probe)

AddProbe 添加探针到存储

func (*Store) Clear

func (ps *Store) Clear()

Clear 清空探针存储

func (*Store) GetAllProbes

func (ps *Store) GetAllProbes() []*Probe

GetAllProbes 获取所有探针列表

func (*Store) GetProbe

func (ps *Store) GetProbe(protocol, name string) *Probe

GetProbe 根据协议和名称获取探针

func (*Store) GetProbeForPort

func (ps *Store) GetProbeForPort(protocol string, port int, ssl bool) []*Probe

GetProbeForPort 获取适用于指定端口的探针列表,先按端口精确匹配度排序,再按稀有度排序

func (*Store) GetProbesByName

func (ps *Store) GetProbesByName(name string) *Probe

GetProbesByName 根据名称获取探针

func (*Store) GetTCPProbes

func (ps *Store) GetTCPProbes() []*Probe

GetTCPProbes 获取TCP探针列表

func (*Store) GetUDPProbes

func (ps *Store) GetUDPProbes() []*Probe

GetUDPProbes 获取UDP探针列表

func (*Store) Load

func (ps *Store) Load() error

func (*Store) LoadFromContent

func (ps *Store) LoadFromContent(content string) error

LoadFromContent 从字符串内容加载探针

func (*Store) LoadFromFile

func (ps *Store) LoadFromFile(filePath string) error

LoadFromFile 从文件加载探针

func (*Store) SetFallbackProbes

func (ps *Store) SetFallbackProbes() error

SetFallbackProbes 设置探针的fallback引用

type StoreOption

type StoreOption func(*Store)

func WithFileName

func WithFileName(fileName string) StoreOption

func WithVersionIntensity

func WithVersionIntensity(versionIntensity int) StoreOption

type TemplateProcessor

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

TemplateProcessor 处理版本信息模板替换

func NewTemplateProcessor

func NewTemplateProcessor(groups map[string]string) *TemplateProcessor

NewTemplateProcessor 创建一个新的模板处理器

func (*TemplateProcessor) ProcessTemplate

func (p *TemplateProcessor) ProcessTemplate(template string) string

ProcessTemplate 处理模板字符串,替换其中的变量

type VersionInfo

type VersionInfo struct {
	// 产品名称
	ProductName string
	// 版本号
	Version string
	// 附加信息
	Info string
	// 主机名
	Hostname string
	// 操作系统
	OS string
	// 设备类型
	DeviceType string
	// CPE标识符
	CPE []string
}

VersionInfo 表示版本信息

Jump to

Keyboard shortcuts

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