socks

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 13 Imported by: 2

README

socks

Build Status Go Reference

Golang socks proxy and dialer

⚠ This is experimental and subject to breaking changes.

Usage

import (
	"log"

	"github.com/hupe1980/socks"
)

func main() {
	log.Fatal(socks.ListenAndServe(":1080")
}
Documentation

See godoc.

Examples

See more complete examples.

License

MIT

Documentation

Index

Constants

View Source
const (
	UsernamePasswordAuthVersion1 = 0x01
)

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string) error

Types

type AddrType

type AddrType uint8
const (
	AddrTypeIPv4 AddrType = 0x01 // IPv4
	AddrTypeFQDN AddrType = 0x03 // FQDN
	AddrTypeIPv6 AddrType = 0x04 // IPv6
)

type AuthMethod

type AuthMethod uint8
const (
	AuthMethodNotRequired         AuthMethod = 0x00 // no authentication required
	AuthMethodGSSAPI              AuthMethod = 0x01 // use GSSAPI
	AuthMethodUsernamePassword    AuthMethod = 0x02 // use username/password
	AuthMethodNoAcceptableMethods AuthMethod = 0xff // no acceptable authentication methods
)

type AuthStatus added in v0.0.4

type AuthStatus uint8
const (
	AuthStatusSuccess AuthStatus = 0x00
	AuthStatusFailure AuthStatus = 0xff
)

type AuthenticateFunc added in v0.0.3

type AuthenticateFunc func(context.Context, *Conn, AuthMethod) error

type Command

type Command uint8
const (
	ConnectCommand   Command = 0x01
	BindCommand      Command = 0x02
	AssociateCommand Command = 0x03
)

func (Command) String added in v0.0.3

func (cmd Command) String() string

type Conn added in v0.0.4

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

func NewConn added in v0.0.4

func NewConn(conn net.Conn) *Conn

func (*Conn) Peek added in v0.0.4

func (c *Conn) Peek(n int) ([]byte, error)

func (*Conn) Read added in v0.0.4

func (c *Conn) Read(req encoding.BinaryUnmarshaler) error

func (*Conn) Tunnel added in v0.0.5

func (c *Conn) Tunnel(target net.Conn) error

func (Conn) WaitForClose added in v0.0.9

func (c Conn) WaitForClose()

func (*Conn) Write added in v0.0.4

func (c *Conn) Write(resp encoding.BinaryMarshaler) error

type Dialer

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

type IdentFunc added in v0.0.8

type IdentFunc func(context.Context, *Conn, *Socks4Request) error

type Listener added in v0.0.7

type Listener interface {
	Listen(ctx context.Context, network string, address string) (net.Listener, error)
}

type MethodSelectRequest

type MethodSelectRequest struct {
	Methods []AuthMethod
}

func (*MethodSelectRequest) MarshalBinary

func (req *MethodSelectRequest) MarshalBinary() ([]byte, error)

func (*MethodSelectRequest) UnmarshalBinary

func (req *MethodSelectRequest) UnmarshalBinary(p []byte) error

type MethodSelectResponse

type MethodSelectResponse struct {
	Method AuthMethod
}

func (*MethodSelectResponse) MarshalBinary

func (resp *MethodSelectResponse) MarshalBinary() ([]byte, error)

func (*MethodSelectResponse) UnmarshalBinary

func (resp *MethodSelectResponse) UnmarshalBinary(p []byte) error

type Options

type Options struct {
	// Logger specifies an optional logger.
	// If nil, logging is done via the log package's standard logger.
	Logger golog.Logger

	Dialer Dialer

	Listener Listener

	// Ident specifies the optional ident function.
	// It must return an error when the ident is failed.
	Ident IdentFunc

	// AuthMethods specifies the list of supported authentication
	// methods.
	// If empty, SOCKS server supports AuthMethodNotRequired.
	AuthMethods []AuthMethod

	// Authenticate specifies the optional authentication
	// function. It must be non-nil when AuthMethods is not empty.
	// It must return an error when the authentication is failed.
	Authenticate AuthenticateFunc
}

type Server

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

func New

func New(optFns ...func(*Options)) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve serves connections from a listener

type Socks4Dialer

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

func NewSocks4Dialer

func NewSocks4Dialer(network, address string, optFns ...func(*Socks4DialerOptions)) *Socks4Dialer

NewSocks4Dialer returns a new Socks4Dialer that dials through the provided proxy server's network and address.

func (*Socks4Dialer) Dial

func (d *Socks4Dialer) Dial(network, addr string) (net.Conn, error)

func (*Socks4Dialer) DialContext

