webprobe

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 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 webprobe 把 Web 服务处理完的请求交给入侵防护,按路径探测规则计数封禁。

扫描器探测路径时请求量很大,这里不走事件总线(每个事件为每个订阅者开协程,还会经过通知中心), 而是在请求结束时同步调用入侵防护注册的处理函数,未注册时只有一次原子读取的开销。

Index

Constants

View Source
const (
	// TLSEOF 对端在握手中途关闭连接(EOF、unexpected EOF):端口探测与扫描器常见,浏览器预连接被丢弃时也会出现
	TLSEOF = "eof"
	// TLSReset 对端重置连接(connection reset、broken pipe)
	TLSReset = "reset"
	// TLSTimeout 握手超时(i/o timeout)
	TLSTimeout = "timeout"
	// TLSProtocol 对端发来的不是有效的 TLS:明文 HTTP、SSLv2、乱码、过大的记录、版本过低等
	TLSProtocol = "protocol"
	// TLSNegotiation 双方没有共同的套件、密钥交换、曲线或应用层协议
	TLSNegotiation = "negotiation"
	// TLSNoCert 请求了本监听器不提供的域名(没有匹配的证书)
	TLSNoCert = "nocert"
	// TLSAlert 对端发来 TLS 警报并中止握手(例如不信任本机证书),多为客户端自身的信任问题,统计时要谨慎
	TLSAlert = "alert"
	// TLSOther 其他原因
	TLSOther = "other"
)

TLS 握手失败的原因类别,规则按类别选择要统计的失败。

Variables

TLSKinds 是全部原因类别,供规则校验与界面选择。

Functions

func ClassifyTLS added in v0.6.8

func ClassifyTLS(reason string) string

ClassifyTLS 按握手失败原因(net/http 日志中的原因部分)归类。 缺少证书的原因由证书模块的错误句给出,格式属于 Web 服务,不在这里识别(见 Web 服务的 reportTLSFail)。

func Report

func Report(h Hit)

Report 在请求结束时调用,没有注册处理函数时直接返回。

func ReportTLS added in v0.6.8

func ReportTLS(f TLSFail)

ReportTLS 在握手失败时调用,没有注册处理函数时直接返回。

func SetHandler

func SetHandler(f func(Hit))

SetHandler 注册处理函数,传 nil 取消注册。同一时间只有一个处理函数。

func SetTLSHandler added in v0.6.8

func SetTLSHandler(f func(TLSFail))

SetTLSHandler 注册握手失败的处理函数,传 nil 取消注册。同一时间只有一个处理函数。

func TLSEnabled added in v0.6.8

func TLSEnabled() bool

TLSEnabled 返回是否有处理函数,调用方据此跳过分类等准备工作。

Types

type Hit

type Hit struct {
	// Addr 为客户端地址(已按可信代理、PROXY 协议还原)
	Addr netip.Addr
	// Listener 为监听的 key
	Listener string
	// Site 为处理请求的站点 key;没有任何站点处理(域名未匹配且没有默认站点)时为空
	Site string
	// Unknown 表示请求的域名没有匹配任何站点,由默认站点处理或直接返回 404
	Unknown bool
	Method  string
	Host    string
	// Path 为请求路径(已解码,未规范化)
	Path string
	// Status 为响应状态码,断开连接记为 444
	Status int
}

Hit 是 Web 服务处理完的一次请求。

type TLSFail added in v0.6.8

type TLSFail struct {
	// Addr 为客户端地址(已按可信代理、PROXY 协议还原)
	Addr netip.Addr
	// Listener 为监听的 key
	Listener string
	// Kind 为原因类别,见 TLS* 常量
	Kind string
	// Reason 为 crypto/tls、net/http 给出的原始原因
	Reason string
}

TLSFail 是一次 TLS 握手失败。

Jump to

Keyboard shortcuts

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