elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
6.04k stars 1.09k forks source link

Bug: don't work cascade end proxy with basic auth and mitm at the same time #416

Open 4n70w4 opened 3 years ago

4n70w4 commented 3 years ago

Hi! I get code from https://github.com/elazarl/goproxy/blob/0581fc3aee2d07555835bed1a876aca196a4a511/examples/cascadeproxy/main.go

and add Mitm handler to middleProxy

middleProxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*$"))).HandleConnect(goproxy.AlwaysMitm)

Now all requests failed: Cannot read TLS response from mitm'd server proxyconnect tcp: tls: first record does not look like a TLS handshake

If I use external https proxy with basic auth:

2021/01/04 03:37:52 serving end proxy server
2021/01/04 03:37:52 serving middle proxy server
2021/01/04 03:37:53 [001] INFO: Running 1 CONNECT handlers
2021/01/04 03:37:53 [001] INFO: on 0th handler: &{2 <nil> 0x792400} webhook.site:443
2021/01/04 03:37:53 [001] INFO: Assuming CONNECT is TLS, mitm proxying it
2021/01/04 03:37:53 [001] INFO: signing for webhook.site
2021/01/04 03:37:53 [002] INFO: req google.site:443
2021/01/04 03:37:55 [002] INFO: Sending request GET https://google.site:443/
2021/01/04 03:37:56 [002] WARN: Cannot read TLS response from mitm'd server proxyconnect tcp: tls: first record does not look like a TLS handshake

If I use goproxy with basic auth:

...
2021/01/04 03:45:09 [002] WARN: Cannot read TLS response from mitm'd server Proxy Authentication Required

But if I use goproxy without basic auth - all ok!

But if I use external proxy without basic auth - all ok!

Is there any way to use Mitm with cascade proxy?

May be related: https://github.com/elazarl/goproxy/issues/177

ngoyal16 commented 3 years ago

@4n70w4 can you help me to setup MITM i am not able to setup that