brook

package module
v0.0.0-...-60c1e63 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: GPL-3.0 Imports: 42 Imported by: 0

README

Brook

Build Status Docs Slides Youtube

Brook


v20200901

  • ❗️Breaking change, you should upgrade both server and client
  • New Docs

v20200909


What is Brook

Brook is a cross-platform strong encryption and not detectable proxy.
Brook's goal is to keep it simple, stupid and not detectable.

Install CLI

The CLI file has both server and client functions

Download from releases

# For example, on linux amd64, v20200909

$ curl -L https://github.com/txthinking/brook/releases/download/v20200909/brook_linux_amd64 -o /usr/bin/brook
$ chmod +x /usr/bin/brook

Install via nami

nami install github.com/txthinking/brook
Install GUI

The GUI file has only client function

Download from releases: macOS, Windows, Android, iOS

Install via brew

brew cask install brook

Usage

Docs

NAME:
   Brook - A cross-platform strong encryption and not detectable proxy

USAGE:
   brook [global options] command [command options] [arguments...]

VERSION:
   20200909

AUTHOR:
   Cloud <cloud@txthinking.com>

COMMANDS:
   server        Run as brook server, both TCP and UDP
   servers       Run as multiple brook servers
   client        Run as brook client, both TCP and UDP, to start a socks5 proxy or a http proxy, [src <-> socks5 <-> $ brook client <-> $ brook server <-> dst], [works with $ brook server]
   map           Run as mapping, both TCP and UDP, this means access [from address] is equal to [to address], [src <-> from address <-> $ brook server <-> to address], [works with $ brook server]
   dns           Run as DNS server, both TCP and UDP, [src <-> $ brook dns <-> $ brook server <-> dns server] or [src <-> $ brook dns <-> dns server for bypass], [works with $ brook server]
   tproxy        Run as transparent proxy, both TCP and UDP, only works on Linux, [src <-> $ brook tproxy <-> $ brook server <-> dst], [works with $ brook server]
   wsserver      Run as brook wsserver, both TCP and UDP, it will start a standard http(s) server and websocket server
   wsclient      Run as brook wsclient, both TCP and UDP, to start a socks5 proxy or a http proxy, [src <-> socks5 <-> $ brook wsclient <-> $ brook wsserver <-> dst], [works with $ brook wsserver]
   link          Print brook link
   qr            Print brook server QR code
   relay         Run as standalone relay, both TCP and UDP, this means access [listen address] is equal to access [to address], [src <-> listen address <-> to address]
   relays        Run as multiple standalone relays
   socks5        Run as standalone standard socks5 server, both TCP and UDP
   socks5tohttp  Convert socks5 to http proxy, [src <-> listen address(http proxy) <-> socks5 address <-> dst]
   hijackhttps   Hijack domains and assume is TCP/TLS/443. Requesting these domains from anywhere in the system will be hijacked . [src <-> $ brook hijackhttps <-> socks5 server] or [src <-> direct]
   pac           Run as PAC server or save PAC to file
   howto         Print some useful tutorial resources
   help, h       Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug, -d               Enable debug (default: false)
   --listen value, -l value  Listen address for debug (default: ":6060")
   --help, -h                show help (default: false)
   --version, -v             print the version (default: false)

COPYRIGHT:
   https://github.com/txthinking/brook

Docs

Contributing

Please read CONTRIBUTING.md first

License

