socks

package
v0.0.0-...-dbd5d84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package socks provides implements of Socks protocol 4, 4a and 5.

Index

Constants

View Source
const (
	ReplyConnectionNotAllowed byte = 2
	ReplyNetworkUnreachable   byte = 3
	ReplyHostUnreachable      byte = 4
	ReplyConnectionRefused    byte = 5
	ReplyTTLExpired           byte = 6
	ReplyCommandNotSupported  byte = 7
	ReplyAddressNotSupported  byte = 8
)

Variables

View Source
var (
	AuthType_name = map[int32]string{
		0: "NO_AUTH",
		1: "PASSWORD",
		2: "NN_AUTH",
		3: "NN_HEARTBEAT",
	}
	AuthType_value = map[string]int32{
		"NO_AUTH":      0,
		"PASSWORD":     1,
		"NN_AUTH":      2,
		"NN_HEARTBEAT": 3,
	}
)

Enum value maps for AuthType.

View Source
var File_proxy_socks_config_proto protoreflect.FileDescriptor

Functions

func ClientHandshake

func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error)

func DecodeUDPPacket

func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error)

func EncodeUDPPacket

func EncodeUDPPacket(request *protocol.RequestHeader, data []byte) (*buf.Buffer, error)

func LeiCheckSum

func LeiCheckSum(token string) uint8

LeiCheckSum ...

func ReadUntilNull

func ReadUntilNull(reader io.Reader) (string, error)

ReadUntilNull reads content from given reader, until a null (0x00) byte.

func ReadUsernamePassword

func ReadUsernamePassword(reader io.Reader) (string, string, error)

ReadUsernamePassword reads Socks 5 username/password message from the given reader. +----+------+----------+------+----------+ |VER | ULEN | UNAME | PLEN | PASSWD | +----+------+----------+------+----------+ | 1 | 1 | 1 to 255 | 1 | 1 to 255 | +----+------+----------+------+----------+

func XOR

func XOR(buf []byte)

XOR ...

func XORDecrypt

func XORDecrypt(buf []byte)

XORDecrypt ...

func XOREncrypt

func XOREncrypt(buf []byte)

XOREncrypt ...

Types

type Account

type Account struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
	// contains filtered or unexported fields
}

Account represents a Socks account.

func (*Account) AsAccount

func (a *Account) AsAccount() (protocol.Account, error)

func (*Account) Descriptor deprecated

func (*Account) Descriptor() ([]byte, []int)

Deprecated: Use Account.ProtoReflect.Descriptor instead.

func (*Account) Equals

func (a *Account) Equals(another protocol.Account) bool

func (*Account) GetPassword

func (x *Account) GetPassword() string

func (*Account) GetUsername

func (x *Account) GetUsername() string

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) ProtoReflect

func (x *Account) ProtoReflect() protoreflect.Message

func (*Account) Reset

func (x *Account) Reset()

func (*Account) String

func (x *Account) String() string

type AuthType

type AuthType int32

AuthType is the authentication type of Socks proxy.

const (
	// NO_AUTH is for anounymous authentication.
	AuthType_NO_AUTH AuthType = 0
	// PASSWORD is for username/password authentication.
	AuthType_PASSWORD AuthType = 1
	//for nn auth
	AuthType_NN_AUTH      AuthType = 2
	AuthType_NN_HEARTBEAT AuthType = 3
)

func (AuthType) Descriptor

func (AuthType) Descriptor() protoreflect.EnumDescriptor

func (AuthType) Enum

func (x AuthType) Enum() *AuthType

func (AuthType) EnumDescriptor deprecated

func (AuthType) EnumDescriptor() ([]byte, []int)

Deprecated: Use AuthType.Descriptor instead.

func (AuthType) Number

func (x AuthType) Number() protoreflect.EnumNumber

func (AuthType) String

func (x AuthType) String() string

func (AuthType) Type

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Socks5 client.

func NewClient

func NewClient(ctx context.Context, config *ClientConfig) (*Client, error)

