|
|
@@ -6,9 +6,13 @@ import (
|
|
6
|
6
|
"errors"
|
|
7
|
7
|
"fmt"
|
|
8
|
8
|
"io"
|
|
|
9
|
+ "net"
|
|
|
10
|
+ "strconv"
|
|
|
11
|
+ "sync"
|
|
9
|
12
|
"time"
|
|
10
|
13
|
|
|
11
|
14
|
"github.com/9seconds/mtg/antireplay"
|
|
|
15
|
+ "github.com/9seconds/mtg/config"
|
|
12
|
16
|
"github.com/9seconds/mtg/conntypes"
|
|
13
|
17
|
"github.com/9seconds/mtg/obfuscated2"
|
|
14
|
18
|
"github.com/9seconds/mtg/protocol"
|
|
|
@@ -27,8 +31,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
|
|
27
|
31
|
|
|
28
|
32
|
for _, expected := range faketlsStartBytes {
|
|
29
|
33
|
if actual, err := bufferedReader.ReadByte(); err != nil || actual != expected {
|
|
30
|
|
- fmt.Println("!!!!!!!!!!!! ERROR !!!!!!!!!!!!", err)
|
|
31
|
|
- return nil, errors.New("qqq")
|
|
|
34
|
+ rewinded.Rewind()
|
|
|
35
|
+ c.cloakHost(rewinded)
|
|
|
36
|
+
|
|
|
37
|
+ return nil, errors.New("failed first bytes of tls handshake")
|
|
32
|
38
|
}
|
|
33
|
39
|
}
|
|
34
|
40
|
|
|
|
@@ -36,8 +42,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
|
|
36
|
42
|
rewinded = stream.NewRewind(rewinded)
|
|
37
|
43
|
|
|
38
|
44
|
if err := c.tlsHandshake(rewinded); err != nil {
|
|
39
|
|
- fmt.Println("!!!!!!!!!!!! ERROR !!!!!!!!!!!!", err)
|
|
40
|
|
- return nil, errors.New("qqq")
|
|
|
45
|
+ rewinded.Rewind()
|
|
|
46
|
+ c.cloakHost(rewinded)
|
|
|
47
|
+
|
|
|
48
|
+ return nil, fmt.Errorf("failed tls handshake: %w", err)
|
|
41
|
49
|
}
|
|
42
|
50
|
|
|
43
|
51
|
conn := stream.NewFakeTLS(socket)
|
|
|
@@ -98,6 +106,35 @@ func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
|
|
98
|
106
|
return nil
|
|
99
|
107
|
}
|
|
100
|
108
|
|
|
|
109
|
+func (c *ClientProtocol) cloakHost(clientConn io.ReadWriteCloser) {
|
|
|
110
|
+ addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
|
|
|
111
|
+ hostConn, err := net.Dial("tcp", addr)
|
|
|
112
|
+
|
|
|
113
|
+ if err != nil {
|
|
|
114
|
+ return
|
|
|
115
|
+ }
|
|
|
116
|
+
|
|
|
117
|
+ defer hostConn.Close()
|
|
|
118
|
+
|
|
|
119
|
+ wg := &sync.WaitGroup{}
|
|
|
120
|
+ wg.Add(2)
|
|
|
121
|
+
|
|
|
122
|
+ go c.pipe(hostConn, clientConn, wg)
|
|
|
123
|
+
|
|
|
124
|
+ go c.pipe(clientConn, hostConn, wg)
|
|
|
125
|
+
|
|
|
126
|
+ wg.Wait()
|
|
|
127
|
+}
|
|
|
128
|
+
|
|
|
129
|
+func (c *ClientProtocol) pipe(dst io.WriteCloser, src io.Reader, wg *sync.WaitGroup) {
|
|
|
130
|
+ defer func() {
|
|
|
131
|
+ wg.Done()
|
|
|
132
|
+ dst.Close()
|
|
|
133
|
+ }()
|
|
|
134
|
+
|
|
|
135
|
+ io.Copy(dst, src) // nolint: errcheck
|
|
|
136
|
+}
|
|
|
137
|
+
|
|
101
|
138
|
func MakeClientProtocol() protocol.ClientProtocol {
|
|
102
|
139
|
return &ClientProtocol{}
|
|
103
|
140
|
}
|