vsocks5

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

README

vsocks5 Build Status

golang socks5, ssh proxy server, 代理服务器

命令行:

  -addr string
        代理服务器地 (format "0.0.0.0:1080")
  -dataBufioSize int
        代理数据交换缓冲区大小,单位字节 (default 10240)
  -log string
        日志文件(默认留空在控制台显示日志)  (format "./vsocks5.txt")
  -proxy string
        代理服务器的上级代理IP地址 (format "https://admin:admin@11.22.33.44:8888" or "ssh://admin:admin@11.22.33.44:22")
  -pwd string
        密码
  -user string
        用户名

命令行例子:vsocks5 -addr 0.0.0.0:1080

Documentation

Index

Constants

View Source
const (
	// CmdConnect 是 TCP 命令
	CmdConnect byte = 0x01
	// CmdBind 是绑定端口命令
	CmdBind byte = 0x02
	// CmdUDP 是 UDP 命令
	CmdUDP byte = 0x03
)
View Source
const (
	// MethodNone 是默认方法
	MethodNone byte = 0x00
	// MethodGSSAPI 是gssapi方法
	MethodGSSAPI byte = 0x01 // MUST support // todo
	// MethodUsernamePassword 是用户名/密码授权方法
	MethodUsernamePassword byte = 0x02 // SHOULD support
	// MethodUnsupportAll 表示不支持所有给定的方法
	MethodUnsupportAll byte = 0xFF
)
View Source
const (
	// ver是socks协议版本
	Ver byte = 0x05

	// UserPassVer 是用户名/密码授权协议版本
	UserPassVer byte = 0x01
	// UserPassStatusSuccess 是用户名/密码授权的成功状态
	UserPassStatusSuccess byte = 0x00
	// UserPassStatusFailure 是用户名/密码授权的失败状态
	UserPassStatusFailure byte = 0x01 // just other than 0x00

	// ATYPIPv4 是ipv4地址类型
	ATYPIPv4 byte = 0x01 // 4 octets
	// ATYPDomain 是域名地址类型
	ATYPDomain byte = 0x03 // The first octet of the address field contains the number of octets of name that follow, there is no terminating NUL octet.
	// ATYPIPv6 is ipv6 地址类型
	ATYPIPv6 byte = 0x04 // 16 octets

	// RepSuccess 意味着回复成功
	RepSuccess byte = 0x00
	// RepServerFailure 意味着服务器故障
	RepServerFailure byte = 0x01
	// RepNotAllowed 表示请求不允许
	RepNotAllowed byte = 0x02
	// RepNetworkUnreachable 表示网络不可达
	RepNetworkUnreachable byte = 0x03
	// RepHostUnreachable 表示主机无法访问
	RepHostUnreachable byte = 0x04
	// RepConnectionRefused 表示连接被拒绝
	RepConnectionRefused byte = 0x05
	// RepTTLExpired 表示 TTL 已过期
	RepTTLExpired byte = 0x06
	// RepCommandNotSupported 表示不支持请求命令
	RepCommandNotSupported byte = 0x07
	// RepAddressNotSupported 表示不支持请求地址
	RepAddressNotSupported byte = 0x08
)

Variables

View Source
var (
	ErrVersion         = errors.New("invalid Version")
	ErrUserPassVersion = errors.New("invalid Version of Username Password Auth")
	ErrBadRequest      = errors.New("bad Request")
	ErrEmptyAddr       = errors.New("invalid Addr")
	ErrHandler         = errors.New("data handler is not set")
	ErrUnsupportCmd    = errors.New("unsupport Command")
	ErrUserPassAuth    = errors.New("invalid Username or Password for Auth")
	ErrTCPConnClose    = errors.New("TCP connection is closed")
	ErrBadReply        = errors.New("bad Reply")
)
View Source
var BuffSize = 32 << 10 // 32k

Functions

func ParseAddress added in v1.0.6

func ParseAddress(address string) (a byte, addr []byte, port []byte, err error)

func ParseBytesAddress added in v1.0.6

func ParseBytesAddress(b []byte) (a byte, addr []byte, port []byte, err error)

Types

type Client

type Client struct {
	Server   string
	Username string
	Password string
	DialTCP  func(network string, laddr, raddr *net.TCPAddr) (net.Conn, error)
}

func (*Client) Dial

func (c *Client) Dial(network, addr string) (net.Conn, error)

func (Client) DialWithLocalAddr

func (c Client) DialWithLocalAddr(network, src, dst string) (net.Conn, error)

type Cmd

type Cmd []byte

type DatagramUDP

