Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
140 lines (117 loc) · 3.92 KB
/
Copy pathmain.go
File metadata and controls
140 lines (117 loc) · 3.92 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"github.com/hashicorp/yamux"
"time"
"strconv"
"strings"
)
var session *yamux.Session
var agentpassword string
var sconn net.Conn
func main() {
listen := flag.String("listen", "", "listen port for receiver address:port")
certificate := flag.String("cert", "", "certificate file")
socks := flag.String("socks", "127.0.0.1:1080", "socks address:port")
connect := flag.String("connect", "", "connect address:port")
proxy := flag.String("proxy", "", "proxy address:port")
optproxytimeout := flag.String("proxytimeout", "", "proxy response timeout (ms)")
proxyauthstring := flag.String("proxyauth", "", "proxy auth Domain/user:Password ")
optuseragent := flag.String("useragent", "", "User-Agent")
optpassword := flag.String("pass", "", "Connect password")
optredirecturl := flag.String("rurl", "", "redirect url. Ex: http://mail.com/login")
recn := flag.Int("recn", 3, "reconnection limit")
//ymx := flag.Bool("ymx", true, "use yamux")
rect := flag.Int("rect", 30, "reconnection delay")
version := flag.Bool("version", false, "version information")
flag.Usage = func() {
fmt.Println("rsockstun - reverse socks5 server/client")
fmt.Println("")
fmt.Println("Usage:")
fmt.Println("0) Generate self-signed SSL certificate: openssl: openssl req -new -x509 -keyout server.key -out server.crt -days 365 -nodes")
fmt.Println("1) Start rsockstun -listen :8080 -socks 127.0.0.1:1080 -cert server on the server.")
fmt.Println("2) Start rsockstun -connect client:8080 on the client inside LAN.")
fmt.Println("3) Connect to 127.0.0.1:1080 on the server with any socks5 client to access into LAN.")
fmt.Println("X) Enjoy. :]")
}
flag.Parse()
if *version {
fmt.Println("rsockstun - reverse socks5 server/client")
os.Exit(0)
}
if *listen != "" {
log.Println("Starting to listen for clients")
if *optproxytimeout != "" {
opttimeout,_ := strconv.Atoi(*optproxytimeout)
proxytout = time.Millisecond * time.Duration(opttimeout)
} else {
proxytout = time.Millisecond * 1000
}
if *optredirecturl != "" {
rurl = *optredirecturl
} else {
rurl = "https://www.microsoft.com/"
}
if *optpassword != "" {
agentpassword = *optpassword
} else {
agentpassword = "RocksDefaultRequestRocksDefaultRequestRocksDefaultRequestRocks!!"
}
go listenForClients(*listen, *certificate)
log.Fatal(listenForSocks(*socks ))
}
if *connect != "" {
if *optproxytimeout != "" {
opttimeout,_ := strconv.Atoi(*optproxytimeout)
proxytimeout = time.Millisecond * time.Duration(opttimeout)
} else {
proxytimeout = time.Millisecond * 1000
}
if *proxyauthstring != "" {
domain = strings.Split(*proxyauthstring, "/")[0]
username = strings.Split(strings.Split(*proxyauthstring, "/")[1],":")[0]
password = strings.Split(strings.Split(*proxyauthstring, "/")[1],":")[1]
} else {
domain = ""
username = ""
password = ""
}
if *optpassword != "" {
agentpassword = *optpassword
} else {
agentpassword = "RocksDefaultRequestRocksDefaultRequestRocksDefaultRequestRocks!!"
}
if *optuseragent != "" {
useragent = *optuseragent
} else {
useragent = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"
}
//log.Fatal(connectForSocks(*connect,*proxy))
if *recn >0 {
for i := 1; i <= *recn; i++ {
log.Printf("Connecting to the far end. Try %d of %d",i,*recn)
error1 := connectForSocks(*connect,*proxy)
log.Print(error1)
log.Printf("Sleeping for %d sec...",*rect)
tsleep := time.Second * time.Duration(*rect)
time.Sleep(tsleep)
}
} else {
for {
log.Printf("Reconnecting to the far end... ")
error1 := connectForSocks(*connect,*proxy)
log.Print(error1)
log.Printf("Sleeping for %d sec...",*rect)
tsleep := time.Second * time.Duration(*rect)
time.Sleep(tsleep)
}
}
log.Fatal("Ending...")
}
fmt.Fprintf(os.Stderr, "You must specify a listen port or a connect address")
os.Exit(1)
}