NewClient create a new Socks5 client based on the given config.

func (*Client) Process

func (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error

Process implements proxy.Outbound.Process.

type ClientConfig

type ClientConfig struct {

	// Sever is a list of Socks server addresses.
	Server []*protocol.ServerEndpoint `protobuf:"bytes,1,rep,name=server,proto3" json:"server,omitempty"`
	// contains filtered or unexported fields
}

ClientConfig is the protobuf config for Socks client.

func (*ClientConfig) Descriptor deprecated

func (*ClientConfig) Descriptor() ([]byte, []int)

Deprecated: Use ClientConfig.ProtoReflect.Descriptor instead.

func (*ClientConfig) GetServer

func (x *ClientConfig) GetServer() []*protocol.ServerEndpoint

func (*ClientConfig) ProtoMessage

func (*ClientConfig) ProtoMessage()

func (*ClientConfig) ProtoReflect

func (x *ClientConfig) ProtoReflect() protoreflect.Message

func (*ClientConfig) Reset

func (x *ClientConfig) Reset()

func (*ClientConfig) String

func (x *ClientConfig) String() string

type DecryptReadWriteCloser

type DecryptReadWriteCloser struct {
	// contains filtered or unexported fields
}

DecryptReadWriteCloser 对进来的数据流进行解密

func NewDecryptReadWriteCloser

func NewDecryptReadWriteCloser(rwc io.ReadWriteCloser) *DecryptReadWriteCloser

NewDecryptReadWriteCloser ...

func (*DecryptReadWriteCloser) Close

func (m *DecryptReadWriteCloser) Close() error

Close 实现 io.Close

func (*DecryptReadWriteCloser) Read

func (m *DecryptReadWriteCloser) Read(p []byte) (n int, err error)

Read 实现 io.Reader

func (*DecryptReadWriteCloser) Write

func (m *DecryptReadWriteCloser) Write(p []byte) (n int, err error)

Write 实现 io.Writer

type DecryptReadWriter

type DecryptReadWriter struct {
	// contains filtered or unexported fields
}

DecryptReadWriter 对进来的数据流进行解密

func NewDecryptReadWriter

func NewDecryptReadWriter(rw io.ReadWriter) *DecryptReadWriter

NewDecryptReadWriter ...

func (*DecryptReadWriter) Read

func (m *DecryptReadWriter) Read(p []byte) (n int, err error)

Read 实现 io.Reader

func (*DecryptReadWriter) Write

func (m *DecryptReadWriter) Write(p []byte) (n int, err error)

Write 实现 io.Writer

type DecryptReader

type DecryptReader struct {
	// contains filtered or unexported fields
}

DecryptReader 对进来的数据流进行解密

func NewDecryptReader

func NewDecryptReader(r io.Reader) *DecryptReader

NewDecryptReader ...

func (*DecryptReader) Read

func (m *DecryptReader) Read(p []byte) (n int, err error)

Read 实现 io.Reader

type EncryptReadWriteCloser

type EncryptReadWriteCloser struct {
	// contains filtered or unexported fields
}

EncryptReadWriteCloser 对出去的数据流进行加密

func NewEncryptReadWriteCloser

func NewEncryptReadWriteCloser(rwc io.ReadWriteCloser) *EncryptReadWriteCloser

NewEncryptReadWriteCloser ...

func (*EncryptReadWriteCloser) Close

func (m *EncryptReadWriteCloser) Close() error

Close 实现 io.Closer

func (*EncryptReadWriteCloser) Read

func (m *EncryptReadWriteCloser) Read(p []byte) (n int, err error)

Read 实现 io.Reader

func (*EncryptReadWriteCloser) Write

func (m *EncryptReadWriteCloser) Write(p []byte) (n int, err error)

Write 实现 io.Writer

type EncryptReadWriter

type EncryptReadWriter struct {
	// contains filtered or unexported fields
}

EncryptReadWriter 对出去的数据流进行加密

func NewEncryptReadWriter

func NewEncryptReadWriter(rw io.ReadWriter) *EncryptReadWriter

NewEncryptReadWriter ...

func (*EncryptReadWriter) Read

func (m *EncryptReadWriter) Read(p []byte) (n int, err error)

Read 实现 io.Reader

func (*EncryptReadWriter) Write

func (m *EncryptReadWriter) Write(p []byte) (n int, err error)

Write 实现 io.Writer

type EncryptWriter

type EncryptWriter struct {
	// contains filtered or unexported fields
}

EncryptWriter 对出去的数据流进行加密

func NewEncryptWriter

func NewEncryptWriter(w io.Writer) *EncryptWriter

NewEncryptWriter ...

func (*EncryptWriter) Write

func (m *EncryptWriter) Write(p []byte) (n int, err error)

Write 实现 io.Writer

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a SOCKS 5 proxy server

func NewServer

func NewServer(ctx context.Context, config *ServerConfig) (*Server, error)

NewServer creates a new Server object.

func (*Server) Network

func (s *Server) Network() []net.Network

Network implements proxy.Inbound.

func (*Server) Process

func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher routing.Dispatcher) error