Licensed under The GPLv3 License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientPacket func([]byte, []byte) ([]byte, []byte, error) = func(dst, d []byte) ([]byte, []byte, error) {
	if 12+4+len(dst)+len(d)+16 > 65507 {
		return nil, nil, errors.New("packet too big")
	}
	return dst, d, nil
}
View Source
var Debug bool = false
View Source
var ServerPacket func([]byte, []byte) ([]byte, []byte, WriterFunc, error) = func(dst, b []byte) ([]byte, []byte, WriterFunc, error) {
	f := func(f func([]byte) (int, error)) io.Writer {
		return WriteFunc(f)
	}
	return dst, b, f, nil
}
View Source
var StreamClientInit func(*StreamClient) (*StreamClient, error) = func(c *StreamClient) (*StreamClient, error) {
	if c.Timeout != 0 {
		if err := c.Server.SetDeadline(time.Now().Add(time.Duration(c.Timeout) * time.Second)); err != nil {
			c.Clean()
			return nil, err
		}
	}
	return c, nil
}
View Source
var StreamServerInit func(*StreamServer, int) (*StreamServer, []byte, error) = func(s *StreamServer, l int) (*StreamServer, []byte, error) {
	if s.Timeout != 0 {
		if err := s.Client.SetDeadline(time.Now().Add(time.Duration(s.Timeout) * time.Second)); err != nil {
			s.Clean()
			return nil, nil, err
		}
	}
	s.ConnFunc = func(conn net.Conn) net.Conn {
		if s.Timeout != 0 {
			conn.SetDeadline(time.Now().Add(time.Duration(s.Timeout) * time.Second))
		}
		return conn
	}
	return s, s.RB[2+16+4 : 2+16+l], nil
}

Functions

func EnableDebug

func EnableDebug()

EnableDebug.

func ErrorReply

func ErrorReply(r *socks5.Request, c *net.TCPConn, e error) error

func GetAddressFromURL

func GetAddressFromURL(s string) (string, error)
func Link(server, password, username string) string

Link

func NextNonce

func NextNonce(b []byte)

func QR

func QR(server, password, username string)

QR generate and print QR code.

func WaitReadErr

func WaitReadErr(conn net.Conn)

Types

type Client

type Client struct {
	Server        *socks5.Server
	ServerAddress string
	Password      []byte
	TCPTimeout    int
	UDPTimeout    int
}

Client.

func NewClient

func NewClient(addr, ip, server, password string, tcpTimeout, udpTimeout int) (*Client, error)

NewClient returns a new Client.

func (*Client) ListenAndServe

func (x *Client) ListenAndServe() error

ListenAndServe will let client start a socks5 proxy.

func (*Client) Shutdown

func (x *Client) Shutdown() error

Shutdown used to stop the client.

func (*Client) TCPHandle

func (x *Client) TCPHandle(s *socks5.Server, c *net.TCPConn, r *socks5.Request) error

TCPHandle handles tcp request.

func (*Client) UDPHandle

func (x *Client) UDPHandle(s *socks5.Server, addr *net.UDPAddr, d *socks5.Datagram) error

UDPHandle handles udp request.

type DNS

type DNS struct {
	TCPAddr            *net.TCPAddr
	UDPAddr            *net.UDPAddr
	ServerTCPAddr      *net.TCPAddr
	ServerUDPAddr      *net.UDPAddr
	Password           []byte
	BypassDomains      map[string]byte
	DNSServer          string
	DNSServerForBypass string
	TCPListen          *net.TCPListener
	UDPConn            *net.UDPConn
	UDPExchanges       *cache.Cache
	TCPTimeout         int
	UDPTimeout         int
	RunnerGroup        *runnergroup.RunnerGroup
	UDPSrc             *cache.Cache
}

DNS.

func NewDNS

func NewDNS(addr, server, password, dnsServer, dnsServerForBypass, bypassList string, tcpTimeout, udpTimeout int) (*DNS, error)

NewDNS.

func (*DNS) Has

func (s *DNS) Has(host string) bool

func (*DNS) ListenAndServe

func (s *DNS) ListenAndServe() error

Run server.

func (*DNS) RunTCPServer

func (s *DNS) RunTCPServer() error

RunTCPServer starts tcp server.

func (*DNS) RunUDPServer

func (s *DNS) RunUDPServer() error

RunUDPServer starts udp server.

func (*DNS) Shutdown

func (s *DNS) Shutdown() error

