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

Reddit example and URL matching does not work #293

Closed
7twin opened this issue Jun 21, 2018 · 13 comments
Closed

Reddit example and URL matching does not work #293

7twin opened this issue Jun 21, 2018 · 13 comments

Comments

@7twin
Copy link

7twin commented Jun 21, 2018

The reddit example and matching against a destination url does not work, it just passes the request through, instead of returning a StatusForbidden

package main

import (
	"github.com/elazarl/goproxy"
	"log"
	"net/http"
)

func main() {
	proxy := goproxy.NewProxyHttpServer()
	proxy.OnRequest(goproxy.DstHostIs("www.reddit.com")).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return r, goproxy.NewResponse(r,
				goproxy.ContentTypeText, http.StatusForbidden,
				"Don't waste your time!")
		})
	log.Fatalln(http.ListenAndServe(":8080", proxy))
}
@cedricve
Copy link

noticed the same

@berkant
Copy link

berkant commented Jul 14, 2018

It's most likely that you're requesting Reddit with HTTPS or your browser is somehow redirecting you from HTTP to HTTPS without drawing your attention.

If the case is so, you will have to use Mitm if I'm not wrong.

You may test this using curl:
curl -x <ProxyIP>:<ProxyPort> http://www.reddit.com/ --verbose

Watch out that I'm using http above. It should return your custom message.

Now test the command also for https. It possibly won't return your custom message. This is because you're spawning a CONNECT to watch the response from website in HTTPS case. You're a spectator here and can't intercept response.

Using Mitm, you will have two TLS channels one of which will be your Man-in-the-Middle where the request and response gets exchanged and the other one will be used to CONNECT to real HTTPS.

@7twin
Copy link
Author

7twin commented Jul 14, 2018

@illenialx that's what I thought might be the issue too, but if I remember right, the eavesdropper example wasn't properly working either, even though it resolves a https connection into a plain http connection iirc

@berkant
Copy link

berkant commented Jul 14, 2018

@7twin I don't know but I am using master version and I made my browser trust cert.pem and cert.key and it works seamlessly for me.

@7twin
Copy link
Author

7twin commented Jul 14, 2018

@illenialx are you using the eavesdropper example? and did you modify the source at all?

@berkant
Copy link

berkant commented Jul 15, 2018

@7twin I think the problem is with your ReqCondition which is the value returned by DstHostIs in your case. If you check it, it will return (www.)reddit.com:443 (= req.URL.Host). Not www.reddit.com. I think it should be corrected to req.Host and a PR may be assessed for this.

@7twin
Copy link
Author

7twin commented Jul 15, 2018

@C-R-o-s-s I'm not sure how I could check what the input for the reqcondition is, since I am just starting with golang, but I did try all combinations of the domain, including :443 and other reqconditions and none of them matched, what script are you using that works?

@berkant
Copy link

berkant commented Jul 16, 2018

@7twin Here you go.

https://play.golang.org/p/O4OMbmPfARV
https://asciinema.org/a/kpm13g8F6fnQOavaShRMeF56H

@7twin
Copy link
Author

7twin commented Jul 16, 2018

@C-R-o-s-s thanks, what certs did you trust, did you generate them via the bash script inside the certs folder? or used the root ones?

@berkant
Copy link

berkant commented Jul 16, 2018

@7twin It doesn't matter. The pregenerated custom root CA in https://github.com/elazarl/goproxy are already generated using that script and OpenSSL conf. If you're OK with the name of the repository and domain to show up, you can use it. Otherwise you're free to generate your own. I also imported ca.key and ca.pem both in system and browser.

@HackProAIT
Copy link

tried
proxy.OnRequest(goproxy.UrlHasPrefix("www.google.com")).HandleConnect(goproxy.AlwaysReject)
it worked!

@pguardiario
Copy link

So is there a solution for blocking https://www.reddit.com/ ?

@ErikPelli
Copy link
Collaborator

The DstHosIs implementation has been updated to block a whole domain, when needed: #608. Closing this issue.

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

7 participants
@cedricve @7twin @berkant @HackProAIT @ErikPelli @pguardiario and others