daze

package module
v1.25.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: MIT Imports: 29 Imported by: 0

README

Daze

Daze is a software that helps you pass through firewalls, in other words, a proxy. It uses a simple yet efficient protocol, ensuring that you never get detected or blocked.

Introduction

Daze is designed as a single-file application. First, compile or download daze:

$ git clone https://github.com/libraries/daze
$ cd daze

# On Linux or macOS
$ cmd/develop.sh
# On Windows
$ cmd/develop.ps1

The build results will be saved in the bin directory. You can keep this directory, and all other files are not required.

Daze is dead simple to use:

# Server side
# You need a machine that can access the Internet, and enter the following command:
$ daze server -l 0.0.0.0:1081 -k $PASSWORD

# Client side
# Use the following command to link your server(replace $SERVER with your server IP):
$ daze client -s $SERVER:1081 -k $PASSWORD
# Now, you are free to visit the Internet
$ curl -x http://127.0.0.1:1080    http://google.com
$ curl -x http://127.0.0.1:1080    https://google.com
$ curl -x socks4://127.0.0.1:1080  https://google.com
$ curl -x socks4a://127.0.0.1:1080 https://google.com
$ curl -x socks5://127.0.0.1:1080  https://google.com
$ curl -x socks5h://127.0.0.1:1080 https://google.com

Daze is still under development. You should make sure that the server and client have the same version number (check with the daze ver command) or commit hash.

Deployment

Daze is implemented in pure Go language, so it can run on almost any operating system. The following are some of the browsers/operating systems commonly used by me:

  1. Android. Cross-compile daze for android: GOOS=android GOARCH=arm64 go build -o daze github.com/libraries/daze/cmd/daze. Push the compiled file to the phone, You can use adb or create an http server and download daze with wget in termux. Run daze client -l 127.0.0.1:1080 ... in the termux. Set the proxy for phone: WLAN -> Settings -> Proxy -> Fill in 127.0.0.1:1080
  2. Chrome. Chrome does not support setting proxies, so a third-party plugin must be used. Proxy SwitchyOmega works very well.
  3. Firefox can configure a proxy in Connection Settings -> Manual proxy configuration -> SOCKSv5 Host=127.0.0.1 and Port=1080. If you see an option Use remote DNS on the page, check it.

Configuration: Bandwidth Limiter

You can limit the maximum bandwidth used by daze. Generally speaking, for daze server, it is recommended to set the bandwidth to a value slightly smaller than the physical bandwidth.

# For daze server, set -b 320k if your physical bandwidth is 3M, where 320 = 3 * 1024 / 8 - 64.
$ daze server ... -b 320k
# For daze client, in most cases no configuration is necessary.
$ daze client ...

Configuration: DNS

The DNS server and DNS protocol used by daze can be specified through command line parameters.

  • DNS: daze ... -dns 1.1.1.1:53
  • DoT: daze ... -dns 1.1.1.1:853
  • DoH: daze ... -dns https://1.1.1.1/dns-query

This article briefly describes the difference between them.

Configuration: Protocols

Daze currently has 4 protocols.

Ashe

The default protocol used by daze is called ashe. Ashe is a TCP-based cryptographic proxy protocol designed to bypass firewalls while providing a good user experience.

Please note that it is the user's responsibility to ensure that the date and time on both the server and client are consistent. The ashe protocol allows for a deviation of up to two minutes.

Baboon

Protocol baboon is a variant of the ashe protocol that operates over HTTP. In this protocol, the daze server masquerades as an HTTP service and requires the user to provide the correct password in order to gain access to the proxy service. If the password is not provided, the daze server will behave as a normal HTTP service. To use the baboon protocol, you must specify the protocol name and a fake site:

$ daze server ... -p baboon -e https://github.com
$ daze client ... -p baboon

Czar

Protocol czar is an implementation of the ashe protocol based on TCP multiplexing. Multiplexing involves reusing a single TCP connection for multiple ashe protocols, which saves time on the TCP three-way handshake. However, this may result in a slight decrease in data transfer rate (approximately 0.19%). In most cases, using Protocol czar provides a better user experience compared to using the ashe protocol directly.

