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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package client
import (
"crypto/tls"
"fmt"
"log"
"net"
"0xacab.org/leap/obfsvpn"
"0xacab.org/leap/obfsvpn/quicwrapper"
"github.com/kalikaneko/socks5"
"github.com/lucas-clemente/quic-go"
"github.com/xtaci/kcp-go"
)
type Client struct {
kcp bool
quic bool
socksAddr string
obfs4Cert string
}
func NewClient(kcp, quic bool, socksAddr, obfs4Cert string) *Client {
return &Client{
kcp: kcp,
quic: quic,
socksAddr: socksAddr,
obfs4Cert: obfs4Cert,
}
}
func (c *Client) Start() bool {
server := &socks5.Server{
Addr: c.socksAddr,
BindIP: "127.0.0.1",
}
dialer, err := obfsvpn.NewDialerFromCert(c.obfs4Cert)
if err != nil {
log.Printf("Error getting dialer: %v\n", err)
return false
}
if c.kcp {
dialer.DialFunc = func(network, address string) (net.Conn, error) {
log.Printf("Dialing kcp://%s\n", address)
return kcp.Dial(address)
}
} else if c.quic {
dialer.DialFunc = func(network, address string) (net.Conn, error) {
tlsConfig := &tls.Config{
InsecureSkipVerify: true, // TODO proper pinning
NextProtos: []string{"quic-echo-example"}, // XXX what is this???
}
c := quicwrapper.NewClient(address, tlsConfig, &quic.Config{}, nil)
return c.Dial()
}
}
server.Dial = dialer.Dial
fmt.Printf("[+] Starting socks5 proxy at %s\n", c.socksAddr)
if err := server.ListenAndServe(); err != nil {
log.Printf("error while listening: %v\n", err)
return false
}
return true
}
|