A Trojan proxy written in golang. An unidentifiable mechanism that helps you bypass GFW.
使用方法
sudo ./trojan-go -cert request
sudo ./trojan-go -cert renew
./trojan-go -config 你的配置文件.json
- TLS隧道传输
- 透明代理 (NAT模式,iptables设置参见这里)
- UDP代理
- 对抗GFW被动/主动检测的机制
- MySQL数据库支持
- 流量统计,用户流量配额限制
- 从数据库中的用户列表进行认证
- TCP性能方面的选项,如TCP Fast Open,端口复用等
特性
移植性
易用
{
"run_type": "server",
"local_addr": "0.0.0.0",
"local_port": 443,
"remote_addr": "127.0.0.1",
"remote_port": 80,
"password": [
"your_awesome_password"
],
"ssl": {
"cert": "your_cert.crt",
"key": "your_key.key"
}
}
{
"run_type": "client",
"local_addr": "127.0.0.1",
"local_port": 1080,
"remote_addr": "www.your_awesome_domain_name.com",
"remote_port": 443,
"password": [
"your_awesome_password"
]
}
自动证书申请
sudo ./trojan-go -cert request
- server.key 服务器私钥
- server.crt 经过Let's Encrypt签名的服务器证书
- user.key 用户Email对应的私钥
- domain_info.json 域名和用户Email信息
sudo ./trojan-go -cert renew
WebSocket
websocket
选项即可启用Websocket支持,例如"websocket": {
"enabled": true,
"path": "/im_a_url_path",
"hostname": "www.your_awesome_domain_name.com"
}
hostname
, 但是服务器和客户端的path
必须相同。服务器开启Websocket支持后可以同时支持Websocket和一般Trojan流量,未配置Websocket选项的客户端依然可以正常使用。多路复用
"mux": {
"enabled": true
}
路由模块
- Proxy 代理。将请求通过TLS隧道进行代理,由trojan服务器和目的地址进行连接。
- Bypass 绕过。直接在本地和目的地址进行连接。
- Block 封锁。不代理请求,直接关闭连接。
"router": {
"enabled": true,
"bypass": [
"geoip:tag1",
"geosite:tag2",
"bypass_list1.txt",
"bypass_list2.txt"
],
"block": [
"block_list.txt"
]
"proxy": [
"proxy_list.txt"
]
}
bypass
,block
, proxy
字段中填入相应的列表文件或者geo数据库tag。列表文件每行是一个域名或者IP地址段(CIDR)。geo数据库geoip和geosite为IP数据库和域名数据库。一旦匹配,则执行相应策略。"router": {
"enabled": true,
"bypass": [
"geoip:cn",
"geoip:private",
"geosite:cn"
]
}
构建
git clone https://github.com/p4gefau1t/trojan-go.git
cd trojan-go
go build
CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -o trojan-go.exe
CGO_ENABLE=0 GOOS=linux GOARCH=arm go build -o trojan-go
致谢
Trojan-Go
Usage
./trojan-go -cert request
./trojan-go -cert renew
./trojan-go -config your_awesome_config_file.json
- TLS tunneling
- Transparent proxy (NAT mode, see here)
- UDP Relaying
- Mechanism against passive and active detection of GFW
- MySQL Database support
- Traffic statistics, quota limits for each user
- Authentication by users record in database
- TCP performance-related options, like TCP fast open, port reusing, etc.
Features
Portable
Easy to use
{
"run_type": "server",
"local_addr": "0.0.0.0",
"local_port": 443,
"remote_addr": "127.0.0.1",
"remote_port": 80,
"password": [
"your_awesome_password"
],
"ssl": {
"cert": "your_cert.crt",
"key": "your_key.key"
}
}
{
"run_type": "client",
"local_addr": "127.0.0.1",
"local_port": 1080,
"remote_addr": "www.your_awesome_domain_name.com",
"remote_port": 443,
"password": [
"your_awesome_password"
]
}
Certificate requesting
` sudo ./trojan-go -cert request
`- server.key: server private key
- server.crt: server certificate signed by Let's Encrypt
- user.key: The private key corresponding to the user's email
- domain_info.json: domain name and user email information
` sudo ./trojan-go -cert renew
`"websocket": {
"enabled": true,
"path": "/im_a_url_path",
"hostname": "www.your_awesome_domain_name.com"
}
hostname
field, but the path
of the server and client must be the same. After Websocket support is enabled on the server, Websocket and general Trojan traffic can be supported at the same time. Clients without Websocket options will still work.Multiplexing
"mux": {
"enabled": true
}
Routing
- Proxy. The request is proxied through the TLS tunnel, and the trojan server will connect to the destination remote endpoints.
- Bypass. Local client will connect to the remote endpoints directly without using the TLS tunnel.
- Block. Close the incoming connection immediately.
"router": {
"enabled": true,
"bypass": [
"geoip:tag1",
"geosite:tag2",
"bypass_list1.txt",
"bypass_list2.txt"
],
"block": [
"block_list.txt"
]
"proxy": [
"proxy_list.txt"
]
}
Build
git clone https://github.com/p4gefau1t/trojan-go.git
cd trojan-go
go build
CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -o trojan-go.exe
CGO_ENABLE=0 GOOS=linux GOARCH=arm go build -o trojan-go
from
https://github.com/p4gefau1t/trojan-go
Trojan server and proxy programs written in Rust.
Trojan-rs
- For the server mode, the protocol is compatible with original trojan except UDP Associate does not support domain address type (maybe later?) If you are not ok with that, you can use the original version, it should work perfectly with the proxy mode.
- For the proxy mode, it uses TPROXY to relay all UDP and TCP packets, and it should work with the original server in both route or local type.
How to use it
hoping@HopingPC:~/workspace/trojan-rs$ trojan --help
trojan 0.3
Hoping White
a trojan implementation using rust
USAGE:
trojan [OPTIONS] --local-addr <local-addr> --password <password> <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-i, --idle-timeout <idle-timeout> time in seconds before closing an inactive connection [default: 120]
-a, --local-addr <local-addr> listen address for server
-l, --log-file <log-file> log file path
-L, --log-level <log-level> log level, 0 for trace, 1 for debug, 2 for info, 3 for warning, 4 for error, 5
for off [default: 2]
-m, --marker <marker> set marker used by tproxy [default: 1]
-p, --password <password> passwords for negotiation
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
proxy run in proxy mode
server run in server mode
hoping@HopingPC:~/workspace/trojan-rs$ trojan help proxy
trojan-proxy
USAGE:
trojan proxy --hostname <hostname>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-H, --hostname <hostname> trojan server hostname
hoping@HopingPC:~/workspace/trojan-rs$ trojan help server
trojan-server
USAGE:
trojan server [OPTIONS] --cert <cert> --key <key>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-n, --alpn <alpn>... alpn protocol supported
-c, --cert <cert> certificate file path, This should contain PEM-format certificates in the
right order (the first certificate should certify KEYFILE, the last should
be a root CA
-d, --dns-cache-time <dns-cache-time> time in seconds for dns query cache [default: 300]
-k, --key <key> private key file path, This should be a RSA private key or PKCS8-encoded
private key, in PEM format.
-r, --remote-addr <remote-addr> http backend server address [default: 127.0.0.1:80]
IPTABLES settings.
IMPORTANT your trojan server IP should be included in byplist or lanlist, otherwise, route loop should occur.
# Add any tproxy policy rules
ip rule add fwmark 0xff table 100
ip route add local 0.0.0.0/0 dev lo table 100
# --------------- Route Rules Begin ---------------------------
# Create a new chain for router
iptables -t mangle -N TROJAN_ROUTE
# Ignore LANs and any other addresses you'd like to bypass the proxy
iptables -t mangle -A TROJAN_ROUTE -m set --match-set lanlist dst -j RETURN
iptables -t mangle -A TROJAN_ROUTE -m set --match-set byplist dst -j RETURN
iptables -t mangle -A TROJAN_ROUTE -m set --match-set chslist dst -j RETURN
# Anything else should be redirected to shadowsocks's local port
iptables -t mangle -A TROJAN_ROUTE -p tcp -j TPROXY --on-port 60080 --on-ip 127.0.0.1 --tproxy-mark 0xff
iptables -t mangle -A TROJAN_ROUTE -p udp -j TPROXY --on-port 60080 --on-ip 127.0.0.1 --tproxy-mark 0xff
# Apply the route rules
iptables -t mangle -A PREROUTING -j TROJAN_ROUTE
# ---------------- Route Rules End -----------------------------
# ---------------- Local Rules Begin --------------------------
# Create new chain for localhost
iptables -t mangle -N TROJAN_LOCAL
# Ignore Lans and any other address you'd like to bypass the proxy
iptables -t mangle -A TROJAN_LOCAL -m set --match-set lanlist dst -j RETURN
iptables -t mangle -A TROJAN_LOCAL -m set --match-set byplist dst -j RETURN
iptables -t mangle -A TROJAN_LOCAL -m set --match-set chslist dst -j RETURN
# Ignore packets sent from trojan itself.
iptables -t mangle -A TROJAN_LOCAL -m mark --mark 0xff -j RETURN
# Mark tcp 80, 443, udp 53 to reroute.
iptables -t mangle -A TROJAN_LOCAL -p udp --dport 53 -j MARK --set-xmark 0xff
iptables -t mangle -A TROJAN_LOCAL -p tcp --dport 80 -j MARK --set-xmark 0xff
iptables -t mangle -A TROJAN_LOCAL -p tcp --dport 443 -j MARK --set-xmark 0xff
# Apply the local rules
iptables -t mangle -A OUTPUT -j TROJAN_LOCAL
# ----------------- Local Rules End --------------------------------
# Flush all the rules to effect immediately
ip route flush cache
A slim client for trojan-gfw, also called TCS.
TCS
A slim cilent for Trojan-GFW.
What's TCS?
TCS(Trojan Client Slim) is a slim and easy client for Trojan-GFW.
TIPS: TCS only gives the most basic functions. If you need full-feature experience, please configure Trojan-G*W manually.
What's supported?
- Now TCS support share link! (With Igniter-TCS)
- Auto configure HTTP proxy.
- Auto save config.
- Auto generate trojan conf. (TLS1.3, H2, etc.)
- G*WList mode to bypass ***. You know what I mean.
Components
- TCS (2.2.0) GPLv3
- Privoxy (3.0.28.0) GPLv2
- Trojan-GFW (1.14.0) GPLv3
TODO
- Use Clash instead of Privoxy
- Local Port settings
- Node list
Smart GFWList updator
Screenshot(s)
One more thing
Welcome to use Telegram to communicate with us. Our group link is https://t.me/trojangfwcs
from https://github.com/KevinZonda/trojan-client-slim/tree/master
-------
轻量高效的 Trojan 代理,使用 Rust 实现.
Trojan-R
高性能的 Trojan 代理,使用 Rust 实现。为嵌入式设备或低性能机器设计。R 意为 Rust / Rapid。
Trojan-R 目前为实验性项目,仍处于重度开发中,协议、接口和配置文件格式均可能改变,请勿用于任何生产环境。
特性
极致性能
牺牲部分灵活性,采用激进的性能优化策略以极力减少不必要的开销。采用更高效的
rustls
(相较 openssl)建立 TLS 隧道以提升加解密的性能表现。使用 tokio 异步运行时,允许
Trojan-R
同时使用所有 CPU 核心,保证低时延和高效的吞吐能力。需要更多 benchmark 数据和更多优化
低内存占用
Rust 无 GC 机制,内存占用可被预计。简化的握手和连接流程,仅使用极少的堆内存和复制。
需要更多 benchmark 数据和更多优化
简易配置
使用 toml 格式配置,仅需数行配置即可启动完整客户端或服务器。
内存安全
使用 Rust 语言实现,可证明的内存安全性。在语法层面保证所有内存操作安全可靠。无竞争条件,无悬挂指针,无 UAF,无 Double Free。
密码学安全
使用
rustls
建立 TLS 加密安全信道,过时的或不安全的密码学套件均被禁用。Trojan-R
强制开启服务器证书校验以防止中间人攻击。隐蔽传输
Trojan-R
使用 TLS 建立代理隧道,难以从正常 TLS 流量中被区分。支持协议回落,在遭到主动探测时将与普通 TLS 服务器表现一致。跨平台支持
Trojan-R
可被交叉编译,支持 Android, Linux,Windows 和 MacOS 等操作系统,以及 x86,x86_64,armv7,aarch64 等硬件平台。
非特性
由于与项目的设计原则冲突,下列特性不计划实现
统计功能,包括 API 和数据库对接等
路由功能
用户自定义协议栈
透明代理
如果需要实现上述功能,请使用其他类似工具与 Trojan-R
组合实现。
设计原则
安全性
Trojan-R
不涉及底层操作,且目前的性能瓶颈与其无关,无使用 unsafe rust 的必要。协议回落和 TLS 配置等安全敏感代码经过仔细考虑和审计,同时也欢迎更多来自开源社区的安全审计。目前
Trojan-R
使用#![forbid(unsafe_code)]
禁用 unsafe rust。如未来有必要使用 unsafe rust 时,必须经过严格审计和测试。使用静态分发而非动态分发
协议实现使用统一的 trait。协议嵌套使用静态分发,以保证嵌套协议栈的函数调用关系在编译时被确定,使编译器可以进行内联和更好的优化。
低内存分配
减少热点代码的内存分配,用引用替换复制,以实现更高的性能和更低的内存开销。
简洁
保持最简洁干净的实现,以保证最低的代码复杂度,尽可能少的性能开销,并增加可靠性和减少攻击面。
部署和使用
Trojan-R
使用 toml 进行配置,参考 config
文件夹下配置文件。
编译
cargo build --release
交叉编译基于 cross
完成,编译前请确认已经安装 cross
(cargo install cross
)
make armv7-unknown-linux-musleabihf
编译默认开启链接时优化,以提升性能并减小可执行文件体积,因此编译耗时可能较其他项目更长。
编译完成后可以使用 strip
去除调试符号表以减少文件体积。
from https://github.com/p4gefau1t/trojan-r
---------