$ daze server ... -p czar
$ daze client ... -p czar

Dahlia

Dahlia is a protocol used for encrypted port forwarding. Unlike many common port forwarding tools, it requires both a server and a client to be configured. Communication between the server and client is encrypted in order to bypass detection by firewalls.

# Port forwarding from 20002 to 20000:
$ daze server -l :20001 -e 127.0.0.1:20000 -p dahlia
$ daze client -l :20002 -s 127.0.0.1:20001 -p dahlia

Reminder again: Dahlia is not a proxy protocol but a port forwarding protocol.

Configuration: Proxy Control

Proxy control is a rule that determines whether network requests (TCP and UDP) go directly to the destination or are forwarded to the daze server. Use the -f option in the daze client to adjust the proxy configuration.

  • Use local network for all requests.
  • Use remote server for all requests.
  • Use both local and remote server (default). In this case, the following two configuration files are enabled:

rule.ls

Daze uses a "rule.ls" file to customize your own rules. File "rule.ls" has the highest priority in routers so you should carefully maintain it. The "rule.ls" is located on the "rule.ls" by default, or you can use daze client -r path/to/rule.ls to apply it. Its syntax is very simple:

L a.com
R b.com
B c.com
  • L(ocale) means using local network.
  • R(emote) means using proxy.
  • B(anned) means to block it, often used to block ads.

Glob is supported, such as R *.google.com.

rule.cidr

Daze also uses a CIDR(Classless Inter-Domain Routing) file to route addresses. The CIDR file is located at "rule.cidr", and has a lower priority than "rule.ls".

By default, daze has configured rule.cidr for China's mainland. You can update it manually via daze gen cn, this will pull the latest data from http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest.

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Conf = struct {
	DialerTimeout time.Duration
	RouterLruSize int
	Socks5LruSize int
}{
	DialerTimeout: time.Second * 8,

	RouterLruSize: 128,

	Socks5LruSize: 8,
}

Conf is acting as package level configuration.

View Source
var Expv = struct {
	RouterCacheCall *expvar.Int
	RouterCacheHits *expvar.Int
	RouterCacheRate expvar.Func
	RouterIPNetCall *expvar.Int
	RouterIPNetTime *ExpvarAverage
}{
	RouterCacheCall: expvar.NewInt("RouterCache.Call"),
	RouterCacheHits: expvar.NewInt("RouterCache.Hits"),
	RouterCacheRate: NewExpvarPercent("RouterCache.Rate", "RouterCache.Hits", "RouterCache.Call"),
	RouterIPNetCall: expvar.NewInt("RouterIPNet.Call"),
	RouterIPNetTime: NewExpvarAverage("RouterIPNet.Time", 64),
}

Expv is a simple wrapper around the expvars package.

Functions

func Dial

func Dial(network string, address string) (net.Conn, error)

Dial connects to the address on the named network.

func Gravity

func Gravity(conn io.ReadWriteCloser, k []byte) io.ReadWriteCloser

Gravity double, happiness double.

func GravityReader

func GravityReader(r io.Reader, k []byte) io.Reader

GravityReader wraps an io.Reader with RC4 crypto.

func GravityWriter

func GravityWriter(w io.Writer, k []byte) io.Writer

GravityWriter wraps an io.Writer with RC4 crypto.

func Link(a, b io.ReadWriteCloser)

Link copies from src to dst and dst to src until either EOF is reached.

func LoadApnic

func LoadApnic() map[string][]*net.IPNet

LoadApnic loads remote resource. APNIC is the Regional Internet Registry administering IP addresses for the Asia Pacific.

func LoadReservedIP

func LoadReservedIP() []*net.IPNet

LoadReservedIP loads reserved ip addresses.

Introduction: See https://en.wikipedia.org/wiki/Reserved_IP_addresses

