Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https proxy example please #192

Closed
suntong opened this issue Oct 11, 2016 · 13 comments
Closed

https proxy example please #192

suntong opened this issue Oct 11, 2016 · 13 comments

Comments

@suntong
Copy link

suntong commented Oct 11, 2016

I'm trying to learn to use goproxy through the example https://github.com/elazarl/goproxy/tree/master/examples/goproxy-httpdump.

I found that it can only handle http requests, not https'. Could you provide an example that can handle https requests please? (As almost all web servers are moving away from http to https now, e.g., github, wikipedia, wordpress, etc).

PS, by "handle https requests" I meant that none of the https requests are dumped by the current goproxy-httpdump program.

Thanks

@suntong
Copy link
Author

suntong commented Oct 14, 2016

Suppose tracking https requests is impossible (or too difficult), then my next question is how to output those "Tunnel to" requests from goproxy-httpdump?

I.e., each https request is lead by a normal HTTP request of type "Tunnel to", which has the following headers:

CONNECT csi.gstatic.com:443 HTTP/1.1
Host: csi.gstatic.com:443
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36

A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.

Version: 3.3 (TLS/1.2)
Random: ...

I need to dump those requests as well from goproxy-httpdump.

Thanks

@sundy-li
Copy link

sundy-li commented Nov 2, 2016

+ 1 

[https://github.com/elazarl/goproxy/blob/master/examples/goproxy-transparent/transparent.go]
This example is not very well...

@elazarl
Copy link
Owner

elazarl commented Nov 28, 2016

@suntong
Copy link
Author

suntong commented Nov 29, 2016

The problem is that I found goproxy can only handle http requests, not https'.
That was the question, and I am afraid that I wasn't able to find the answer from the goproxy-eavesdropper example. Maybe I'm wrong about that.

@fredcy
Copy link
Contributor

fredcy commented Apr 11, 2017

I've built a simple HTTPS logging proxy on top of goproxy, at https://github.com/fredcy/proxy

@rahulwa
Copy link

rahulwa commented Apr 12, 2017

I guess if you add this to your main function, it should work. It will do man-in-the-middle attacks against HTTPS.

proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*:443$"))).
	HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
		return goproxy.MitmConnect, host
	})

@fredcy
Copy link
Contributor

fredcy commented Apr 12, 2017

That's pretty much what I do in my logging proxy.
https://github.com/fredcy/proxy/blob/73914b909caf97d0f92a0d9b075c3fda33197b0f/main.go#L109-L110

@suntong
Copy link
Author

suntong commented Apr 12, 2017

Thanks a lot @fredcy & @rahulwa, I'll look into it this weekend and get back to you...

@suntong
Copy link
Author

suntong commented Apr 13, 2017

This, in deed, is doing man-in-the-middle attacks against HTTPS, which is not allowed by default.

The fiddler circumvents it by installing its own Root Certificate into the system (on Windows), @fredcy, how did you solve the problem? Thx.

@fredcy
Copy link
Contributor

fredcy commented Apr 13, 2017

I imported the CA certificate embedded in goproxy into the Keystore on my MacOS client and marked it as trusted. With that done my Mac client uses the proxy without any complaints or warnings about cert problems.

The needed certificate is contained in the certs.go file. At the time of writing it's here:

goproxy/certs.go

Lines 24 to 57 in 4327d5f

var CA_CERT = []byte(`-----BEGIN CERTIFICATE-----
MIIF9DCCA9ygAwIBAgIJAODqYUwoVjJkMA0GCSqGSIb3DQEBCwUAMIGOMQswCQYD
VQQGEwJJTDEPMA0GA1UECAwGQ2VudGVyMQwwCgYDVQQHDANMb2QxEDAOBgNVBAoM
B0dvUHJveHkxEDAOBgNVBAsMB0dvUHJveHkxGjAYBgNVBAMMEWdvcHJveHkuZ2l0
aHViLmlvMSAwHgYJKoZIhvcNAQkBFhFlbGF6YXJsQGdtYWlsLmNvbTAeFw0xNzA0
MDUyMDAwMTBaFw0zNzAzMzEyMDAwMTBaMIGOMQswCQYDVQQGEwJJTDEPMA0GA1UE
CAwGQ2VudGVyMQwwCgYDVQQHDANMb2QxEDAOBgNVBAoMB0dvUHJveHkxEDAOBgNV
BAsMB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zZi6toy4E49viYjFk5J0
C6ZcFC04VYWWx6z0HwJuAS08tZ37JuFXpJGfXJOjZCQyxse0Lg0tuKLMeXDCk2Y3
Ba0noeuNyHRoWXXPyiUoeApkVCU5gIsyiJSWOjhJ5hpJG06rQNfNYexgKrrraEin
o0jmEMtJMx5TtD83hSnLCnFGBBq5lkE7jgXME1KsbIE3lJZzRX1mQwUK8CJDYxye
i6M/dzSvy0SsPvz8fTAlprXRtWWtJQmxgWENp3Dv+0Pmux/l+ilk7KA4sMXGhsfr
bvTOeWl1/uoFTPYiWR/ww7QEPLq23yDFY04Q7Un0qjIk8ExvaY8lCkXMgc8i7sGY
VfvOYb0zm67EfAQl3TW8Ky5fl5CcxpVCD360Bzi6hwjYixa3qEeBggOixFQBFWft
8wrkKTHpOQXjn4sDPtet8imm9UYEtzWrFX6T9MFYkBR0/yye0FIh9+YPiTA6WB86
NCNwK5Yl6HuvF97CIH5CdgO+5C7KifUtqTOL8pQKbNwy0S3sNYvB+njGvRpR7pKV
BUnFpB/Atptqr4CUlTXrc5IPLAqAfmwk5IKcwy3EXUbruf9Dwz69YA==
-----END CERTIFICATE-----`)

I think the ca.pem file is supposed to be exactly that cert but it's out of date. I opened #216 about that.

@elazarl
Copy link
Owner

elazarl commented Apr 13, 2017 via email

@fredcy
Copy link
Contributor

fredcy commented Apr 13, 2017

OK. #218

@suntong
Copy link
Author

suntong commented Apr 16, 2017

I spent time working on something else, but
looks good. 👍

@suntong suntong closed this as completed Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants