项目作者: shadowsocks

项目描述 :
A Rust port of shadowsocks
高级语言: Rust
项目地址: git://github.com/shadowsocks/shadowsocks-rust.git
创建时间: 2014-10-15T11:02:36Z
项目社区:https://github.com/shadowsocks/shadowsocks-rust

开源协议:MIT License

下载


shadowsocks

License
Build & Test
Build MSRV
Build Releases
Build Nightly Releases
Gurubase

crates.io
Release
shadowsocks-rust
aur shadowsocks-rust-git
NixOS
snap shadowsocks-rust
homebrew shadowsocks-rust
MacPorts shadowsocks-rust

This is a port of shadowsocks.

shadowsocks is a fast tunnel proxy that helps you bypass firewalls.

Library Description
shadowsocks crates.io docs.rs shadowsocks core protocol
shadowsocks-service crates.io docs.rs Services for serving shadowsocks
shadowsocks-rust crates.io Binaries running common shadowsocks services

Related Projects:

Build & Install

Optional Features

  • hickory-dns - Uses hickory-resolver as DNS resolver instead of tokio‘s builtin.

  • local-http - Allow using HTTP protocol for sslocal

    • local-http-native-tls - Support HTTPS with native-tls

    • local-http-rustls - Support HTTPS with rustls

  • local-tunnel - Allow using tunnel protocol for sslocal

  • local-socks4 - Allow using SOCKS4/4a protocol for sslocal

  • local-redir - Allow using redir (transparent proxy) protocol for sslocal

  • local-dns - Allow using dns protocol for sslocal, serves as a DNS server proxying queries to local or remote DNS servers by ACL rules

  • local-fake-dns - FakeDNS, allocating an IP address for each individual Query from a specific IP pool

  • local-tun - TUN interface support for sslocal

  • local-online-config - SIP008 Online Configuration Delivery

  • stream-cipher - Enable deprecated stream ciphers. WARN: stream ciphers are UNSAFE!

  • aead-cipher-extra - Enable non-standard AEAD ciphers

  • aead-cipher-2022 - Enable AEAD-2022 ciphers (SIP022)

  • aead-cipher-2022-extra - Enable AEAD-2022 extra ciphers (non-standard ciphers)

Memory Allocators

This project uses system (libc) memory allocator (Rust’s default). But it also allows you to use other famous allocators by features:

  • jemalloc - Uses jemalloc as global memory allocator
  • mimalloc - Uses mi-malloc as global memory allocator
  • tcmalloc - Uses TCMalloc as global memory allocator. It tries to link system-wide tcmalloc by default, use vendored from source with tcmalloc-vendored.
  • snmalloc - Uses snmalloc as global memory allocator
  • rpmalloc - Uses rpmalloc as global memory allocator

crates.io

Install from crates.io:

  1. # Install from crates.io
  2. cargo install shadowsocks-rust

then you can find sslocal and ssserver in $CARGO_HOME/bin.

Install using Homebrew

For macOS and Linux, you can install it using Homebrew:

  1. brew install shadowsocks-rust

Install using snap

  1. # Install from snapstore
  2. snap install shadowsocks-rust
  3. # List services
  4. snap services shadowsocks-rust
  5. # Enable and start shadowsocks-rust.sslocal-daemon snap service
  6. snap start --enable shadowsocks-rust.sslocal-daemon
  7. # Show generated systemd service status
  8. systemctl status snap.shadowsocks-rust.sslocal-daemon.service
  9. # Override generated systemd service (configure startup options)
  10. systemctl edit snap.shadowsocks-rust.sslocal-daemon.service
  11. ## NOTE: you can pass args to sslocal:
  12. ## [Service]
  13. ## ExecStart=
  14. ## ExecStart=/usr/bin/snap run shadowsocks-rust.sslocal-daemon -b "127.0.0.1:1080" --server-url "ss://...."
  15. # Restart generated systemd service to apply changes
  16. systemctl restart snap.shadowsocks-rust.sslocal-daemon.service
  17. # ... and show service status
  18. systemctl status snap.shadowsocks-rust.sslocal-daemon.service

Default configuration file path probably is /var/snap/shadowsocks-rust/common/etc/shadowsocks-rust/config.json.

Download release

Download static-linked build here.

  • Most of them are built with cross. Build environment details could be found in its README, such as glibc’s version.
  • x86_64-apple-darwin, aarch64-apple-darwin are built in github’s macos-latest image. Information could be found in here.
  • x86_64-pc-windows-msvc is built in github’s windows-latest image. Information could be found in here.

Docker

This project provided Docker images for the linux/i386 and linux/amd64 and linux/arm64/v8 architectures.

:warning: Docker containers do not have access to IPv6 by default: Make sure to disable IPv6 Route in the client or enable IPv6 access to docker containers.

