This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
/
main.go
76 lines (64 loc) · 2.18 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"EasierConnect/core"
"flag"
"fmt"
"log"
"runtime"
"time"
"github.com/pquerna/otp/totp"
)
func main() {
// CLI args
host, port, username, password, socksBind, twfId, totpKey := "", 0, "", "", "", "", ""
flag.StringVar(&host, "server", "", "EasyConnect server address (e.g. vpn.nju.edu.cn, sslvpn.sysu.edu.cn)")
flag.StringVar(&username, "username", "", "Your username")
flag.StringVar(&password, "password", "", "Your password")
flag.StringVar(&totpKey, "totp-key", "", "If provided, this program will automatically generate TOTP code using this key and and input it, instead of asking user.")
flag.StringVar(&socksBind, "socks-bind", ":1080", "The addr socks5 server listens on (e.g. 0.0.0.0:1080)")
flag.StringVar(&twfId, "twf-id", "", "Login using twfID captured (mostly for debug usage)")
flag.IntVar(&port, "port", 443, "EasyConnect port address (e.g. 443)")
debugDump := false
flag.BoolVar(&debugDump, "debug-dump", false, "Enable traffic debug dump (only for debug usage)")
flag.Parse()
if host == "" || ((username == "" || password == "") && twfId == "") {
log.Fatal("Missing required cli args, refer to `EasierConnect --help`.")
}
server := fmt.Sprintf("%s:%d", host, port)
client := core.NewEasyConnectClient(server)
var ip []byte
var err error
if twfId != "" {
if len(twfId) != 16 {
panic("len(twfid) should be 16!")
}
ip, err = client.LoginByTwfId(twfId)
} else {
ip, err = client.Login(username, password)
if err == core.ERR_NEXT_AUTH_SMS {
fmt.Print(">>>Please enter your sms code<<<:")
smsCode := ""
fmt.Scan(&smsCode)
ip, err = client.AuthSMSCode(smsCode)
} else if err == core.ERR_NEXT_AUTH_TOTP {
TOTPCode := ""
if totpKey == "" {
fmt.Print(">>>Please enter your TOTP Auth code<<<:")
fmt.Scan(&TOTPCode)
} else {
TOTPCode, err = totp.GenerateCode(totpKey, time.Now())
if err != nil {
panic(err)
}
log.Printf("Generated TOTP code %s", TOTPCode)
}
ip, err = client.AuthTOTP(TOTPCode)
}
}
if err != nil {
log.Fatal(err.Error())
}
log.Printf("Login success, your IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
client.ServeSocks5(socksBind, debugDump)
runtime.KeepAlive(client)
}