Shutdown server.

func (*DNS) TCPHandle

func (s *DNS) TCPHandle(c *net.TCPConn) error

TCPHandle handles request.

func (*DNS) UDPHandle

func (s *DNS) UDPHandle(addr *net.UDPAddr, b []byte) error

UDPHandle handles packet.

type HijackHTTPS

type HijackHTTPS struct {
	Dial               proxy.Dialer
	ListenIP           string
	DNSServerForBypass string
	BypassDomains      map[string]byte
	UDPDNSServer       *dns.Server
	TCPDNSServer       *dns.Server
	HTTPSServer        net.Listener
	TCPTimeout         int
	UDPTimeout         int
	RunnerGroup        *runnergroup.RunnerGroup
}

HijackHTTPS.

func NewHijackHTTPS

func NewHijackHTTPS(socks5addr, socks5username, socks5password, listenIP, dnsForBypass, bypassList string, tcpTimeout, udpTimeout int) (*HijackHTTPS, error)

NewHijackHTTPS.

func (*HijackHTTPS) DNSHandle

func (s *HijackHTTPS) DNSHandle(network string) dns.Handler

func (*HijackHTTPS) HTTPSHandle

func (s *HijackHTTPS) HTTPSHandle(c net.Conn) error

func (*HijackHTTPS) Has

func (s *HijackHTTPS) Has(host string) bool

func (*HijackHTTPS) ListenAndServe

func (s *HijackHTTPS) ListenAndServe() error

Run server.

func (*HijackHTTPS) RunHTTPSServer

func (s *HijackHTTPS) RunHTTPSServer() error

func (*HijackHTTPS) RunTCPDNSServer

func (s *HijackHTTPS) RunTCPDNSServer() error

func (*HijackHTTPS) RunUDPDNSServer

func (s *HijackHTTPS) RunUDPDNSServer() error

func (*HijackHTTPS) Shutdown

func (s *HijackHTTPS) Shutdown() error

type Map

type Map struct {
	TCPAddr       *net.TCPAddr
	UDPAddr       *net.UDPAddr
	RemoteAddress string
	ServerTCPAddr *net.TCPAddr
	ServerUDPAddr *net.UDPAddr
	Password      []byte
	TCPListen     *net.TCPListener
	UDPConn       *net.UDPConn
	UDPExchanges  *cache.Cache
	TCPTimeout    int
	UDPTimeout    int
	RunnerGroup   *runnergroup.RunnerGroup
	UDPSrc        *cache.Cache
}

Map.

func NewMap

func NewMap(from, to, remote, password string, tcpTimeout, udpTimeout int) (*Map, error)

NewMap.

func (*Map) ListenAndServe

func (s *Map) ListenAndServe() error

Run server.

func (*Map) RunTCPServer

func (s *Map) RunTCPServer() error

RunTCPServer starts tcp server.

func (*Map) RunUDPServer

func (s *Map) RunUDPServer() error

RunUDPServer starts udp server.

func (*Map) Shutdown

func (s *Map) Shutdown() error

Shutdown server.

func (*Map) TCPHandle

func (s *Map) TCPHandle(c *net.TCPConn) error

TCPHandle handles request.

func (*Map) UDPHandle

func (s *Map) UDPHandle(addr *net.UDPAddr, b []byte) error

UDPHandle handles packet.

type PAC

type PAC struct {
	Addr string
	File string
	// global/white/black
	Proxy      string
	Mode       string
	DomainURL  string
	CidrURL    string
	DomainData []byte
	CidrData   []byte
	HTTPServer *http.Server
	Body       []byte
}

func NewPAC

func NewPAC(addr, file, proxy, mode, domainURL, cidrURL string) *PAC

func (*PAC) ListenAndServe

func (p *PAC) ListenAndServe() error

func (*PAC) MakeBody

func (p *PAC) MakeBody() (io.Reader, error)

func (*PAC) ServeHTTP

