0
0
mirror of https://github.com/XTLS/REALITY.git synced 2025-08-22 14:38:35 +00:00

Add probe for all modern fingerprint

This commit is contained in:
yuhan6665 2025-06-08 17:17:34 -04:00
parent 50752aec6b
commit cb47a5839c
4 changed files with 67 additions and 9 deletions

7
go.mod
View File

@ -9,3 +9,10 @@ require (
golang.org/x/crypto v0.39.0
golang.org/x/sys v0.33.0
)
require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

13
go.sum
View File

@ -1,5 +1,16 @@
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pires/go-proxyproto v0.8.1 h1:9KEixbdJfhrbtjpz/ZwCdWDD2Xem0NZ38qMYaASJgp0=
github.com/pires/go-proxyproto v0.8.1/go.mod h1:ZKAAyp3cgy5Y5Mo4n9AlScrkCZwUy0g3Jf+slqQVcuU=
github.com/refraction-networking/utls v1.7.3 h1:L0WRhHY7Oq1T0zkdzVZMR6zWZv+sXbHB9zcuvsAEqCo=
@ -8,3 +19,5 @@ golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

View File

@ -3,6 +3,7 @@ package reality
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"net"
"sync"
@ -14,16 +15,23 @@ import (
var GlobalPostHandshakeRecordsLock sync.Mutex
var GlobalPostHandshakeRecordsLens map[*Config]map[string][]int
var GlobalPostHandshakeRecordsLens map[string]map[string][]int
func DetectPostHandshakeRecordsLens(config *Config) map[string][]int {
func InitAllRecords(config *Config) {
DetectPostHandshakeRecordsLens(config, "hellochrome_131") // init most used first
for f, _ := range ModernFingerprints {
DetectPostHandshakeRecordsLens(config, f)
}
}
func DetectPostHandshakeRecordsLens(config *Config, fingerprint string) map[string][]int {
GlobalPostHandshakeRecordsLock.Lock()
defer GlobalPostHandshakeRecordsLock.Unlock()
if GlobalPostHandshakeRecordsLens == nil {
GlobalPostHandshakeRecordsLens = make(map[*Config]map[string][]int)
GlobalPostHandshakeRecordsLens = make(map[string]map[string][]int)
}
if GlobalPostHandshakeRecordsLens[config] == nil {
GlobalPostHandshakeRecordsLens[config] = make(map[string][]int)
if GlobalPostHandshakeRecordsLens[fingerprint] == nil {
GlobalPostHandshakeRecordsLens[fingerprint] = make(map[string][]int)
for sni := range config.ServerNames {
target, err := net.Dial("tcp", config.Dest)
if err != nil {
@ -36,8 +44,9 @@ func DetectPostHandshakeRecordsLens(config *Config) map[string][]int {
}
detectConn := &DetectConn{
Conn: target,
PostHandshakeRecordsLens: GlobalPostHandshakeRecordsLens[config],
PostHandshakeRecordsLens: GlobalPostHandshakeRecordsLens[fingerprint],
Sni: sni,
Fingerprint: fingerprint,
}
uConn := utls.UClient(detectConn, &utls.Config{
ServerName: sni,
@ -48,7 +57,7 @@ func DetectPostHandshakeRecordsLens(config *Config) map[string][]int {
io.Copy(io.Discard, uConn)
}
}
return GlobalPostHandshakeRecordsLens[config]
return GlobalPostHandshakeRecordsLens[fingerprint]
}
type DetectConn struct {
@ -56,6 +65,7 @@ type DetectConn struct {
PostHandshakeRecordsLens map[string][]int
Sni string
CcsSent bool
Fingerprint string
}
func (c *DetectConn) Write(b []byte) (n int, err error) {
@ -80,5 +90,33 @@ func (c *DetectConn) Read(b []byte) (n int, err error) {
break
}
}
fmt.Printf("REALITY fingerprint probe: %v\tSni: %v\tlen(postHandshakeRecord): %v\n", c.Fingerprint, c.Sni, c.PostHandshakeRecordsLens[c.Sni])
return 0, io.EOF
}
var ModernFingerprints = map[string]*utls.ClientHelloID{
// One of these will be chosen as `random` at startup
"hellofirefox_99": &utls.HelloFirefox_99,
"hellofirefox_102": &utls.HelloFirefox_102,
"hellofirefox_105": &utls.HelloFirefox_105,
"hellofirefox_120": &utls.HelloFirefox_120,
"hellochrome_83": &utls.HelloChrome_83,
"hellochrome_87": &utls.HelloChrome_87,
"hellochrome_96": &utls.HelloChrome_96,
"hellochrome_100": &utls.HelloChrome_100,
"hellochrome_102": &utls.HelloChrome_102,
"hellochrome_106_shuffle": &utls.HelloChrome_106_Shuffle,
"hellochrome_120": &utls.HelloChrome_120,
"hellochrome_131": &utls.HelloChrome_131,
"helloios_13": &utls.HelloIOS_13,
"helloios_14": &utls.HelloIOS_14,
"helloedge_85": &utls.HelloEdge_85,
"helloedge_106": &utls.HelloEdge_106,
"hellosafari_16_0": &utls.HelloSafari_16_0,
"hello360_11_0": &utls.Hello360_11_0,
"helloqq_11_1": &utls.HelloQQ_11_1,
// "hellogolang": &utls.HelloGolang,
// "hellorandomized": &utls.HelloRandomized,
// "hellorandomizedalpn": &utls.HelloRandomizedALPN,
// "hellorandomizednoalpn": &utls.HelloRandomizedNoALPN,
}

4
tls.go
View File

@ -162,7 +162,7 @@ func Value(vals ...byte) (value int) {
// The configuration config must be non-nil and must include
// at least one certificate or else set GetCertificate.
func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
postHandshakeRecordsLens := DetectPostHandshakeRecordsLens(config)
postHandshakeRecordsLens := DetectPostHandshakeRecordsLens(config, "hellochrome_131")
remoteAddr := conn.RemoteAddr().String()
if config.Show {
@ -473,7 +473,7 @@ func (l *listener) Accept() (net.Conn, error) {
// The configuration config must be non-nil and must include
// at least one certificate or else set GetCertificate.
func NewListener(inner net.Listener, config *Config) net.Listener {
go DetectPostHandshakeRecordsLens(config)
go InitAllRecords(config)
l := new(listener)
l.Listener = inner
l.config = config