Documentation ¶
Overview ¶
Package gomitmproxy implements a configurable mitm proxy wring purely in go.
Index ¶
- func ExtractBasicAuth(headerValue string) (username string, password string, err error)
- type AuthorizationFunc
- type CanMITMFunc
- type Config
- type Context
- type OnConnectFunc
- type OnErrorFunc
- type OnRequestFunc
- type OnResponseFunc
- type Proxy
- type Session
- func (s *Session) Ctx() (ctx *Context)
- func (s *Session) GetProp(key string) (v interface{}, ok bool)
- func (s *Session) ID() (id string)
- func (s *Session) RemoteAddr() (addr string)
- func (s *Session) Request() (req *http.Request)
- func (s *Session) Response() (resp *http.Response)
- func (s *Session) SetProp(key string, val interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthorizationFunc ¶
AuthorizationFunc is a declartion of the Config.Authorize handler.
func BasicPasswordAuthorizer ¶
func BasicPasswordAuthorizer(username, password string) AuthorizationFunc
BasicPasswordAuthorizer returns an HTTP authorization header value according to RFC2617. See 2 (end of page 4) https://www.ietf.org/rfc/rfc2617.txt: "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials." It is not meant to be urlencoded.
type CanMITMFunc ¶
CanMITMFunc is a declaration of the Config.CanMITM handler.
type Config ¶
type Config struct { // ListenAddr is the TCP address the proxy should listen to. ListenAddr *net.TCPAddr // TLSConfig is a *tls.Config to use for the HTTP over TLS proxy. If not set // the proxy will work as a simple plain HTTP proxy. TLSConfig *tls.Config // MITMConfig defines the MITM configuration of the proxy. If it is not set // MITM won't be enabled for this proxy instance. MITMConfig *mitm.Config // MITMExceptions is a list of hostnames for which MITM will be disabled. MITMExceptions []string // APIHost is a name of the gomitmproxy API hostname. If it is not set, the // API won't be exposed via HTTP. // // Here are the methods exposed: // 1. apihost/cert.crt - serves the authority cert if MITMConfig is // configured. APIHost string // OnConnect is called when the proxy tries to open a new net.Conn. This // function allows hijacking the remote connection and replacing it with a // different one. // // 1. When the proxy handles the HTTP CONNECT. // IMPORTANT: In this case we don't actually use the remote connections. // It is only used to check if the remote endpoint is available. // 2. When the proxy bypasses data from the client to the remote endpoint. // For instance, it could happen when there's a WebSocket connection. OnConnect OnConnectFunc // OnRequest is called when the request has been just received, but has not // been sent to the remote server. // // At this stage, it is possible to do the following things: // 1. Modify or even replace the request. // 2. Supply an HTTP response to be written to the client. // // Return nil instead of *http.Request or *http.Response to keep the // original request / response. // // Note that even if you supply your own HTTP response here, the OnResponse // handler will be called anyway! OnRequest OnRequestFunc // OnResponse is called when the response has been just received, but has // not been sent to the local client. At this stage you can either keep the // original response, or you can replace it with a new one. OnResponse OnResponseFunc // OnError is called if there's an issue with retrieving the response from // the remote server. OnError OnErrorFunc // CanMITMFunc is called to check if the CONNECT request should me MITM'd. // If this is nil, it will be used the default implementation that checks // for port 443 and MITMExceptions CanMITM CanMITMFunc // Authorize is called to check the Proxy-Authorization header Authorize AuthorizationFunc // SendEmptyClientCertificate determines whether an error will be returned // or if an empty certificate will be sent if a TLS client certificate // is requested by the server SendEmptyClientCertificate bool }
Config is the configuration of the Proxy.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context contains all the necessary information about the connection that is currently being processed by the proxy.
func (*Context) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection.
The difference is that our contexts can be nested, so we search for the topmost parent context recursively and call SetDeadline for its connection only as this is the real underlying network connection.
type OnConnectFunc ¶
OnConnectFunc is a declaration of the Config.OnConnect handler.
type OnErrorFunc ¶
OnErrorFunc is a declaration of the Config.OnError handler.
type OnRequestFunc ¶
OnRequestFunc is a declaration of the Config.OnRequest handler.
type OnResponseFunc ¶
OnResponseFunc is a declaration of the Config.OnResponse handler.
type Proxy ¶
type Proxy struct { // Config is the proxy's configuration. // TODO(ameshkov): make it a field. Config // contains filtered or unexported fields }
Proxy is a structure with the proxy server configuration and current state.
func (*Proxy) Close ¶
func (p *Proxy) Close()
Close sets the proxy to the closing state so it stops receiving new connections, finishes processing any inflight requests, and closes existing connections without reading anymore requests from them.
TODO(ameshkov): make it return an error.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session contains all the necessary information about the request-response pair that is currently being processed.
func (*Session) RemoteAddr ¶
RemoteAddr returns this session's remote address.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package mitm implements methods for working with certificates and TLS configurations that are used for MITMing connections.
|
Package mitm implements methods for working with certificates and TLS configurations that are used for MITMing connections. |
Package proxyutil contains different utility methods that will be helpful to gomitmproxy users.
|
Package proxyutil contains different utility methods that will be helpful to gomitmproxy users. |