Documentation
¶
Index ¶
- Variables
- func GetFingerprintDir() string
- func ListFingerprints() ([]string, error)
- func NewUtlsConn(conn net.Conn, opts *Options, clientHello *tls.ClientHelloInfo) (*utls.UConn, error)
- func SaveFingerprint(name string, fp *Fingerprint) error
- func UtlsStateToTlsState(state utls.ConnectionState) *tls.ConnectionState
- type Addon
- type BaseAddon
- func (addon *BaseAddon) AccessProxyServer(req *http.Request, res http.ResponseWriter)
- func (addon *BaseAddon) ClientConnected(*ClientConn)
- func (addon *BaseAddon) ClientDisconnected(*ClientConn)
- func (addon *BaseAddon) Request(*Flow)
- func (addon *BaseAddon) Requestheaders(*Flow)
- func (addon *BaseAddon) Response(*Flow)
- func (addon *BaseAddon) Responseheaders(*Flow)
- func (addon *BaseAddon) ServerConnected(*ConnContext)
- func (addon *BaseAddon) ServerDisconnected(*ConnContext)
- func (addon *BaseAddon) StreamRequestModifier(f *Flow, in io.Reader) io.Reader
- func (addon *BaseAddon) StreamResponseModifier(f *Flow, in io.Reader) io.Reader
- func (addon *BaseAddon) TlsEstablishedServer(*ConnContext)
- func (addon *BaseAddon) WebsocketHandshake(f *Flow)
- func (addon *BaseAddon) WebsocketMessage(f *Flow, msg *WebSocketMessage)
- type ClientConn
- type ConnContext
- type Fingerprint
- type Flow
- type InstanceLogAddon
- func (addon *InstanceLogAddon) ClientConnected(client *ClientConn)
- func (addon *InstanceLogAddon) ClientDisconnected(client *ClientConn)
- func (addon *InstanceLogAddon) Request(f *Flow)
- func (addon *InstanceLogAddon) Requestheaders(f *Flow)
- func (addon *InstanceLogAddon) Response(f *Flow)
- func (addon *InstanceLogAddon) ServerConnected(connCtx *ConnContext)
- func (addon *InstanceLogAddon) ServerDisconnected(connCtx *ConnContext)
- func (addon *InstanceLogAddon) SetLogger(logger *InstanceLogger)
- func (addon *InstanceLogAddon) TlsEstablishedServer(connCtx *ConnContext)
- type InstanceLogger
- func (il *InstanceLogger) Debug(args ...interface{})
- func (il *InstanceLogger) Debugf(format string, args ...interface{})
- func (il *InstanceLogger) Error(args ...interface{})
- func (il *InstanceLogger) Errorf(format string, args ...interface{})
- func (il *InstanceLogger) Fatal(args ...interface{})
- func (il *InstanceLogger) Fatalf(format string, args ...interface{})
- func (il *InstanceLogger) GetEntry() *log.Entry
- func (il *InstanceLogger) Info(args ...interface{})
- func (il *InstanceLogger) Infof(format string, args ...interface{})
- func (il *InstanceLogger) Warn(args ...interface{})
- func (il *InstanceLogger) Warnf(format string, args ...interface{})
- func (il *InstanceLogger) WithFields(fields log.Fields) *log.Entry
- type LogAddon
- func (addon *LogAddon) ClientConnected(client *ClientConn)
- func (addon *LogAddon) ClientDisconnected(client *ClientConn)
- func (addon *LogAddon) Requestheaders(f *Flow)
- func (addon *LogAddon) ServerConnected(connCtx *ConnContext)
- func (addon *LogAddon) ServerDisconnected(connCtx *ConnContext)
- func (addon *LogAddon) WebsocketHandshake(f *Flow)
- func (addon *LogAddon) WebsocketMessage(f *Flow, msg *WebSocketMessage)
- type Options
- type Proxy
- func (proxy *Proxy) AddAddon(addon Addon)
- func (proxy *Proxy) Addr() string
- func (proxy *Proxy) Close() error
- func (proxy *Proxy) GetCertificate() x509.Certificate
- func (proxy *Proxy) GetCertificateByCN(commonName string) (*tls.Certificate, error)
- func (proxy *Proxy) SetAuthProxy(fn func(res http.ResponseWriter, req *http.Request) (bool, error))
- func (proxy *Proxy) SetShouldInterceptRule(rule func(req *http.Request) bool)
- func (proxy *Proxy) SetUpstreamProxy(fn func(req *http.Request) (*url.URL, error))
- func (proxy *Proxy) Shutdown(ctx context.Context) error
- func (proxy *Proxy) Start() error
- type Request
- type Response
- type ServerConn
- type UpstreamCertAddon
- type WebSocketMessage
Constants ¶
This section is empty.
Variables ¶
var FingerprintDir string
Functions ¶
func GetFingerprintDir ¶
func GetFingerprintDir() string
func ListFingerprints ¶
func NewUtlsConn ¶
func NewUtlsConn(conn net.Conn, opts *Options, clientHello *tls.ClientHelloInfo) (*utls.UConn, error)
NewUtlsConn creates and configures a utls.UConn based on the proxy options and client hello info. It handles standard fingerprints, "client" mirroring, and saved profiles.
func SaveFingerprint ¶
func SaveFingerprint(name string, fp *Fingerprint) error
func UtlsStateToTlsState ¶
func UtlsStateToTlsState(state utls.ConnectionState) *tls.ConnectionState
Helper to convert utls state to standard tls state
Types ¶
type Addon ¶
type Addon interface {
// A client has connected to mitmproxy. Note that a connection can correspond to multiple HTTP requests.
ClientConnected(*ClientConn)
// A client connection has been closed (either by us or the client).
ClientDisconnected(*ClientConn)
// Mitmproxy has connected to a server.
ServerConnected(*ConnContext)
// A server connection has been closed (either by us or the server).
ServerDisconnected(*ConnContext)
// The TLS handshake with the server has been completed successfully.
TlsEstablishedServer(*ConnContext)
// HTTP request headers were successfully read. At this point, the body is empty.
Requestheaders(*Flow)
// The full HTTP request has been read.
Request(*Flow)
// HTTP response headers were successfully read. At this point, the body is empty.
Responseheaders(*Flow)
// The full HTTP response has been read.
Response(*Flow)
// Stream request body modifier
StreamRequestModifier(*Flow, io.Reader) io.Reader
// Stream response body modifier
StreamResponseModifier(*Flow, io.Reader) io.Reader
// onAccessProxyServer
AccessProxyServer(req *http.Request, res http.ResponseWriter)
// WebSocket connection established (handshake complete)
WebsocketHandshake(*Flow)
// WebSocket message received from client
WebsocketMessage(*Flow, *WebSocketMessage)
}
type BaseAddon ¶
type BaseAddon struct{}
BaseAddon do nothing
func (*BaseAddon) AccessProxyServer ¶
func (addon *BaseAddon) AccessProxyServer(req *http.Request, res http.ResponseWriter)
func (*BaseAddon) ClientConnected ¶
func (addon *BaseAddon) ClientConnected(*ClientConn)
func (*BaseAddon) ClientDisconnected ¶
func (addon *BaseAddon) ClientDisconnected(*ClientConn)
func (*BaseAddon) Requestheaders ¶
func (*BaseAddon) Responseheaders ¶
func (*BaseAddon) ServerConnected ¶
func (addon *BaseAddon) ServerConnected(*ConnContext)
func (*BaseAddon) ServerDisconnected ¶
func (addon *BaseAddon) ServerDisconnected(*ConnContext)
func (*BaseAddon) StreamRequestModifier ¶
func (*BaseAddon) StreamResponseModifier ¶
func (*BaseAddon) TlsEstablishedServer ¶
func (addon *BaseAddon) TlsEstablishedServer(*ConnContext)
func (*BaseAddon) WebsocketHandshake ¶
func (*BaseAddon) WebsocketMessage ¶
func (addon *BaseAddon) WebsocketMessage(f *Flow, msg *WebSocketMessage)
type ClientConn ¶
type ClientConn struct {
Id uuid.UUID
Conn net.Conn
Tls bool
NegotiatedProtocol string
UpstreamCert bool // Connect to upstream server to look up certificate details. Default: True
// contains filtered or unexported fields
}
client connection
func (*ClientConn) MarshalJSON ¶
func (c *ClientConn) MarshalJSON() ([]byte, error)
type ConnContext ¶
type ConnContext struct {
ClientConn *ClientConn `json:"clientConn"`
ServerConn *ServerConn `json:"serverConn"`
Intercept bool `json:"intercept"` // Indicates whether to parse HTTPS
FlowCount atomic.Uint32 `json:"-"` // Number of HTTP requests made on the same connection
// contains filtered or unexported fields
}
connection context
func (*ConnContext) Id ¶
func (connCtx *ConnContext) Id() uuid.UUID
type Fingerprint ¶
type Fingerprint struct {
Name string `json:"name"`
CipherSuites []uint16 `json:"cipher_suites"`
SupportedVersions []uint16 `json:"supported_versions"`
SupportedCurves []uint16 `json:"supported_curves"`
SupportedPoints []uint8 `json:"supported_points"`
SignatureSchemes []uint16 `json:"signature_schemes"`
ALPNProtocols []string `json:"alpn_protocols"`
}
func LoadFingerprint ¶
func LoadFingerprint(name string) (*Fingerprint, error)
func NewFingerprintFromClientHello ¶
func NewFingerprintFromClientHello(name string, info *tls.ClientHelloInfo) *Fingerprint
Convert tls.ClientHelloInfo to Fingerprint struct
func (*Fingerprint) ToSpec ¶
func (fp *Fingerprint) ToSpec() *utls.ClientHelloSpec
Convert Fingerprint to utls.ClientHelloSpec
type Flow ¶
type Flow struct {
Id uuid.UUID
ConnContext *ConnContext
Request *Request
Response *Response
// https://docs.mitmproxy.org/stable/overview-features/#streaming
// 如果为 true,则不缓冲 Request.Body 和 Response.Body,且不进入之后的 Addon.Request 和 Addon.Response
Stream bool
UseSeparateClient bool // use separate http client to send http request
// Metadata to pass data between addons. Not persisted by default unless handled by storage addon.
Metadata map[string]interface{}
// contains filtered or unexported fields
}
flow
func (*Flow) MarshalJSON ¶
type InstanceLogAddon ¶
type InstanceLogAddon struct {
BaseAddon
// contains filtered or unexported fields
}
InstanceLogAddon logs with instance identification
func NewInstanceLogAddonWithFile ¶
func NewInstanceLogAddonWithFile(addr string, instanceName string, logFilePath string) *InstanceLogAddon
NewInstanceLogAddonWithFile creates a new instance-aware log addon with file output
func (*InstanceLogAddon) ClientConnected ¶
func (addon *InstanceLogAddon) ClientConnected(client *ClientConn)
func (*InstanceLogAddon) ClientDisconnected ¶
func (addon *InstanceLogAddon) ClientDisconnected(client *ClientConn)
func (*InstanceLogAddon) Request ¶
func (addon *InstanceLogAddon) Request(f *Flow)
func (*InstanceLogAddon) Requestheaders ¶
func (addon *InstanceLogAddon) Requestheaders(f *Flow)
func (*InstanceLogAddon) Response ¶
func (addon *InstanceLogAddon) Response(f *Flow)
func (*InstanceLogAddon) ServerConnected ¶
func (addon *InstanceLogAddon) ServerConnected(connCtx *ConnContext)
func (*InstanceLogAddon) ServerDisconnected ¶
func (addon *InstanceLogAddon) ServerDisconnected(connCtx *ConnContext)
func (*InstanceLogAddon) SetLogger ¶
func (addon *InstanceLogAddon) SetLogger(logger *InstanceLogger)
SetLogger allows setting a custom instance logger
func (*InstanceLogAddon) TlsEstablishedServer ¶
func (addon *InstanceLogAddon) TlsEstablishedServer(connCtx *ConnContext)
type InstanceLogger ¶
type InstanceLogger struct {
InstanceID string
InstanceName string
Port string
LogFilePath string
// contains filtered or unexported fields
}
func NewInstanceLogger ¶
func NewInstanceLogger(addr string, instanceName string) *InstanceLogger
NewInstanceLogger creates a logger with instance identification
func NewInstanceLoggerWithFile ¶
func NewInstanceLoggerWithFile(addr string, instanceName string, logFilePath string) *InstanceLogger
NewInstanceLoggerWithFile creates a logger with instance identification and optional file output
func (*InstanceLogger) Debug ¶
func (il *InstanceLogger) Debug(args ...interface{})
Debug logs at debug level
func (*InstanceLogger) Debugf ¶
func (il *InstanceLogger) Debugf(format string, args ...interface{})
Debugf logs formatted at debug level
func (*InstanceLogger) Error ¶
func (il *InstanceLogger) Error(args ...interface{})
Error logs at error level
func (*InstanceLogger) Errorf ¶
func (il *InstanceLogger) Errorf(format string, args ...interface{})
Errorf logs formatted at error level
func (*InstanceLogger) Fatal ¶
func (il *InstanceLogger) Fatal(args ...interface{})
Fatal logs at fatal level
func (*InstanceLogger) Fatalf ¶
func (il *InstanceLogger) Fatalf(format string, args ...interface{})
Fatalf logs formatted at fatal level
func (*InstanceLogger) GetEntry ¶
func (il *InstanceLogger) GetEntry() *log.Entry
GetEntry returns the underlying logrus entry
func (*InstanceLogger) Info ¶
func (il *InstanceLogger) Info(args ...interface{})
Info logs at info level
func (*InstanceLogger) Infof ¶
func (il *InstanceLogger) Infof(format string, args ...interface{})
Infof logs formatted at info level
func (*InstanceLogger) Warn ¶
func (il *InstanceLogger) Warn(args ...interface{})
Warn logs at warn level
func (*InstanceLogger) Warnf ¶
func (il *InstanceLogger) Warnf(format string, args ...interface{})
Warnf logs formatted at warn level
func (*InstanceLogger) WithFields ¶
func (il *InstanceLogger) WithFields(fields log.Fields) *log.Entry
WithFields adds additional fields to the logger
type LogAddon ¶
type LogAddon struct {
BaseAddon
}
LogAddon log connection and flow
func (*LogAddon) ClientConnected ¶
func (addon *LogAddon) ClientConnected(client *ClientConn)
func (*LogAddon) ClientDisconnected ¶
func (addon *LogAddon) ClientDisconnected(client *ClientConn)
func (*LogAddon) Requestheaders ¶
func (*LogAddon) ServerConnected ¶
func (addon *LogAddon) ServerConnected(connCtx *ConnContext)
func (*LogAddon) ServerDisconnected ¶
func (addon *LogAddon) ServerDisconnected(connCtx *ConnContext)
func (*LogAddon) WebsocketHandshake ¶
func (*LogAddon) WebsocketMessage ¶
func (addon *LogAddon) WebsocketMessage(f *Flow, msg *WebSocketMessage)
type Options ¶
type Options struct {
Debug int
Addr string
StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式
SslInsecure bool
CaRootPath string
NewCaFunc func() (cert.CA, error) //创建 Ca 的函数
Upstream string
LogFilePath string // Path to write logs to file
TlsFingerprint string // TLS fingerprint to emulate (chrome, firefox, ios, or random)
FingerprintSave string // Save decoding client hello to file
}
type Proxy ¶
type Proxy struct {
Opts *Options
Version string
Addons []Addon
// contains filtered or unexported fields
}
func (*Proxy) GetCertificate ¶
func (proxy *Proxy) GetCertificate() x509.Certificate
func (*Proxy) GetCertificateByCN ¶
func (proxy *Proxy) GetCertificateByCN(commonName string) (*tls.Certificate, error)
func (*Proxy) SetAuthProxy ¶
func (*Proxy) SetShouldInterceptRule ¶
func (*Proxy) SetUpstreamProxy ¶
type Request ¶
type Request struct {
Method string
URL *url.URL
Proto string
Header http.Header
Body []byte
// contains filtered or unexported fields
}
flow http request
func NewRequest ¶
func (*Request) DecodedBody ¶
func (*Request) MarshalJSON ¶
func (*Request) UnmarshalJSON ¶
type Response ¶
type Response struct {
StatusCode int `json:"statusCode"`
Header http.Header `json:"header"`
Body []byte `json:"-"`
BodyReader io.Reader
// contains filtered or unexported fields
}
flow http response
func (*Response) DecodedBody ¶
func (*Response) IsTextContentType ¶
func (*Response) ReplaceToDecodedBody ¶
func (r *Response) ReplaceToDecodedBody()
type ServerConn ¶
type ServerConn struct {
Id uuid.UUID
Address string
Conn net.Conn
// contains filtered or unexported fields
}
server connection
func (*ServerConn) MarshalJSON ¶
func (c *ServerConn) MarshalJSON() ([]byte, error)
func (*ServerConn) TlsState ¶
func (c *ServerConn) TlsState() *tls.ConnectionState
type UpstreamCertAddon ¶
type UpstreamCertAddon struct {
BaseAddon
UpstreamCert bool // Connect to upstream server to look up certificate details.
}
func NewUpstreamCertAddon ¶
func NewUpstreamCertAddon(upstreamCert bool) *UpstreamCertAddon
func (*UpstreamCertAddon) ClientConnected ¶
func (addon *UpstreamCertAddon) ClientConnected(conn *ClientConn)
type WebSocketMessage ¶
type WebSocketMessage struct {
Type int
Data []byte
FromClient bool // true if message is from client, false if from server
}
WebSocketMessage