|
|
@@ -8,7 +8,7 @@ import (
|
|
8
|
8
|
"sync"
|
|
9
|
9
|
"time"
|
|
10
|
10
|
|
|
11
|
|
- "github.com/9seconds/mtg/v2/mtglib/internal/faketls/clienthello"
|
|
|
11
|
+ "github.com/9seconds/mtg/v2/mtglib/internal/faketls"
|
|
12
|
12
|
"github.com/9seconds/mtg/v2/mtglib/internal/faketls/record"
|
|
13
|
13
|
"github.com/9seconds/mtg/v2/mtglib/internal/obfuscated2"
|
|
14
|
14
|
"github.com/9seconds/mtg/v2/mtglib/internal/relay"
|
|
|
@@ -58,7 +58,7 @@ func (p *Proxy) ServeConn(conn net.Conn) {
|
|
58
|
58
|
ctx.logger.Info("Stream has been finished")
|
|
59
|
59
|
}()
|
|
60
|
60
|
|
|
61
|
|
- if err := p.doFakeTLSHandshake(ctx); err != nil {
|
|
|
61
|
+ if err := p.doFakeTLSHandshake(ctx, ctx.clientConn); err != nil {
|
|
62
|
62
|
p.logger.InfoError("faketls handshake is failed", err)
|
|
63
|
63
|
|
|
64
|
64
|
return
|
|
|
@@ -121,17 +121,28 @@ func (p *Proxy) Shutdown() {
|
|
121
|
121
|
p.workerPool.Release()
|
|
122
|
122
|
}
|
|
123
|
123
|
|
|
124
|
|
-func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) error {
|
|
|
124
|
+func (p *Proxy) doFakeTLSHandshake(ctx *streamContext, conn net.Conn) error {
|
|
125
|
125
|
clientHelloRecord := record.AcquireRecord()
|
|
126
|
126
|
defer record.ReleaseRecord(clientHelloRecord)
|
|
127
|
127
|
|
|
128
|
|
- if err := clientHelloRecord.Read(ctx.clientConn); err != nil {
|
|
|
128
|
+ if err := clientHelloRecord.Read(conn); err != nil {
|
|
129
|
129
|
return fmt.Errorf("cannot read client hello: %w", err)
|
|
130
|
130
|
}
|
|
131
|
131
|
|
|
132
|
|
- hello, _ := clienthello.ParseHandshake(p.secret.Key[:],
|
|
|
132
|
+ hello, err := faketls.ParseClientHello(p.secret.Key[:],
|
|
133
|
133
|
clientHelloRecord.Payload.Bytes())
|
|
134
|
|
- fmt.Println(hello)
|
|
|
134
|
+ if err != nil {
|
|
|
135
|
+ return fmt.Errorf("cannot parse client hello: %w", err)
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ if err := p.timeAttackDetector.Valid(hello.Time); err != nil {
|
|
|
139
|
+ return fmt.Errorf("invalid time: %w", err)
|
|
|
140
|
+ }
|
|
|
141
|
+ if p.antiReplayCache.SeenBefore(hello.SessionID) {
|
|
|
142
|
+ p.logger.Warning("anti replay attack was detected")
|
|
|
143
|
+
|
|
|
144
|
+ return fmt.Errorf("anti replay attack from %s", ctx.ClientIP().String())
|
|
|
145
|
+ }
|
|
135
|
146
|
|
|
136
|
147
|
return fmt.Errorf("SUCCESS")
|
|
137
|
148
|
}
|