gomitmproxy

package module
v0.0.0-...-3c4870d Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 25 Imported by: 0

README

gomitmproxy

实现中间人代理服务,支持http(s)/socks5协议代理服务,同时支持设置外部代理。 可将tls中间人解密body数据上传kafka等消息中间件。

参数

  -addr string
        host:port of the proxy (default ":8890")
  -allow-tls-urls string
        allow requests using tls protocol
  -auth-password string
        proxy auth password
  -auth-username string
        proxy auth username
  -cert string
        filepath to the CA certificate used to sign MITM certificates
  -downstream-proxy-url string
        URL of downstream proxy
  -generate-ca-cert
        generate CA certificate and private key for MITM
  -kafka-brokers string
        kafka brokers eg. localhost:9092,localhost:9092,localhost:9092
  -kafka-topic string
        kafka topic
  -key string
        filepath to the private key of the CA used to sign MITM certificates
  -organization string
        organization name for MITM certificates (default "Go Mitmproxy Proxy")
  -skip-tls-verify
        skip TLS server verification; insecure
  -socks-addr string
        socks5 proxy (default ":8892")
  -tls-addr string
        host:port of the proxy over TLS (default ":8891")
  -use-local-ca-cert
        use local CA certificate and private key for MITM (~/.config/gomitmproxy)
  -v int
        log level
  -validity duration
        window of time that MITM certificates are valid (default 1h0m0s)

开始

git clone https://github.com/zhaozuodong/gomitmproxy.git
cd gomitmproxy
go build -o gomitmproxy cmd/main.go
./gomitmproxy -v 1 -cert="your-cert-path" -key="your-cert-key-path" -auth-username="your auth username" -auth-password="your auth password" -downstream-proxy-url="your-external-Proxy"

docker 案例

docker run -d --name gomitmproxy -p 8892:8892 zhaozuodong/gomitmproxy:latest ./gomitmproxy -v 1 -auth-username="test" -auth-password="test123" -downstream-proxy-url="socks5://127.0.0.1:8889" -use-local-ca-cert=true -kafka-topic="test-topic" -kafka-brokers="127.0.0.1:9192,127.0.0.1:9292,127.0.0.1:9392" -allow-tls-urls="/api/sns/v3/user/info,/api/sns/v4/note/user/posted"

# docker compose 案例

version: '3'
services:
  gomitmproxy-server1:
    image: zhaozuodong/gomitmproxy:latest
    restart: always
    working_dir: /go/src/gomitmproxy
    command: ./gomitmproxy -v 1 -auth-username="test" -auth-password="test123" -downstream-proxy-url="socks5://127.0.0.1:8889" -use-local-ca-cert=true -kafka-topic="test-topic" -kafka-brokers="127.0.0.1:9192,127.0.0.1:9292,127.0.0.1:9392" -allow-tls-urls="/api/sns/v3/user/info,/api/sns/v4/note/user/posted"
    ports:
      - "8892:8892"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Username string
	Password string
}

type Context

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

Context provides information and storage for a single request/response pair. Contexts are linked to shared session that is used for multiple requests on a single connection.

func NewContext

func NewContext(req *http.Request) *Context

NewContext returns a context for the in-flight HTTP request.

func (*Context) APIRequest

func (ctx *Context) APIRequest()

APIRequest marks the requests as a request to the proxy API.

func (*Context) Get

func (ctx *Context) Get(key string) (interface{}, bool)

Get takes key and returns the associated value from the context.

func (*Context) ID

func (ctx *Context) ID() string

ID returns the context ID.

func (*Context) IsAPIRequest

func (ctx *Context) IsAPIRequest() bool

IsAPIRequest returns true when the request patterns matches a pattern in the proxy mux. The mux is usually defined as a parameter to the api.Forwarder, which uses http.DefaultServeMux by default.

func (*Context) Session

func (ctx *Context) Session() *Session

Session returns the session for the context.

func (*Context) Set

func (ctx *Context) Set(key string, val interface{})

Set takes a key and associates it with val in the context. The value is persisted for the duration of the request and is removed on the following request.

func (*Context) SkipLogging

func (ctx *Context) SkipLogging()

SkipLogging skips logging by gomitmproxy loggers for the current request.

func (*Context) SkipRoundTrip

func (ctx *Context) SkipRoundTrip()

SkipRoundTrip skips the round trip for the current request.

func (*Context) SkippingLogging

func (ctx *Context) SkippingLogging() bool

SkippingLogging returns whether the current request / response pair will be logged.

func (*Context) SkippingRoundTrip

func (ctx *Context) SkippingRoundTrip() bool

SkippingRoundTrip returns whether the current round trip will be skipped.

type Proxy

type Proxy struct {
	*Auth
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy() *Proxy

func (*Proxy) AllowTlsUrls

func (p *Proxy) AllowTlsUrls(urls []string)

func (*Proxy) Close

func (p *Proxy) Close()

func (*Proxy) Closing

func (p *Proxy) Closing() bool

func (*Proxy) GetAllowTlsUrls

func (p *Proxy) GetAllowTlsUrls() []string

func (*Proxy) GetRoundTripper

func (p *Proxy) GetRoundTripper() http.RoundTripper

func (*Proxy) Serve

func (p *Proxy) Serve(l net.Listener) error

func (*Proxy) SetDial

func (p *Proxy) SetDial(dial func(string, string) (net.Conn, error))

func (*Proxy) SetDownstreamProxy

func (p *Proxy) SetDownstreamProxy(proxyURL *url.URL)

func (*Proxy) SetMITM

func (p *Proxy) SetMITM(config *mitm.Config)

func (*Proxy) SetRoundTripper

func (p *Proxy) SetRoundTripper(rt http.RoundTripper)

func (*Proxy) SetTimeout

func (p *Proxy) SetTimeout(timeout time.Duration)

func (*Proxy) StartSocks5

func (p *Proxy) StartSocks5(httpAddr, socks5Addr string)

func (*Proxy) Use

func (p *Proxy) Use(handlers ...middlewares.Middleware)

type Session

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

Session provides information and storage about a connection.

func (*Session) Get

func (s *Session) Get(key string) (interface{}, bool)

Get takes key and returns the associated value from the session.

func (*Session) Hijack

func (s *Session) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack takes control of the connection from the proxy. No further action will be taken by the proxy and the connection will be closed following the return of the hijacker.

func (*Session) Hijacked

func (s *Session) Hijacked() bool

Hijacked returns whether the connection has been hijacked.

func (*Session) ID

func (s *Session) ID() string

ID returns the session ID.

func (*Session) IsSecure

func (s *Session) IsSecure() bool

IsSecure returns whether the current session is from a secure connection, such as when receiving requests from a TLS connection that has been MITM'd.

func (*Session) MarkInsecure

func (s *Session) MarkInsecure()

MarkInsecure marks the session as insecure.

func (*Session) MarkSecure

func (s *Session) MarkSecure()

MarkSecure marks the session as secure.

func (*Session) Set

func (s *Session) Set(key string, val interface{})

Set takes a key and associates it with val in the session. The value is persisted for the entire session across multiple requests and responses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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