func (d *Socks4Dialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

type Socks4DialerOptions added in v0.0.3

type Socks4DialerOptions struct {
	UserID string

	// Logger specifies an optional logger.
	// If nil, logging is done via the log package's standard logger.
	Logger golog.Logger

	// ProxyDialer specifies the optional dialer for
	// establishing the transport connection.
	ProxyDialer Dialer
}

type Socks4Request

type Socks4Request struct {
	CMD    Command
	Addr   string
	UserID string
}

func (*Socks4Request) MarshalBinary

func (req *Socks4Request) MarshalBinary() ([]byte, error)

func (*Socks4Request) UnmarshalBinary

func (req *Socks4Request) UnmarshalBinary(p []byte) error

type Socks4Response

type Socks4Response struct {
	Status Socks4Status
	Addr   string
}

func (*Socks4Response) MarshalBinary

func (resp *Socks4Response) MarshalBinary() ([]byte, error)

func (*Socks4Response) UnmarshalBinary

func (resp *Socks4Response) UnmarshalBinary(p []byte) error

type Socks4Status

type Socks4Status uint8
const (
	Socks4StatusGranted       Socks4Status = 0x5a
	Socks4StatusRejected      Socks4Status = 0x5b
	Socks4StatusNoIdentd      Socks4Status = 0x5c
	Socks4StatusInvalidUserID Socks4Status = 0x5d
)

func (Socks4Status) String added in v0.0.7

func (code Socks4Status) String() string

type Socks5Dialer

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

func NewSocks5Dialer

func NewSocks5Dialer(network, address string, optFns ...func(*Socks5DialerOptions)) *Socks5Dialer

NewSocks5Dialer returns a new Socks5Dialer that dials through the provided proxy server's network and address.

func (*Socks5Dialer) Dial

func (d *Socks5Dialer) Dial(network, addr string) (net.Conn, error)

func (*Socks5Dialer) DialContext

func (d *Socks5Dialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

type Socks5DialerOptions added in v0.0.3

type Socks5DialerOptions struct {
	// Logger specifies an optional logger.
	// If nil, logging is done via the log package's standard logger.
	Logger golog.Logger

	// ProxyDialer specifies the optional dialer for
	// establishing the transport connection.
	ProxyDialer Dialer

	// AuthMethods specifies the list of request authentication
	// methods.
	// If empty, SOCKS client requests only AuthMethodNotRequired.
	AuthMethods []AuthMethod

	// Authenticate specifies the optional authentication
	// function. It must be non-nil when AuthMethods is not empty.
	// It must return an error when the authentication is failed.
	Authenticate AuthenticateFunc
}

type Socks5Request

type Socks5Request struct {
	CMD  Command
	Addr string
}

func (*Socks5Request) MarshalBinary

func (req *Socks5Request) MarshalBinary() ([]byte, error)

func (*Socks5Request) UnmarshalBinary

func (req *Socks5Request) UnmarshalBinary(p []byte) error

type Socks5Response

type Socks5Response struct {
	Status Socks5Status
	Addr   string
}

func (*Socks5Response) MarshalBinary

func (resp *Socks5Response) MarshalBinary() ([]byte, error)

func (*Socks5Response) UnmarshalBinary

func (resp *Socks5Response) UnmarshalBinary(p []byte) error

type Socks5Status

type Socks5Status uint8
const (
	Socks5StatusGranted              Socks5Status = 0x00
	Socks5StatusFailure              Socks5Status = 0x01
	Socks5StatusNotAllowed           Socks5Status = 0x02
	Socks5StatusNetworkUnreaachable  Socks5Status = 0x03
	Socks5StatusHostUnreachable      Socks5Status = 0x04
	Socks5StatusConnectionRefused    Socks5Status = 0x05
	Socks5StatusTTLExpired           Socks5Status = 0x06
	Socks5StatusCMDNotSupported      Socks5Status = 0x07
	Socks5StatusAddrTypeNotSupported Socks5Status = 0x08
)

func (Socks5Status) String added in v0.0.7

func (code Socks5Status) String() string

type UsernamePasswordAuthRequest added in v0.0.4

type UsernamePasswordAuthRequest struct {
	Username string
	Password string
}

func (*UsernamePasswordAuthRequest) MarshalBinary added in v0.0.4

func (req *UsernamePasswordAuthRequest) MarshalBinary() ([]byte, error)

func (*UsernamePasswordAuthRequest) UnmarshalBinary added in v0.0.4

func (req *UsernamePasswordAuthRequest) UnmarshalBinary(p []byte) error

type UsernamePasswordAuthResponse added in v0.0.4

type UsernamePasswordAuthResponse struct {
	Status AuthStatus
}

func (*UsernamePasswordAuthResponse) MarshalBinary added in v0.0.4

func (resp *UsernamePasswordAuthResponse) MarshalBinary() ([]byte, error)

func (*UsernamePasswordAuthResponse) UnmarshalBinary added in v0.0.4

func (resp *UsernamePasswordAuthResponse) UnmarshalBinary(p []byte) error

type UsernamePasswordAuthVersion added in v0.0.4

type UsernamePasswordAuthVersion uint8

type Version

type Version byte
const (
	Socks4Version Version = 0x04
	Socks5Version Version = 0x05
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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