An unexpected Redis sandbox escape affecting Debian-based distros
A sandbox escape in Redis on Debian-based distributions allowed an attacker with access to the eval command to execute arbitrary operating system commands. This was possible because the Lua package variable was not removed, enabling loading of the os library.
ubercomp.com
Published on ubercomp.com
This post describes how I broke the Redis sandbox, but only for Debian and Debian-derived Linux distributions. Upstream Redis is not affected.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could execute arbitrary code on the machine running Redis, but only on Debian-based distributions; upstream Redis is not affected.
What the attacker needed
Redis on Debian-based distro; Access to eval command
The fix
The fix was to add package=nil to the end of the Lua initialization in the Debian build script.
How it was found
- Connect to a Redis server on a Debian-based system.
- Use the eval command to run a Lua script that loads the os library via package.loadlib.
- Call os.execute to run a system command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Redis is a database that lets you run small scripts written in the Lua language. Normally, these scripts are sandboxed so they cannot run system commands. On Debian and Ubuntu, a mistake left a backdoor open, letting anyone who can send commands to Redis run programs on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.