-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (45 loc) · 1.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"flag"
"log"
"net/http"
"fmt"
"os"
netproxy "golang.org/x/net/proxy"
"github.com/elazarl/goproxy"
)
func main() {
verbose := flag.Bool("v", false, "Should every proxy request be logged to stdout")
addr := flag.String("addr", "127.0.0.1:8080", "Proxy listen address")
customcert := flag.Bool("cert", false, "Use custom CA files (ca.pem and ca.pem.key) in the same folder")
socks := flag.String("socks", "", "Socks proxy to connect")
flag.Parse()
if *socks == ""{
fmt.Fprintln(os.Stdout, "SOCKS Proxy not set")
os.Exit(1)
}
if *customcert {
var caCert = cert()
var caKey = key()
setCA(caCert, caKey)
}
proxy := goproxy.NewProxyHttpServer()
proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
proxy.OnRequest().DoFunc(
func(req *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
dialer, err := netproxy.SOCKS5("tcp", *socks, nil, netproxy.Direct)
if err != nil {
fmt.Fprintln(os.Stdout, "Error connencting SOCKS proxy::", err)
}
transport := &http.Transport{Dial: dialer.Dial}
client := &http.Client{Transport: transport}
req.RequestURI = ""
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stdout, "Can't GET page:", err)
}
return nil, resp
})
proxy.Verbose = *verbose
log.Fatal(http.ListenAndServe(*addr, proxy))
}