socks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoAuth means no authentication is used when connecting
	NoAuth = uint8(0)

	// UserPassAuth means a user/password is used when connecting
	UserPassAuth = uint8(2)
)

Variables

This section is empty.

Functions

func StreamHandler

func StreamHandler(tunnelConn io.ReadWriter, originConn net.Conn, log *zerolog.Logger)

func StreamNetHandler

func StreamNetHandler(tunnelConn io.ReadWriter, accessPolicy *ipaccess.Policy, log *zerolog.Logger)

Types

type AddrSpec

type AddrSpec struct {
	FQDN string
	IP   net.IP
	Port int
}

AddrSpec is used to return the target IPv4, IPv6, or a FQDN

func (AddrSpec) Address

func (a AddrSpec) Address() string

Address returns a string suitable to dial; prefer returning IP-based address, fallback to FQDN

func (*AddrSpec) String

func (a *AddrSpec) String() string

String gives a host version of the Address

type AuthHandler

type AuthHandler interface {
	Handle(io.Reader, io.Writer) error
	Register(uint8, Authenticator)
}

AuthHandler handles socks authentication requests

func NewAuthHandler

func NewAuthHandler() AuthHandler

NewAuthHandler creates a default auth handler

type Authenticator

type Authenticator interface {
	Handle(io.Reader, io.Writer) error
}

Authenticator is the connection passed in as a reader/writer to support different authentication types

func NewNoAuthAuthenticator

func NewNoAuthAuthenticator() Authenticator

NewNoAuthAuthenticator creates a authless Authenticator

func NewUserPassAuthAuthenticator

func NewUserPassAuthAuthenticator(isValid func(string, string) bool) Authenticator

NewUserPassAuthAuthenticator creates a new username/password validator Authenticator

type ConnDialer

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

ConnDialer is like NetDialer but with an existing TCP dialer already created

func (*ConnDialer) Dial

func (d *ConnDialer) Dial(address string) (io.ReadWriteCloser, *AddrSpec, error)

Dial is a TCP dialer but already created

type ConnectionHandler

type ConnectionHandler interface {
	Serve(io.ReadWriter) error
}

ConnectionHandler is the Serve method to handle connections from a local TCP listener of the standard library (net.Listener)

func NewConnectionHandler

func NewConnectionHandler(requestHandler RequestHandler) ConnectionHandler

NewConnectionHandler creates a standard SOCKS5 connection handler This process connections from a generic TCP listener from the standard library

type Dialer

type Dialer interface {
	Dial(string) (io.ReadWriteCloser, *AddrSpec, error)
}

Dialer is used to provided the transport of the proxy

func NewConnDialer

func NewConnDialer(conn net.Conn) Dialer

NewConnDialer creates a new dialer with a already created net.conn (TCP expected)

func NewNetDialer

func NewNetDialer() Dialer

NewNetDialer creates a new dialer

type NetDialer

type NetDialer struct {
}

NetDialer is a standard TCP dialer

func (*NetDialer) Dial

func (d *NetDialer) Dial(address string) (io.ReadWriteCloser, *AddrSpec, error)

Dial is a base TCP dialer

type NoAuthAuthenticator

type NoAuthAuthenticator struct{}

NoAuthAuthenticator is used to handle the No Authentication mode

func (*NoAuthAuthenticator) Handle

func (a *NoAuthAuthenticator) Handle(reader io.Reader, writer io.Writer) error

Handle writes back the version and NoAuth

type Request

type Request struct {
	// Protocol version
	Version uint8
	// Requested command
	Command uint8
	// AddrSpec of the destination
	DestAddr *AddrSpec
	// contains filtered or unexported fields
}

Request is a SOCKS5 command with supporting field of the connection

func NewRequest

func NewRequest(bufConn io.Reader) (*Request, error)

NewRequest creates a new request from the connection data stream

type RequestHandler

type RequestHandler interface {
	Handle(*Request, io.ReadWriter) error
}

RequestHandler is the functions needed to handle a SOCKS5 command

func NewRequestHandler

func NewRequestHandler(dialer Dialer, accessPolicy *ipaccess.Policy) RequestHandler

NewRequestHandler creates a standard SOCKS5 request handler This handles the SOCKS5 commands and proxies them to their destination

type StandardAuthHandler

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

StandardAuthHandler loads the default authenticators

func (*StandardAuthHandler) Handle

func (h *StandardAuthHandler) Handle(bufConn io.Reader, conn io.Writer) error

Handle gets the methods from the SOCKS5 client and authenticates with the first supported method

func (*StandardAuthHandler) Register

func (h *StandardAuthHandler) Register(method uint8, a Authenticator)

Register adds/replaces an Authenticator to use when handling Authentication requests

type StandardConnectionHandler

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

StandardConnectionHandler is the base implementation of handling SOCKS5 requests

func (*StandardConnectionHandler) Serve

Serve process new connection created after calling `Accept()` in the standard library

type StandardRequestHandler

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

StandardRequestHandler implements the base socks5 command processing

func (*StandardRequestHandler) Handle

func (h *StandardRequestHandler) Handle(req *Request, conn io.ReadWriter) error

Handle processes and responds to socks5 commands

type UserPassAuthAuthenticator

type UserPassAuthAuthenticator struct {
	IsValid func(string, string) bool
}

UserPassAuthAuthenticator is used to handle the user/password mode

func (*UserPassAuthAuthenticator) Handle

func (a *UserPassAuthAuthenticator) Handle(reader io.Reader, writer io.Writer) error

Handle writes back the version and NoAuth

Jump to

Keyboard shortcuts

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