Using the following snippet I'm easily able to do HTTP(S) requests which are routed through the proxy (Burp Suite) which I'm using.
proxyURL, _ := url.Parse("http://127.0.0.1:8080")
caCert, _ := ioutil.ReadFile(/path/to/proxycert)
caCertPool, _ := x509.SystemCertPool()
caCertPool.AppendCertsFromPEM(caCert)
tlsConfig := &tls.Config{RootCAs: caCertPool}
tr := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: tlsConfig}
http.DefaultTransport = tr
[...]
req, _ == http.NewRequest("GET", address, nil)
resp _ := http.DefaultClient.Do(req)
Using the following snippet I'm also able to send raw tcp streams and receive the first line of the response
//http
dialer := net.Dialer{Timeout: 15 * time.Second}
conn, _ := dialer.Dial("tcp", address)
defer conn.Close()
fmt.Fprint(conn, "GET / HTTP etc...")
resp, _ = bufio.NewReader(conn).ReadString('\n')
fmt.Print(resp)
//https
connS, _ := tls.Dial("tcp", address, tlsConfig)
defer connS.Close()
fmt.Fprint(connS, "GET / HTTP etc...")
resp, _ = bufio.NewReader(conn).ReadString('\n')
fmt.Print(resp)
I now need to route this TCP stream through the before mentioned proxy. I tried a lot with proxy.FromURL but had no success yet.
dialerP, _ := proxy.FromURL("http://127.0.0.1:8080", proxy.Direct)
conn, _ := dialerP.Dial("tcp", address)