func NewExpvarPercent

func NewExpvarPercent(name string, n string, d string) expvar.Func

NewExpvarPercent creates a new expvar.Func that calculates the ratio of two expvar.Int or expvar.Float metrics.

func OpenFile

func OpenFile(name string) (io.ReadCloser, error)

OpenFile select the appropriate method to open the file based on the incoming args automatically.

Examples: OpenFile("/etc/hosts") OpenFile("https://raw.githubusercontent.com/libraries/daze/master/README.md")

func ResolverAny

func ResolverAny(addr string) *net.Resolver

ResolverDot returns a DoT resolver. Depending on the addr entered, the dns, dot or doh protocol will be used automatically.

Dns: 1.1.1.1:53 Dot: 1.1.1.1:853 Doh: https://1.1.1.1/dns-query

func ResolverDns

func ResolverDns(addr string) *net.Resolver

ResolverDns returns a DNS resolver.

func ResolverDoh

func ResolverDoh(addr string) *net.Resolver

ResolverDoh returns a DoH resolver. For further information, see https://datatracker.ietf.org/doc/html/rfc8484.

func ResolverDot

func ResolverDot(addr string) *net.Resolver

ResolverDot returns a DoT resolver. For further information, see https://datatracker.ietf.org/doc/html/rfc7858.

func Salt

func Salt(s string) []byte

Salt converts the stupid password passed in by the user to 32-sized byte array.

func SizeParser

func SizeParser(s string) uint64

SizeParser converts a string like "1K", "1M", or "1G" to bytes as uint64. It expects the input string to end with a unit (K, M, or G) and panics if the unit is invalid. The number part can be a float (e.g., "1.5M") and is converted to bytes based on the unit.

Types

type Aimbot

type Aimbot struct {
	Remote Dialer
	Locale Dialer
	Router Router
}

Aimbot automatically distinguish whether to use a proxy or a local network.

func NewAimbot

func NewAimbot(client Dialer, option *AimbotOption) *Aimbot

NewAimbot returns a new Aimbot.

func (*Aimbot) Dial

func (s *Aimbot) Dial(ctx *Context, network string, address string) (io.ReadWriteCloser, error)

Dial connects to the address on the named network.

type AimbotOption

type AimbotOption struct {
	Type string
	Rule string
	Cidr string
}

AimbotOption provides configuration for quick initialization of Aimbot.

type Context

type Context struct {
	Cid uint32
}

Context carries infomations for a tcp connection.

type Dialer

type Dialer interface {
	Dial(ctx *Context, network string, address string) (io.ReadWriteCloser, error)
}

Dialer abstracts the way to establish network connections.

type Direct

type Direct struct{}

Direct is the default dialer for connecting to an address.

func (*Direct) Dial

func (d *Direct) Dial(ctx *Context, network string, address string) (io.ReadWriteCloser, error)

Dial implements daze.Dialer.

type ExpvarAverage

type ExpvarAverage struct {
	F *expvar.Float
	L float64
}

ExpvarAverage is a structure to maintain a running average using expvar.Float.

func NewExpvarAverage

func NewExpvarAverage(name string, length int) *ExpvarAverage

NewExpvarAverage creates and initializes a new ExpvarAverage instance.

func (*ExpvarAverage) Add

func (e *ExpvarAverage) Add(value float64)

Adds a new value to the running average. This is not strictly concurrency-safe, but it won't have much impact on the data.

type Locale

type Locale struct {
	Closer io.Closer
	Dialer Dialer
	Limits *rate.Limits
	Listen string
}

Locale is the main process of daze. In most cases, it is usually deployed as a daemon on a local machine.

func NewLocale

func NewLocale(listen string, dialer Dialer) *Locale

NewLocale returns a Locale.

func (*Locale) Close

func (l *Locale) Close() error

Close listener.

func (*Locale) Run

func (l *Locale) Run() error

Run it.

func (*Locale) Serve

func (l *Locale) Serve(ctx *Context, cli io.ReadWriteCloser) error

