GithubHelp home page GithubHelp logo

p4gefau1t / trojan-go Goto Github PK

View Code? Open in Web Editor NEW
7.5K 132.0 1.6K 7.3 MB

Go实现的Trojan代理,支持多路复用/路由功能/CDN中转/Shadowsocks混淆插件,多平台,无依赖。A Trojan proxy written in Go. An unidentifiable mechanism that helps you bypass GFW. https://p4gefau1t.github.io/trojan-go/

License: GNU General Public License v3.0

Go 98.25% Shell 0.18% Dockerfile 0.27% Makefile 1.29%
gfw trojan-gfw anticensorship proxy golang china tunnel privacy transparent-proxy network

trojan-go's Introduction

Trojan-Go Go Report Card Downloads

使用 Go 实现的完整 Trojan 代理,兼容原版 Trojan 协议及配置文件格式。安全、高效、轻巧、易用。

Trojan-Go 支持多路复用提升并发性能;使用路由模块实现国内外分流;支持 CDN 流量中转(基于 WebSocket over TLS);支持使用 AEAD 对 Trojan 流量进行二次加密(基于 Shadowsocks AEAD);支持可插拔的传输层插件,允许替换 TLS,使用其他加密隧道传输 Trojan 协议流量。

预编译二进制可执行文件可在 Release 页面下载。解压后即可直接运行,无其他组件依赖。

如遇到配置和使用问题、发现 bug,或是有更好的想法,欢迎加入 Telegram 交流反馈群

简介

完整介绍和配置教程,参见 Trojan-Go 文档

Trojan-Go 兼容原版 Trojan 的绝大多数功能,包括但不限于:

  • TLS 隧道传输
  • UDP 代理
  • 透明代理 (NAT 模式,iptables 设置参考这里)
  • 对抗 GFW 被动检测 / 主动检测的机制
  • MySQL 数据持久化方案
  • MySQL 用户权限认证
  • 用户流量统计和配额限制

同时,Trojan-Go 还扩展实现了更多高效易用的功能特性:

  • 便于快速部署的「简易模式」
  • Socks5 / HTTP 代理自动适配
  • 基于 TProxy 的透明代理(TCP / UDP)
  • 全平台支持,无特殊依赖
  • 基于多路复用(smux)降低延迟,提升并发性能
  • 自定义路由模块,可实现国内外分流 / 广告屏蔽等功能
  • Websocket 传输支持,以实现 CDN 流量中转(基于 WebSocket over TLS)和对抗 GFW 中间人攻击
  • TLS 指纹伪造,以对抗 GFW 针对 TLS Client Hello 的特征识别
  • 基于 gRPC 的 API 支持,以实现用户管理和速度限制等
  • 可插拔传输层,可将 TLS 替换为其他协议或明文传输,同时有完整的 Shadowsocks 混淆插件支持
  • 支持对用户更友好的 YAML 配置文件格式

图形界面客户端

Trojan-Go 服务端兼容所有原 Trojan 客户端,如 Igniter、ShadowRocket 等。以下是支持 Trojan-Go 扩展特性(Websocket / Mux 等)的客户端:

  • Qv2ray:跨平台客户端,支持 Windows / macOS / Linux,使用 Trojan-Go 核心,支持所有 Trojan-Go 扩展特性。
  • Igniter-Go:Android 客户端,Fork 自 Igniter,将 Igniter 核心替换为 Trojan-Go 并做了一定修改,支持所有 Trojan-Go 扩展特性。

使用方法

  1. 快速启动服务端和客户端(简易模式)

    • 服务端

      sudo ./trojan-go -server -remote 127.0.0.1:80 -local 0.0.0.0:443 -key ./your_key.key -cert ./your_cert.crt -password your_password
    • 客户端

      ./trojan-go -client -remote example.com:443 -local 127.0.0.1:1080 -password your_password
  2. 使用配置文件启动客户端 / 服务端 / 透明代理 / 中继(一般模式)

    ./trojan-go -config config.json
  3. 使用 URL 启动客户端(格式参见文档)

    ./trojan-go -url 'trojan-go://[email protected]/?type=ws&path=%2Fpath&host=your-site.com'
  4. 使用 Docker 部署

    docker run \
        --name trojan-go \
        -d \
        -v /etc/trojan-go/:/etc/trojan-go \
        --network host \
        p4gefau1t/trojan-go

    或者

    docker run \
        --name trojan-go \
        -d \
        -v /path/to/host/config:/path/in/container \
        --network host \
        p4gefau1t/trojan-go \
        /path/in/container/config.json

