0
0
Fork 0
mirror of https://github.com/semigodking/redsocks.git synced 2026-04-21 06:29:40 +00:00
transparent redirector of any TCP/UDP connection to proxy
  • C 98.3%
  • Makefile 1.1%
  • Shell 0.6%
Find a file
2026-03-10 09:56:18 +08:00
.github/workflows Fix CI pipeline for FreeBSD 2026-03-04 04:17:45 -08:00
debian Version bump - 0.65 and update docs. 2015-10-16 10:05:19 +08:00
doc Add README from balabit.com - it's nice doc about TPROXY. 2012-12-04 20:59:13 +04:00
extra Add source files required for building with Android NDK 2017-03-06 17:34:48 +08:00
tools Merge remote branch 'darkk/redsocks/master' 2016-03-09 14:44:52 +08:00
.gitignore add xnu folder to ignore file 2017-07-30 11:06:56 +02:00
autoproxy.c One more step to support IPv6 2019-09-27 00:37:05 +08:00
base.c added support for FreeBSD/OpenBSD (#201) 2024-06-29 22:46:19 +08:00
base.h One more step to support IPv6 2019-09-27 00:37:05 +08:00
base64.c add base64 and md5 library for http auth 2010-11-14 14:34:08 +08:00
base64.h minor fixes 2010-11-14 22:35:22 +08:00
direct.c Allow 'direct' to forward connections to specific destination 2020-12-29 10:49:29 +08:00
encrypt.c Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
encrypt.h Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
http-auth.c Fix memory leak in Basic http-auth 2016-04-13 13:59:12 +08:00
http-auth.h remove time limit between consective attempts 2010-11-19 01:03:20 +08:00
http-connect.c Compatible with non-standard HTTP proxies 2023-09-21 22:41:13 +08:00
http-relay.c Compatible with non-standard HTTP proxies 2023-09-21 22:41:13 +08:00
https-connect.c refine build with openssl 1.1.0+ (#114) 2019-03-13 20:43:49 +08:00
ipcache.c One more step to support IPv6 2019-09-27 00:37:05 +08:00
ipcache.h Refine code and make autoproxy much configurable 2015-02-17 11:34:38 +08:00
libc-compat.h added support for FreeBSD/OpenBSD (#201) 2024-06-29 22:46:19 +08:00
LICENSE add license, Apache-2.0 2020-07-05 01:17:57 -04:00
list.h Use __typeof instead of typeof. 2014-07-05 01:11:34 +02:00
log.c Merge branch 'darkk/redsocks' (early part) 2017-03-07 15:48:22 +08:00
log.h Emit better errors from config file parser 2016-03-09 01:12:38 +03:00
main.c Fix: program exits abnormally in daemon mode on FreeBSD 11. 2018-01-11 21:45:01 +08:00
main.h Refine code and make autoproxy much configurable 2015-02-17 11:34:38 +08:00
Makefile Add new encryption methods and fix bugs 2026-03-04 18:15:25 +08:00
md5.c multiple definition of `md5_init' 2016-02-20 00:48:50 +08:00
md5.h multiple definition of `md5_init' 2016-02-20 00:48:50 +08:00
parser.c Emit better errors from config file parser 2017-03-07 16:11:19 +08:00
parser.h Increase range of IP cache stale time to 32-bit value 2016-04-15 11:06:55 +08:00
README Merge remote branch 'darkk/redsocks/master' 2016-03-09 14:44:52 +08:00
README.md Add new encryption methods and fix bugs 2026-03-04 18:15:25 +08:00
redsocks.c added support for FreeBSD/OpenBSD (#201) 2024-06-29 22:46:19 +08:00
redsocks.conf.example Accept hostname in 'relay' 2023-09-20 18:29:24 +08:00
redsocks.h One more step to support IPv6 2019-09-27 00:37:05 +08:00
redsocks2.service Merge remote branch 'darkk/redsocks/master' 2016-03-09 14:44:52 +08:00
redudp.c Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
redudp.h Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
shadowsocks-udp.c Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
shadowsocks.c Add new encryption methods and fix bugs 2026-03-04 18:15:25 +08:00
shadowsocks.h Fix: shadowsocks not working 2019-11-23 17:32:27 +08:00
socks4.c One more step to support IPv6 2019-09-27 00:37:05 +08:00
socks5-udp.c Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
socks5.c Add IPv6 support to socks5 subsystem 2020-02-29 03:05:46 +00:00
socks5.h Add IPv6 support to socks5 subsystem 2020-02-29 03:05:46 +00:00
tcpdns.c added support for FreeBSD/OpenBSD (#201) 2024-06-29 22:46:19 +08:00
tcpdns.h One more step to support IPv6 2019-09-27 00:37:05 +08:00
uthash.h Add missing C header file 2026-03-10 09:56:18 +08:00
utils.c Improve UDP performance, fix UDP bug with AEAD 2026-03-10 09:51:28 +08:00
utils.h Many improvements to socks5 support 2024-05-28 22:18:57 +08:00
version.h Added -h, -? CLI options for help & -v for redsocks-version. 2011-11-27 03:30:43 +04:00

REDSOCKS2

Linux Build Status FreeBSD Build Status

This is a modified version of original redsocks. The name is changed to REDSOCKS2 to distinguish with original redsocks. REDSOCKS2 contains several new features besides many bug fixes to original redsocks.

  1. Redirect TCP connections which are blocked via proxy automatically without need of blacklist.
  2. Redirect UDP based DNS requests via TCP connection.
  3. Integrated shadowsocks proxy support.
  4. Redirect TCP connections without proxy.
  5. Redirect TCP connections via specified network interface.
  6. UDP transparent proxy via shadowsocks proxy.
  7. Support Ful-cone NAT Traversal when working with shadowsocks or socks5 proxy.
  8. Integrated HTTPS proxy support(HTTP CONNECT over SSL).
  9. Support TCP Fast Open on local server side and shadowsocks client side.
  10. Support port reuse (SO_REUSEPORT).
  11. Support IPv6.

Chinese Reference

HOW TO BUILD

Prerequisites

The following libraries are required.

  • libevent2
  • OpenSSL >= 1.1.1 or mbedTLS >= 2.16

Note: PolarSSL is no longer supported. Use mbedTLS instead.

Steps

On general Linux, simply run command below to build with OpenSSL.

$ make

To compile with mbedTLS

$ make USE_CRYPTO_MBEDTLS=true

To compile static binaries (with Tomatoware)

$ make ENABLE_STATIC=true

By default, HTTPS proxy support is disabled. To enable this feature, you need to compile like (Require libevent2 compiled with OpenSSL support):

$ make ENABLE_HTTPS_PROXY=true

To compile without shadowsocks support:

$ make DISABLE_SHADOWSOCKS=true

Since this variant of redsocks is customized for running with Openwrt, please read documents here (http://wiki.openwrt.org/doc/devel/crosscompile) for how to cross compile.

MacOS

To build on a MacOS system, you will have to install OpenSSL headers and libevent2 For this, brew is your best friends

$ brew install openssl libevent

Makefile include the folder of openssl headers and lib installed by brew.

To build with PF and run on MacOS, you will need some pf headers that are not included with a standard MacOS installation. You can find them on this repository : https://github.com/apple/darwin-xnu And the Makefile will going find this file for you

Configurations

Please see 'redsocks.conf.example' for whole picture of configuration file. Below are additional sample configuration sections for different usage. Operations required to iptables are not listed here.

Redirect Blocked Traffic via Proxy Automatically

To use the autoproxy feature, please change the redsocks section in configuration file like this:

redsocks {
 bind = "192.168.1.1:1081";
 relay = "192.168.1.1:9050";
 type = socks5; // I use socks5 proxy for GFW'ed IP
 autoproxy = 1; // I want autoproxy feature enabled on this section.
 // timeout is meaningful when 'autoproxy' is non-zero.
 // It specified timeout value when trying to connect to destination
 // directly. Default is 10 seconds. When it is set to 0, default
 // timeout value will be used.
 // NOTE: decreasing the timeout value may lead increase of chance for
 // normal IP to be misjudged.
 timeout = 13;
 //type = http-connect;
 //login = username;
 //password = passwd;
}

Redirect Blocked Traffic via VPN Automatically

Suppose you have VPN connection setup with interface tun0. You want all all blocked traffic pass through via VPN connection while normal traffic pass through via default internet connection.

redsocks {
	bind = "192.168.1.1:1081";
	interface = tun0; // Outgoing interface for blocked traffic
	type = direct;
	timeout = 13;
	autoproxy = 1;
}

Redirect Blocked Traffic via shadowsocks proxy

Similar like other redsocks section. The encryption method is specified by field 'login'.

redsocks {
	bind = "192.168.1.1:1080";
	type = shadowsocks;
	relay = "192.168.1.1:8388";
	timeout = 13;
	autoproxy = 1;
	login = "aes-128-cfb"; // field 'login' is reused as encryption
	                       // method of shadowsocks
	password = "your password"; // Your shadowsocks password
}

redudp {
	bind = "127.0.0.1:1053";
	relay = "123.123.123.123:1082";
	type = shadowsocks;
	login = rc4-md5;
	password = "ss server password";
	dest = "8.8.8.8:53";
	udp_timeout = 3;
}

List of supported encryption methods(Compiled with OpenSSL >= 1.1.1):

table
rc4
rc4-md5
aes-128-cfb
aes-192-cfb
aes-256-cfb
bf-cfb
camellia-128-cfb
camellia-192-cfb
camellia-256-cfb
cast5-cfb
des-cfb
idea-cfb
rc2-cfb
seed-cfb
aes-128-gcm
aes-192-gcm
aes-256-gcm
chacha20-ietf-poly1305

List of supported encryption methods(Compiled with mbedTLS >= 2.16):

table
ARC4-128
AES-128-CFB128
AES-192-CFB128
AES-256-CFB128
BLOWFISH-CFB64
CAMELLIA-128-CFB128
CAMELLIA-192-CFB128
CAMELLIA-256-CFB128
AES-128-GCM
AES-192-GCM
AES-256-GCM
CHACHA20-POLY1305

Note: chacha20-ietf-poly1305 requires OpenSSL >= 1.1.0 or mbedTLS >= 2.16 with ChachaPoly support.

Redirect UDP based DNS Request via TCP connection

Sending DNS request via TCP connection is one way to prevent from DNS poisoning. You can redirect all UDP based DNS requests via TCP connection with the following config section.

tcpdns {
	// Transform UDP DNS requests into TCP DNS requests.
	// You can also redirect connections to external TCP DNS server to
	// REDSOCKS transparent proxy via iptables.
	bind = "192.168.1.1:1053"; // Local server to act as DNS server
	tcpdns1 = "8.8.4.4:53";    // DNS server that supports TCP DNS requests
	tcpdns2 = 8.8.8.8;      // DNS server that supports TCP DNS requests
	timeout = 4;            // Timeout value for TCP DNS requests
}

Then, you can either redirect all your DNS requests to the local IP:port configured above by iptables, or just change your system default DNS upstream server as the local IP:port configured above.

AUTHOR

Zhuofei Wang semigodking@gmail.com