Serve serves incoming connections and handle it with a different handler(ServeProxy/ServeSocks4/ServeSocks5).

func (*Locale) ServeProxy

func (l *Locale) ServeProxy(ctx *Context, cli io.ReadWriteCloser) error

ServeProxy serves traffic in HTTP Proxy/Tunnel format.

Introduction: See https://en.wikipedia.org/wiki/Proxy_server See https://en.wikipedia.org/wiki/HTTP_tunnel See https://www.infoq.com/articles/Web-Sockets-Proxy-Servers/

func (*Locale) ServeSocks4

func (l *Locale) ServeSocks4(ctx *Context, cli io.ReadWriteCloser) error

ServeSocks4 serves traffic in SOCKS4/SOCKS4a format.

Introduction: See https://en.wikipedia.org/wiki/SOCKS See http://ftp.icm.edu.pl/packages/socks/socks4/SOCKS4.protocol

func (*Locale) ServeSocks5

func (l *Locale) ServeSocks5(ctx *Context, cli io.ReadWriteCloser) error

ServeSocks5 serves traffic in SOCKS5 format.

Introduction: See https://en.wikipedia.org/wiki/SOCKS See https://tools.ietf.org/html/rfc1928

func (*Locale) ServeSocks5TCP

func (l *Locale) ServeSocks5TCP(ctx *Context, cli io.ReadWriteCloser, dst string) error

ServeSocks5TCP serves socks5 TCP protocol.

func (*Locale) ServeSocks5UDP

func (l *Locale) ServeSocks5UDP(ctx *Context, cli io.ReadWriteCloser) error

ServeSocks5UDP serves socks5 UDP protocol.

func (*Locale) ServeSocks5UDPRead

func (l *Locale) ServeSocks5UDPRead(srv io.Reader, bnd *net.UDPConn, app *net.UDPAddr, pre []byte) error

ServeSocks5UDPRead handles the reading and forwarding of udp data.

type RandomReader

type RandomReader struct{}

RandomReader is a simple random number generator. Note that it is not cryptographically secure, but for daze, the randomness it provides is enough.

func (*RandomReader) Read

func (r *RandomReader) Read(p []byte) (int, error)

Read implements io.Reader.

type ReadWriteCloser

type ReadWriteCloser struct {
	io.Reader
	io.Writer
	io.Closer
}

ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.

type Road

type Road uint32

A Road represents a host's road mode.

const (
	// RoadLocale means it don't need a proxy
	RoadLocale Road = iota
	// RoadRemote means it should accessed through proxy
	RoadRemote
	// RoadFucked means it is pure rubbish
	RoadFucked
	// RoadPuzzle means ?
	RoadPuzzle
)

func (Road) String

func (r Road) String() string

type Router

type Router interface {
	// The host must be a literal IP address, or a host name that can be resolved to IP addresses.
	// Examples:
	//   Road("golang.org")
	//   Road("192.0.2.1")
	Road(ctx *Context, host string) Road
}

Router is a selector that will judge the host address.

type RouterCache

type RouterCache struct {
	Lru *lru.Lru[string, Road]
	Raw Router
}

RouterCache cache routing results for next use.

func NewRouterCache

func NewRouterCache(r Router) *RouterCache

NewRouterCache returns a new Cache object.

func (*RouterCache) Road

func (r *RouterCache) Road(ctx *Context, host string) Road

Road implements daze.Router.

type RouterChain

type RouterChain struct {
	L []Router
}

RouterChain concat multiple routers in series.

func NewRouterChain

func NewRouterChain(router ...Router) *RouterChain

NewRouterChain returns a new RouterChain.

func (*RouterChain) Road

func (r *RouterChain) Road(ctx *Context, host string) Road

Road implements daze.Router.

type RouterIPNet

type RouterIPNet struct {
	L []*net.IPNet
	R []*net.IPNet
	B []*net.IPNet
}

RouterIPNet is a router by IPNets. It judges whether an IP or domain name is within its range.

