Redis Persistence via CONFIG SET
Redis's CONFIG SET command lets you change the working directory and the RDB dump filename at runtime. If Redis runs as a privileged user and you have command access, you can write arbitrary files to the filesystem — including SSH authorized keys, cron jobs, and webshells.
This technique requires either unauthenticated access or a known Redis password. No Redis client libraries needed — redis-cli and raw TCP work.
Check Write Capability
Before attempting, confirm Redis will actually write the file — test with a throwaway path:
If no permission errors, Redis can write files. The actual content will be wrapped in RDB format markers — the payload needs to survive them (SSH keys and cron jobs tolerate this; binary payloads do not).
Write SSH Authorized Keys
This is the cleanest approach — places your public key in the target user's authorized_keys so you can SSH in persistently.
Generate a key pair on your attacker box:
Write the public key to Redis with newlines padding to survive RDB markers:
Point Redis at the target user's .ssh directory:
Verify it worked, then connect:
If Redis does not run as root, try /home/$USER/.ssh based on the running process owner. Check with:
Write a Cron Job
Place a cron entry that calls back with a reverse shell. The RDB file format includes extra bytes, but cron ignores lines it cannot parse — the payload line survives.
Start a listener:
Write a cron file:
The cron file will be owned by Redis's process user. If Redis runs as root, this gives you a root cron entry. Wait up to 60 seconds for the first execution.
On systems using /etc/cron.d instead:
The cron syntax in /etc/cron.d requires a username field:
Write a Webshell
If a web server is running on the same host and you can identify the webroot path, write a PHP or other shell:
Trigger it:
The RDB markers around the PHP code will cause some garbage output before and after the command result, but the shell executes correctly.
Common webroot paths to try: /var/www/html, /var/www, /srv/http, /usr/share/nginx/html.
Authenticated Redis
If Redis requires a password, prepend -a $PASSWORD to all commands:
Or authenticate inline:
Clean Up
After establishing the real persistence mechanism, remove the key you set to avoid leaving obvious indicators:
Restore the original dir and dbfilename to avoid breaking Redis's normal operation:
References
-
Official CONFIG SET documentationredis.io/docs/latest/commands/config-set (opens in new tab)
-
CLI usage and connection optionsredis.io/docs/latest/develop/tools/cli (opens in new tab)
Was this helpful?
Your feedback helps improve this page.