diff --git a/component/simple-obfs/http.go b/component/simple-obfs/http.go index bedf9f4..151d108 100644 --- a/component/simple-obfs/http.go +++ b/component/simple-obfs/http.go @@ -2,10 +2,10 @@ package obfs import ( "bytes" + "crypto/rand" "encoding/base64" "fmt" "io" - "math/rand" "net" "net/http" @@ -65,7 +65,7 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) { randBytes := make([]byte, 16) rand.Read(randBytes) req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:])) - req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", rand.Int()%54, rand.Int()%2)) + req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", randInt()%54, randInt()%2)) req.Header.Set("Upgrade", "websocket") req.Header.Set("Connection", "Upgrade") req.Host = ho.host diff --git a/component/simple-obfs/obfs.go b/component/simple-obfs/obfs.go index f041d57..50f519c 100644 --- a/component/simple-obfs/obfs.go +++ b/component/simple-obfs/obfs.go @@ -1,4 +1,15 @@ // Package obfs provides obfuscation functionality for Shadowsocks protocol. package obfs +import ( + "crypto/rand" + "math" + "math/big" +) + // Ref: github.com/Dreamacro/clash/component/simple-obfs + +func randInt() int { + n, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt)) + return int(n.Int64()) +} diff --git a/component/simple-obfs/tls.go b/component/simple-obfs/tls.go index 8e9c05b..b3d5d1c 100644 --- a/component/simple-obfs/tls.go +++ b/component/simple-obfs/tls.go @@ -2,19 +2,15 @@ package obfs import ( "bytes" + "crypto/rand" "encoding/binary" "io" - "math/rand" "net" "time" "github.com/xjasonlyu/tun2socks/v2/common/pool" ) -func init() { - rand.Seed(time.Now().Unix()) -} - const ( chunkSize = 1 << 14 // 2 ** 14 == 16 * 1024 )