A simple, lightweight socks5 transparent proxy for Linux. (IPv4/IPv6/TCP/UDP)
Go to file
2020-05-17 16:53:07 +08:00
conf HevConfig: Format config file. 2019-09-26 19:04:42 +08:00
src HevConfig: Bump up to 1.7.3. 2020-04-20 11:08:19 +08:00
third-part ThirdPart: HevTaskSystem: Update to b473ce4. 2020-05-17 16:52:16 +08:00
.clang-format Tools: Update clang format config. 2018-10-19 13:28:59 +08:00
.gitignore Build: Make out directories on building. 2018-11-30 17:28:54 +08:00
.gitlab-ci.yml CI: Fix build system init. 2020-05-17 16:53:07 +08:00
.gitmodules ThirdPart: IniParser: Cleanup. 2019-09-18 22:07:00 +08:00
Android.mk Build: Link to YAML. 2019-09-18 22:40:33 +08:00
Application.mk Build: Set NDK toolchain version = clang. 2018-11-07 00:21:30 +08:00
build.mk Build: Import build make file. 2018-11-08 21:14:34 +08:00
Makefile Build: Fix installation. 2019-09-26 19:05:00 +08:00
README.md README: Update configs. 2019-09-18 23:25:21 +08:00

HevSocks5Tproxy

status

HevSocks5Tproxy is a simple, lightweight transparent proxy for Linux.

Features

  • Redirect TCP connections.
  • Redirect DNS queries. (see server)
  • IPv4/IPv6. (dual stack)

How to Build

Linux:

git clone git://github.com/heiher/hev-socks5-tproxy
cd hev-socks5-tproxy
git submodule init
git submodule update
make

Android:

mkdir hev-socks5-tproxy
cd hev-socks5-tproxy
git clone git://github.com/heiher/hev-socks5-tproxy jni
cd jni
git submodule init
git submodule update
ndk-build

How to Use

Config

main:
  workers: 4

socks5:
  port: 1080
  address: 127.0.0.1

tcp:
  port: 1088
  listen-address: 0.0.0.0

dns:
  port: 5300
  listen-address: 0.0.0.0

#misc:
#  log-file: null # stdout, stderr or file-path
#  log-level: warn # debug, info or error
#  pid-file: /run/hev-socks5-tproxy.pid
#  limit-nofile: -1

Run

bin/hev-socks5-tproxy conf/main.yml

Redirect rules

Global mode

# IPv4
# Base rules
iptables -t nat -N HTPROXY
iptables -t nat -A HTPROXY -d 0.0.0.0/8 -j RETURN
iptables -t nat -A HTPROXY -d 127.0.0.0/8 -j RETURN
iptables -t nat -A HTPROXY -d 169.254.0.0/16 -j RETURN
iptables -t nat -A HTPROXY -d 224.0.0.0/4 -j RETURN
iptables -t nat -A HTPROXY -d 240.0.0.0/4 -j RETURN
iptables -t nat -A HTPROXY -p udp --dport 53 -j REDIRECT --to-ports 5300
iptables -t nat -A HTPROXY -p tcp -j REDIRECT --to-ports 1088

# Bypass socks5 servers
iptables -t nat -A HTPROXY -d [SOCKS5_SERVER_ADDRESS] -j RETURN

# For local host
iptables -t nat -I OUTPUT -j HTPROXY

# For other hosts (tproxy gateway)
iptables -t nat -I PREROUTING -j HTPROXY

# IPv6
# Base rules
ip6tables -t nat -N HTPROXY
ip6tables -t nat -A HTPROXY -d ::1 -j RETURN
ip6tables -t nat -A HTPROXY -p udp --dport 53 -j REDIRECT --to-ports 5300
ip6tables -t nat -A HTPROXY -p tcp -j REDIRECT --to-ports 1088

# Bypass socks5 servers
ip6tables -t nat -A HTPROXY -d [SOCKS5_SERVER_ADDRESS] -j RETURN

# For local host
ip6tables -t nat -I OUTPUT -j HTPROXY

# For other hosts (tproxy gateway)
ip6tables -t nat -I PREROUTING -j HTPROXY

Per app mode

#!/bin/bash
# /usr/local/bin/tproxy

NET_CLS_DIR="/sys/fs/cgroup/net_cls/tproxy"
NET_CLS_ID=88
TP_TCP_PORT=1088
TP_DNS_PORT=5300

if [ ! -e ${NET_CLS_DIR} ]; then
	sudo sh -c "mkdir -p ${NET_CLS_DIR}; \
		chmod 0666 ${NET_CLS_DIR}/tasks; \
		echo ${NET_CLS_ID} > ${NET_CLS_DIR}/net_cls.classid; \
		iptables -t nat -D OUTPUT -p tcp \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_TCP_PORT}; \
		iptables -t nat -D OUTPUT -p udp --dport 53 \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_DNS_PORT}; \
		ip6tables -t nat -D OUTPUT -p tcp \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_TCP_PORT}; \
		ip6tables -t nat -D OUTPUT -p udp --dport 53 \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_DNS_PORT}; \
		iptables -t nat -I OUTPUT -p tcp \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_TCP_PORT}; \
		iptables -t nat -I OUTPUT -p udp --dport 53 \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_DNS_PORT}; \
		ip6tables -t nat -I OUTPUT -p tcp \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_TCP_PORT}; \
		ip6tables -t nat -I OUTPUT -p udp --dport 53 \
			-m cgroup --cgroup ${NET_CLS_ID} \
			-j REDIRECT --to-ports ${TP_DNS_PORT};" 2>&1 2> /dev/null
fi

echo $$ > ${NET_CLS_DIR}/tasks

exec "$@"
tproxy wget URL
tproxy git clone URL

Authors

License

LGPL