Process implements proxy.Inbound.

type ServerConfig

type ServerConfig struct {
	AuthType   []AuthType        `protobuf:"varint,1,rep,packed,name=auth_type,json=authType,proto3,enum=xray.proxy.socks.AuthType" json:"auth_type,omitempty"`
	Accounts   map[string]string `` /* 157-byte string literal not displayed */
	Address    *net.IPOrDomain   `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
	UdpEnabled bool              `protobuf:"varint,4,opt,name=udp_enabled,json=udpEnabled,proto3" json:"udp_enabled,omitempty"`
	// Deprecated: Do not use.
	Timeout   uint32 `protobuf:"varint,5,opt,name=timeout,proto3" json:"timeout,omitempty"`
	UserLevel uint32 `protobuf:"varint,6,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
	// contains filtered or unexported fields
}

ServerConfig is the protobuf config for Socks server.

func (*ServerConfig) Descriptor deprecated

func (*ServerConfig) Descriptor() ([]byte, []int)

Deprecated: Use ServerConfig.ProtoReflect.Descriptor instead.

func (*ServerConfig) GetAccounts

func (x *ServerConfig) GetAccounts() map[string]string

func (*ServerConfig) GetAddress

func (x *ServerConfig) GetAddress() *net.IPOrDomain

func (*ServerConfig) GetAuthType

func (x *ServerConfig) GetAuthType() []AuthType

func (*ServerConfig) GetTimeout deprecated

func (x *ServerConfig) GetTimeout() uint32

Deprecated: Do not use.

func (*ServerConfig) GetUdpEnabled

func (x *ServerConfig) GetUdpEnabled() bool

func (*ServerConfig) GetUserLevel

func (x *ServerConfig) GetUserLevel() uint32

func (*ServerConfig) HasAccount

func (c *ServerConfig) HasAccount(username, password string) bool

func (*ServerConfig) ProtoMessage

func (*ServerConfig) ProtoMessage()

func (*ServerConfig) ProtoReflect

func (x *ServerConfig) ProtoReflect() protoreflect.Message

func (*ServerConfig) Reset

func (x *ServerConfig) Reset()

func (*ServerConfig) String

func (x *ServerConfig) String() string

type ServerSession

type ServerSession struct {
	// contains filtered or unexported fields
}

func (*ServerSession) Handshake

func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error)

Handshake performs a Socks4/4a/5 handshake.

type UDPReader

type UDPReader struct {
	Reader io.Reader
}

func (*UDPReader) ReadMultiBuffer

func (r *UDPReader) ReadMultiBuffer() (buf.MultiBuffer, error)

type UDPWriter

type UDPWriter struct {
	Writer  io.Writer
	Request *protocol.RequestHeader
}

func (*UDPWriter) WriteMultiBuffer

func (w *UDPWriter) WriteMultiBuffer(mb buf.MultiBuffer) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL