Heyiwei/LTM2 TLP:CLEAR

Linux RAT · Malware analysis

Heyiwei / LTM2

A bespoke, encrypted command-and-control backdoor — reverse-engineered from the wire format down to the key schedule.

Heyiwei is a ground-up custom, multi-architecture Linux backdoor that spreads to IoT and Linux hosts through an ADB/telnet stager. It is not Mirai or Gafgyt. It carries its own named, fully engineered encrypted transport — LTM2 — built from X25519 key exchange, a keyed-BLAKE2b key schedule, and XChaCha20-Poly1305 authenticated records. It had run roughly a year with no public documentation and near-zero antivirus coverage before it was caught.

0​/75 on VirusTotal (i686 build) 11 architecture builds X25519 · XChaCha20-Poly1305 · BLAKE2b 4 services · 0 flood primitives ~1 year undocumented

01 · Lineage

Why it isn’t Mirai

The generic trojan.mirai label is exactly what lets a serious custom implant pass as commodity noise. The distinction is structural, not stylistic: Heyiwei shares no strings, config format, or attack-table layout with either common family. Where they use a byte-XOR table or plaintext ASCII, it uses real asymmetric cryptography.

TraitMiraiGafgyt / BashliteHeyiwei / LTM2
Configsingle-byte XOR tableplaintextX25519 + BLAKE2b schedule
C2 transportnear-plaintext TLVplaintext ASCIIXChaCha20-Poly1305 AEAD
Command setDDoS attack tableflood methodsshell / exec / push / pull
Shared stringsyes, well-knownyes, well-knownnone

Automated triage first flagged “Speck / Salsa20 / RC4.” Those were false positives — Salsa20’s quarter-round is structurally identical to ChaCha’s, and the “RC4” 256-byte buffer is locale parsing, not a cipher. The real stack, confirmed by the constants and the label strings left in the clear, is X25519 + XChaCha20-Poly1305 + keyed BLAKE2b — the shape of Monocypher.

02 · Transport

The LTM2 handshake

LTM2 is a compact, Noise-flavored channel: ephemeral elliptic-curve key exchange, a transcript-bound key schedule, then per-direction authenticated records. The whole protocol was recovered from the un-obfuscated x86-64 build and cross-checked against bytes captured from a running sample in an isolated lab.

CLIENT · bot SERVER · C2 LTM2CHLO · 104 B ephemeral X25519 pub · bot-ID · nonce LTM2SHLO · 72 B ephemeral X25519 pub · nonce X25519 shared secret keyed-BLAKE2b schedule → per-direction key + IV XChaCha20-Poly1305 records per-direction sequence · strict anti-replay
Two round trips establish an authenticated, per-direction channel. Everything after the server-hello is encrypted; the only fixed markers on the wire are the two 8-byte magics.

Client-Hello byte layout

Confirmed against a live 104-byte capture — the sample resolved its C2 to a lab sink and sent this before any reply:

OffsetLenField
08"LTM2CHLO" magic
830bot-ID — ASCII hex token from getrandom, fresh per infection
38200 00 — pad to 32
4032nonce
7232X25519 ephemeral public key

The identity field is the human-readable per-device bot-ID, null-padded — not an opaque blob. The Server-Hello mirrors it at 72 bytes: "LTM2SHLO" | nonce[32] | server_pub[32].

03 · Key schedule

Where “bespoke” stops being an opinion

This is the heart of the family. Below is the key derivation straight out of the decompiled x86-64 build — decompiler names kept, primitives annotated. The shared secret is used as the key of a keyed hash, and the entire client-hello and server-hello are absorbed into the master, binding every session key to the exact handshake transcript.

ghidra x86-64 build · key schedule decompiled
/* master = BLAKE2b( key = X25519 shared secret,
                     data = "LTM2 session master" || CHLO || SHLO ) */
FUN_00407587(ctx, 0x20, shared, 0x20);                 // keyed init, key = 32-byte shared secret
FUN_004076c7(ctx, "LTM2 session master", 0x13);        // absorb 19-byte label
FUN_004076c7(ctx, chlo, 0x68);                         // absorb the full 104-byte CHLO
FUN_004076c7(ctx, shlo, 0x48);                         // absorb the full  72-byte SHLO
FUN_004076d6(ctx, master);                             // finalize -> 32-byte session master

/* two 48-byte directional secrets, each keyed by the master */
FUN_0040775b(c2s, 0x30, master, 0x20, "LTM2 client to server", 0x15);  // -> key[32] | iv[16]
FUN_0040775b(s2c, 0x30, master, 0x20, "LTM2 server to client", 0x15);  // -> key[32] | iv[16]

A clean-room reimplementation reproduces it exactly — same labels, same transcript binding, same split into a 32-byte key and 16-byte IV per direction:

python reconstructed schedule verified
master = blake2b(b"LTM2 session master" + chlo + shlo, key=shared, digest_size=32)
c2s    = blake2b(b"LTM2 client to server",             key=master, digest_size=48)
s2c    = blake2b(b"LTM2 server to client",             key=master, digest_size=48)
# key, iv = dir[:32], dir[32:48]   (per direction)

This is competent, modern cryptographic engineering — the opposite of a reused XOR byte, and nothing any IoT-bot family ships.

04 · Records

Framing and the application layer

Every post-handshake byte is one AEAD record. Header integers are big-endian — the single ordering that makes the whole thing validate — and the 12-byte header is reused verbatim as the authenticated associated data.