特性

一般情况下,Trojan-Go 和 Trojan 是互相兼容的,但一旦使用下面介绍的扩展特性(如多路复用、Websocket 等),则无法兼容。

移植性

编译得到的 Trojan-Go 单个可执行文件不依赖其他组件。同时,你可以很方便地编译(或交叉编译) Trojan-Go,然后在你的服务器、PC、树莓派,甚至路由器上部署;可以方便地使用 build tag 删减模块,以缩小可执行文件体积。

例如,交叉编译一个可在 mips 处理器、Linux 操作系统上运行的、只有客户端功能的 Trojan-Go,只需执行下面的命令,得到的可执行文件可以直接在目标平台运行:

CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -tags "client" -trimpath -ldflags "-s -w -buildid="

完整的 tag 说明参见 Trojan-Go 文档

易用

配置文件格式与原版 Trojan 兼容,但做了大幅简化,未指定的字段会被赋予默认值,由此可以更方便地部署服务端和客户端。以下是一个简单例子,完整的配置文件可以参见这里

服务端配置文件 server.json

{
  "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",
    "sni": "www.your-awesome-domain-name.com"
  }
}

客户端配置文件 client.json

{
  "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"]
}

可以使用更简明易读的 YAML 语法进行配置。以下是一个客户端的例子,与上面的 client.json 等价:

客户端配置文件 client.yaml

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

WebSocket

Trojan-Go 支持使用 TLS + Websocket 承载 Trojan 协议,使得利用 CDN 进行流量中转成为可能。

服务端和客户端配置文件中同时添加 websocket 选项即可启用 Websocket 支持,例如

"websocket": {
    "enabled": true,
    "path": "/your-websocket-path",
    "hostname": "www.your-awesome-domain-name.com"
}

完整的选项说明参见 Trojan-Go 文档

可以省略 hostname, 但服务端和客户端的 path 必须一致。服务端开启 Websocket 支持后,可以同时支持 Websocket 和一般 Trojan 流量。未配置 Websocket 选项的客户端依然可以正常使用。

由于 Trojan 并不支持 Websocket,因此,虽然开启了 Websocket 支持的 Trojan-Go 服务端可以兼容所有客户端,但如果要使用 Websocket 承载流量,请确保双方都使用 Trojan-Go。

多路复用

在很差的网络条件下,一次 TLS 握手可能会花费很多时间。Trojan-Go 支持多路复用(基于 smux),通过一条 TLS 隧道连接承载多条 TCP 连接的方式,减少 TCP 和 TLS 握手带来的延迟,以期提升高并发情景下的性能。

启用多路复用并不能提高测速得到的链路速度,但能降低延迟、提升大量并发请求时的网络体验,例如浏览含有大量图片的网页等。

你可以通过设置客户端的 mux 选项 enabled 字段启用它:

"mux": {
    "enabled": true
}

只需开启客户端 mux 配置即可,服务端会自动检测是否启用多路复用并提供支持。完整的选项说明参见 Trojan-Go 文档

路由模块

Trojan-Go 客户端内建一个简单实用的路由模块,以方便实现国内直连、海外代理等自定义路由功能。

路由策略有三种:

  • Proxy 代理:将请求通过 TLS 隧道进行代理,由 Trojan 服务端与目的地址进行连接。
  • Bypass 绕过:直接使用本地设备与目的地址进行连接。
  • Block 封锁:不发送请求,直接关闭连接。

要激活路由模块,请在配置文件中添加 router 选项,并设置 enabled 字段为 true

