Documentation
¶
Overview ¶
Package ciproxy a proxy frame implement by tcp,udp
Package ciproxy proxyHandle 代理响应处理头 ¶
Package ciproxy 流量转发
Index ¶
- Constants
- Variables
- func AddMITMMiddleware(mw middleware.Middleware)
- func CryptTraffic(data []byte, cryptor *TrafficCryptor) ([]byte, error)
- func DecryptTraffic(data []byte, cryptor *TrafficCryptor) ([]byte, error)
- func GetInterceptor() *mitm.Interceptor
- func HttpInterceptProxyHandle(c *Context)
- func HttpProxyHandle(c *Context)
- func HttpsProxyHandle(c *Context)
- func HttpsSniffDetailProxyHandle(c *Context)
- func HttpsSniffProxyHandle(c *Context)
- func ServeProxy(p *ProxyServe)
- func SetInterceptorConfig(config *mitm.InterceptorConfig)
- func TeeDoRequestTransfer(c *Context)
- func TeeTransfer(destination io.WriteCloser, source io.ReadCloser)
- func Transfer(destination io.WriteCloser, source io.ReadCloser)
- func TunnelProxyHandle(c *Context)
- func TunnelTransfer(client, server io.ReadWriteCloser, cryptor *TrafficCryptor)
- func WebsocketProxyHandle(c *Context)
- type Context
- type Cryptor
- type FeatureFlags
- type FileWriter
- type LogLevel
- type Logger
- func (l *Logger) Debug(msg string, args ...interface{})
- func (l *Logger) Error(msg string, args ...interface{})
- func (l *Logger) Info(msg string, args ...interface{})
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) Warn(msg string, args ...interface{})
- type Middleware
- type MiddlewareFunc
- type NOPCryptor
- type ProxyConfig
- type ProxyError
- type ProxyHandle
- type ProxyHandlersChain
- type ProxyServe
- func (s *ProxyServe) AddHandle(proxyHandle ProxyHandle)
- func (s *ProxyServe) AddMiddleware(proxyHandle ProxyHandle)
- func (s *ProxyServe) Handle(handler ProxyHandle) *ProxyServe
- func (s *ProxyServe) IsRunning() bool
- func (s *ProxyServe) Run() error
- func (s *ProxyServe) ServerHandleListen()
- func (s *ProxyServe) SetHost(ip, port string) *ProxyServe
- func (s *ProxyServe) SetMaxConnections(max int64) *ProxyServe
- func (s *ProxyServe) SetMethod(method string) *ProxyServe
- func (s *ProxyServe) Shutdown(ctx context.Context) error
- func (s *ProxyServe) Start() error
- func (s *ProxyServe) StartWithContext(ctx context.Context) error
- func (s *ProxyServe) Stats() ServerStats
- func (s *ProxyServe) Use(middleware ...ProxyHandle) *ProxyServe
- type ServerOption
- type ServerStats
- type TLSConfig
- type TimeoutConfig
- type TrafficCryptor
- type TransferOption
- type TransferOptions
Constants ¶
const ( HttpProxy = "HttpProxy" HttpsProxy = "HttpsProxy" HttpsSniffProxy = "HttpsSniffProxy" HttpsSniffDetailProxy = "HttpsSniffDetailProxy" HttpInterceptProxy = "HttpInterceptProxy" // 新增:完整的 HTTPS MITM 拦截代理 WebsocketProxy = "WebsocketProxy" TcpNormalProxy = "TcpNormal" TcpTunnelProxy = "TcpTunnel" PortProxy = "PortProxy" DefaultProxy = "All" )
ProxyMethod constant proxyMethod
const ( ProxyVersion = "v0.0.0" ProxyMode = "Debug" // DefaultIp DefaultPort defaultServerConfig DefaultIp = "127.0.0.1" DefaultPort = "" ProxyOrganization = "www.cilang.buzz" )
Proxy Config
const ( DefaultConnectProtocol = "Tcp" DefaultOutTime = 10 * time.Second )
connectConfig Connect Config Constant
Variables ¶
var ( ErrInvalidRequest = errors.New("invalid request") ErrConnectionFailed = errors.New("remote connection failed") ErrTLSHandshakeFailed = errors.New("TLS handshake failed") ErrCertificateLoad = errors.New("certificate load failed") ErrProtocolNotSupported = errors.New("protocol not supported") ErrEntryNotFound = errors.New("traffic entry not found") )
标准错误定义
var DefaultConfig = ProxyConfig{ IP: DefaultIp, Port: "8080", Protocol: DefaultConnectProtocol, Method: HttpProxy, LogPath: "", TLS: TLSConfig{ CertPath: "", KeyPath: "", }, Timeout: TimeoutConfig{ Connect: DefaultOutTime, Read: 30 * time.Second, Write: 30 * time.Second, }, Features: FeatureFlags{ EnableTrafficCapture: false, EnableTrafficReplay: false, EnableTunnelCrypt: false, }, }
DefaultConfig 默认配置
var DefaultWriter io.Writer = os.Stdout
DefaultWriter reference gin
var WithBufferSize = transfer.WithBufferSize
WithBufferSize 设置缓冲区大小
var WithCryptor = transfer.WithCryptor
WithCryptor 设置加密器
var WithDataCallback = transfer.WithDataCallback
WithDataCallback 设置数据回调
var WithErrorCallback = transfer.WithErrorCallback
WithErrorCallback 设置错误回调
Functions ¶
func AddMITMMiddleware ¶
func AddMITMMiddleware(mw middleware.Middleware)
AddMITMMiddleware 添加 MITM 中间件
func CryptTraffic ¶
func CryptTraffic(data []byte, cryptor *TrafficCryptor) ([]byte, error)
CryptTraffic 流量加密
func DecryptTraffic ¶
func DecryptTraffic(data []byte, cryptor *TrafficCryptor) ([]byte, error)
DecryptTraffic 流量解密
func HttpInterceptProxyHandle ¶
func HttpInterceptProxyHandle(c *Context)
HttpInterceptProxyHandle 完整的 HTTPS MITM 拦截处理 支持请求/响应拦截、修改、流量捕获、HTTP/1.1 和 HTTP/2
func HttpsSniffDetailProxyHandle ¶
func HttpsSniffDetailProxyHandle(c *Context)
HttpsSniffDetailProxyHandle https中间人处理
func HttpsSniffProxyHandle ¶
func HttpsSniffProxyHandle(c *Context)
HttpsSniffProxyHandle https中间人处理
func ServeProxy ¶
func ServeProxy(p *ProxyServe)
ServeProxy 启动监听(向后兼容) Deprecated: 使用 ProxyServe.Start() 代替 迁移示例:
旧: ServeProxy(proxyServe) 新: proxyServe.Start()
func SetInterceptorConfig ¶
func SetInterceptorConfig(config *mitm.InterceptorConfig)
SetInterceptorConfig 设置拦截器配置
func TeeDoRequestTransfer ¶
func TeeDoRequestTransfer(c *Context)
TeeDoRequestTransfer traffic transfer 流量Io转发,手动处理请求
func TeeTransfer ¶
func TeeTransfer(destination io.WriteCloser, source io.ReadCloser)
TeeTransfer traffic transfer 流量Io转发 使用 DefaultWriter 作为 tee 输出
func Transfer ¶
func Transfer(destination io.WriteCloser, source io.ReadCloser)
Transfer traffic transfer 流量Io转发 注意:忽略错误以保持向后兼容
func TunnelTransfer ¶
func TunnelTransfer(client, server io.ReadWriteCloser, cryptor *TrafficCryptor)
TunnelTransfer 加密流量转发
Types ¶
type FeatureFlags ¶
type FeatureFlags struct {
EnableTrafficCapture bool `json:"enableTrafficCapture"`
EnableTrafficReplay bool `json:"enableTrafficReplay"`
EnableTunnelCrypt bool `json:"enableTunnelCrypt"`
}
FeatureFlags 功能开关
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter 文件写入器
type ProxyConfig ¶
type ProxyConfig struct {
// 网络设置
IP string `json:"ip"`
Port string `json:"port"`
Protocol string `json:"protocol"`
// 代理设置
Method string `json:"method"`
LogPath string `json:"logPath"`
// TLS设置
TLS TLSConfig `json:"tls"`
// 超时设置
Timeout TimeoutConfig `json:"timeout"`
// 功能开关
Features FeatureFlags `json:"features"`
}
ProxyConfig 代理服务配置
type ProxyError ¶
ProxyError 表示代理相关错误
func NewProxyError ¶
func NewProxyError(op, host string, err error) *ProxyError
NewProxyError 创建新的代理错误
func (*ProxyError) Error ¶
func (e *ProxyError) Error() string
func (*ProxyError) Unwrap ¶
func (e *ProxyError) Unwrap() error
type ProxyHandlersChain ¶
type ProxyHandlersChain = context.ProxyHandlersChain
ProxyHandlersChain 处理器链
type ProxyServe ¶
type ProxyServe struct {
// ========== 向后兼容字段 ==========
// Deprecated: 使用 config.IP 代替
Ip string `json:"ip,omitempty"`
// Deprecated: 使用 config.Port 代替
Port string `json:"port,omitempty"`
// Deprecated: 使用 config.Method 代替
Method string `json:"method,omitempty"`
// Deprecated: 使用 config.Protocol 代替
Protocol string `json:"protocol,omitempty"`
// Deprecated: 使用 config.LogPath 代替
LogPath string `json:"logPath,omitempty"`
// Deprecated: 内部使用
Host string
// Deprecated: 内部使用
ProxyHandlersChain ProxyHandlersChain
// contains filtered or unexported fields
}
ProxyServe 代理服务器
func (*ProxyServe) AddHandle ¶
func (s *ProxyServe) AddHandle(proxyHandle ProxyHandle)
AddHandle 设置自定义代理响应处理(从尾部添加) Deprecated: 使用 Handle() 代替
func (*ProxyServe) AddMiddleware ¶
func (s *ProxyServe) AddMiddleware(proxyHandle ProxyHandle)
AddMiddleware 从头部添加中间件 Deprecated: 使用 Use() 代替
func (*ProxyServe) Handle ¶
func (s *ProxyServe) Handle(handler ProxyHandle) *ProxyServe
Handle 添加处理器(链式调用)
func (*ProxyServe) ServerHandleListen ¶
func (s *ProxyServe) ServerHandleListen()
ServerHandleListen ServerHandle 服务代理处理 Deprecated: 使用 Start() 代替
func (*ProxyServe) SetHost ¶
func (s *ProxyServe) SetHost(ip, port string) *ProxyServe
SetHost 设置监听地址(链式调用)
func (*ProxyServe) SetMaxConnections ¶
func (s *ProxyServe) SetMaxConnections(max int64) *ProxyServe
SetMaxConnections 设置最大连接数(链式调用)
func (*ProxyServe) SetMethod ¶
func (s *ProxyServe) SetMethod(method string) *ProxyServe
SetMethod 设置代理方法(链式调用)
func (*ProxyServe) Shutdown ¶
func (s *ProxyServe) Shutdown(ctx context.Context) error
Shutdown 优雅关闭服务器
func (*ProxyServe) StartWithContext ¶
func (s *ProxyServe) StartWithContext(ctx context.Context) error
StartWithContext 使用上下文启动服务器
func (*ProxyServe) Use ¶
func (s *ProxyServe) Use(middleware ...ProxyHandle) *ProxyServe
Use 添加中间件(链式调用)
type ServerOption ¶
type ServerOption func(*ProxyServe)
ServerOption 服务器选项函数
func WithMaxConnections ¶
func WithMaxConnections(max int64) ServerOption
WithMaxConnections 设置最大连接数
type ServerStats ¶
type ServerStats struct {
TotalConnections int64 // 总连接数
ActiveConnections int64 // 当前活跃连接数
FailedConnections int64 // 失败连接数
BytesReceived int64 // 接收字节数
BytesSent int64 // 发送字节数
StartTime time.Time // 启动时间
}
ServerStats 服务器统计信息
type TLSConfig ¶
type TLSConfig struct {
CertPath string `json:"certPath"`
KeyPath string `json:"keyPath"`
CertData []byte `json:"certData,omitempty"`
KeyData []byte `json:"keyData,omitempty"`
}
TLSConfig TLS证书配置
type TimeoutConfig ¶
type TimeoutConfig struct {
Connect time.Duration `json:"connect"`
Read time.Duration `json:"read"`
Write time.Duration `json:"write"`
}
TimeoutConfig 超时配置
type TrafficCryptor ¶
type TrafficCryptor = transfer.TrafficCryptor
TrafficCryptor 流量加密器
func NewTrafficCryptor ¶
func NewTrafficCryptor(key []byte) (*TrafficCryptor, error)
NewTrafficCryptor 创建新的流量加密器
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
config_demo
command
|
|
|
custom_proxy_server
command
|
|
|
generate_cert
command
|
|
|
http_proxy_server
command
|
|
|
https_proxy_server
command
|
|
|
https_sniff_proxy_server
command
|
|
|
middleware_demo
command
|
|
|
mitm_proxy_server
command
|
|
|
traffic_capture_server
command
|
|
|
traffic_replay
command
|
|
|
tunnel_proxy_client
command
|
|
|
tunnel_proxy_server
command
|
|
|
websocket_proxy_server
command
|
|
|
pkg
|
|
|
util
Package util 生成Http响应内容
|
Package util 生成Http响应内容 |