mitm

package
v0.9.20 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalRequestStats = &RequestStats{}
View Source
var GlobalUpstreamStats = &UpstreamProtocolStats{
	stats: make(map[string]*RequestStats),
}

Functions

This section is empty.

Types

type MITM

type MITM struct {
	ListenHTTPS bool   //开启 HTTPS 代理服务器
	EnableMITM  bool   //启用 HTTPS 中间人解密,关闭时 CONNECT 走 TCP 隧道透传
	HTTPAddr    string //HTTP listen addr
	HTTPSAddr   string //HTTPS listen addr
	TLSConf     *TLSConfig
	Print       bool //打印请求详情

	Scheduler      func(req *http.Request) (proxy string, err error) //代理调度 func
	Filter         func(req *http.Request) error                     //请求鉴权、清洗、限流
	OnProxyFailure func(proxyURI string)                             //上游代理不可用时的回调(如 407 需要认证)
	// contains filtered or unexported fields
}

MITM 中间人

func (*MITM) Dump

func (m *MITM) Dump(clientResponse http.ResponseWriter, clientRequest *http.Request)

Dump rt

func (*MITM) FakeCert

func (m *MITM) FakeCert(domain string) (*tls.Certificate, error)

FakeCert rt

func (*MITM) GenerateCA

func (m *MITM) GenerateCA() error

GenerateCA rt

func (*MITM) Init

func (m *MITM) Init()

Init mitm

func (*MITM) ServeHTTP

func (m *MITM) ServeHTTP()

type ProcessCounts added in v0.5.0

type ProcessCounts struct {
	Lightpanda int `json:"lightpanda"`
}

func GetProcessCounts added in v0.5.0

func GetProcessCounts() ProcessCounts

type ProxyConnectError added in v0.9.12

type ProxyConnectError struct {
	StatusCode int
	Status     string
}

ProxyConnectError 上游代理在 CONNECT 握手阶段返回的非 200 响应, 携带 StatusCode 以便上层区分 407(需要认证)等可识别的失败原因

func (*ProxyConnectError) Error added in v0.9.12

func (e *ProxyConnectError) Error() string

type RequestStats added in v0.5.0

type RequestStats struct {
	TotalRequests    atomic.Int64
	SuccessRequests  atomic.Int64
	FailedRequests   atomic.Int64
	BytesTransferred atomic.Int64
}

RequestStats 代理请求的全局运行时统计(atomic,无锁)

func (*RequestStats) Snapshot added in v0.5.0

func (s *RequestStats) Snapshot() RequestStatsSnapshot

type RequestStatsSnapshot added in v0.5.0

type RequestStatsSnapshot struct {
	TotalRequests    int64   `json:"total_requests"`
	SuccessRequests  int64   `json:"success_requests"`
	FailedRequests   int64   `json:"failed_requests"`
	SuccessRate      float64 `json:"success_rate"`
	BytesTransferred int64   `json:"bytes_transferred"`
}

type TLSConfig

type TLSConfig struct {
	PrivateKeyFile  string
	CertFile        string
	Organization    string
	CommonName      string
	ServerTLSConfig *tls.Config
}

TLSConfig TLS配置

type UpstreamProtocolStats added in v0.9.1

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

UpstreamProtocolStats 按上游代理协议(http/https/socks4/socks5)分别统计请求数和流量

func (*UpstreamProtocolStats) Get added in v0.9.1

func (u *UpstreamProtocolStats) Get(protocol string) *RequestStats

func (*UpstreamProtocolStats) Snapshot added in v0.9.1

Jump to

Keyboard shortcuts

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