type DatagramUDP struct {
	Rsv     []byte // 0x00 0x00
	Frag    byte
	Atyp    byte
	DstAddr []byte
	DstPort []byte // 2 bytes
	Data    []byte
}

数据报文是UDP包

func NewRequestUDP added in v1.0.6

func NewRequestUDP(atyp byte, dstaddr []byte, dstport []byte, data []byte) *DatagramUDP

client/server

+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
+----+------+------+----------+----------+----------+
| 2  |  1   |  1   | Variable |    2     | Variable |
+----+------+------+----------+----------+----------+

func ReadRequestUDP added in v1.0.6

func ReadRequestUDP(bb []byte) (*DatagramUDP, error)

server/server

+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
+----+------+------+----------+----------+----------+
| 2  |  1   |  1   | Variable |    2     | Variable |
+----+------+------+----------+----------+----------+

func (*DatagramUDP) Address

func (d *DatagramUDP) Address() string

func (*DatagramUDP) Bytes

func (d *DatagramUDP) Bytes() []byte

Bytes return []byte

type DefaultHandle

type DefaultHandle struct {
	Dialer
	BuffSize int
	// contains filtered or unexported fields
}

func (*DefaultHandle) TCP

func (T *DefaultHandle) TCP(cconn net.Conn, r *RequestTCP) error

func (*DefaultHandle) UDP

func (T *DefaultHandle) UDP(proxyUDP *net.UDPConn, cAddr *net.UDPAddr, d *DatagramUDP) error

type Dialer

type Dialer struct {
	Dial        func(network, address string) (net.Conn, error)
	DialContext func(ctx context.Context, network, address string) (net.Conn, error)
}

type Handler

type Handler interface {
	TCP(net.Conn, *RequestTCP) error
	UDP(*net.UDPConn, *net.UDPAddr, *DatagramUDP) error
}

type Negotiate added in v1.0.6

type Negotiate struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*Negotiate) Auth added in v1.0.6

func (T *Negotiate) Auth(username, password string) error

验证账号

type NegotiationReply

type NegotiationReply struct {
	Ver    byte
	Method byte
}

func NewNegotiateMethodReply added in v1.0.6

func NewNegotiateMethodReply(method byte) *NegotiationReply

server

+----+--------+
|VER | METHOD |
+----+--------+
| 1  |   1    |
+----+--------+

func ReadNegotiateMethodReply added in v1.0.6

func ReadNegotiateMethodReply(r io.Reader) (*NegotiationReply, error)

client

+----+--------+
|VER | METHOD |
+----+--------+
| 1  |   1    |
+----+--------+

func (*NegotiationReply) WriteTo

func (r *NegotiationReply) WriteTo(w io.Writer) (int64, error)

type NegotiationReplyAuth

type NegotiationReplyAuth struct {
	Ver    byte
	Status byte
}

func NewNegotiateAuthReply added in v1.0.6

func NewNegotiateAuthReply(status byte) *NegotiationReplyAuth

server

+----+--------+
|VER | STATUS |
+----+--------+
| 1  |   1    |
+----+--------+

func ReadNegotiateAuthReply added in v1.0.6

func ReadNegotiateAuthReply(r io.Reader) (*NegotiationReplyAuth, error)

client

+----+--------+
|VER | STATUS |
+----+--------+
| 1  |   1    |
+----+--------+

func (*NegotiationReplyAuth) WriteTo

func (r *NegotiationReplyAuth) WriteTo(w io.Writer) (int64, error)

type NegotiationRequest

type NegotiationRequest struct {
	Ver      byte
	NMethods byte
	Methods  []byte // 1-255 bytes
}

func NewNegotiateMethodRequest added in v1.0.6

func NewNegotiateMethodRequest(methods []byte) *NegotiationRequest

client

+----+----------+----------+
|VER | NMETHODS | METHODS  |
+----+----------+----------+
| 1  |    1     | 1 to 255 |
+----+----------+----------+

func ReadNegotiateMethodRequest added in v1.0.6

func ReadNegotiateMethodRequest(r io.Reader) (*NegotiationRequest, error)

server

+----+----------+----------+
|VER | NMETHODS | METHODS  |
+----+----------+----------+
| 1  |    1     | 1 to 255 |
+----+----------+----------+

func (*NegotiationRequest) WriteTo

func (r *NegotiationRequest) WriteTo(w io.Writer) (int64, error)

type NegotiationRequestAuth

type NegotiationRequestAuth struct {
	Ver    byte
	Ulen   byte
	Uname  []byte // 1-255 bytes
	Plen   byte
	Passwd []byte // 1-255 bytes
}