func (p *PAC) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*PAC) Shutdown

func (p *PAC) Shutdown() error

func (*PAC) WriteToFile

func (p *PAC) WriteToFile() error

func (*PAC) WriteToStdout

func (p *PAC) WriteToStdout() error

type PacketClient

type PacketClient struct {
	Server        net.Conn
	Password      []byte
	RB            []byte
	WB            []byte
	Dst           []byte
	Timeout       int
	RemoteAddress net.Addr
}

func NewPacketClient

func NewPacketClient(password []byte) *PacketClient

func (*PacketClient) Clean

func (c *PacketClient) Clean()

func (*PacketClient) LocalToServer

func (c *PacketClient) LocalToServer(dst, d []byte, server net.Conn, timeout int) error

func (*PacketClient) RunServerToLocal

func (c *PacketClient) RunServerToLocal(server net.Conn, timeout int, tolocal func(dst, d []byte) (int, error)) error

func (*PacketClient) ServerToLocal

func (c *PacketClient) ServerToLocal(server net.Conn, timeout int, tolocal func(dst, d []byte) (int, error)) error

type PacketServer

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

func NewPacketServer

func NewPacketServer(password []byte) *PacketServer

func (*PacketServer) Clean

func (s *PacketServer) Clean()

func (*PacketServer) RemoteToClient

func (s *PacketServer) RemoteToClient(remote net.Conn, timeout int, dst []byte, toclient io.Writer) error

type PacketStream

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

func NewPacketStream

func NewPacketStream(w func(d []byte) (int, error)) (*PacketStream, func(b []byte) error)

func (*PacketStream) Close

func (c *PacketStream) Close() error

func (*PacketStream) LocalAddr

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

func (*PacketStream) Read

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

func (*PacketStream) RemoteAddr

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

func (*PacketStream) SetDeadline

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

func (*PacketStream) SetReadDeadline

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

func (*PacketStream) SetWriteDeadline

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

func (*PacketStream) Write

func (c *PacketStream) Write(b []byte) (int, error)

type Relay

type Relay struct {
	TCPAddr       *net.TCPAddr
	UDPAddr       *net.UDPAddr
	RemoteTCPAddr *net.TCPAddr
	RemoteUDPAddr *net.UDPAddr
	TCPListen     *net.TCPListener
	UDPConn       *net.UDPConn
	UDPExchanges  *cache.Cache
	TCPTimeout    int
	UDPTimeout    int
	RunnerGroup   *runnergroup.RunnerGroup
	UDPSrc        *cache.Cache
}

Relay is relay server.

func NewRelay

func NewRelay(addr, remote string, tcpTimeout, udpTimeout int) (*Relay, error)

NewRelay returns a Relay.

func (*Relay) ListenAndServe

func (s *Relay) ListenAndServe() error

Run server.

func (*Relay) RunTCPServer

func (s *Relay) RunTCPServer() error

RunTCPServer starts tcp server.

func (*Relay) RunUDPServer

func (s *Relay) RunUDPServer() error

RunUDPServer starts udp server.

func (*Relay) Shutdown

func (s *Relay) Shutdown() error

Shutdown server.

func (*Relay) TCPHandle

func (s *Relay) TCPHandle(c *net.TCPConn) error

TCPHandle handles request.

func (*Relay) UDPHandle

func (s *Relay) UDPHandle(addr *net.UDPAddr, b []byte) error

UDPHandle handles packet.

type Server

type Server struct {
	Password     []byte
	TCPAddr      *net.TCPAddr
	UDPAddr      *net.UDPAddr
	TCPListen    *net.TCPListener
	UDPConn      *net.UDPConn
	UDPExchanges *cache.Cache
	TCPTimeout   int
	UDPTimeout   int
	RunnerGroup  *runnergroup.RunnerGroup
	UDPSrc       *cache.Cache
}

Server.

func NewServer

func NewServer(addr, password string, tcpTimeout, udpTimeout int) (*Server, error)

