Trojan protocol: how it works, trojan:// links and detection

Trojan is a proxy protocol that runs inside an ordinary TLS connection, so its server looks like an HTTPS website with a real certificate. The client proves itself with a hash of a password, and anyone who comes without it is handed to a real web server. It shares only a name with Trojan malware.

Updated

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

  1. 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.

  2. 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.

  3. 2021

    Trojan-Go 0.10.6

    The last Trojan-Go release, September 2021. The protocol lives on in Xray, V2Ray, sing-box and mihomo.

  4. 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).

  5. 2023

    Trojan-killer

    In May 2023 the Xray team published Trojan-killer, a demo that flags TLS inside TLS in Trojan traffic.

  6. 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, 01 for CONNECT (TCP) or 03 for 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.

Example
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 (%40 for @). 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 reality with pbk and sid.
  • 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, tcp if omitted, or ws, grpc, httpupgrade, xhttp with their host, path or serviceName.
  • 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 port

  • Trojan-Go

    StateLast release 0.10.6, September 2021

    TransportsTCP, WebSocket

    ExtrasMultiplexing, Shadowsocks AEAD layer, trojan-go:// links

  • Xray

    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, or type: trojan in a Clash file

    What it isA server of the Trojan proxy protocol

    What to doPaste it into a client that supports Trojan

  • Trojan:Win32/… in Windows Security

    What 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.exe or trojan-go.exe in a proxy client's folder

    What 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 valid

    CauseThe 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 authority

    CauseA self-signed certificate

    What to doAsk for a real one or for its SHA-256 to pin

  • Works over tcp, not over ws

    Causepath or host doesn't match the server

    What 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

Compare these programs

Sources

How we write and check

In Veli

Trojan in Veli

Paste a trojan:// link into Profiles → Add: the app names the protocol under the field and makes a profile with the name from the link. Subscriptions with trojan:// lines are read the same way. Trojan connects on Windows, macOS, Linux and Android, and the rules of Apps and sites work on it.

On a computer it runs on the sing-box module, and links with xhttp or mKCP on Xray; the app offers to install what is missing. On Android a link with allowInsecure=1 and no certificate fingerprint is refused, and the app says why. Veli doesn't install Trojan on your own server: from the app you can install VLESS Reality, AmneziaWG, WireGuard, Shadowsocks and OpenVPN there.

Questions

Is Trojan VPN a virus?

No. Trojan is a proxy protocol with an unlucky name, and a trojan:// link is plain text that can't run anything. Names like Trojan:Win32 in an antivirus report are malware and have nothing to do with it.

Can the Great Firewall detect Trojan?

It can be found without breaking TLS. TLS-based servers, Trojan among them, were blocked in China from October 2022, and a 2024 study detected about 74% of Trojan flows by the TLS handshake inside them. Multiplexing lowers that, but doesn't remove it.

Trojan vs VLESS: what is the difference?

Both run inside TLS and both need a domain for a real certificate. Trojan checks a password; VLESS checks a UUID, has the Vision flow against TLS inside TLS and can run over Reality without a domain. A trojan:// link you were given works as it is.

Does Trojan support UDP?

Yes. After a UDP ASSOCIATE command, UDP packets travel inside the same TLS connection, each with its address and length. On a lossy line they wait for retransmissions like any TCP traffic.

What is Trojan-Go and is it still maintained?

A rewrite of Trojan in Go from 2020 that added WebSocket, multiplexing and an optional Shadowsocks layer. It reads ordinary trojan:// links, but its last release was 0.10.6 in September 2021.

Does Trojan need a domain?

Yes, for a valid certificate. Without one the server needs a self-signed certificate that every client has to be told to trust, or to pin by its SHA-256.