func NewRouterIPNet

func NewRouterIPNet() *RouterIPNet

NewRouterIPNet returns a new RouterIPNet object.

func (*RouterIPNet) FromFile

func (r *RouterIPNet) FromFile(name string)

FromFile loads a CIDR file.

func (*RouterIPNet) Road

func (r *RouterIPNet) Road(ctx *Context, host string) Road

Road implements daze.Router.

type RouterRight

type RouterRight struct {
	R Road
}

RouterRight always returns the same road.

func NewRouterRight

func NewRouterRight(road Road) *RouterRight

NewRouterRight returns a new RouterRight.

func (*RouterRight) Road

func (r *RouterRight) Road(ctx *Context, host string) Road

Road implements daze.Router.

type RouterRules

type RouterRules struct {
	L []string
	R []string
	B []string
}

RouterRules aims to be a minimal configuration file format that's easy to read due to obvious semantics. There are two parts per line on the RULE file: mode and glob. mode is on the left of the space sign and glob is on the right. mode is a character that describes whether the host should be accessed through a proxy, and the glob is a glob-style string.

Glob patterns: * h?llo matches hello, hallo and hxllo * h*llo matches hllo and heeeello * h[ae]llo matches hello and hallo, but not hillo * h[^e]llo matches hallo, hbllo, ... but not hello * h[a-b]llo matches hallo and hbllo

This is a normal RULE document: L a.com a.a.com R b.com *.b.com B c.com

L(ocale) means using locale network R(emote) means using remote network B(anned) means to block it

func NewRouterRules

func NewRouterRules() *RouterRules

NewRouterRules returns a new RoaderRules.

func (*RouterRules) FromFile

func (r *RouterRules) FromFile(name string)

FromFile loads a RULE file.

func (*RouterRules) Road

func (r *RouterRules) Road(ctx *Context, host string) Road

Road implements daze.Router.

type Tester

type Tester struct {
	Listen string
	Closer io.Closer
}

A remote server for testing.

func NewTester

func NewTester(listen string) *Tester

NewTester returns a new Tester.

func (*Tester) Close

func (t *Tester) Close() error

Close listener.

func (*Tester) TCP

func (t *Tester) TCP() error

Run it on TCP.

func (*Tester) TCPServe

func (t *Tester) TCPServe(cli io.ReadWriteCloser)

TCPServe serves incoming connections.

func (*Tester) UDP

func (t *Tester) UDP() error

Run it on UDP.

func (*Tester) UDPServe

func (t *Tester) UDPServe(cli *net.UDPConn) error

UDPServe serves incoming connections.

type WireConn

type WireConn struct {
	Call func(b []byte) ([]byte, error)
	Data *bytes.Buffer
}

WireConn structure can be used for DoH protocol processing.

func (*WireConn) Close

func (c *WireConn) Close() error

func (*WireConn) LocalAddr

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

func (*WireConn) Read

func (c *WireConn) Read(b []byte) (n int, err error)

func (*WireConn) RemoteAddr

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

func (*WireConn) SetDeadline

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

func (*WireConn) SetReadDeadline

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

func (*WireConn) SetWriteDeadline

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

func (*WireConn) Write

func (c *WireConn) Write(b []byte) (n int, err error)

Directories

Path Synopsis
cmd
daze command
lib
doa
Package doa stands for "dead or alive".
Package doa stands for "dead or alive".
gracefulexit
Package gracefulexit provides a method to exit the program gracefully.
Package gracefulexit provides a method to exit the program gracefully.
lru
Package lru implements an LRU cache.
Package lru implements an LRU cache.
pretty
Package pretty provides utilities for beautifying console output.
Package pretty provides utilities for beautifying console output.
pretty/cmd/tree command
priority
Package priority implements a priority mutex.
Package priority implements a priority mutex.
rate
Package rate provides a rate limiter.
Package rate provides a rate limiter.
rate/cmd/race command
protocol

Jump to

Keyboard shortcuts

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