Quellcode durchsuchen

First version of website cloaking

tags/1.0^2
9seconds vor 6 Jahren
Ursprung
Commit
d8216f776d
1 geänderte Dateien mit 41 neuen und 4 gelöschten Zeilen
  1. 41
    4
      faketls/client_protocol.go

+ 41
- 4
faketls/client_protocol.go Datei anzeigen

6
 	"errors"
6
 	"errors"
7
 	"fmt"
7
 	"fmt"
8
 	"io"
8
 	"io"
9
+	"net"
10
+	"strconv"
11
+	"sync"
9
 	"time"
12
 	"time"
10
 
13
 
11
 	"github.com/9seconds/mtg/antireplay"
14
 	"github.com/9seconds/mtg/antireplay"
15
+	"github.com/9seconds/mtg/config"
12
 	"github.com/9seconds/mtg/conntypes"
16
 	"github.com/9seconds/mtg/conntypes"
13
 	"github.com/9seconds/mtg/obfuscated2"
17
 	"github.com/9seconds/mtg/obfuscated2"
14
 	"github.com/9seconds/mtg/protocol"
18
 	"github.com/9seconds/mtg/protocol"
27
 
31
 
28
 	for _, expected := range faketlsStartBytes {
32
 	for _, expected := range faketlsStartBytes {
29
 		if actual, err := bufferedReader.ReadByte(); err != nil || actual != expected {
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
 	rewinded = stream.NewRewind(rewinded)
42
 	rewinded = stream.NewRewind(rewinded)
37
 
43
 
38
 	if err := c.tlsHandshake(rewinded); err != nil {
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
 	conn := stream.NewFakeTLS(socket)
51
 	conn := stream.NewFakeTLS(socket)
98
 	return nil
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
 func MakeClientProtocol() protocol.ClientProtocol {
138
 func MakeClientProtocol() protocol.ClientProtocol {
102
 	return &ClientProtocol{}
139
 	return &ClientProtocol{}
103
 }
140
 }

Laden…
Abbrechen
Speichern