wire AEAD record
record = [ len:u32 BE ] [ seq:u64 BE ] [ tag:16B Poly1305 ] [ XChaCha20( type || payload ) ]
         └──────── 12-byte header = AEAD associated data ────────┘
         len   = len(payload) + 1          // +1 is the type byte
         nonce = dir_IV[0:16] || seq(BE,8)  // HChaCha20 subkey from IV, 8-byte inner nonce
         seq   per-direction, from 0, strictly incrementing  // anti-replay

Inside the AEAD the application protocol is binary: one type byte, then a payload. The design is SSH-connection-shaped — channels, windows, exit status — not a botnet’s flat command list. Only one channel is open at a time.

TypeDirMeaningPayload
0x01c→sbeaconhost=… arch=… kernel=… uid=…
0x02s→cack (required or bot aborts)empty
0x03/04s→c / c→sping / pongempty
0x0As→copen shell — PTY /bin/sh -i8-byte winsize
0x0Bs→copen exec — /bin/sh -ccommand, NUL-term
0x0Cs→copen push — write file[hdr][dest\0]
0x0Ds→copen pull — read filesrc path\0
0x14bothdataraw channel bytes
0x16/17s→cfile-commit / eofsize + BLAKE2b-256
0x19c→schannel exit4-byte status
05 · Validation

The break

The key schedule was not guessed — it was proven. A lab LTM2 server (pure reimplementation of X25519, keyed BLAKE2b, and XChaCha20-Poly1305, self-tested against RFC 7748 / 8439 and the XChaCha vectors) was stood up to talk only to a captured sample in an isolated victim VM. It completed the handshake, derived the session keys, and read the traffic.

The Poly1305 tag verified on the very first record.

A wrong key schedule fails the MAC. A first-try verification means every label, length, endianness, and nonce construction is exactly right — the whole scheme is recovered.

decrypted type-1 beacon · lab
seq=0  type=1 (beacon)  len=61
host=<hostname> arch=i686 kernel=5.4.0-216-generic uid=0\x00

All four services were then exercised end-to-end against the sample: interactive shell, one-shot exec, and file push/pull — the last two each carrying an unkeyed BLAKE2b-256 integrity trailer, with push staged to a temp name and atomically renamed only after the hash checks out.

06 · Capabilities

A four-service RAT — and no flood code

The decrypted channel offers exactly four services: interactive shell, one-shot exec, file push, and file pull. The “no DDoS” finding is confirmed, not assumed — a complete inventory of every socket call site found only C2 TCP, the DNS resolver, and one local Unix socket:

// socket() call sites, x86-64 build — complete inventory
no SOCK_RAW        no IP_HDRINCL      no bind / listen / accept
no flood loop      no attack dispatch  no rival-bot kill-list
only: C2 TCP  ·  DNS resolver (UDP/TCP)  ·  one AF_UNIX

Port 25565 is simply the C2 port — it blends with Minecraft traffic and the mc. subdomain is camouflage, not evidence of a booter. The net threat is heavier than a flood bot: a persistent, encrypted, interactive foothold with arbitrary file read and write on every infected device.

07 · Build & persistence

Tradecraft

Static, stripped ELF built with GCC 15.2.0 on a current 2025 Ubuntu toolchain, in 11 architectures (x86-64, i686, i586, aarch64, ARM v4l–v7l, MIPS, MIPSEL). The x86-64 build was not string-obfuscated the way the 32-bit builds are — which is how the config, the persistence paths, and the LTM2 label strings were readable in the first place. The loader calls itself “Heyiwei stager v3”; its author’s own English developer comments reference a prior run on a 54-device list and a MIPS-endianness bug they fixed — a competent, iterating operator.

Persistence is comprehensive and multi-init: systemd, SysV + rcS, OpenRC, OpenWrt rc.common, and a custom control script. It installs to /usr/local/bin/Heyiwei, single-instances on /tmp/Heyiwei.lock, and masquerades in the process table as the kernel thread khungtaskd.

08 · Detection

Signatures

The two 8-byte handshake magics are the one reliable fixed marker on an otherwise fully encrypted channel. Port-agnostic, since the C2 can move off 25565. The CHLO rule was confirmed exact against a live 104-byte Client-Hello.

suricata ltm2.rules
alert tcp any any -> any any (msg:"Heyiwei/LTM LTM2 C2 client-hello";
    flow:established,to_server; dsize:104; content:"LTM2CHLO"; depth:8;
    classtype:trojan-activity; sid:9500001; rev:1;)
alert tcp any any -> any any (msg:"Heyiwei/LTM LTM2 C2 server-hello";
    flow:established,to_client; dsize:72;  content:"LTM2SHLO"; depth:8;
    classtype:trojan-activity; sid:9500002; rev:1;)

A passive dissector parses the handshake and walks the AEAD framing for triage. It cannot decrypt — session keys are per-connection ephemerals — but it reliably identifies and structures an LTM2 stream from a single direction of capture.

09 · Indicators

Indicators of compromise

C2
mc.heyiwei.net · TCP 25565   (apex heyiwei.net parked 185.53.179.146 / .128, 199.59.243.228; NS *.dyna-ns.net)
Protocol magic
LTM2CHLO (104 B → server) · LTM2SHLO (72 B → client)
Host artifacts
/usr/local/bin/Heyiwei · /tmp/Heyiwei.lock · /etc/ltm/Heyiwei-control · Heyiwei.service · env HEYIWEI_SERVICE=1 · proc name khungtaskd
Delivery
loader on :8080 colocated with the C2; second loader 143.246.56.120:8080; delivered by 45.144.52.239 (H2NEXUS Cloud, UAE)
Sample · x86-64
62e2b8a6c75cde2ec395c34ac5055be0d0c51d796e93d37b2f1681a833693896
Sample · i686
cc1b33edd4b08c51884b3e8da0d1536fa531a7119e6ab08e5d3a29b0c91188e5