| 1 | package goproxyscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ |
| 2 | |
| 3 | import "net/httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/" |
| 4 | |
| 5 | // ReqHandler will "tamper" with the request coming to the proxy server |
| 6 | // If Handle returns req,nil the proxy will send the returned request |
| 7 | // to the destination server. If it returns nil,resp the proxy will |
| 8 | // skip sending any requests, and will simply return the response `resp` |
| 9 | // to the client. |
| 10 | type ReqHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ReqHandler# interface { |
| 11 | Handlescip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ReqHandler#Handle.(req *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#) |
| 12 | } |
| 13 | |
| 14 | // A wrapper that would convert a function to a ReqHandler interface type |
| 15 | type FuncReqHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncReqHandler# func(req *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#) |
| 16 | |
| 17 | // FuncReqHandler.Handle(req,ctx) <=> FuncReqHandler(req,ctx) |
| 18 | func (f FuncReqHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncReqHandler#) Handlescip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncReqHandler#Handle().(req *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.18 `net/http`/Request#, *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#) { |
| 19 | return f(req, ctx) |
| 20 | } |
| 21 | |
| 22 | // after the proxy have sent the request to the destination server, it will |
| 23 | // "filter" the response through the RespHandlers it has. |
| 24 | // The proxy server will send to the client the response returned by the RespHandler. |
| 25 | // In case of error, resp will be nil, and ctx.RoundTrip.Error will contain the error |
| 26 | type RespHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/RespHandler# interface { |
| 27 | Handlescip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/RespHandler#Handle.(resp *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response# |
| 28 | } |
| 29 | |
| 30 | // A wrapper that would convert a function to a RespHandler interface type |
| 31 | type FuncRespHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncRespHandler# func(resp *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response# |
| 32 | |
| 33 | // FuncRespHandler.Handle(req,ctx) <=> FuncRespHandler(req,ctx) |
| 34 | func (f FuncRespHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncRespHandler#) Handlescip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncRespHandler#Handle().(resp *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) *httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.18 `net/http`/Response# { |
| 35 | return f(resp, ctx) |
| 36 | } |
| 37 | |
| 38 | // When a client send a CONNECT request to a host, the request is filtered through |
| 39 | // all the HttpsHandlers the proxy has, and if one returns true, the connection is |
| 40 | // sniffed using Man in the Middle attack. |
| 41 | // That is, the proxy will create a TLS connection with the client, another TLS |
| 42 | // connection with the destination the client wished to connect to, and would |
| 43 | // send back and forth all messages from the server to the client and vice versa. |
| 44 | // The request and responses sent in this Man In the Middle channel are filtered |
| 45 | // through the usual flow (request and response filtered through the ReqHandlers |
| 46 | // and RespHandlers) |
| 47 | type HttpsHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/HttpsHandler# interface { |
| 48 | HandleConnectscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/HttpsHandler#HandleConnect.(req string, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*ConnectActionscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ConnectAction#, string) |
| 49 | } |
| 50 | |
| 51 | // A wrapper that would convert a function to a HttpsHandler interface type |
| 52 | type FuncHttpsHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncHttpsHandler# func(host string, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*ConnectActionscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ConnectAction#, string) |
| 53 | |
| 54 | // FuncHttpsHandler should implement the RespHandler interface |
| 55 | func (f FuncHttpsHandlerscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncHttpsHandler#) HandleConnectscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/FuncHttpsHandler#HandleConnect().(host string, ctx *ProxyCtxscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ProxyCtx#) (*ConnectActionscip-go gomod github.com/elazarl/goproxy . `github.com/elazarl/goproxy`/ConnectAction#, string) { |
| 56 | return f(host, ctx) |
| 57 | } |