daze

package module
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 27 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.

Getting Started

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

$ git clone https://github.com/mohanson/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 socks5://127.0.0.1:1080 google.com

Using Daze for Different Platforms

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:

Android

  1. Cross-compile daze for Android: GOOS=android GOARCH=arm64 go build -o daze github.com/mohanson/daze/cmd/daze
  2. Push the compiled file to the phone. You can use adb or create an HTTP server and download daze with wget in termux.
  3. Run daze client -l 127.0.0.1:1080 ... in the termux.
  4. Set the proxy for phone: WLAN -> Settings -> Proxy -> Fill in 127.0.0.1:1080

Chrome

Chrome does not support setting proxies, so a third-party plugin must be used. Proxy SwitchyOmega works very well.

Firefox

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.

Network Model And Concepts

Daze's network model consists of 7 components:

+-------------+        +-------------+        +----------+        +-------------+        +-----------+
| Destination | <----> | Daze server | <----> | Firewall | <----> | Daze client | <----> |    User   |
+-------------+        +------+------+        +----------+        +-------------+        +-----------+
                              |                                          |                     |
                              +------------- Middle Protocol ------------+-- Client Protocol --+
  • Destination: The destination is an internet service provider, for example, google.com.
  • Daze Server: A Daze server is an instance that runs using the command daze server.
  • Firewall: A firewall is a network security system that monitors and controls incoming and outgoing network traffic based on pre-determined security rules.
  • Daze Client: A Daze client is an instance that runs using the command daze client.
  • User: A user is a browser or any other application attempting to access the destination.
  • Middle Protocol: The middle protocol is the communication protocol between the Daze server and Daze client. Data is encrypted and obfuscated to bypass firewalls.
  • Client Protocol: The client protocol is the communication protocol between the Daze client and the user.

Protocols

Client Protocols

The Daze client implements five different proxy protocols in one port. These protocols are HTTP Proxy, HTTPS Tunnel, SOCKS4, SOCKS4a, and SOCKS5.

# HTTP Proxy
$ curl -x http://127.0.0.1:1080    http(s)://google.com
# HTTPS Tunnel
$ curl -x http://127.0.0.1:1080    http(s)://google.com
# SOCKS4
$ curl -x socks4://127.0.0.1:1080  http(s)://google.com
# SOCKS4a
$ curl -x socks4a://127.0.0.1:1080 http(s)://google.com
# SOCKS5
$ curl -x socks5://127.0.0.1:1080  http(s)://google.com

Why can one port support so many protocols? Because it's magic!

Middle Protocols

Daze currently has 4 middle 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.

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).

File rule.ls

Daze uses a "rule.ls" file to customize your own rules(optional). "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.

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.

File 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.

DNS resolver

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. I know many people don't like to read articles, so I just suggest that add -dns 1.1.1.1:853 in daze.

Documentation

Index

Constants

This section is empty.

Variables

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

	RouterLruSize: 64,
}

Conf is acting as package level configuration.

Functions

func Dial added in v1.17.1

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 Hang added in v1.15.8

func Hang()

Hang prevent program from exiting.

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 added in v1.18.2

func LoadReservedIP() []*net.IPNet

LoadReservedIP loads reserved ip addresses.

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

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/mohanson/daze/master/README.md")

func Reno added in v1.17.2

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

Reno is a slow start reconnection algorithm.

func ResolverDns added in v1.19.2

func ResolverDns(addr string) *net.Resolver

ResolverDns returns a DNS resolver.

func ResolverDoh added in v1.19.4

func ResolverDoh(addr string) *net.Resolver

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

func ResolverDot added in v1.19.2

func ResolverDot(addr string) *net.Resolver

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

func Salt added in v1.16.1

func Salt(s string) []byte

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

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 added in v1.18.0

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 added in v1.18.0

type AimbotOption struct {
	Type string
	Rule string
	Cidr string
}

AimbotOption provides configuration for quick initialization of Aimbot.

type Cdoh added in v1.19.4

type Cdoh struct {
	Server string
	Buffer *bytes.Buffer
}

Cdoh structure can be used for DoH protocol processing.

func (Cdoh) Close added in v1.19.4

func (c Cdoh) Close() error

func (Cdoh) LocalAddr added in v1.19.4

func (c Cdoh) LocalAddr() net.Addr

func (Cdoh) Read added in v1.19.4

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

func (Cdoh) RemoteAddr added in v1.19.4

func (c Cdoh) RemoteAddr() net.Addr

func (Cdoh) SetDeadline added in v1.19.4

func (c Cdoh) SetDeadline(t time.Time) error

func (Cdoh) SetReadDeadline added in v1.19.4

func (c Cdoh) SetReadDeadline(t time.Time) error

func (Cdoh) SetWriteDeadline added in v1.19.4

func (c Cdoh) SetWriteDeadline(t time.Time) error

func (Cdoh) Write added in v1.19.4

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

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 Locale

type Locale struct {
	Listen string
	Dialer Dialer
	Closer io.Closer
}

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 added in v1.15.8

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, app 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, app 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, app 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, app 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, app io.ReadWriteCloser, dst string) error

ServeSocks5TCP serves socks5 TCP protocol.

func (*Locale) ServeSocks5UDP

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

ServeSocks5UDP serves socks5 UDP protocol.

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 added in v1.17.1

type RouterChain struct {
	L []Router
}

RouterChain concat multiple routers in series.

func NewRouterChain added in v1.17.1

func NewRouterChain(router ...Router) *RouterChain

NewRouterChain returns a new RouterChain.

func (*RouterChain) Road added in v1.17.1

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 added in v1.18.2

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 added in v1.18.2

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 added in v1.17.1

type Tester struct {
	Listen string
	Closer io.Closer
}

A remote server for testing.

func NewTester added in v1.17.1

func NewTester(listen string) *Tester

NewTester returns a new Tester.

func (*Tester) Close added in v1.17.1

func (t *Tester) Close() error

Close listener.

func (*Tester) TCP added in v1.17.1

func (t *Tester) TCP() error

Run it on TCP.

func (*Tester) TCPServe added in v1.17.1

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

TCPServe serves incoming connections.

func (*Tester) UDP added in v1.17.1

func (t *Tester) UDP() error

Run it on UDP.

func (*Tester) UDPServe added in v1.17.1

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

UDPServe serves incoming connections.

Directories

Path Synopsis
cmd
lib
doa
lru
protocol

Jump to

Keyboard shortcuts

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