socks

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version     = 5
	UserPassVer = 1
)

Version = 5

View Source
const (
	MethodNoAuth uint8 = iota
	MethodGSSAPI
	MethodUserPass
	MethodNoAcceptable uint8 = 0xFF
)

Methods

View Source
const (
	CmdConnect uint8 = iota + 1
	CmdBind
	CmdUDP
	CmdUDPOverTCP
)

Commands

View Source
const (
	AddrIPv4   uint8 = 1
	AddrDomain       = 3
	AddrIPv6         = 4
)

Address types

View Source
const (
	Succeeded uint8 = iota
	Failure
	Allowed
	NetUnreachable
	HostUnreachable
	ConnRefused
	TTLExpired
	CmdUnsupported
	AddrUnsupported
)

Response codes

Variables

View Source
var (
	ErrBadVersion  = errors.New("Bad version")
	ErrBadFormat   = errors.New("Bad format")
	ErrBadAddrType = errors.New("Bad address type")
	ErrShortBuffer = errors.New("Short buffer")
	ErrBadMethod   = errors.New("Bad method")
	ErrAuthFailure = errors.New("Auth failure")
)

Errors

Functions

func ReadMethods

func ReadMethods(r io.Reader) ([]uint8, error)

ReadMethods returns methods Method selection

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

func WriteMethod

func WriteMethod(method uint8, w io.Writer) error

WriteMethod send the selected method to the client

func WriteMethods

func WriteMethods(methods []uint8, w io.Writer) error

WriteMethods send method select request to the server

Types

type Addr

type Addr struct {
	Type uint8
	Host string
	Port uint16
}

Addr has following struct

+------+----------+----------+
| ATYP |   ADDR   |   PORT   |
+------+----------+----------+
|  1   | Variable |    2     |
+------+----------+----------+

func NewAddr

func NewAddr(sa string) (addr *Addr, err error)

NewAddr creates an address object

func NewAddrFromAddr

func NewAddrFromAddr(ln, conn net.Addr) (addr *Addr, err error)

NewAddrFromAddr creates an address object

func NewAddrFromPair

func NewAddrFromPair(host string, port int) (addr *Addr)

NewAddrFromPair creates an address object from host and port pair

func (*Addr) Decode

func (addr *Addr) Decode(b []byte) error

Decode an address from the stream

func (*Addr) Encode

func (addr *Addr) Encode(b []byte) (int, error)

Encode an address to the stream

func (*Addr) Length

func (addr *Addr) Length() (n int)

Length of the address

func (*Addr) String

func (addr *Addr) String() string

type Reply

type Reply struct {
	Rep  uint8
	Addr *Addr
}

Reply is a SOCKSv5 reply

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

func NewReply

func NewReply(rep uint8, addr *Addr) *Reply

NewReply creates a socks5 reply

func ReadReply

func ReadReply(r io.Reader) (*Reply, error)

ReadReply reads a reply from the stream

func (*Reply) String

func (r *Reply) String() string

func (*Reply) Write

func (r *Reply) Write(w io.Writer) (err error)

type Request

type Request struct {
	Cmd  uint8
	Addr *Addr
}

Request represent a socks5 request The SOCKSv5 request

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

func NewRequest

func NewRequest(cmd uint8, addr *Addr) *Request

NewRequest creates an request object

func ReadRequest

func ReadRequest(r io.Reader) (*Request, error)

ReadRequest reads request from the stream

func (*Request) String

func (r *Request) String() string

func (*Request) Write

func (r *Request) Write(w io.Writer) (err error)

type UDPDatagram

type UDPDatagram struct {
	Header *UDPHeader
	Data   []byte
}

UDPDatagram represent an UDP request

func NewUDPDatagram

func NewUDPDatagram(header *UDPHeader, data []byte) *UDPDatagram

NewUDPDatagram creates an UDPDatagram

func ReadUDPDatagram

func ReadUDPDatagram(r io.Reader) (*UDPDatagram, error)

ReadUDPDatagram reads an UDPDatagram from the stream

func (*UDPDatagram) Write

func (d *UDPDatagram) Write(w io.Writer) error

type UDPHeader

type UDPHeader struct {
	Rsv  uint16
	Frag uint8
	Addr *Addr
}

UDPHeader is the header of an UDP request

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

func NewUDPHeader

func NewUDPHeader(rsv uint16, frag uint8, addr *Addr) *UDPHeader

NewUDPHeader creates an UDPHeader

func (*UDPHeader) String

func (h *UDPHeader) String() string

func (*UDPHeader) Write

func (h *UDPHeader) Write(w io.Writer) error

type UserPassRequest added in v0.5.0

type UserPassRequest struct {
	Version  byte
	Username string
	Password string
}

Username/Password authentication request

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

func NewUserPassRequest added in v0.5.0

func NewUserPassRequest(ver byte, u, p string) *UserPassRequest

func ReadUserPassRequest added in v0.5.0

func ReadUserPassRequest(r io.Reader) (*UserPassRequest, error)

func (*UserPassRequest) String added in v0.5.0

func (req *UserPassRequest) String() string

func (*UserPassRequest) Write added in v0.5.0

func (req *UserPassRequest) Write(w io.Writer) error

type UserPassResponse added in v0.5.0

type UserPassResponse struct {
	Version byte
	Status  byte
}

Username/Password authentication response

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

func NewUserPassResponse added in v0.5.0

func NewUserPassResponse(ver, status byte) *UserPassResponse

func ReadUserPassResponse added in v0.5.0

func ReadUserPassResponse(r io.Reader) (*UserPassResponse, error)

func (*UserPassResponse) String added in v0.5.0

func (res *UserPassResponse) String() string

func (*UserPassResponse) Write added in v0.5.0

func (res *UserPassResponse) Write(w io.Writer) error

Jump to

Keyboard shortcuts

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