NewServer.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

Run server.

func (*Server) RunTCPServer

func (s *Server) RunTCPServer() error

RunTCPServer starts tcp server.

func (*Server) RunUDPServer

func (s *Server) RunUDPServer() error

RunUDPServer starts udp server.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown server.

func (*Server) TCPHandle

func (s *Server) TCPHandle(c *net.TCPConn) error

TCPHandle handles request.

func (*Server) UDPHandle

func (s *Server) UDPHandle(addr *net.UDPAddr, b []byte) error

UDPHandle handles packet.

type Socks5Server

type Socks5Server struct {
	Server *socks5.Server
}

Socks5Server is raw socks5 server.

func NewSocks5Server

func NewSocks5Server(addr, ip, userName, password string, tcpTimeout, udpTimeout int) (*Socks5Server, error)

NewSocks5Server returns a new Socks5Server.

func (*Socks5Server) ListenAndServe

func (x *Socks5Server) ListenAndServe() error

ListenAndServe will let client start to listen and serve.

func (*Socks5Server) Shutdown

func (x *Socks5Server) Shutdown() error

Shutdown used to stop the client.

type Socks5ToHTTP

type Socks5ToHTTP struct {
	Addr           *net.TCPAddr
	Socks5Address  string
	Socks5Username string
	Socks5Password string
	Dial           proxy.Dialer
	TCPTimeout     int
	Listen         *net.TCPListener
}

func NewSocks5ToHTTP

func NewSocks5ToHTTP(addr, socks5addr, socks5username, socks5password string, tcpTimeout int) (*Socks5ToHTTP, error)

func (*Socks5ToHTTP) Handle

func (s *Socks5ToHTTP) Handle(c *net.TCPConn) error

func (*Socks5ToHTTP) ListenAndServe

func (s *Socks5ToHTTP) ListenAndServe() error

func (*Socks5ToHTTP) Shutdown

func (s *Socks5ToHTTP) Shutdown() error

type StreamClient

type StreamClient struct {
	Server net.Conn

	RB            []byte
	WB            []byte
	Timeout       int
	Network       string
	RemoteAddress net.Addr
	Cache         []byte
	// contains filtered or unexported fields
}

func NewStreamClient

func NewStreamClient(network string, password, dst []byte, server net.Conn, timeout int) (*StreamClient, error)

func (*StreamClient) Clean

func (c *StreamClient) Clean()

func (*StreamClient) Exchange

func (c *StreamClient) Exchange(local net.Conn) error

func (*StreamClient) ReadL

func (c *StreamClient) ReadL() (int, error)

func (*StreamClient) WriteL

func (c *StreamClient) WriteL(l int) error

type StreamServer

type StreamServer struct {
	Client net.Conn

	RB       []byte
	WB       []byte
	Timeout  int
	Network  string
	ConnFunc func(net.Conn) net.Conn
	// contains filtered or unexported fields
}

func NewStreamServer

func NewStreamServer(password []byte, client net.Conn, timeout int) (*StreamServer, []byte, error)

func (*StreamServer) Clean

func (s *StreamServer) Clean()

func (*StreamServer) Exchange

func (s *StreamServer) Exchange(remote net.Conn) error

func (*StreamServer) Read

func (s *StreamServer) Read() (int, error)

func (*StreamServer) Write

func (s *StreamServer) Write(l int) error

type Tproxy

type Tproxy struct {
	TCPAddr       *net.TCPAddr
	UDPAddr       *net.UDPAddr
	ServerTCPAddr *net.TCPAddr
	ServerUDPAddr *net.UDPAddr
	Password      []byte
	TCPListen     *net.TCPListener
	UDPConn       *net.UDPConn
	UDPExchanges  *cache.Cache
	UDPSrc        *cache.Cache
	TCPTimeout    int
	UDPTimeout    int
	RunnerGroup   *runnergroup.RunnerGroup
}

