Redis Webshell Write – Planting a Shell via File Write
When Redis runs on a host that also serves a web application, you can redirect the Redis DB save path to the web root and write a webshell. The Redis RDB file format adds garbage bytes around your payload, but PHP, JSP, and other interpreters parse and execute only valid code: the garbage is ignored. A single PHP tag embedded in an otherwise corrupt file is enough. Prerequisites for this technique:
- CONFIG access to change
diranddbfilename - A web server running on the target (Apache, Nginx, Tomcat)
- A known or guessable web root path
- Redis process has write permission to the web root
Prerequisites Check
1 - CONFIG access:
Must return a path.
2 - A web server is running on the target:
Confirm HTTP/HTTPS ports are open.
3 - You know or can guess the web root path:
Common web roots to try:
/var/www/html
/var/www
/usr/share/nginx/html
/srv/www/htdocs
/opt/lampp/htdocs
/var/www/html/wordpress
/var/www/html/uploads
Test each:
OK
OK confirms Redis can write there.
4 - The web server interprets the file type you write: Know whether the target runs PHP, JSP, ASP, or another interpreted language. Match the webshell format to the server.
Step 1 - Record Original Config
Step 2 - Write the Webshell Payload
Flush existing data to minimise file corruption:
Shells:
Step 3 - Save to Web Root
Confirm the save completed:
Step 4 - Trigger the Webshell
For the command parameter webshell:
The output will contain Redis RDB garbage around it: look for your command output embedded in the response.
For a reverse shell, start your listener first:
Or trigger a bash reverse shell via the command parameter:
Step 5 - If the Webshell Returns Garbage Only
The RDB header and footer corrupt small payloads. Try a larger PHP comment padding to push the valid PHP code away from the binary garbage:
Or empty the DB first, set only the shell key, and save immediately before any other writes corrupt the file:
Step 6 - Restore Original Config
Delete the webshell:
Or from a shell on the target:
References
-
Redis PentestingTOOL: Redis Pentesting, book.hacktricks.xyz/network-services-pentesting/6379-pentesting-redis (opens in new tab)
HackTricks Webshell write technique and web root path enumeration guidance.