增加防探测功能,增加流量加密功能
This commit is contained in:
49
shadow/rand.go
Normal file
49
shadow/rand.go
Normal file
@ -0,0 +1,49 @@
|
||||
package shadow
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"io"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type RandReader struct {
|
||||
io.Reader
|
||||
}
|
||||
|
||||
func (r RandReader) Read(p []byte) (n int, err error) {
|
||||
buf := make([]byte, 32)
|
||||
randBytes := md5.Sum(RandomByte(16))
|
||||
copy(buf[0:], randBytes[:])
|
||||
|
||||
preHashData := bytes.NewBuffer(randBytes[:])
|
||||
sum := md5.Sum([]byte(HandshakePassword))
|
||||
preHashData.Write(sum[:])
|
||||
hash := md5.Sum(preHashData.Bytes())
|
||||
copy(buf[16:], hash[:])
|
||||
copy(p, buf)
|
||||
return 32, nil
|
||||
}
|
||||
|
||||
func RandomByte(size int) []byte {
|
||||
buf := make([]byte, size)
|
||||
for i := 0; i < size; i++ {
|
||||
buf[i] = byte(rand.Intn(255))
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
func VerifyKey(p []byte, key string) bool {
|
||||
if len(p) != 32 {
|
||||
return false
|
||||
}
|
||||
buf := make([]byte, 16)
|
||||
copy(buf, p[0:16])
|
||||
buffer := bytes.NewBuffer(buf)
|
||||
sum := md5.Sum([]byte(key))
|
||||
buffer.Write(sum[:])
|
||||
|
||||
hash := md5.Sum(buffer.Bytes())
|
||||
|
||||
return bytes.Equal(hash[:], p[16:])
|
||||
}
|
Reference in New Issue
Block a user