GithubHelp home page GithubHelp logo

p4gefau1t / trojan-go Goto Github PK

View Code? Open in Web Editor NEW
7.4K 7.4K 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%
anticensorship china gfw go golang network privacy proxy tls transparent-proxy trojan-gfw trojan-go tunnel

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

功能支持

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

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

X86版本CPU负载很高

X86_CPU负载高.png

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

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

原版在使用数据库的情况下将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

服务端配置好了证书

请问如何后台自启

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

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

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

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的一些特性以外,其他都是一样的

第一步 申请证书失败了

➜ 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

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

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

关于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的行为。

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

[bug] 会无限创建MySQL连接

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

QQ截图20200605111231

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

远程对接数据库老是掉线

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

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

前端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

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

[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

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

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.

请问目前透明代理(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, 是正常的可以接听的.

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,先說聲謝謝幫忙!

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

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

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

关于自动 ssl

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

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

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

上游代理/绑定某个nic

首先非常作者!

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

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.