vsocks5

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 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 is connect command
	CmdConnect byte = 0x01
	// CmdBind is bind command
	CmdBind byte = 0x02
	// CmdUDP is UDP command
	CmdUDP byte = 0x03
)
View Source
const (
	// MethodNone is none method
	MethodNone byte = 0x00
	// MethodGSSAPI is gssapi method
	MethodGSSAPI byte = 0x01 // MUST support // todo
	// MethodUsernamePassword is username/assword auth method
	MethodUsernamePassword byte = 0x02 // SHOULD support
	// MethodUnsupportAll means unsupport all given methods
	MethodUnsupportAll byte = 0xFF
)
View Source
const (
	// Ver is socks protocol version
	Ver byte = 0x05

	// UserPassVer is username/password auth protocol version
	UserPassVer byte = 0x01
	// UserPassStatusSuccess is success status of username/password auth
	UserPassStatusSuccess byte = 0x00
	// UserPassStatusFailure is failure status of username/password auth
	UserPassStatusFailure byte = 0x01 // just other than 0x00

	// ATYPIPv4 is ipv4 address type
	ATYPIPv4 byte = 0x01 // 4 octets
	// ATYPDomain is domain address type
	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 address type
	ATYPIPv6 byte = 0x04 // 16 octets

	// RepSuccess means that success for repling
	RepSuccess byte = 0x00
	// RepServerFailure means the server failure
	RepServerFailure byte = 0x01
	// RepNotAllowed means the request not allowed
	RepNotAllowed byte = 0x02
	// RepNetworkUnreachable means the network unreachable
	RepNetworkUnreachable byte = 0x03
	// RepHostUnreachable means the host unreachable
	RepHostUnreachable byte = 0x04
	// RepConnectionRefused means the connection refused
	RepConnectionRefused byte = 0x05
	// RepTTLExpired means the TTL expired
	RepTTLExpired byte = 0x06
	// RepCommandNotSupported means the request command not supported
	RepCommandNotSupported byte = 0x07
	// RepAddressNotSupported means the request address not supported
	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

This section is empty.

Types

type Client

type Client struct {
	Server   string
	Username string
	Password string
	DialTCP  func(net string, laddr, raddr *net.TCPAddr) (*net.TCPConn, error)
	// contains filtered or unexported fields
}

func (*Client) Close

func (c *Client) Close() 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)

func (*Client) LocalAddr

func (c *Client) LocalAddr() net.Addr

func (*Client) Read

func (c *Client) Read(b []byte) (int, error)

func (*Client) RemoteAddr

func (c *Client) RemoteAddr() net.Addr

func (*Client) SetDeadline

func (c *Client) SetDeadline(t time.Time) error

func (*Client) SetReadDeadline

func (c *Client) SetReadDeadline(t time.Time) error

func (*Client) SetWriteDeadline

func (c *Client) SetWriteDeadline(t time.Time) error

func (*Client) Write

func (c *Client) Write(b []byte) (int, 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 (*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(clientConn net.Conn, r *RequestTCP) error

func (*DefaultHandle) UDP

func (T *DefaultHandle) UDP(proxyUDP *net.UDPConn, clientAddr *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 NegotiationReply

type NegotiationReply struct {
	Ver    byte
	Method byte
}

func (*NegotiationReply) WriteTo

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

type NegotiationReplyAuth

type NegotiationReplyAuth struct {
	Ver    byte
	Status byte
}

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 (*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 (*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 (*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 (*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) UDP

func (r *RequestTCP) UDP(clientTCPConn net.Conn, proxyAddr *net.UDPAddr) (clientUDPAddr *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
main command

Jump to

Keyboard shortcuts

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