func NewNegotiateAuthRequest added in v1.0.6

func NewNegotiateAuthRequest(username []byte, password []byte) *NegotiationRequestAuth

client

+----+------+----------+------+----------+
|VER | ULEN |  UNAME   | PLEN |  PASSWD  |
+----+------+----------+------+----------+
| 1  |  1   | 1 to 255 |  1   | 1 to 255 |
+----+------+----------+------+----------+

func ReadNegotiateAuthRequest added in v1.0.6

func ReadNegotiateAuthRequest(r io.Reader) (*NegotiationRequestAuth, error)

server

+----+------+----------+------+----------+
|VER | ULEN |  UNAME   | PLEN |  PASSWD  |
+----+------+----------+------+----------+
| 1  |  1   | 1 to 255 |  1   | 1 to 255 |
+----+------+----------+------+----------+

func (*NegotiationRequestAuth) WriteTo

func (r *NegotiationRequestAuth) WriteTo(w io.Writer) (int64, error)

type ReplyTCP

type ReplyTCP struct {
	Ver  byte
	Rep  byte
	Rsv  byte // 0x00
	Atyp byte
	// CONNECT socks server's address which used to connect to dst addr
	// BIND ...
	// UDP socks server's address which used to connect to dst addr
	BndAddr []byte
	// CONNECT socks server's port which used to connect to dst addr
	// BIND ...
	// UDP socks server's port which used to connect to dst addr
	BndPort []byte // 2 bytes
}

func NewReplyTCP added in v1.0.6

func NewReplyTCP(rep byte, atyp byte, bndaddr []byte, bndport []byte) *ReplyTCP

server

+----+-----+-------+------+----------+----------+
|VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
+----+-----+-------+------+----------+----------+
| 1  |  1  | X'00' |  1   | Variable |    2     |
+----+-----+-------+------+----------+----------+

func ReadReplyTCP added in v1.0.6

func ReadReplyTCP(r io.Reader) (*ReplyTCP, error)

client

+----+-----+-------+------+----------+----------+
|VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
+----+-----+-------+------+----------+----------+
| 1  |  1  | X'00' |  1   | Variable |    2     |
+----+-----+-------+------+----------+----------+

func (*ReplyTCP) Address

func (r *ReplyTCP) Address() string

func (*ReplyTCP) WriteTo

func (r *ReplyTCP) WriteTo(w io.Writer) (int64, error)

type RequestTCP

type RequestTCP struct {
	Ver     byte
	Cmd     byte
	Rsv     byte // 0x00
	Atyp    byte
	DstAddr []byte
	DstPort []byte // 2 bytes
}

func NewRequestTCP added in v1.0.6

func NewRequestTCP(cmd byte, atyp byte, dstaddr []byte, dstport []byte) *RequestTCP

client

+----+-----+-------+------+----------+----------+
|VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
+----+-----+-------+------+----------+----------+
| 1  |  1  | X'00' |  1   | Variable |    2     |
+----+-----+-------+------+----------+----------+

func ReadRequestTCP added in v1.0.6

func ReadRequestTCP(r io.Reader) (*RequestTCP, error)

server

+----+-----+-------+------+----------+----------+
|VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
+----+-----+-------+------+----------+----------+
| 1  |  1  | X'00' |  1   | Variable |    2     |
+----+-----+-------+------+----------+----------+

func (*RequestTCP) Address

func (r *RequestTCP) Address() string

func (*RequestTCP) RemoteConnect

func (r *RequestTCP) RemoteConnect(dial *Dialer, w io.Writer) (rc net.Conn, err error)

func (*RequestTCP) ReplyError added in v1.0.6

func (r *RequestTCP) ReplyError(rep byte, w io.Writer) error

func (*RequestTCP) UDP

func (r *RequestTCP) UDP(cconn net.Conn, proxyAddr *net.UDPAddr) (caddr *net.UDPAddr, err error)

func (*RequestTCP) WriteTo

func (r *RequestTCP) WriteTo(w io.Writer) (int64, error)

type Server

type Server struct {
	Auth      func(username, password string) bool
	Supported Cmd
	Addr      string

	Handle   Handler
	ErrorLog *log.Logger // 日志
	Method   byte
	// contains filtered or unexported fields
}

func (*Server) Close

func (T *Server) Close() error

func (*Server) ListenAndServe

func (T *Server) ListenAndServe() error

func (*Server) ServerTCP

func (T *Server) ServerTCP() error

func (*Server) ServerUDP

func (T *Server) ServerUDP() error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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