Pull from GitHub Container Registry

Docker will pull the image of the appropriate architecture from our GitHub Packages.

  1. docker pull ghcr.io/shadowsocks/sslocal-rust:latest
  2. docker pull ghcr.io/shadowsocks/ssserver-rust:latest

Build on the local machine(Optional)

If you want to build the Docker image yourself, you need to use the BuildX.

  1. docker buildx build -t shadowsocks/ssserver-rust:latest -t shadowsocks/ssserver-rust:v1.15.2 --target ssserver .
  2. docker buildx build -t shadowsocks/sslocal-rust:latest -t shadowsocks/sslocal-rust:v1.15.2 --target sslocal .

Run the container

You need to mount the configuration file into the container and create an external port map for the container to connect to it.

  1. docker run --name sslocal-rust \
  2. --restart always \
  3. -p 1080:1080/tcp \
  4. -v /path/to/config.json:/etc/shadowsocks-rust/config.json \
  5. -dit ghcr.io/shadowsocks/sslocal-rust:latest
  6. docker run --name ssserver-rust \
  7. --restart always \
  8. -p 8388:8388/tcp \
  9. -p 8388:8388/udp \
  10. -v /path/to/config.json:/etc/shadowsocks-rust/config.json \
  11. -dit ghcr.io/shadowsocks/ssserver-rust:latest

Deploy to Kubernetes

This project provided yaml manifests for deploying to Kubernetes.

You can leverage k8s Service to expose traffic outside, like LoadBalancer or NodePort which gains more fine-grained compared with fixed host or port.

For a more interesting use case, you can use a Ingress(Istio, nginx, etc.) which routes the matched traffic to shadowsocks along with the real web service.

Using kubectl

kubectl apply -f https://github.com/shadowsocks/shadowsocks-rust/raw/master/k8s/shadowsocks-rust.yaml

You can change the config via editing the ConfigMap named shadowsocks-rust.

For more fine-grained control, use helm.

Using helm

helm install my-release k8s/chart -f my-values.yaml

Below is the common default values you can change:

  1. # This is the shadowsocks config which will be mount to /etc/shadowocks-rust.
  2. # You can put arbitrary yaml here, and it will be translated to json before mounting.
  3. servers:
  4. - server: "::"
  5. server_port: 8388
  6. service_port: 80 # the k8s service port, default to server_port
  7. password: mypassword
  8. method: aes-256-gcm
  9. fast_open: true
  10. mode: tcp_and_udp
  11. # plugin: v2ray-plugin
  12. # plugin_opts: server;tls;host=github.com
  13. # Whether to download v2ray and xray plugin.
  14. downloadPlugins: false
  15. # Name of the ConfigMap with config.json configuration for shadowsocks-rust.
  16. configMapName: ""
  17. service:
  18. # Change to LoadBalancer if you are behind a cloud provider like aws, gce, or tke.
  19. type: ClusterIP
  20. # Bind shadowsocks port port to host, i.e., we can use host:port to access shawdowsocks server.
  21. hostPort: false
  22. replicaCount: 1
  23. image:
  24. repository: ghcr.io/shadowsocks/ssserver-rust
  25. pullPolicy: IfNotPresent
  26. # Overrides the image tag whose default is the chart appVersion.
  27. tag: "latest"

Build from source

Use cargo to build. NOTE: RAM >= 2GiB

  1. cargo build --release

Then sslocal and ssserver will appear in ./target/(debug|release)/, it works similarly as the two binaries in the official ShadowSocks’ implementation.

  1. make install TARGET=release

Then sslocal, ssserver, ssmanager and ssurl will be installed to /usr/local/bin (variable PREFIX).

For Windows users, if you have encountered any problem in building, check and discuss in #102.

target-cpu optimization

If you are building for your current CPU platform (for example, build and run on your personal computer), it is recommended to set target-cpu=native feature to let rustc generate and optimize code for the CPU running the compiler.

  1. export RUSTFLAGS="-C target-cpu=native"

Build standalone binaries

Requirements:

  • Docker
  1. ./build/build-release

Then sslocal, ssserver, ssmanager, ssservice and ssurl will be packaged in

  • ./build/shadowsocks-${VERSION}-stable.x86_64-unknown-linux-musl.tar.xz
  • ./build/shadowsocks-${VERSION}-stable.x86_64-pc-windows-gnu.zip

Read Cargo.toml for more details.

For Linux with low GLIBC versions, set CROSS_CONFIG to CentOS based image:

  1. export CROSS_CONFIG=Cross-centos.toml

Getting Started

Generate a safe and secured password for a specific encryption method (aes-128-gcm in the example) with:

  1. ssservice genkey -m "aes-128-gcm"

