Skip to content
SSRF Write-up Advanced

Known-Plaintext Attack on PHP-Proxy: From Broken Encryption to FastCGI RCE

PHP-Proxy encrypts URLs with a Caesar cipher, allowing an attacker to recover the encryption key from a single known plaintext-ciphertext pair. With the key, the attacker can craft encrypted SSRF payloads to read local files and, if PHP-FPM listens on a TCP socket, achieve remote code execution via the gopher protocol.

mf-akbar Follow

Published on mf-akbar.medium.com

I discovered PHP-Proxy while researching web proxy implementations. The project caught my attention because, despite being abandoned by its developers, I noticed numerous active deployments still running in production environments.

Muh. Fani Akbar, on mf-akbar.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application used a Caesar cipher (a monoalphabetic substitution) to encrypt URLs instead of a secure authenticated encryption scheme, making key recovery trivial from a known plaintext-ciphertext pair.

Impact

An attacker could read local files and, if PHP-FPM listens on a TCP socket, execute arbitrary commands as the web server user.

What the attacker needed

PHP-Proxy instance accessible; Ability to submit a URL via the form; PHP-FPM listening on a TCP socket (for RCE)

The fix

The application should use authenticated encryption like AES-256-GCM with a random IV for each encryption operation.

How it was found

  1. Submit a known URL through the normal form interface and capture the encrypted value from the redirect's Location header.
  2. Use the known plaintext and ciphertext with the str_rot_pass function to recover the encryption key.
  3. Encrypt a malicious URL (e.g., file:///etc/passwd) with the recovered key and submit it directly to the /?q= parameter.
  4. For RCE, craft a FastCGI binary packet that sets PHP_VALUE to auto_prepend_file = php://input and includes PHP code to execute, then encode it as a gopher:// URL to [redacted]:9000.
  5. Encrypt the gopher URL with the recovered key and submit it to /?q= to trigger command execution.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

PHP-Proxy is a tool that lets you browse other websites through its own server. It hides the real address by scrambling it with a very old and weak method called a Caesar cipher, which just shifts letters around. Because the scrambling is so simple, if you know one original address and its scrambled version, you can work out the secret key and then scramble any address you like, including ones that let you read files on the server or run commands.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.