Tproxy.

func NewTproxy

func NewTproxy(addr, server, password string, tcpTimeout, udpTimeout int) (*Tproxy, error)

NewTproxy.

func (*Tproxy) ClearAutoScripts

func (s *Tproxy) ClearAutoScripts() error

func (*Tproxy) ListenAndServe

func (s *Tproxy) ListenAndServe() error

Run server.

func (*Tproxy) RunAutoScripts

func (s *Tproxy) RunAutoScripts() error

func (*Tproxy) RunTCPServer

func (s *Tproxy) RunTCPServer() error

RunTCPServer starts tcp server.

func (*Tproxy) RunUDPServer

func (s *Tproxy) RunUDPServer() error

RunUDPServer starts udp server.

func (*Tproxy) Shutdown

func (s *Tproxy) Shutdown() error

Shutdown server.

func (*Tproxy) TCPHandle

func (s *Tproxy) TCPHandle(c *net.TCPConn) error

TCPHandle handles request.

func (*Tproxy) UDPHandle

func (s *Tproxy) UDPHandle(addr, daddr *net.UDPAddr, b []byte) error

type UDPExchange

type UDPExchange struct {
	Conn net.Conn
	Any  interface{}
	Dst  []byte
}

type WSClient

type WSClient struct {
	Server        *socks5.Server
	ServerHost    string
	ServerAddress string
	TLSConfig     *tls.Config
	Password      []byte
	TCPTimeout    int
	UDPTimeout    int
	TCPListen     *net.TCPListener
	Path          string
	UDPExchanges  *cache.Cache
}

WSClient.

func NewWSClient

func NewWSClient(addr, ip, server, password string, tcpTimeout, udpTimeout int) (*WSClient, error)

NewWSClient.

func (*WSClient) DialWebsocket

func (x *WSClient) DialWebsocket(src string) (net.Conn, error)

func (*WSClient) ListenAndServe

func (x *WSClient) ListenAndServe() error

ListenAndServe will let client start a socks5 proxy.

func (*WSClient) Shutdown

func (x *WSClient) Shutdown() error

Shutdown used to stop the client.

func (*WSClient) TCPHandle

func (x *WSClient) TCPHandle(s *socks5.Server, c *net.TCPConn, r *socks5.Request) error

TCPHandle handles tcp request.

func (*WSClient) UDPHandle

func (x *WSClient) UDPHandle(s *socks5.Server, addr *net.UDPAddr, d *socks5.Datagram) error

UDPHandle handles udp request.

type WSServer

type WSServer struct {
	Password    []byte
	Domain      string
	TCPAddr     *net.TCPAddr
	HTTPServer  *http.Server
	HTTPSServer *http.Server
	TCPTimeout  int
	UDPTimeout  int
	Path        string
	UDPSrc      *cache.Cache
}

WSServer.

func NewWSServer

func NewWSServer(addr, password, domain, path string, tcpTimeout, udpTimeout int) (*WSServer, error)

NewWSServer.

func (*WSServer) ListenAndServe

func (s *WSServer) ListenAndServe() error

Run server.

func (*WSServer) ServeHTTP

func (s *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WSServer) Shutdown

func (s *WSServer) Shutdown() error

Shutdown server.

func (*WSServer) TCPHandle

func (s *WSServer) TCPHandle(ss *StreamServer, dst []byte) error

TCPHandle handles request.

func (*WSServer) UDPHandle

func (s *WSServer) UDPHandle(ss *StreamServer, src string, dstb []byte) error

UDPHandle handles packet.

type WriteFunc

type WriteFunc func([]byte) (int, error)

func (WriteFunc) Write

func (f WriteFunc) Write(b []byte) (int, error)

type WriterFunc

type WriterFunc func(func([]byte) (int, error)) io.Writer

func PacketClientToRemote

func PacketClientToRemote(p, b []byte) ([]byte, []byte, WriterFunc, error)

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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