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

Handle connect hijack & MITM at the same time not working #530

Open
k0ngoz opened this issue Mar 17, 2024 · 2 comments
Open

Handle connect hijack & MITM at the same time not working #530

k0ngoz opened this issue Mar 17, 2024 · 2 comments

Comments

@k0ngoz
Copy link

k0ngoz commented Mar 17, 2024

I have been unable to use .handleConnect, to hijack the CONNECT requests, and also .DoFunc to be able to access and modify request data.

When using .handleConnect, my .DoFunc function is just not triggered at all.

`
p := goproxy.NewProxyHttpServer()

homeDir, err := os.UserHomeDir()
if err != nil {
	log.Fatalf("Error getting home directory: %v", err)
}

caCertPath := filepath.Join(homeDir, ".mitmproxy", "mitmproxy-ca-cert.pem")
caKeyPath := filepath.Join(homeDir, ".mitmproxy", "mitmproxy-ca.pem")

caCert, err := ioutil.ReadFile(caCertPath)
if err != nil {
	log.Fatalf("Error reading CA certificate: %v", err)
}

caKey, err := ioutil.ReadFile(caKeyPath)
if err != nil {
	log.Fatalf("Error reading CA private key: %v", err)
}

goproxyCa, err := tls.X509KeyPair(caCert, caKey)
if err != nil {
	log.Fatalf("Error loading key pair: %v", err)
}

ca := x509.NewCertPool()
ca.AppendCertsFromPEM(caCert)
goproxy.GoproxyCa = goproxyCa

p.OnRequest().HandleConnect(goproxy.FuncHttpsHandler(
	func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
		log.Println("Handling HTTPS CONNECT request for:", host)
		return &goproxy.ConnectAction{
			Action:    goproxy.ConnectHijack,
			TLSConfig: goproxy.TLSConfigFromCA(&goproxyCa),
			Hijack:    getTLSHijackFunc(hj),
		}, host
	}))

// Handle regular HTTP requests
p.OnRequest().DoFunc(
	func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {

		log.Println("Received regular HTTP request:", r.Method, r.URL.String())
		return r, nil
	},
)

log.Fatal(http.ListenAndServe(opts.ListenAddress, p))

`

@k0ngoz k0ngoz changed the title Handle connect hijack & MITM at the same time Handle connect hijack & MITM at the same time not working Mar 17, 2024
@prafgup
Copy link

prafgup commented Aug 9, 2024

Hey @k0ngoz, I have a similar use-case, where one is able to Hijack CONNECT and also able to modify the request data, which currently does not work due to SSL certificate failures.

@elazarl
Copy link
Owner

elazarl commented Aug 30, 2024

@k0ngoz hi, any news?

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

3 participants