"router": {
    "enabled": true,
    "bypass": [
        "geoip:cn",
        "geoip:private",
        "full:localhost"
    ],
    "block": [
        "cidr:192.168.1.1/24",
    ],
    "proxy": [
        "domain:google.com",
    ],
    "default_policy": "proxy"
}

完整的选项说明参见 Trojan-Go 文档

AEAD 加密

Trojan-Go 支持基于 Shadowsocks AEAD 对 Trojan 协议流量进行二次加密,以保证 Websocket 传输流量无法被不可信的 CDN 识别和审查:

"shadowsocks": {
    "enabled": true,
    "password": "my-password"
}

如需开启,服务端和客户端必须同时开启并保证密码一致。

传输层插件

Trojan-Go 支持可插拔的传输层插件,并支持 Shadowsocks SIP003 标准的混淆插件。下面是使用 v2ray-plugin 的一个例子:

此配置并不安全,仅作为演示

服务端配置:

"transport_plugin": {
    "enabled": true,
    "type": "shadowsocks",
    "command": "./v2ray-plugin",
    "arg": ["-server", "-host", "www.baidu.com"]
}

客户端配置:

"transport_plugin": {
    "enabled": true,
    "type": "shadowsocks",
    "command": "./v2ray-plugin",
    "arg": ["-host", "www.baidu.com"]
}

完整的选项说明参见 Trojan-Go 文档

构建

请确保 Go 版本 >= 1.14

使用 make 进行编译:

git clone https://github.com/p4gefau1t/trojan-go.git
cd trojan-go
make
make install #安装systemd服务等,可选

或者使用 Go 自行编译:

go build -tags "full"

Go 支持通过设置环境变量进行交叉编译,例如:

编译适用于 64 位 Windows 操作系统的可执行文件:

CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags "full"

编译适用于 Apple Silicon 的可执行文件:

CGO_ENABLED=0 GOOS=macos GOARCH=arm64 go build -tags "full"

编译适用于 64 位 Linux 操作系统的可执行文件:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags "full"

致谢

Stargazers over time

Stargazers over time

trojan-go's People

Contributors

bigbighill avatar brlin-tw avatar cecini avatar colachg avatar ducksoft avatar fregie avatar inevity avatar llc1123 avatar loyalsoldier avatar p4gefau1t avatar peter-tank avatar pjfjjl4d avatar soffchen avatar teddysun avatar tokumeikoi avatar weidideng avatar x0d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trojan-go's Issues

上游代理/绑定某个nic

首先非常作者!

请问是否支持将服务端的outbound链接接入某个上游代理或者绑定给某个network interface呢?

ARM架構無法使用websocket???

ubuntu 20.04
raspberry pi 3b+ armv7l 32bit

