summaryrefslogtreecommitdiff
path: root/client/main.go
blob: 0c7edcc75eacc5d029d5527bbd4ef3324c34b7e7 (plain)
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
package main

import (
	"flag"
	"fmt"
	"io"
	"log"
	"net"
	"os"

	"0xacab.org/leap/obfsvpn"
	socks5 "github.com/armon/go-socks5"
)

func main() {
	// Setup logging.
	logger := log.New(os.Stderr, "", log.LstdFlags)
	debug := log.New(io.Discard, "DEBUG ", log.LstdFlags)

	// setup command line flags.
	var (
		verbose     bool
		obfs4Cert   string
		obfs4Remote string
		socksPort   string
		socksHost   string
	)

	socksPort = "8080"
	socksHost = "127.0.0.1"

	flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
	flags.BoolVar(&verbose, "v", verbose, "Enable verbose logging")
	flags.StringVar(&obfs4Cert, "c", obfs4Cert, "The remote obfs4 certificate")
	flags.StringVar(&obfs4Remote, "r", obfs4Remote, "The remote obfs4 endpoint (ip:port)")
	flags.StringVar(&socksPort, "p", socksPort, "The port for the local socks5 proxy (default: 8080)")
	flags.StringVar(&socksHost, "i", socksHost, "The host for the local socks5 proxy (default: localhost)")
	err := flags.Parse(os.Args[1:])
	if err != nil {
		logger.Fatalf("error parsing flags: %v", err)
	}
	// Configure logging.
	if verbose {
		debug.SetOutput(os.Stderr)
	}

	dialer, err := obfsvpn.NewDialerFromCert(obfs4Cert)
	if err != nil {
		logger.Fatalf("cannot get dialer: %v", err)
	}

	socksConf := &socks5.Config{
		Dial: dialer.Dial,
	}

	server, err := socks5.New(socksConf)
	if err != nil {
		panic(err)
	}

	addr := net.JoinHostPort(socksHost, socksPort)
	fmt.Printf("[+] Started socks5 proxy at %s\n", addr)
	if err := server.ListenAndServe("tcp", addr); err != nil {
		panic(err)
	}
}