On this page
Facts
What it is
Proxy hidden inside TLS
Since, by
2017, the trojan-gfw project
Transport
TCP with TLS; UDP framed inside it
Encryption
TLS only, nothing of its own
To the network it looks like
An HTTPS website with a valid certificate
Usual port
443/TCP
Comes as
trojan:// link
License
GPL-3.0 (trojan-gfw, Trojan-Go)
Latest release
trojan v1.16.0, June 10, 2020
In Veli
Windows, macOS, Linux, Android · link
Own server from the app
No
Versions and history
- 2017
trojan-gfw
The first release, 0.1.0, came out in October 2017: a C++ program built on OpenSSL. Version 1.0.0 followed in March 2018.
- 2020
Trojan-Go; last trojan-gfw release
Trojan-Go, a rewrite in Go, started in March 2020 and added WebSocket, multiplexing and an optional Shadowsocks layer. trojan-gfw 1.16.0 in June 2020 is the original's last release.
- 2021
Trojan-Go 0.10.6
The last Trojan-Go release, September 2021. The protocol lives on in Xray, V2Ray, sing-box and mihomo.
- 2022
Blocking in China
From 3 October 2022 users in China reported TLS-based servers, Trojan among them, blocked first by port and then by IP address (GFW Report).
- 2023
Trojan-killer
In May 2023 the Xray team published Trojan-killer, a demo that flags TLS inside TLS in Trojan traffic.
- 2024
TLS-in-TLS study
A USENIX Security 2024 paper detected about 74% of Trojan connections by the handshake inside them, 18% with multiplexing on.
How Trojan works
Trojan adds no encryption of its own: TLS does all of it. The client opens a normal TLS connection, checks the certificate as a browser would, and sends one request inside, made of the parts listed below.
What makes Trojan hard to probe is what happens to everything else. If the hash is wrong, or the bytes are not a Trojan request at all, the server passes the decrypted stream to a real web server, by default 127.0.0.1:80, so a browser or a probe gets a website. Xray applies the rule byte by byte: a first packet shorter than 58 bytes, a 57th byte that is not \r, or an unknown password all go to the fallback.
UDP rides inside the same TLS stream: after a UDP ASSOCIATE request each packet is framed as address, port, a two-byte length, CRLF and the data. Games and calls work, but on a lossy line they wait for lost packets like any TCP traffic.
- Password hash: SHA-224 of the password as 56 hex characters, then CRLF. The server keeps a list of passwords, so several people can share one port.
- Command: one byte,
01for CONNECT (TCP) or03for UDP ASSOCIATE. - Destination: address type, address and port in the SOCKS5 format, then CRLF.
- Payload: the first data follows at once, without waiting for a reply.
A trojan:// link, field by field
The original project only drafted the form trojan://password@host:port and never finalised it. The query parameters were added later by clients and use the same names as VLESS links, so most apps read the same set. The values below are made up.
trojan://p4ssw0rd@vpn.example.com:443?security=tls&sni=vpn.example.com&fp=chrome&type=ws&host=vpn.example.com&path=%2Ftr#Server-1- p4ssw0rd: the password, percent-encoded if it has special characters (
%40for @). There is no user name: whoever has the link can use the server. - vpn.example.com:443: server and port. 443 is the norm, because that is where HTTPS lives.
- security=tls: write it out, since not every client assumes TLS when it is missing. Some apps also accept
realitywithpbkandsid. - sni: the name sent in the TLS handshake. It must match the certificate.
- fp and alpn: the browser whose handshake the client imitates, and the protocols it offers.
- type: the transport,
tcpif omitted, orws,grpc,httpupgrade,xhttpwith theirhost,pathorserviceName. - allowInsecure=1: skip the certificate check. Current Xray refuses it and wants
pcs, the SHA-256 of the certificate, instead. - #Server-1: only the name in the list.
Server programs and transports
A Trojan server needs a domain that points to it, a valid certificate for that domain, a website behind it for strangers, and usually TCP port 443. The certificate is the disguise itself: a self-signed one stands out and has to be allowed in every client by hand.
The two programs written for Trojan no longer get releases, while the protocol lives on in general-purpose cores, V2Ray among them. Trojan-Go writes trojan-go:// links when a server uses its own features, such as WebSocket or the Shadowsocks layer, so that the original program doesn't try to open them.
trojan-gfw (C++)
StateLast release 1.16.0, June 2020
TransportsTCP with TLS
ExtrasFallback to
remote_addr, HTTP/2 visitors to a separate portTrojan-Go
StateLast release 0.10.6, September 2021
TransportsTCP, WebSocket
ExtrasMultiplexing, Shadowsocks AEAD layer,
trojan-go://linksXray
StateMaintained
TransportsTCP, WebSocket, gRPC, HTTPUpgrade, XHTTP and others
ExtrasFallbacks as in VLESS; no Vision flow for Trojan
sing-box
StateMaintained
TransportsTCP, WebSocket, gRPC, HTTP, HTTPUpgrade, QUIC
ExtrasMultiplexing; gRPC only in builds that include it
mihomo (Clash Meta)
StateMaintained
TransportsTCP, WebSocket, gRPC
ExtrasReads Trojan-Go's Shadowsocks layer (
ss-opts)
What a censor sees
From outside, a Trojan connection is a TLS session: the server's IP address, the port and the domain in SNI are visible, the rest is encrypted. A filter that blocks the domain or the address doesn't need to recognise Trojan at all; what can give Trojan away is the shape of the session.
The client's handshake. trojan-gfw makes its TLS handshake with OpenSSL, not like a browser. Xray and sing-box can imitate a browser through uTLS (fp), and Xray imitates Chrome by default. When servers running Trojan, V2Ray and Xray over TLS were blocked in China from 3 October 2022, first by port, mostly 443, then sometimes by IP address, GFW Report suspected the client's TLS fingerprint but said this was not measured (net4people issue 129).
TLS inside TLS. When a browser opens an HTTPS site through Trojan, a second handshake travels inside the first, and its packet sizes and round trips show through the encryption. In May 2023 the Xray team released Trojan-killer, a demo that flags this. Xue et al. (USENIX Security 2024) measured it on Merit, a US network, in March 2023: 73.7% of Trojan-Go flows over TLS were detected at a false positive rate of 0.054%, and 17.9% when eight streams shared one connection.
Probing. Junk or a wrong password gets the fallback website, so probing alone finds a web server. How the Great Firewall itself picks out Trojan is not public: no paper describes it the way GFW Report did for Shadowsocks, and the 2022 reports are observations by users.
Trojan the protocol and Trojan the malware
Search results for this word are mostly about viruses. A quick way to tell which one is in front of you:
A
trojan://link, ortype: trojanin a Clash fileWhat it isA server of the Trojan proxy protocol
What to doPaste it into a client that supports Trojan
Trojan:Win32/…in Windows SecurityWhat it isMalware: in Microsoft's names the first word is the kind of threat
What to doLet the antivirus remove it and run a full scan
trojan.exeortrojan-go.exein a proxy client's folderWhat it isThe original programs of the protocol
What to doCompare the file with the project's release on GitHub
If a trojan:// link doesn't connect
Connected, but no site opens, or an HTTP answer instead of data
CauseWrong password: the server treats you as a visitor of its website
What to doCopy the link again, whole
x509: certificate has expired or is not yet validCauseThe certificate ran out, or the device's clock is wrong
What to doTurn on automatic time; if it stays, tell whoever runs the server
x509: certificate signed by unknown authorityCauseA self-signed certificate
What to doAsk for a real one or for its SHA-256 to pin
Works over
tcp, not overwsCause
pathorhostdoesn't match the serverWhat to doCompare them with the server's settings
Strengths and weaknesses
Strengths
- Looks like an ordinary HTTPS site with a valid certificate, and a stranger who knocks gets that site.
- Simple: a password and TLS, with no cryptography of its own to get wrong.
- Every major core speaks it: Xray, V2Ray, sing-box and mihomo, and the apps built on them.
- Carries UDP inside the same connection, so it works wherever TCP to port 443 does.
Weaknesses
- TLS inside TLS shows in packet sizes: 74% of flows were detected in the 2024 study without multiplexing.
- Needs a domain, a certificate and a website behind the server.
- Runs over TCP, so packet loss slows everything down, UDP included.
- The programs written for it stopped getting releases in 2020 and 2021.
Where it works
Programs and servers from our comparison tables that list this protocol.
Clients
- Happ
- Hiddify
- v2RayTun
- INCY
- Karing
- v2rayNG
- v2rayN
- NekoBox for Android
- NekoRay
- Throne
- V2Box
- AmneziaVPN
- Clash Verge Rev
- Clash Party
- FlClash
- Shadowrocket
- Stash
- mihomo
- sing-box
- podkop
- PassWall
- PassWall 2
- OpenClash
Servers and panels
- 3X-UI
- Marzban
- Remnawave
- S-UI
- Hiddify Manager
Sources
- trojan-gfw docs: the Trojan protocol
- Trojan-Go docs: URL scheme draft
- Xray docs: Trojan inbound and fallbacks
- sing-box docs: Trojan outbound
- Xray share link standard: the VLESS link fields
- GFW Report: large scale blocking of TLS-based tools in China, October 2022
- Xue et al., USENIX Security 2024: encapsulated TLS handshakes
- XTLS Trojan-killer: a TLS in TLS detection demo