
CakePHP 5.4.2 - Alto - Remoto - Proxy - trustedProxies rispetta X-Forwarded-* da qualsiasi REMOTE_ADDR
abraxaslabs.tech · github.com/abraxas · @abraxas_null · [email protected] · cakephp-trusted-proxies
Classe: Bypass del redirect HTTPS / spoof IP-host Portata: Remota
CakePHP 5.4.2 (887b641) - Cake Software Foundation
HttpsEnforcerMiddleware con trustedProxies => ['10.0.0.1'] chiama setTrustedProxies, che imposta trustProxy = true e non confronta mai la lista con REMOTE_ADDR. Dopodiché, scheme(), host() e clientIp() onorano gli header dell'attaccante X-Forwarded-Proto / X-Forwarded-For / X-Forwarded-Host / X-Real-IP.
Il middleware predefinito ha trustedProxies null e non abilita questo comportamento. La configurazione documentata per il load-balancer è il caso esposto. Un client HTTP non autenticato che non è il proxy elencato può saltare il redirect HTTPS e falsificare l'IP del client e l'Host.
| ID | nessuna CVE al momento |
| Classe | Bypass del redirect HTTPS / spoof IP-host |
| Portata | Remota (HTTP non autenticato; app con trustedProxies impostato) |
| CWE | CWE-441, CWE-346 |
| CVSS | Alto: 7.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N |
| Prodotto | CakePHP |
| Affetto | 5.4.2 (887b641de9f7aba06071f98f17edcbc573cbcf63) |
| Auth | nessuna. App con HttpsEnforcerMiddleware trustedProxies impostato |
| Licenza | GNU Affero GPL v3.0 |
| Lab | solo 127.0.0.1 |
Richiede un'app che abbia abilitato trustedProxies (tipico reverse-proxy con enforcement HTTPS). Non è necessario connettersi da un IP proxy elencato.
| Privilegio | Metodo / sink | Provato in lab o dedotto |
|---|---|---|
| Saltare il redirect HTTPS / il percorso HSTS | GET / HTTP con X-Forwarded-Proto: https | Provato in lab. 200, scheme=https, witness in JSON |
Falsificare clientIp() | X-Forwarded-For: 203.0.113.50 | Provato in lab. client_ip=203.0.113.50 |
Falsificare host() | X-Forwarded-Host: spoof.invalid | Provato in lab. host=spoof.invalid |
Falsificare tramite X-Real-IP | X-Real-IP: 198.51.100.9 | Provato in lab. client_ip=198.51.100.9 |
Bypassare ACL IP / rate limit basati su clientIp() | Stesso spoof | Dedotto. Il default remote_addr di RateLimitMiddleware non è questo bug |
| Controllo negativo | Stessi header forwarded su /control (senza trustedProxies) | Provato in lab. Ancora 301 verso https |
Chiuso su questo residuo: default trustedProxies => null; REMOTE_ADDR stesso è ancora l'IP del bridge Docker nel lab (192.168.208.1, non il 10.0.0.1 elencato). Non è RCE. Non è un bug del cookie-jar.
Ho fissato cakephp/cakephp 5.4.2. ServerRequest::setTrustedProxies():
public function setTrustedProxies(array $proxies): void
{
$this->trustedProxies = $proxies;
$this->trustProxy = true;
$this->uri = $this->uri->withScheme($this->scheme());
}
HttpsEnforcerMiddleware lo chiama ogni volta che trustedProxies è non-null. Gli IP elencati vengono poi usati come array_diff sulla catena XFF, non come controllo del peer che si connette.
Vicoli ciechi già registrati: trattare il middleware predefinito come questo residuo (non lo è); chiamare x-forwarded-for di RateLimitMiddleware lo stesso bug (la bakery 5.4.1 ha già spostato quel default su remote_addr); sostenere che REMOTE_ADDR stesso fosse falsificato. Teatro: una reverse shell.
python3 cakephp-trusted-proxies-Abraxas-Labs.py
oppure
cd lab
./run.sh
Composer cakephp/cakephp 5.4.2 in PHP 8.3. App minimale: / usa trustedProxies => ['10.0.0.1']; /control no. HTTP su loopback a 127.0.0.1:19430.
/ senza header forwarded -> 301 https./control con proto/for/host/real-ip -> 301 https./ con X-Forwarded-Proto: https -> 200, scheme https, trust_proxy=true, REMOTE_ADDR non è 10.0.0.1./ con XFF + Host -> client_ip=203.0.113.50, host=spoof.invalid./ con X-Real-IP -> client_ip=198.51.100.9.SUCCESS cakephp-trusted-proxies pin=5.4.2 how=app remote-addr=192.168.208.1 listed-proxy=10.0.0.1 proto-bypass=200 control-redirect=301 client-ip=203.0.113.50 host=spoof.invalid x-real-ip=198.51.100.9 CAKEPHP-TRUSTED-PROXIES-WITNESS
Onorare gli header forwarded solo quando REMOTE_ADDR è nella lista dei trusted-proxy (Symfony isFromTrustedProxy()). Una lista vuota non deve abilitare la fiducia.
887b641de9f7aba06071f98f17edcbc573cbcf63)src/Http/ServerRequest.php · src/Http/Middleware/HttpsEnforcerMiddleware.phpGNU Affero GPL v3.0. Vedi LICENSE. Solo lab su loopback. Nessuna garanzia.