Documentation ¶
Overview ¶
Package socks5 provies socks5 proxy for proxy.Client and proxy.Server.
Supports USER/PASSWORD authentication.
Reference ¶
English: https://www.ietf.org/rfc/rfc1928.txt
中文: https://aber.sh/articles/Socks5/
参考 https://studygolang.com/articles/31404
USER/PASSWORD authentication rfc:
https://datatracker.ietf.org/doc/html/rfc1929
注意,socks5可能同时使用tcp和udp,但是一定会使用到tcp,socks5的network只能设置为tcp或者dual
Off Topic ¶
纵观各种代理协议,vless/vmess/trojan/shadowsocks协议 都借鉴了socks5,有不少类似的地方。 所以 制作代理, 有必要先学习socks5标准。
关于socks4, 它太简单了, 既不支持udp, 也不支持ipv6, 也没有验证功能, 所以本作不予支持
Index ¶
- Constants
- func Client_EstablishUDPAssociate(conn net.Conn) (port int, err error)
- func Client_ReadUDPResponse(udpConn *net.UDPConn, supposedServerAddr *net.UDPAddr) (target netLayer.Addr, data []byte, e error)
- func Client_RequestUDP(udpConn *net.UDPConn, target *netLayer.Addr, data []byte) error
- type Client
- func (c *Client) EstablishUDPChannel(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (netLayer.MsgConn, error)
- func (*Client) GetCreator() proxy.ClientCreator
- func (c *Client) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (result io.ReadWriteCloser, err error)
- func (*Client) Name() string
- type ClientCreator
- type ClientUDPConn
- func (cpc *ClientUDPConn) Associate() (err error)
- func (cpc *ClientUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
- func (cpc *ClientUDPConn) Fullcone() bool
- func (cpc *ClientUDPConn) Read(p []byte) (n int, err error)
- func (cpc *ClientUDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (cpc *ClientUDPConn) ReadMsg() (data []byte, target netLayer.Addr, err error)
- func (cpc *ClientUDPConn) Write(p []byte) (n int, err error)
- func (cpc *ClientUDPConn) WriteMsg(p []byte, addr netLayer.Addr) (err error)
- func (cpc *ClientUDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type Server
- type ServerCreator
- type ServerUDPConn
Constants ¶
const ( AuthNone = 0x00 AuthPassword = 0x02 AuthNoACCEPTABLE = 0xff )
SOCKS auth type
const ( CmdConnect = 0x01 CmdBind = 0x02 CmdUDPAssociate = 0x03 )
SOCKS request commands as defined in RFC 1928 section 4
const ( ATypIP4 = 0x1 ATypDomain = 0x3 ATypIP6 = 0x4 )
SOCKS address types as defined in RFC 1928 section 4
Note: vmess/vless用的是123,而这里用的是134,所以是不一样的。
const Name = "socks5"
const Version5 = 0x05
socks5 version number.
Variables ¶
This section is empty.
Functions ¶
func Client_EstablishUDPAssociate ¶
传入 conn必须非nil,否则panic
Types ¶
type Client ¶
func (*Client) EstablishUDPChannel ¶
func (*Client) GetCreator ¶ added in v1.2.4
func (*Client) GetCreator() proxy.ClientCreator
type ClientCreator ¶ added in v1.2.1
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) MultiTransportLayer ¶ added in v1.2.4
func (ClientCreator) MultiTransportLayer() bool
true
type ClientUDPConn ¶
type ClientUDPConn struct { *net.UDPConn ServerAddr *net.TCPAddr //用于建立 udp associate的 服务器地址 ServerUDPPort_forMe int //socks5服务会为每一个socks5客户端留一个专用的udp端口 WriteUDP_Target *net.UDPAddr // contains filtered or unexported fields }
实现 net.PacketConn , net.Conn 和 netLayer.MsgConn
func (*ClientUDPConn) Associate ¶
func (cpc *ClientUDPConn) Associate() (err error)
func (*ClientUDPConn) CloseConnWithRaddr ¶
func (cpc *ClientUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
func (*ClientUDPConn) Fullcone ¶
func (cpc *ClientUDPConn) Fullcone() bool
func (*ClientUDPConn) ReadMsg ¶ added in v1.2.5
func (cpc *ClientUDPConn) ReadMsg() (data []byte, target netLayer.Addr, err error)
type Server ¶
type Server struct { proxy.Base *utils.MultiUserMap TrustClient bool //如果为true,则每次握手读取客户端响应前, 不设置deadline. 这能减少一些开销, 但要保证客户端确实可信,不是坏蛋。如果客户端无法被信任,比如在公网或者 不止你一个人使用,则一定要为false,否则会被攻击,导致Server卡住, 造成大量悬垂连接。 }
type ServerCreator ¶
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) MultiTransportLayer ¶ added in v1.2.4
func (ServerCreator) MultiTransportLayer() bool
true
func (ServerCreator) NewServer ¶
func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error)
func (ServerCreator) URLToListenConf ¶ added in v1.2.4
func (ServerCreator) URLToListenConf(u *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error)
type ServerUDPConn ¶
用于socks5服务端的 udp连接, 实现 netLayer.MsgConn
func (*ServerUDPConn) CloseConnWithRaddr ¶
func (u *ServerUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
func (*ServerUDPConn) Fullcone ¶
func (u *ServerUDPConn) Fullcone() bool