mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
UDP noise (#3711)
* added udp noise * adding protobuf settings * freedom json parser and clean up * resolve confict * fix and clean up * use net.conn instead of packetconnwrapper * avoid constructing SequentialWriter directly --------- Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>
This commit is contained in:
parent
8674ed5a0d
commit
002d08bf83
@ -18,6 +18,7 @@ type FreedomConfig struct {
|
|||||||
Redirect string `json:"redirect"`
|
Redirect string `json:"redirect"`
|
||||||
UserLevel uint32 `json:"userLevel"`
|
UserLevel uint32 `json:"userLevel"`
|
||||||
Fragment *Fragment `json:"fragment"`
|
Fragment *Fragment `json:"fragment"`
|
||||||
|
Noise *Noise `json:"noise"`
|
||||||
ProxyProtocol uint32 `json:"proxyProtocol"`
|
ProxyProtocol uint32 `json:"proxyProtocol"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +28,11 @@ type Fragment struct {
|
|||||||
Interval string `json:"interval"`
|
Interval string `json:"interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Noise struct {
|
||||||
|
Packet string `json:"packet"`
|
||||||
|
Delay string `json:"delay"`
|
||||||
|
}
|
||||||
|
|
||||||
// Build implements Buildable
|
// Build implements Buildable
|
||||||
func (c *FreedomConfig) Build() (proto.Message, error) {
|
func (c *FreedomConfig) Build() (proto.Message, error) {
|
||||||
config := new(freedom.Config)
|
config := new(freedom.Config)
|
||||||
@ -143,6 +149,76 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if c.Noise != nil {
|
||||||
|
config.Noise = new(freedom.Noise)
|
||||||
|
var err, err2 error
|
||||||
|
p := strings.Split(strings.ToLower(c.Noise.Packet), ":")
|
||||||
|
if len(p) != 2 {
|
||||||
|
return nil, errors.New("invalid type for packet")
|
||||||
|
}
|
||||||
|
switch p[0] {
|
||||||
|
case "rand":
|
||||||
|
randValue := strings.Split(p[1], "-")
|
||||||
|
if len(randValue) > 2 {
|
||||||
|
return nil, errors.New("Only 2 values are allowed for rand")
|
||||||
|
}
|
||||||
|
if len(randValue) == 2 {
|
||||||
|
config.Noise.LengthMin, err = strconv.ParseUint(randValue[0], 10, 64)
|
||||||
|
config.Noise.LengthMax, err2 = strconv.ParseUint(randValue[1], 10, 64)
|
||||||
|
}
|
||||||
|
if len(randValue) == 1 {
|
||||||
|
config.Noise.LengthMin, err = strconv.ParseUint(randValue[0], 10, 64)
|
||||||
|
config.Noise.LengthMax = config.Noise.LengthMin
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("invalid value for rand LengthMin").Base(err)
|
||||||
|
}
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, errors.New("invalid value for rand LengthMax").Base(err2)
|
||||||
|
}
|
||||||
|
if config.Noise.LengthMin > config.Noise.LengthMax {
|
||||||
|
config.Noise.LengthMin, config.Noise.LengthMax = config.Noise.LengthMax, config.Noise.LengthMin
|
||||||
|
}
|
||||||
|
if config.Noise.LengthMin == 0 {
|
||||||
|
return nil, errors.New("rand lengthMin or lengthMax cannot be 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
case "str":
|
||||||
|
//user input string
|
||||||
|
config.Noise.StrNoise = strings.TrimSpace(p[1])
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, errors.New("Invalid packet,only rand and str are supported")
|
||||||
|
}
|
||||||
|
if c.Noise.Delay != "" {
|
||||||
|
d := strings.Split(strings.ToLower(c.Noise.Delay), "-")
|
||||||
|
if len(d) > 2 {
|
||||||
|
return nil, errors.New("Invalid delay value")
|
||||||
|
}
|
||||||
|
if len(d) == 2 {
|
||||||
|
config.Noise.DelayMin, err = strconv.ParseUint(d[0], 10, 64)
|
||||||
|
config.Noise.DelayMax, err2 = strconv.ParseUint(d[1], 10, 64)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
config.Noise.DelayMin, err = strconv.ParseUint(d[0], 10, 64)
|
||||||
|
config.Noise.DelayMax = config.Noise.DelayMin
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("Invalid value for DelayMin").Base(err)
|
||||||
|
}
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, errors.New("Invalid value for DelayMax").Base(err2)
|
||||||
|
}
|
||||||
|
if config.Noise.DelayMin > config.Noise.DelayMax {
|
||||||
|
config.Noise.DelayMin, config.Noise.DelayMax = config.Noise.DelayMax, config.Noise.DelayMin
|
||||||
|
}
|
||||||
|
if config.Noise.DelayMin == 0 {
|
||||||
|
return nil, errors.New("DelayMin or DelayMax cannot be 0")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.Noise.DelayMin = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if c.Timeout != nil {
|
if c.Timeout != nil {
|
||||||
config.Timeout = *c.Timeout
|
config.Timeout = *c.Timeout
|
||||||
|
@ -91,7 +91,7 @@ func (x Config_DomainStrategy) Number() protoreflect.EnumNumber {
|
|||||||
|
|
||||||
// Deprecated: Use Config_DomainStrategy.Descriptor instead.
|
// Deprecated: Use Config_DomainStrategy.Descriptor instead.
|
||||||
func (Config_DomainStrategy) EnumDescriptor() ([]byte, []int) {
|
func (Config_DomainStrategy) EnumDescriptor() ([]byte, []int) {
|
||||||
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{2, 0}
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{3, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DestinationOverride struct {
|
type DestinationOverride struct {
|
||||||
@ -228,6 +228,85 @@ func (x *Fragment) GetIntervalMax() uint64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Noise struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
LengthMin uint64 `protobuf:"varint,1,opt,name=length_min,json=lengthMin,proto3" json:"length_min,omitempty"`
|
||||||
|
LengthMax uint64 `protobuf:"varint,2,opt,name=length_max,json=lengthMax,proto3" json:"length_max,omitempty"`
|
||||||
|
DelayMin uint64 `protobuf:"varint,3,opt,name=delay_min,json=delayMin,proto3" json:"delay_min,omitempty"`
|
||||||
|
DelayMax uint64 `protobuf:"varint,4,opt,name=delay_max,json=delayMax,proto3" json:"delay_max,omitempty"`
|
||||||
|
StrNoise string `protobuf:"bytes,5,opt,name=str_noise,json=strNoise,proto3" json:"str_noise,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) Reset() {
|
||||||
|
*x = Noise{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_proxy_freedom_config_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Noise) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *Noise) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_proxy_freedom_config_proto_msgTypes[2]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use Noise.ProtoReflect.Descriptor instead.
|
||||||
|
func (*Noise) Descriptor() ([]byte, []int) {
|
||||||
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) GetLengthMin() uint64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.LengthMin
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) GetLengthMax() uint64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.LengthMax
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) GetDelayMin() uint64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.DelayMin
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) GetDelayMax() uint64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.DelayMax
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Noise) GetStrNoise() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.StrNoise
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@ -240,12 +319,13 @@ type Config struct {
|
|||||||
UserLevel uint32 `protobuf:"varint,4,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
UserLevel uint32 `protobuf:"varint,4,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
||||||
Fragment *Fragment `protobuf:"bytes,5,opt,name=fragment,proto3" json:"fragment,omitempty"`
|
Fragment *Fragment `protobuf:"bytes,5,opt,name=fragment,proto3" json:"fragment,omitempty"`
|
||||||
ProxyProtocol uint32 `protobuf:"varint,6,opt,name=proxy_protocol,json=proxyProtocol,proto3" json:"proxy_protocol,omitempty"`
|
ProxyProtocol uint32 `protobuf:"varint,6,opt,name=proxy_protocol,json=proxyProtocol,proto3" json:"proxy_protocol,omitempty"`
|
||||||
|
Noise *Noise `protobuf:"bytes,7,opt,name=noise,proto3" json:"noise,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
func (x *Config) Reset() {
|
||||||
*x = Config{}
|
*x = Config{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[2]
|
mi := &file_proxy_freedom_config_proto_msgTypes[3]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -258,7 +338,7 @@ func (x *Config) String() string {
|
|||||||
func (*Config) ProtoMessage() {}
|
func (*Config) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *Config) ProtoReflect() protoreflect.Message {
|
func (x *Config) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proxy_freedom_config_proto_msgTypes[2]
|
mi := &file_proxy_freedom_config_proto_msgTypes[3]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -271,7 +351,7 @@ func (x *Config) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
||||||
func (*Config) Descriptor() ([]byte, []int) {
|
func (*Config) Descriptor() ([]byte, []int) {
|
||||||
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{2}
|
return file_proxy_freedom_config_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) GetDomainStrategy() Config_DomainStrategy {
|
func (x *Config) GetDomainStrategy() Config_DomainStrategy {
|
||||||
@ -317,6 +397,13 @@ func (x *Config) GetProxyProtocol() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Config) GetNoise() *Noise {
|
||||||
|
if x != nil {
|
||||||
|
return x.Noise
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var File_proxy_freedom_config_proto protoreflect.FileDescriptor
|
var File_proxy_freedom_config_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_proxy_freedom_config_proto_rawDesc = []byte{
|
var file_proxy_freedom_config_proto_rawDesc = []byte{
|
||||||
@ -343,29 +430,42 @@ var file_proxy_freedom_config_proto_rawDesc = []byte{
|
|||||||
0x6c, 0x5f, 0x6d, 0x69, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x69, 0x6e, 0x74,
|
0x6c, 0x5f, 0x6d, 0x69, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x69, 0x6e, 0x74,
|
||||||
0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x69, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x6e, 0x74, 0x65,
|
0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x69, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x6e, 0x74, 0x65,
|
||||||
0x72, 0x76, 0x61, 0x6c, 0x5f, 0x6d, 0x61, 0x78, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b,
|
0x72, 0x76, 0x61, 0x6c, 0x5f, 0x6d, 0x61, 0x78, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b,
|
||||||
0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x61, 0x78, 0x22, 0x82, 0x04, 0x0a, 0x06,
|
0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x61, 0x78, 0x22, 0x9c, 0x01, 0x0a, 0x05,
|
||||||
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x52, 0x0a, 0x0f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e,
|
0x4e, 0x6f, 0x69, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f,
|
||||||
0x5f, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32,
|
0x6d, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6c, 0x65, 0x6e, 0x67, 0x74,
|
||||||
0x29, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x66, 0x72, 0x65,
|
0x68, 0x4d, 0x69, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x6d,
|
||||||
0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x44, 0x6f, 0x6d, 0x61,
|
0x61, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,
|
||||||
0x69, 0x6e, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x52, 0x0e, 0x64, 0x6f, 0x6d, 0x61,
|
0x4d, 0x61, 0x78, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x5f, 0x6d, 0x69, 0x6e,
|
||||||
0x69, 0x6e, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x1c, 0x0a, 0x07, 0x74, 0x69,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x4d, 0x69, 0x6e,
|
||||||
0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x02, 0x18, 0x01, 0x52,
|
0x12, 0x1b, 0x0a, 0x09, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x5f, 0x6d, 0x61, 0x78, 0x18, 0x04, 0x20,
|
||||||
0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x5a, 0x0a, 0x14, 0x64, 0x65, 0x73, 0x74,
|
0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x4d, 0x61, 0x78, 0x12, 0x1b, 0x0a,
|
||||||
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65,
|
0x09, 0x73, 0x74, 0x72, 0x5f, 0x6e, 0x6f, 0x69, 0x73, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72,
|
0x52, 0x08, 0x73, 0x74, 0x72, 0x4e, 0x6f, 0x69, 0x73, 0x65, 0x22, 0xb3, 0x04, 0x0a, 0x06, 0x43,
|
||||||
0x6f, 0x78, 0x79, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x44, 0x65, 0x73, 0x74,
|
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x52, 0x0a, 0x0f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x5f,
|
||||||
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x52,
|
0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x29,
|
||||||
0x13, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x76, 0x65, 0x72,
|
0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x66, 0x72, 0x65, 0x65,
|
||||||
0x72, 0x69, 0x64, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6c, 0x65, 0x76,
|
0x64, 0x6f, 0x6d, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69,
|
||||||
0x65, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x4c, 0x65,
|
0x6e, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x52, 0x0e, 0x64, 0x6f, 0x6d, 0x61, 0x69,
|
||||||
0x76, 0x65, 0x6c, 0x12, 0x38, 0x0a, 0x08, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x18,
|
0x6e, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x1c, 0x0a, 0x07, 0x74, 0x69, 0x6d,
|
||||||
0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f,
|
0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x02, 0x18, 0x01, 0x52, 0x07,
|
||||||
0x78, 0x79, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x46, 0x72, 0x61, 0x67, 0x6d,
|
0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x5a, 0x0a, 0x14, 0x64, 0x65, 0x73, 0x74, 0x69,
|
||||||
0x65, 0x6e, 0x74, 0x52, 0x08, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x0a,
|
0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x18,
|
||||||
0x0e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18,
|
0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f,
|
||||||
0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74,
|
0x78, 0x79, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x44, 0x65, 0x73, 0x74, 0x69,
|
||||||
0x6f, 0x63, 0x6f, 0x6c, 0x22, 0xa9, 0x01, 0x0a, 0x0e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53,
|
0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x52, 0x13,
|
||||||
|
0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4f, 0x76, 0x65, 0x72, 0x72,
|
||||||
|
0x69, 0x64, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6c, 0x65, 0x76, 0x65,
|
||||||
|
0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x4c, 0x65, 0x76,
|
||||||
|
0x65, 0x6c, 0x12, 0x38, 0x0a, 0x08, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x05,
|
||||||
|
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78,
|
||||||
|
0x79, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65,
|
||||||
|
0x6e, 0x74, 0x52, 0x08, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x0a, 0x0e,
|
||||||
|
0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x06,
|
||||||
|
0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x63, 0x6f, 0x6c, 0x12, 0x2f, 0x0a, 0x05, 0x6e, 0x6f, 0x69, 0x73, 0x65, 0x18, 0x07, 0x20, 0x01,
|
||||||
|
0x28, 0x0b, 0x32, 0x19, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e,
|
||||||
|
0x66, 0x72, 0x65, 0x65, 0x64, 0x6f, 0x6d, 0x2e, 0x4e, 0x6f, 0x69, 0x73, 0x65, 0x52, 0x05, 0x6e,
|
||||||
|
0x6f, 0x69, 0x73, 0x65, 0x22, 0xa9, 0x01, 0x0a, 0x0e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53,
|
||||||
0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x53, 0x5f, 0x49, 0x53,
|
0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x53, 0x5f, 0x49, 0x53,
|
||||||
0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x10, 0x01, 0x12, 0x0b,
|
0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x10, 0x01, 0x12, 0x0b,
|
||||||
0x0a, 0x07, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x55,
|
0x0a, 0x07, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x55,
|
||||||
@ -398,24 +498,26 @@ func file_proxy_freedom_config_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_proxy_freedom_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
var file_proxy_freedom_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
var file_proxy_freedom_config_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
var file_proxy_freedom_config_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||||
var file_proxy_freedom_config_proto_goTypes = []any{
|
var file_proxy_freedom_config_proto_goTypes = []any{
|
||||||
(Config_DomainStrategy)(0), // 0: xray.proxy.freedom.Config.DomainStrategy
|
(Config_DomainStrategy)(0), // 0: xray.proxy.freedom.Config.DomainStrategy
|
||||||
(*DestinationOverride)(nil), // 1: xray.proxy.freedom.DestinationOverride
|
(*DestinationOverride)(nil), // 1: xray.proxy.freedom.DestinationOverride
|
||||||
(*Fragment)(nil), // 2: xray.proxy.freedom.Fragment
|
(*Fragment)(nil), // 2: xray.proxy.freedom.Fragment
|
||||||
(*Config)(nil), // 3: xray.proxy.freedom.Config
|
(*Noise)(nil), // 3: xray.proxy.freedom.Noise
|
||||||
(*protocol.ServerEndpoint)(nil), // 4: xray.common.protocol.ServerEndpoint
|
(*Config)(nil), // 4: xray.proxy.freedom.Config
|
||||||
|
(*protocol.ServerEndpoint)(nil), // 5: xray.common.protocol.ServerEndpoint
|
||||||
}
|
}
|
||||||
var file_proxy_freedom_config_proto_depIdxs = []int32{
|
var file_proxy_freedom_config_proto_depIdxs = []int32{
|
||||||
4, // 0: xray.proxy.freedom.DestinationOverride.server:type_name -> xray.common.protocol.ServerEndpoint
|
5, // 0: xray.proxy.freedom.DestinationOverride.server:type_name -> xray.common.protocol.ServerEndpoint
|
||||||
0, // 1: xray.proxy.freedom.Config.domain_strategy:type_name -> xray.proxy.freedom.Config.DomainStrategy
|
0, // 1: xray.proxy.freedom.Config.domain_strategy:type_name -> xray.proxy.freedom.Config.DomainStrategy
|
||||||
1, // 2: xray.proxy.freedom.Config.destination_override:type_name -> xray.proxy.freedom.DestinationOverride
|
1, // 2: xray.proxy.freedom.Config.destination_override:type_name -> xray.proxy.freedom.DestinationOverride
|
||||||
2, // 3: xray.proxy.freedom.Config.fragment:type_name -> xray.proxy.freedom.Fragment
|
2, // 3: xray.proxy.freedom.Config.fragment:type_name -> xray.proxy.freedom.Fragment
|
||||||
4, // [4:4] is the sub-list for method output_type
|
3, // 4: xray.proxy.freedom.Config.noise:type_name -> xray.proxy.freedom.Noise
|
||||||
4, // [4:4] is the sub-list for method input_type
|
5, // [5:5] is the sub-list for method output_type
|
||||||
4, // [4:4] is the sub-list for extension type_name
|
5, // [5:5] is the sub-list for method input_type
|
||||||
4, // [4:4] is the sub-list for extension extendee
|
5, // [5:5] is the sub-list for extension type_name
|
||||||
0, // [0:4] is the sub-list for field type_name
|
5, // [5:5] is the sub-list for extension extendee
|
||||||
|
0, // [0:5] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_proxy_freedom_config_proto_init() }
|
func init() { file_proxy_freedom_config_proto_init() }
|
||||||
@ -449,6 +551,18 @@ func file_proxy_freedom_config_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proxy_freedom_config_proto_msgTypes[2].Exporter = func(v any, i int) any {
|
file_proxy_freedom_config_proto_msgTypes[2].Exporter = func(v any, i int) any {
|
||||||
|
switch v := v.(*Noise); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_proxy_freedom_config_proto_msgTypes[3].Exporter = func(v any, i int) any {
|
||||||
switch v := v.(*Config); i {
|
switch v := v.(*Config); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@ -467,7 +581,7 @@ func file_proxy_freedom_config_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_proxy_freedom_config_proto_rawDesc,
|
RawDescriptor: file_proxy_freedom_config_proto_rawDesc,
|
||||||
NumEnums: 1,
|
NumEnums: 1,
|
||||||
NumMessages: 3,
|
NumMessages: 4,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 0,
|
NumServices: 0,
|
||||||
},
|
},
|
||||||
|
@ -20,6 +20,13 @@ message Fragment {
|
|||||||
uint64 interval_min = 5;
|
uint64 interval_min = 5;
|
||||||
uint64 interval_max = 6;
|
uint64 interval_max = 6;
|
||||||
}
|
}
|
||||||
|
message Noise {
|
||||||
|
uint64 length_min = 1;
|
||||||
|
uint64 length_max = 2;
|
||||||
|
uint64 delay_min = 3;
|
||||||
|
uint64 delay_max = 4;
|
||||||
|
string str_noise = 5;
|
||||||
|
}
|
||||||
|
|
||||||
message Config {
|
message Config {
|
||||||
enum DomainStrategy {
|
enum DomainStrategy {
|
||||||
@ -41,4 +48,5 @@ message Config {
|
|||||||
uint32 user_level = 4;
|
uint32 user_level = 4;
|
||||||
Fragment fragment = 5;
|
Fragment fragment = 5;
|
||||||
uint32 proxy_protocol = 6;
|
uint32 proxy_protocol = 6;
|
||||||
|
Noise noise = 7;
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,16 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writer = NewPacketWriter(conn, h, ctx, UDPOverride)
|
writer = NewPacketWriter(conn, h, ctx, UDPOverride)
|
||||||
|
if h.config.Noise != nil {
|
||||||
|
errors.LogDebug(ctx, "NOISE", h.config.Noise.StrNoise, h.config.Noise.LengthMin, h.config.Noise.LengthMax,
|
||||||
|
h.config.Noise.DelayMin, h.config.Noise.DelayMax)
|
||||||
|
writer = &NoisePacketWriter{
|
||||||
|
Writer: writer,
|
||||||
|
noise: h.config.Noise,
|
||||||
|
firstWrite: true,
|
||||||
|
UDPOverride: UDPOverride,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
|
if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
|
||||||
@ -329,6 +339,7 @@ func NewPacketWriter(conn net.Conn, h *Handler, ctx context.Context, UDPOverride
|
|||||||
UDPOverride: UDPOverride,
|
UDPOverride: UDPOverride,
|
||||||
Conn: iConn,
|
Conn: iConn,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return &buf.SequentialWriter{Writer: conn}
|
return &buf.SequentialWriter{Writer: conn}
|
||||||
}
|
}
|
||||||
@ -385,6 +396,45 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NoisePacketWriter struct {
|
||||||
|
buf.Writer
|
||||||
|
noise *Noise
|
||||||
|
firstWrite bool
|
||||||
|
UDPOverride net.Destination
|
||||||
|
}
|
||||||
|
|
||||||
|
// MultiBuffer writer with Noise in first packet
|
||||||
|
func (w *NoisePacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
|
if w.firstWrite {
|
||||||
|
w.firstWrite = false
|
||||||
|
//Do not send Noise for dns requests(just to be safe)
|
||||||
|
if w.UDPOverride.Port == 53 {
|
||||||
|
return w.Writer.WriteMultiBuffer(mb)
|
||||||
|
}
|
||||||
|
var noise []byte
|
||||||
|
var err error
|
||||||
|
//User input string
|
||||||
|
if w.noise.StrNoise != "" {
|
||||||
|
noise = []byte(w.noise.StrNoise)
|
||||||
|
} else {
|
||||||
|
//Random noise
|
||||||
|
noise, err = GenerateRandomBytes(randBetween(int64(w.noise.LengthMin),
|
||||||
|
int64(w.noise.LengthMax)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
w.Writer.WriteMultiBuffer(buf.MultiBuffer{buf.FromBytes(noise)})
|
||||||
|
|
||||||
|
if w.noise.DelayMin != 0 {
|
||||||
|
time.Sleep(time.Duration(randBetween(int64(w.noise.DelayMin), int64(w.noise.DelayMax))) * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return w.Writer.WriteMultiBuffer(mb)
|
||||||
|
}
|
||||||
|
|
||||||
type FragmentWriter struct {
|
type FragmentWriter struct {
|
||||||
fragment *Fragment
|
fragment *Fragment
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
@ -471,3 +521,13 @@ func randBetween(left int64, right int64) int64 {
|
|||||||
bigInt, _ := rand.Int(rand.Reader, big.NewInt(right-left))
|
bigInt, _ := rand.Int(rand.Reader, big.NewInt(right-left))
|
||||||
return left + bigInt.Int64()
|
return left + bigInt.Int64()
|
||||||
}
|
}
|
||||||
|
func GenerateRandomBytes(n int64) ([]byte, error) {
|
||||||
|
b := make([]byte, n)
|
||||||
|
_, err := rand.Read(b)
|
||||||
|
// Note that err == nil only if we read len(b) bytes.
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user