Create a ShadowSocks’ configuration file. Example

  1. {
  2. "server": "my_server_ip",
  3. "server_port": 8388,
  4. "password": "rwQc8qPXVsRpGx3uW+Y3Lj4Y42yF9Bs0xg1pmx8/+bo=",
  5. "method": "aes-256-gcm",
  6. // ONLY FOR `sslocal`
  7. // Delete these lines if you are running `ssserver` or `ssmanager`
  8. "local_address": "127.0.0.1",
  9. "local_port": 1080
  10. }

Detailed explanation of the configuration file could be found in shadowsocks’ documentation. (Link to original project, not maintained anymore !)

:warning: For snap installations, configuration file is most probably located in /var/snap/shadowsocks-rust/common/etc/shadowsocks-rust/config.json (see https://github.com/shadowsocks/shadowsocks-rust/issues/621 / https://github.com/shadowsocks/shadowsocks-rust/issues/1146)

In shadowsocks-rust, we also have an extended configuration file format, which is able to define more than one server. You can also disable individual servers.

  1. {
  2. "servers": [
  3. {
  4. "server": "127.0.0.1",
  5. "server_port": 8388,
  6. "password": "rwQc8qPXVsRpGx3uW+Y3Lj4Y42yF9Bs0xg1pmx8/+bo=",
  7. "method": "aes-256-gcm",
  8. "timeout": 7200
  9. },
  10. {
  11. "server": "127.0.0.1",
  12. "server_port": 8389,
  13. "password": "/dliNXn5V4jg6vBW4MnC1I8Jljg9x7vSihmk6UZpRBM=",
  14. "method": "chacha20-ietf-poly1305"
  15. },
  16. {
  17. "disabled": true,
  18. "server": "eg.disable.me",
  19. "server_port": 8390,
  20. "password": "mGvbWWay8ueP9IHnV5F1uWGN2BRToiVCAWJmWOTLU24=",
  21. "method": "chacha20-ietf-poly1305"
  22. }
  23. ],
  24. // ONLY FOR `sslocal`
  25. // Delete these lines if you are running `ssserver` or `ssmanager`
  26. "local_port": 1080,
  27. "local_address": "127.0.0.1"
  28. }

sslocal automatically selects the best server with the lowest latency and the highest availability.

Start Shadowsocks client and server with:

  1. sslocal -c config.json
  2. ssserver -c config.json

If you Build it with Cargo:

  1. cargo run --bin sslocal -- -c config.json
  2. cargo run --bin ssserver -- -c config.json

List all available arguments with -h.

Usage

Start local client with configuration file

  1. # Read local client configuration from file
  2. sslocal -c /path/to/shadowsocks.json

Socks5 Local client

  1. # Pass all parameters via command line
  2. sslocal -b "127.0.0.1:1080" -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "v2ray-plugin" --plugin-opts "server;tls;host=github.com"
  3. # Pass server with SIP002 URL
  4. sslocal -b "127.0.0.1:1080" --server-url "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ@127.0.0.1:8388/?plugin=v2ray-plugin%3Bserver%3Btls%3Bhost%3Dgithub.com"

HTTP Local client

  1. sslocal -b "127.0.0.1:3128" --protocol http -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty"

All parameters are the same as Socks5 client, except --protocol http.

Tunnel Local client

  1. # Set 127.0.0.1:8080 as the target for forwarding to
  2. sslocal --protocol tunnel -b "127.0.0.1:3128" -f "127.0.0.1:8080" -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty"
  • --protocol tunnel enables local client Tunnel mode
  • -f "127.0.0.1:8080 sets the tunnel target address

Transparent Proxy Local client

NOTE: It currently only supports

  • Linux (with iptables targets REDIRECT and TPROXY)
  • BSDs (with pf), such as OS X 10.10+, FreeBSD, …
  1. sslocal -b "127.0.0.1:60080" --protocol redir -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --tcp-redir "redirect" --udp-redir "tproxy"

Redirects connections with iptables configurations to the port that sslocal is listening on.

  • --protocol redir enables local client Redir mode
  • (optional) --tcp-redir sets TCP mode to REDIRECT (Linux)
  • (optional) --udp-redir sets UDP mode to TPROXY (Linux)

Tun interface client

NOTE: It currently only supports

  • Linux, Android
  • macOS, iOS
  • Windows

Linux

Create a Tun interface with name tun0

  1. ip tuntap add mode tun tun0
  2. ifconfig tun0 inet 10.255.0.1 netmask 255.255.255.0 up

Start sslocal with --protocol tun and binds to tun0

  1. sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface lo0 --tun-interface-name tun0

macOS

  1. sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface lo0 --tun-interface-address 10.255.0.1/24

It will create a Tun interface with address 10.255.0.1 and netmask 255.255.255.0.

Windows

Download wintun.dll from Wintun, and place it in the folder with shadowsocks’ runnable binaries, or in the system PATH.

  1. sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface "Ethernet 0" --tun-interface-name "shadowsocks"

Local client for Windows Service

Compile it by enabling --features "winservice" (not included in the default build):

  1. cargo build --release --bin "sswinservice" --features "winservice"

Install it as a Windows Service (PowerShell):

  1. New-Service -Name "shadowsocks-local-service" `
  2. -DisplayName "Shadowsocks Local Service" `
  3. -BinaryPathName "<Path\to>\sswinservice.exe local -c <Path\to>\local_config.json"

There are other ways to install sswinservice as a Windows Service, for example, the sc command.

As you may have noticed that the -BinaryPathName contains not only just the sswinservice.exe, but local -c local_config.json. These command line parameters will be used as the default parameter when the Windows Service starts. You can also start the service with customized parameters.

Learn more from Microsoft’s Document.

The sswinservice‘s parameter works exactly the same as ssservice. It supports local, server and manager subcommands.

Server

  1. # Read server configuration from file
  2. ssserver -c /path/to/shadowsocks.json
  3. # Pass all parameters via command line
  4. ssserver -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "v2ray-plugin" --plugin-opts "server;tls;host=github.com"

Server Manager

Supported Manage Multiple Users API:

  • add - Starts a server instance
  • remove - Deletes an existing server instance
  • list - Lists all current running servers
  • ping - Lists all servers’ statistic data

NOTE: stat command is not supported. Because servers are running in the same process with the manager itself.

  1. # Start it just with --manager-address command line parameter
  2. ssmanager --manager-address "127.0.0.1:6100"
  3. # For *nix system, manager can bind to unix socket address
  4. ssmanager --manager-address "/tmp/shadowsocks-manager.sock"
  5. # You can also provide a configuration file
  6. #
  7. # `manager_address` key must be provided in the configuration file
  8. ssmanager -c /path/to/shadowsocks.json
  9. # Create one server by UDP
  10. echo 'add: {"server_port":8388,"password":"hello-kitty"}' | nc -u '127.0.0.1' '6100'
  11. # Close one server by unix socket
  12. echo 'remove: {"server_port":8388}' | nc -Uu '/tmp/shadowsocks-manager.sock'

For manager UI, check more details in the shadowsocks-manager project.

Example configuration:

  1. {
  2. // Required option
  3. // Address that ssmanager is listening on
  4. "manager_address": "127.0.0.1",
  5. "manager_port": 6100,
  6. // Or bind to a Unix Domain Socket
  7. "manager_address": "/tmp/shadowsocks-manager.sock",
  8. "servers": [
  9. // These servers will be started automatically when ssmanager is started
  10. ],
  11. // Outbound socket binds to this IP address
  12. // For choosing different network interface on the same machine
  13. "local_address": "xxx.xxx.xxx.xxx",
  14. // Other options that may be passed directly to new servers
  15. }

Configuration

  1. {
  2. // LOCAL: Listen address. This is exactly the same as `locals[0]`
  3. // SERVER: Bind address for remote sockets, mostly used for choosing interface
  4. // Don't set it if you don't know what's this for.
  5. "local_address": "127.0.0.1",
  6. "local_port": 1080,
  7. // Extended multiple local configuration
  8. "locals": [
  9. {
  10. // Basic configuration, a SOCKS5 local server
  11. "local_address": "127.0.0.1",
  12. "local_port": 1080,
  13. // OPTIONAL. Setting the `mode` for this specific local server instance.
  14. // If not set, it will derive from the outer `mode`
  15. "mode": "tcp_and_udp",
  16. // OPTIONAL. Authentication configuration file
  17. // Configuration file document could be found in the next section.
  18. "socks5_auth_config_path": "/path/to/auth.json",
  19. // OPTIONAL. Instance specific ACL
  20. "acl": "/path/to/acl/file.acl",
  21. // OPTIONAL. macOS launchd activate socket
  22. "launchd_tcp_socket_name": "TCPListener",
  23. "launchd_udp_socket_name": "UDPListener"
  24. },
  25. {
  26. // SOCKS5, SOCKS4/4a local server
  27. "protocol": "socks",
  28. // Listen address
  29. "local_address": "127.0.0.1",
  30. "local_port": 1081,
  31. // OPTIONAL. Enables UDP relay
  32. "mode": "tcp_and_udp",
  33. // OPTIONAL. Customizing the UDP's binding address. Depending on `mode`, if
  34. // - TCP is enabled, then SOCKS5's UDP Association command will return this address
  35. // - UDP is enabled, then SOCKS5's UDP server will listen to this address.
  36. "local_udp_address": "127.0.0.1",
  37. "local_udp_port": 2081,
  38. // OPTIONAL. macOS launchd activate socket
  39. "launchd_tcp_socket_name": "TCPListener",
  40. "launchd_udp_socket_name": "UDPListener"
  41. },
  42. {
  43. // Tunnel local server (feature = "local-tunnel")
  44. "protocol": "tunnel",
  45. // Listen address
  46. "local_address": "127.0.0.1",
  47. "local_port": 5353,
  48. // Forward address, the target of this tunnel
  49. // In this example, this will build a `127.0.0.1:5353` -> `8.8.8.8:53` tunnel
  50. "forward_address": "8.8.8.8",
  51. "forward_port": 53,
  52. // OPTIONAL. Customizing whether to start TCP and UDP tunnel
  53. "mode": "tcp_only",
  54. // OPTIONAL. macOS launchd activate socket
  55. "launchd_tcp_socket_name": "TCPListener",
  56. "launchd_udp_socket_name": "UDPListener"
  57. },
  58. {
  59. // HTTP local server (feature = "local-http")
  60. "protocol": "http",
  61. // Listen address
  62. "local_address": "127.0.0.1",
  63. "local_port": 3128,
  64. // OPTIONAL. macOS launchd activate socket
  65. "launchd_tcp_socket_name": "TCPListener"
  66. },
  67. {
  68. // DNS local server (feature = "local-dns")
  69. // This DNS works like China-DNS, it will send requests to `local_dns` and `remote_dns` and choose by ACL rules
  70. "protocol": "dns",
  71. // Listen address
  72. "local_address": "127.0.0.1",
  73. "local_port": 53,
  74. // OPTIONAL. DNS local server uses `tcp_and_udp` mode by default
  75. "mode": "udp_only",
  76. // Local DNS address, DNS queries will be sent directly to this address
  77. "local_dns_address": "114.114.114.114",
  78. // OPTIONAL. Local DNS's port, 53 by default
  79. "local_dns_port": 53,
  80. // Remote DNS address, DNS queries will be sent through ssserver to this address
  81. "remote_dns_address": "8.8.8.8",
  82. // OPTIONAL. Remote DNS's port, 53 by default
  83. "remote_dns_port": 53,
  84. // OPTIONAL. dns client cache size for fetching dns queries.
  85. "client_cache_size": 5,
  86. // OPTIONAL. macOS launchd activate socket
  87. "launchd_tcp_socket_name": "TCPListener",
  88. "launchd_udp_socket_name": "UDPListener"
  89. },
  90. {
  91. // Tun local server (feature = "local-tun")
  92. "protocol": "tun",
  93. // Tun interface name
  94. "tun_interface_name": "tun0",
  95. // Tun interface address
  96. //
  97. // It has to be a host address in CIDR form
  98. "tun_interface_address": "10.255.0.1/24"
  99. },
  100. {
  101. // Transparent Proxy (redir) local server (feature = "local-redir")
  102. "protocol": "redir",
  103. // OPTIONAL: TCP type, may be different between platforms
  104. // Linux/Android: redirect (default), tproxy
  105. // FreeBSD/OpenBSD: pf (default), ipfw
  106. // NetBSD/macOS/Solaris: pf (default), ipfw
  107. "tcp_redir": "tproxy",
  108. // OPTIONAL: UDP type, may be different between platforms
  109. // Linux/Android: tproxy (default)
  110. // FreeBSD/OpenBSD: pf (default)
  111. "udp_redir": "tproxy"
  112. },
  113. {
  114. // FakeDNS local server (feature = "local-fake-dns")
  115. // FakeDNS is a DNS server that allocates an IPv4 / IPv6 address in a specific pool for each queries.
  116. // Subsequence requests from the other local interfaces that the target addresses includes those allocated IP addresses,
  117. // will be substituted back to their original domain name addresses.
  118. // This feature is useful mostly for transparent proxy, which will allow the proxied domain names to be resolved remotely.
  119. "protocol": "fake-dns",
  120. // Listen address
  121. "local_address": "127.0.0.1",
  122. "local_port": 10053,
  123. // IPv4 address pool (for A records)
  124. "fake_dns_ipv4_network": "10.255.0.0/16",
  125. // IPv6 address pool (for AAAA records)
  126. "fake_dns_ipv6_network": "fdf2:e786:ab40:9d2f::/64",
  127. // Persistent storage for all allocated DNS records
  128. "fake_dns_database_path": "/var/shadowsocks/fakedns.db",
  129. // OPTIONAL: Record expire duration in seconds, 10s by default
  130. "fake_dns_record_expire_duration": 10
  131. }
  132. ],
  133. // Server configuration
  134. // listen on :: for dual stack support, no need add [] around.
  135. "server": "::",
  136. // Change to use your custom port number
  137. "server_port": 8388,
  138. "method": "aes-256-gcm",
  139. "password": "your-password",
  140. "plugin": "v2ray-plugin",
  141. "plugin_opts": "mode=quic;host=github.com",
  142. "plugin_args": [
  143. // Each line is an argument passed to "plugin"
  144. "--verbose"
  145. ],
  146. "plugin_mode": "tcp_and_udp", // SIP003u, default is "tcp_only"
  147. // Server: TCP socket timeout in seconds.
  148. // Client: TCP connection timeout in seconds.
  149. // Omit this field if you don't have specific needs.
  150. "timeout": 7200,
  151. // Extended multiple server configuration
  152. // LOCAL: Choosing the best server to connect dynamically
  153. // SERVER: Creating multiple servers in one process
  154. "servers": [
  155. {
  156. // Fields are the same as the single server's configuration
  157. // Individual servers can be disabled
  158. // "disabled": true,
  159. "address": "0.0.0.0",
  160. "port": 8389,
  161. "method": "aes-256-gcm",
  162. "password": "your-password",
  163. "plugin": "...",
  164. "plugin_opts": "...",
  165. "plugin_args": [],
  166. "plugin_mode": "...",
  167. "timeout": 7200,
  168. // Customized weight for local server's balancer
  169. //
  170. // Weight must be in [0, 1], default is 1.0.
  171. // The higher weight, the server may rank higher.
  172. "tcp_weight": 1.0,
  173. "udp_weight": 1.0,
  174. // OPTIONAL. Instance specific ACL
  175. "acl": "/path/to/acl/file.acl",
  176. },
  177. {
  178. // Same key as basic format "server" and "server_port"
  179. "server": "0.0.0.0",
  180. "server_port": 8388,
  181. "method": "chacha20-ietf-poly1305",
  182. // Read the actual password from environment variable PASSWORD_FROM_ENV
  183. "password": "${PASSWORD_FROM_ENV}"
  184. },
  185. {
  186. // AEAD-2022
  187. "server": "::",
  188. "server_port": 8390,
  189. "method": "2022-blake3-aes-256-gcm",
  190. "password": "3SYJ/f8nmVuzKvKglykRQDSgg10e/ADilkdRWrrY9HU=",
  191. // For Server (OPTIONAL)
  192. // Support multiple users with Extensible Identity Header
  193. // https://github.com/Shadowsocks-NET/shadowsocks-specs/blob/main/2022-2-shadowsocks-2022-extensible-identity-headers.md
  194. "users": [
  195. {
  196. "name": "username",
  197. // User's password must have the same length as server's password
  198. "password": "4w0GKJ9U3Ox7CIXGU4A3LDQAqP6qrp/tUi/ilpOR9p4="
  199. }
  200. ],
  201. // For Client (OPTIONAL)
  202. // If EIH enabled, then "password" should have the following format: iPSK:iPSK:iPSK:uPSK
  203. // - iPSK is one of the middle relay servers' PSK, for the last `ssserver`, it must be server's PSK ("password")
  204. // - uPSK is the user's PSK ("password")
  205. // Example:
  206. // "password": "3SYJ/f8nmVuzKvKglykRQDSgg10e/ADilkdRWrrY9HU=:4w0GKJ9U3Ox7CIXGU4A3LDQAqP6qrp/tUi/ilpOR9p4="
  207. },
  208. {
  209. "...": "Any other fields",
  210. // Some optional fields for this specific server
  211. // Outbound socket options
  212. // Linux Only (SO_MARK)
  213. "outbound_fwmark": 255,
  214. // FreeBSD only (SO_USER_COOKIE)
  215. "outbound_user_cookie": 255,
  216. // `SO_BINDTODEVICE` (Linux), `IP_BOUND_IF` (BSD), `IP_UNICAST_IF` (Windows) socket option for outbound sockets
  217. "outbound_bind_interface": "eth1",
  218. // Outbound socket bind() to this IP (choose a specific interface)
  219. "outbound_bind_addr": "11.22.33.44",
  220. // Outbound UDP socket allows IP fragmentation (default false)
  221. "outbound_udp_allow_fragmentation": false,
  222. }
  223. ],
  224. // Global configurations for UDP associations
  225. "udp_timeout": 300, // Timeout for UDP associations (in seconds), 5 minutes by default
  226. "udp_max_associations": 512, // Maximum UDP associations to be kept in one server, unlimited by default
  227. // Options for Manager
  228. "manager_address": "127.0.0.1", // Could be a path to UNIX socket, /tmp/shadowsocks-manager.sock
  229. "manager_port": 5300, // Not needed for UNIX socket
  230. // DNS server's address for resolving domain names
  231. // For *NIX and Windows, it uses system's configuration by default
  232. //
  233. // Value could be IP address of DNS server, for example, "8.8.8.8".
  234. // DNS client will automatically request port 53 with both TCP and UDP protocol.
  235. //
  236. // - system, uses system provided API (`getaddrinfo` on *NIX)
  237. //
  238. // It also allows some pre-defined well-known public DNS servers:
  239. // - google (TCP, UDP)
  240. // - cloudflare (TCP, UDP)
  241. // - cloudflare_tls (TLS), enable by feature "dns-over-tls"
  242. // - cloudflare_https (HTTPS), enable by feature "dns-over-https"
  243. // - quad9 (TCP, UDP)
  244. // - quad9_tls (TLS), enable by feature "dns-over-tls"
  245. //
  246. // The field is only effective if feature "hickory-dns" is enabled.
  247. "dns": "google",
  248. // Configure `cache_size` for "hickory-dns" ResolverOpts. Set to "0" to disable DNS cache.
  249. "dns_cache_size": 0,
  250. // Mode, could be one of the
  251. // - tcp_only
  252. // - tcp_and_udp
  253. // - udp_only
  254. "mode": "tcp_only",
  255. // TCP_NODELAY
  256. "no_delay": false,
  257. // Enables `SO_KEEPALIVE` and set `TCP_KEEPIDLE`, `TCP_KEEPINTVL` to the specified seconds
  258. "keep_alive": 15,
  259. // Soft and Hard limit of file descriptors on *NIX systems
  260. "nofile": 10240,
  261. // Try to resolve domain name to IPv6 (AAAA) addresses first
  262. "ipv6_first": false,
  263. // Set IPV6_V6ONLY for all IPv6 listener sockets
  264. // Only valid for locals and servers listening on `::`
  265. "ipv6_only": false,
  266. // Outbound socket options
  267. // Linux Only (SO_MARK)
  268. "outbound_fwmark": 255,
  269. // FreeBSD only (SO_USER_COOKIE)
  270. "outbound_user_cookie": 255,
  271. // `SO_BINDTODEVICE` (Linux), `IP_BOUND_IF` (BSD), `IP_UNICAST_IF` (Windows) socket option for outbound sockets
  272. "outbound_bind_interface": "eth1",
  273. // Outbound socket bind() to this IP (choose a specific interface)
  274. "outbound_bind_addr": "11.22.33.44",
  275. // Outbound UDP socket allows IP fragmentation (default false)
  276. "outbound_udp_allow_fragmentation": false,
  277. // Balancer customization
  278. "balancer": {
  279. // MAX Round-Trip-Time (RTT) of servers
  280. // The timeout seconds of each individual checks
  281. "max_server_rtt": 5,
  282. // Interval seconds between each check
  283. "check_interval": 10,
  284. // Interval seconds between each check for the best server
  285. // Optional. Specify to enable shorter checking interval for the best server only.
  286. "check_best_interval": 5
  287. },
  288. // SIP008 Online Configuration Delivery
  289. // https://shadowsocks.org/doc/sip008.html
  290. "online_config": {
  291. "config_url": "https://path-to-online-sip008-configuration",
  292. // Optional. Seconds between each update to config_url. Default to 3600s
  293. "update_interval": 3600,
  294. // Optional. Whitelist of plugins (RECOMMENDED for all users)
  295. // SECURITY: To avoid executing untrusted commands loaded from config_url
  296. "allowed_plugins": [
  297. "v2ray-plugin"
  298. ]
  299. },
  300. // Service configurations
  301. // Logger configuration
  302. "log": {
  303. // Equivalent to `-v` command line option
  304. "level": 1,
  305. "format": {
  306. // Euiqvalent to `--log-without-time`
  307. "without_time": false,
  308. },
  309. // Equivalent to `--log-config`
  310. // More detail could be found in https://crates.io/crates/log4rs
  311. "config_path": "/path/to/log4rs/config.yaml"
  312. },
  313. // Runtime configuration
  314. "runtime": {
  315. // single_thread or multi_thread
  316. "mode": "multi_thread",
  317. // Worker threads that are used in multi-thread runtime
  318. "worker_count": 10
  319. }
  320. }

SOCKS5 Authentication Configuration

The configuration file is set by socks5_auth_config_path in locals.

  1. {
  2. // Password/Username Authentication (RFC1929)
  3. "password": {
  4. "users": [
  5. {
  6. "user_name": "USERNAME in UTF-8",
  7. "password": "PASSWORD in UTF-8"
  8. }
  9. ]
  10. }
  11. }

Environment Variables

  • SS_SERVER_PASSWORD: A default password for servers that created from command line argument (--server-addr)
  • SS_SYSTEM_DNS_RESOLVER_FORCE_BUILTIN: "system" DNS resolver force use system’s builtin (getaddrinfo in *NIX)

Supported Ciphers

AEAD 2022 Ciphers

  • 2022-blake3-aes-128-gcm, 2022-blake3-aes-256-gcm
  • 2022-blake3-chacha20-poly1305, 2022-blake3-chacha8-poly1305

These Ciphers require "password" to be a Base64 string of key that have exactly the same length of Cipher’s Key Size. It is recommended to use ssservice genkey -m "METHOD_NAME" to generate a secured and safe key.

AEAD Ciphers

  • chacha20-ietf-poly1305
  • aes-128-gcm, aes-256-gcm

Stream Ciphers

  • plain or none (No encryption, only used for debugging or with plugins that ensure transport security)
Deprecated



- table
- aes-128-cfb, aes-128-cfb1, aes-128-cfb8, aes-128-cfb128
- aes-192-cfb, aes-192-cfb1, aes-192-cfb8, aes-192-cfb128
- aes-256-cfb, aes-256-cfb1, aes-256-cfb8, aes-256-cfb128
- aes-128-ctr
- aes-192-ctr
- aes-256-ctr
- camellia-128-cfb, camellia-128-cfb1, camellia-128-cfb8, camellia-128-cfb128
- camellia-192-cfb, camellia-192-cfb1, camellia-192-cfb8, camellia-192-cfb128
- camellia-256-cfb, camellia-256-cfb1, camellia-256-cfb8, camellia-256-cfb128
- rc4-md5
- chacha20-ietf


ACL

sslocal, ssserver, and ssmanager support ACL file with syntax like shadowsocks-libev. Some examples could be found in here.

Available sections

  • For local servers (sslocal, ssredir, …)
    • Modes:
      • [bypass_all] - ACL runs in BlackList mode. Bypasses all addresses that didn’t match any rules.
      • [proxy_all] - ACL runs in WhiteList mode. Proxies all addresses that didn’t match any rules.
    • Rules:
      • [bypass_list] - Rules for connecting directly
      • [proxy_list] - Rules for connecting through proxies
  • For remote servers (ssserver)
    • Modes:
      • [reject_all] - ACL runs in BlackList mode. Rejects all clients that didn’t match any rules.
      • [accept_all] - ACL runs in WhiteList mode. Accepts all clients that didn’t match any rules.
    • Rules:
      • [white_list] - Rules for accepted clients
      • [black_list] - Rules for rejected clients
      • [outbound_block_list] - Rules for blocking outbound addresses.

Example

  1. # SERVERS
  2. # For ssserver, accepts requests from all clients by default
  3. [accept_all]
  4. # Blocks these clients
  5. [black_list]
  6. 1.2.3.4
  7. 127.0.0.1/8
  8. # Disallow these outbound addresses
  9. [outbound_block_list]
  10. 127.0.0.1/8
  11. ::1
  12. # Using regular expression
  13. ^[a-z]{5}\.baidu\.com
  14. # Match exactly
  15. |baidu.com
  16. # Match with subdomains
  17. ||google.com
  18. # An internationalized domain name should be converted to punycode
  19. # |☃-⌘.com - WRONG
  20. |xn----dqo34k.com
  21. # ||джpумлатест.bрфa - WRONG
  22. ||xn--p-8sbkgc5ag7bhce.xn--ba-lmcq
  23. # CLIENTS
  24. # For sslocal, ..., bypasses all targets by default
  25. [bypass_all]
  26. # Proxy these addresses
  27. [proxy_list]
  28. ||google.com
  29. 8.8.8.8

Useful Tools

  1. ssurl is for encoding and decoding ShadowSocks URLs (SIP002). Example:

    1. ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmQ@127.0.0.1:8388/?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.baidu.com

Notes

It supports the following features:

  • SOCKS5 CONNECT command
  • SOCKS5 UDP ASSOCIATE command (partial)
  • SOCKS4/4a CONNECT command
  • Various crypto algorithms
  • Load balancing (multiple servers) and server delay checking
  • SIP004 AEAD ciphers
  • SIP003 Plugins
  • SIP003u Plugin with UDP support
  • SIP002 Extension ss URLs
  • SIP022 AEAD 2022 ciphers
  • HTTP Proxy Supports (RFC 7230 and CONNECT)
  • Defend against replay attacks, shadowsocks/shadowsocks-org#44
  • Manager APIs, supporting Manage Multiple Users
  • ACL (Access Control List)
  • Support HTTP/HTTPS Proxy protocol

TODO

  • Documentation
  • Extend configuration format
  • Improved logging format (waiting for the new official log crate)
  • Support more ciphers without depending on libcrypto (waiting for an acceptable Rust crypto lib implementation)
  • Windows support.
  • Build with stable rustc (blocking by crypto2).
  • Support HTTP Proxy protocol
  • AEAD ciphers. (proposed in SIP004, still under discussion)
  • Choose server based on delay #152

License

The MIT License (MIT)

Copyright (c) 2014 Y. T. CHUNG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Stargazers over time

Stargazers over time