本來使用trojan,試用trojan-go,將trojan的config file,cp去/etc/trojan-go的路徑,用trojan-go執行它,能成功,但當按照trojan-go文檔,加上websocket後,卻報錯了:

     Loaded: loaded (/lib/systemd/system/trojan-go.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2020-06-01 08:36:16 HKT; 2s ago
       Docs: https://github.com/p4gefau1t/trojan-go
    Process: 6936 ExecStart=/usr/bin/trojan-go/trojan-go -config /etc/trojan-go/config.json (code=exited, status=23)
   Main PID: 6936 (code=exited, status=23)

Jun 01 08:36:16 ubuntu systemd[1]: Started Trojan-Go - An unidentifiable mechanism that helps you bypass GFW.
Jun 01 08:36:16 ubuntu trojan-go[6936]: [INFO]  2020/06/01 08:36:16 Trojan-Go v0.5.1
Jun 01 08:36:16 ubuntu trojan-go[6936]: [INFO]  2020/06/01 08:36:16 Loading config file from /etc/trojan-go/config.json
Jun 01 08:36:16 ubuntu trojan-go[6936]: [ERROR] 2020/06/01 08:36:16 github.com/p4gefau1t/trojan-go/proxy.(*proxyOption).Handle:option.go:38 Failed to parse config file | inval>
Jun 01 08:36:16 ubuntu systemd[1]: trojan-go.service: Main process exited, code=exited, status=23/n/a
Jun 01 08:36:16 ubuntu systemd[1]: trojan-go.service: Failed with result ```

我使用的是說明文檔裡的範例:

https://p4gefau1t.github.io/trojan-go/advance/websocket/

最奇怪的是,當我在config.json裡刪除websocket的代碼,restart trojan-go service,仍然會報錯,我要把原本trojan的config.json,再cp一次去/etc/trojan-go,才能再次正常啟動。

以下為我原本trojan配置檔裡的內容:

{
    "run_type": "server",
    "local_addr": "::",
    "local_port": 443,
    "remote_addr": "::",
    "remote_port": 80,
    "password": [
        "password1",
        "password2"
    ],
    "log_level": 0,
    "ssl": {
        "cert": "/path/fullchain.cer",
        "key": "/path/cert.key",
        "key_password": "",
        "cipher": "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-SHA384",
        "cipher_tls13":"TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
        "prefer_server_cipher": true,
        "alpn": [
            "http/1.1",
            "h2"
        ],
        "reuse_session": true,
        "session_ticket": false,
        "session_timeout": 600,
        "plain_http_response": "",
        "curves": "secp384r1",
        "dhparam": "/etc/nginx/ssl/dhparam.pem"
    },
    "tcp": {
        "prefer_ipv4": false,
        "no_delay": true,
        "keep_alive": true,
        "reuse_port": false,
        "fast_open": true,
        "fast_open_qlen": 20
    },
    "mysql": {
        "enabled": false,
        "server_addr": "127.0.0.1",
        "server_port": 3306,
        "database": "trojan",
        "username": "trojan",
       "password": ""
    }
}

不知道問題出在那,令我用不了websocket,先說聲謝謝幫忙!

远程对接数据库老是掉线

出现一个和原版类似的问题,就是远程对接的数据库,用过一段时间后就不能用

日志也不报错,就是停留在不能使用的那个时候

前端HTTPS也无法访问

已多次出现,不知道是什么原因

Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 conn proxy ends
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 user INVALID_HASH conn to 127.0.0.1:80 closed sent: 106.27 KiB recv: 1.53 KiB
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 conn proxy ends
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 user INVALID_HASH conn to 127.0.0.1:80 closed sent: 61.46 KiB recv: 1.09 KiB
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 conn proxy ends
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 user INVALID_HASH conn to 127.0.0.1:80 closed sent: 99.90 KiB recv: 1.05 KiB
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 conn proxy ends
Mar 22 07:23:12 debian trojan[72243]: [INFO]  2020/03/22 07:23:12 user INVALID_HASH conn to 127.0.0.1:80 closed sent: 135.31 KiB recv: 1.10 KiB
Mar 22 07:23:19 debian trojan[72243]: [INFO]  2020/03/22 07:23:19 buffered data has been written into the database
Mar 22 07:24:03 debian trojan[72243]: [ERROR] 2020/03/22 07:24:03 github.com/p4gefau1t/trojan-go/proxy.(*Server).handleConn:server.go:52 failed to read hash | EOF

[bug] 会无限创建MySQL连接

trojan-go 在mySQL鉴权模式下,会无限创建与数据库的连接,导致数据库过载,拒绝新的连接。但 trojan-go 本身似乎一直在使用之前创建的连接,所以工作正常。

QQ截图20200605111231

已确定是 trojan-go 的原因,因为重启 trojan-go 进程后数据库连接数立即恢复正常。
用的是 master 分支当前最新编译的版本。

能否手动指定配置文件路径

第一次使用,用的trojan-gfw的systemd例子用了,结果启动失败,查看日志才发现找不到配置项。所以能否让用户自定义配置路径呢?谢谢!

More Advanced Router Support

V2ray has a very powerful router, trojan-go also add router functionality recently.
See this link for specific detail about v2ray's router.
It would be nice that trojan-go support v2ray's router rules, for instance, domain:.
As a result, there is no need to use a converter between v2ray and trojan-go rules.
Anyway, thanks for developing such a nice client :).

domain: [ string ]

An array of domains. Available formats are:

Plaintext: If this string matches any part of the targeting domain, this rule takes effet. Example: rule "sina.com" matches targeting domain "sina.com", "sina.com.cn" and "www.sina.com", but not "sina.cn".
Regular expression: Begining with "regexp:", the rest is a regular expression. When the regexp matches targeting domain, this rule takes effect. Example: rule "regexp:\\.goo.*\\.com$" matches "www.google.com" and "fonts.googleapis.com", but not "google.com".
Subdomain (recommended): Begining with "domain:" and the rest is a domain. When the targeting domain is exactly the value, or is a subdomain of the value, this rule takes effect. Example: rule "domain:v2ray.com" matches "www.v2ray.com", "v2ray.com", but not "xv2ray.com".
Full domain: Begining with "full:" and the rest is a domain. When the targeting domain is exactly the value, the rule takes effect. Example: rule "domain:v2ray.com" matches "v2ray.com", but not "www.v2ray.com".
Pre-defined domain list: Begining with "geosite:" and the rest is a name, such as geosite:google or geosite:cn. See Pre-defined domain list for more detail.
Domains from file: Such as "ext:file:tag". The value must begin with ext: (lowercase), and followed by filename and tag. The file is placed in resource directory, and has the same format of geosite.dat. The tag must exist in the file.

X86版本CPU负载很高

X86_CPU负载高.png

因为VPS的内存小,想尽可能的优化内存占用,在Debian 7 X86下,trojan-go跑200M带宽占用了80%的CPU.
然后在Debian 8 X64试了下,发现X64版没有这个问题,占用只在20%左右.
这个是因为32位性能不如64位吗?

[Feature Request] 支持脱离配置通过命令行运行

比如

server:
-type server -local_port 1234 -password 1234 -cert xxxx -key xxxx

client:
-type client -local_port 1234 -password 1234 -remote_addr xxxx -remote_port 1234

这样可以脱离配置文件,一条命令搞定一切。

请问目前透明代理(nat)模式下是否支持UDP转发?

我是用一台linux主机做透明网关, 配置如下

client.json

{
    "run_type": "nat",
    "local_addr": "0.0.0.0",
    "local_port": 7892,
    "remote_addr": "mydomain.com",
    "remote_port": 443,
    "password": [
        "mypassword"
    ],
    "ssl": {
        "sni": "mydomain.com"
    }
}

iptables转发配置

/sbin/ip rule add fwmark 1 table 100
/sbin/ip route add local 0.0.0.0/0 dev lo table 100

iptables -t mangle -N TROJAN
iptables -t mangle -A TROJAN -d 127.0.0.1/32 -j RETURN
iptables -t mangle -A TROJAN -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A TROJAN -d 255.255.255.255/32 -j RETURN
iptables -t mangle -A TROJAN -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A TROJAN -p udp -j TPROXY --on-port 7892 --tproxy-mark 1
iptables -t mangle -A PREROUTING -p udp -j TROJAN

请问在这种配置下是否可以实现udp的透明代理(其实就是是否支持tproxy)?
我测试google voice语音电话可以拨打出去, 但是听不到对方声音, 类似的配置改成v2ray的dokodemo-door, 是正常的可以接听的.

如何禁用配置文件中的密码

原版在使用数据库的情况下将password设置为null即可仅使用数据库的密码

go版这样设置的话启动时会报错 提示无密码

这点文档里好像都没提过 不知道是不是我配置有问题

尝试走cloudflare的cdn失败?

[DEBUG] 2020/04/18 13:44:46 github.com/p4gefau1t/trojan-go/proxy/client.DialTLSToServer:client.go:44 TLS handshaked cipher: TLS_AES_128_GCM_SHA256 resume: false
[ERROR] 2020/04/18 13:44:47 github.com/p4gefau1t/trojan-go/proxy/client.(*Client).handleSocksConn:client.go:165 failed to dail to remote server | failed to start websocket connection | x509: certificate signed by unknown authority

服务端配置好了证书

第一步 申请证书失败了

➜ trojan-go-darwin-amd64 sudo ./trojan-go-darwin-amd64 -cert request Password: [INFO] 2020/04/21 23:00:43 Trojan-Go v0.2.0 initializing [INFO] 2020/04/21 23:00:43 loading config file from /Users/btop/Downloads/trojan-go-darwin-amd64/config.json [ERROR] 2020/04/21 23:00:43 github.com/p4gefau1t/trojan-go/proxy.(*proxyOption).Handle:option.go:34 failed to read config file | open /Users/btop/Downloads/trojan-go-darwin-amd64/config.json: no such file or directory
下载的release版本,按照文档说明执行了一下 提示要找config.json

功能支持

大佬好
可否支持mysql或者api的方式用户管理和流量统计

关于Trojan-Go引入混淆插件的初步设想和讨论

如果不出意外,我们将在未来引入类似Shadowsocks的SIP003的可插拔传输层的混淆插件支持。

shadowsocks/shadowsocks-org#28

引入的目的,是让Trojan协议不再局限于TLS和伪装HTTPS网站,而可以伪装其他流量和服务器。如MySQL流量和MySQL服务器,HTTP流量和HTTP服务器,以及其他土制协议等等。你甚至可以将Shadowsocks,v2ray等作为插件。

此选项是可选的。如果用户选择开启插件功能,Trojan-Go将不再使用TLS作为传输层,而是使用插件作为传输层,内容全部明文传输。由插件来加密和混淆明文,保证信道的安全性和隐蔽性。 开启插件功能后,除了TLS选项失效以外,其他Trojan-Go特性完全可用。其中包括服务端抵抗主动探测的特性。

注意,一旦选择开启插件传输,Trojan-Go将完全信任用户提供的插件的可靠性和安全性,Trojan-Go仅仅做鉴权和抵抗主动探测的工作,而不进行任何加密。

下面是一些解释和设想


最近v2ray已有讨论制订新协议的issue。除去其中的情绪化的部分,我认为讨论的意义还是比较深刻的。

v2ray/v2ray-core#2526

个人的观点是,TLS非常可能是未来穿透防火墙的主力军。但是鸡蛋不能放在一个篮子里。我们不能将战线完全收缩到TLS上,完全放弃其他协议。各类土制协议(不保证密码学安全,但是完全私有的协议)应该得到支持。保持代理协议的多样性,可以大大阻碍防火墙的维护人员,研究学习各类代理,以及部署相应的探测机制,增加审查的难度。因为,防火墙不可能探测和识别一个未公开的、它从来不知道的协议;即使公开,也因为协议数量众多,无法进行有效审查。

简而言之,做一个可能不太恰当的比喻,如果说TLS是正规军,正面对抗防火墙,那么土制协议如同游击队,满地开花。我们的目的,是通过农村包围城市,让防火墙淹没在人民战争的汪洋大海中。

基于以上的观点,Trojan-Go可能在未来引入类似Shadowsocks的可插拔传输层混淆插件。但与其有一些不同。由于Trojan协议本身并不进行加密,且基于Trojan本身的抵抗主动探测的精神来看,合格的插件需要满足下面几个原则:

  1. 插件本身可以对传输内容进行加密,混淆和完整性校验,以及可以抵抗重放攻击

  2. 服务端的插件,在检验到内容被篡改/遭到重放时,必须将此连接交由Trojan-Go处理而不是直接断开,Trojan-Go将此连接重定向到配置文件中预设的端口上

其中第二点的设计目的,与HTTPS站点伪装的目的类似。

为了方便理解,举一个例子。

  1. 假设你的插件伪装的是MySQL流量。防火墙通过流量嗅探,发现你的MySQL流量大得异常,决定主动连接你的服务器进行主动探测。

  2. 防火墙连接到你的服务器并发送探测载荷,你的Trojan-Go服务端插件,经过校验,发现这个异常连接不是代理流量,于是将这个连接交由Trojan-Go处理。

  3. **Trojan-Go发现这个连接异常,将这个连接重定向到一个真正的MySQL服务器上。**于是,防火墙开始与一个真正的MySQL进行交互,发现其行为与真实MySQL服务器无异。

于是自始至终,防火墙无法判断你的服务器是否是Trojan-Go服务器。因为被动探测(流量嗅探)来看,你的流量是MySQL流量。主动探测来看,你的服务器行为就是MySQL的行为。

如果大家有更好的想法,建议或者意见,都可以在下方进行讨论。

请问下必须先TLS然后在WS吗?

我本身的配置是ok的,使用websocket,可以正常访问,然后套了一个cdn,就不行了,我尝试调整cdn的模式,调整为回源,也可以访问,我在服务器上架一个简单的websocket服务器,可以通过cdn中转,可以设置为直接ws然后ws里面TLS加密之类的吗?(可否去掉最外层的SSL)

请问如何后台自启

因为tg群 显示 无法进入,
所以只能来这里询问问题

1、如何把运行命令,后台运行+开机自启

2、如何禁用日志,我看见服务器运行后,上网会出现info,请问可以禁用不显示吗?

关于自动 ssl

简单看了一下代码,发现 ssl 自动那个不太自动。
是否可以实现像 caddy 那样的?提供域名就行,启动caddy后就自动获取证书了。

好像有些难度,我不了解 trojan 协议,能否这样改:

用 http 监听端口,用 certmagic 或者 autocert 获取证书,然后在 http.Handler 里面 hijack 拿到 connection, 再处理 trojan 协议。
这样再外层就是一个 http server, 不是现在的 trojan tcp server. 不知道是否可行。
@p4gefau1t

Suggestions for improving trojan:// url format

For now, trojan-go use trojan-gfw compatible trojan:// uri to pass client-side configuration. I would like to suggest that trojan-go design an extension format to support trojan-go specific features. Here is my rough draft.

Current format

trojan://[password]@[host]:[port]?peer=[server_name]#[remark (url encoded)]

Draft

  1. keep the trojan:// uri scheme
  2. stay #peer= # at the end of the url
  3. pass trojan-go specific arguments after "?" (just like http url)
  4. separate arguments with "&"
trojan://[password]@[host]:[port]?wss=[bool]&mux=[bool]&peer=[server_name]#[remark (url encoded)]

Reference

https://github.com/trojan-gfw/trojan-url

Failed to parse config file open

config.json file is following:

{
"run_type": "client",
"local_addr": "127.0.0.1",
"local_port": 1080,
"remote_addr": "dj.itu.me",
"remote_port": 443,
"password": [
"1100981"
],
"ssl": {
"cert": "",
"sni": ""
}
}

image

trojan-go似乎只绑定ipv6地址,没有绑定ipv4

分别试验了trojan和trojan-go,
trojan在同时有ipv6和ipv4情况下,会按照设置内容绑定0.0.0.0:443
trojan-go在同时有ipv6和ipv4情况下,会绑定:::443,也即ipv6端口,ipv4没有绑定,端口仍然是空的未占用状态
已经使用netstat查看,不存在其他软件占用443端口,trojan和trojan-go没有同时启动,是分别试验的,配置除了trojan-go的一些特性以外,其他都是一样的

kill 掉进程之后,再启动报错

kill 掉进程之后报错
unexpected fault address 0x0
fatal error: fault
[signal SIGBUS: bus error code=0x1 addr=0x0 pc=0x110021d0001761]

goroutine 1 [running, locked to thread]:
runtime.throw(0x5da897, 0x5)
/snap/go/5569/src/runtime/panic.go:1114 +0x54 fp=0x400005edb0 sp=0x400005ed80 pc=0x40a24
runtime.sigpanic()
/snap/go/5569/src/runtime/signal_unix.go:692 +0x424 fp=0x400005ede0 sp=0x400005edb0 pc=0x57184
go.starlark.net/starlark.init()
/home/p4gefau1t/go/pkg/mod/[email protected]/starlark/int.go:161 +0x58 fp=0x400005ee50 sp=0x400005edf0 pc=0x4770e8
runtime: unexpected return pc for runtime.doInit called from 0x0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.