๐ Introduction
Web Cache Poisoning์ ์บ์ ์๋ฒ๋ค์ ์บ์ ์ ์ฑ ์ ์ด์ฉํ ๊ณต๊ฒฉ ๋ฐฉ๋ฒ์ผ๋ก ํน์ ํ HTTP Request๋ฅผ ํตํด ๋ค๋ฅธ ์ฌ์ฉ์์ ์๋น์ค ๋์์ ์ํฅ์ ์ค ์ ์๋ ๋ถ๋ถ๋ค์ Cache ์์ผ ์๋น์ค๋ฅผ ์ ์์ ์ ์ฌ์ฉํ์ง ๋ชปํ๊ฒ ํ๊ฑฐ๋(DOS), ๋ค๋ฅธ ์ทจ์ฝ์ ๊ณผ์ ์ฐ๊ณ๋ฅผ ์ํ ๋ถ๋ถ์ผ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
๐ก Offensive techniques
Detect
HTTP Header, Query ๋ฑ์ ์์์ ํค๋, ๊ฐ ๋ฑ์ ์์ฒญํ์ฌ ์๋ฒ์์ ์บ์๋๋์ง ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค. ๋ง์ฝ ์บ์๊ฐ ๋๋ ๊ฒฝ์ฐ ๋ค๋ฅธ ์ฌ์ฉ์๋ ํด๋น ๊ฒฝ๋ก๋ก ์ง์ ์ ์บ์๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ๊ธฐ ๋๋ฌธ์ ์ํฅ์ ์ค ์ ์์ต๋๋ค.
Attack Request / Response
๋ง์ฝ X-Location ํค๋๊ฐ Cache ๋์์ด๊ณ Response์ ์ํฅ(Location ํค๋)์ ๋ผ์น๋ค๋ฉด..
GET /?cache_busting=1234 HTTP/1.1
Host: example.com
X-Location: https://www.hahwul.com
HTTP/1.1 200 OK
Location: https://www.hahwul.com
Victim Request / Response
์ผ๋ฐ ์ฌ์ฉ์๊ฐ X-Location ํค๋๊ฐ ์์ด๋, ์บ์๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์์ ๊ณต๊ฒฉ์๊ฐ ์๋ํ ์ฌ์ดํธ๋ก ์ด๋ํฉ๋๋ค.
GET /?cache_busting=1234 HTTP/1.1
Host: example.com
HTTP/1.1 200 OK
Location: https://www.hahwul.com
Cache key
์บ์๋ ์ปจํ ์ธ ๊ฐ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ๋์ผํ๊ฒ ์ ๋ฌ๋๋ ๊ฒ์ ์๋๋๋ค. ๋ฌผ๋ก ๋ฌด์กฐ๊ฑด ์บ์ํ์ฌ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ ๋ฌํ๋ ๊ฒฝ์ฐ๋ ์์ง๋ง, ํน์ ์กฐ๊ฑด์ ์ํด ๊ฐ์ ์ฌ์ฉ์๋ผ๊ณ ํ๋จ๋๋ฉด ์ ๋ฌํ๋ ์๋ฒ๋ ์์ต๋๋ค.
๊ทธ๋ฐ ์๋ฒ๋ค์ด ์ฌ์ฉํ๋ ํน์ ์กฐ๊ฑด์ด ๋ฐ๋ก Cache key์ ๋๋ค. Cache key๋ ์บ์ ์๋ฒ๊ฐ HTTP ์์ฒญ์ ์์ ํ ๋, ์ง์ ์ฒ๋ฆฌํ ์ ์๋ ์บ์๋ ์๋ต์ด ์๋์ง ๋๋ ๋ฐฑ์๋ ์๋ฒ์ ์ฒ๋ฆฌ ์์ฒญ์ ์ ๋ฌํด์ผ ํ๋์ง ์ฌ๋ถ๋ฅผ ๋จผ์ ํ์ธํด์ผ ํ๋๋ฐ, ์ด ๋ ์ฌ์ฉ๋๋ฉฐ ์ด๋ฅผ ํตํด์ ๋๋ฑํ ์์ฒญ์ ์๋ณํฉ๋๋ค.
- HTTP Scheme
- HTTP Host
- Path
- Query string
- Etcโฆ
๊ธฐ๋ณธ์ ์ผ๋ก Host ํค๋์ URI Query๋ ํฌํจ๋๋ฉฐ, ์ฌ๊ธฐ์ ์บ์ ์๋ฒ์ ์ค์ ์ ๋ฐ๋ผ์ ์ถ๊ฐ๋ก ๊ฐ์ด ๋ ๋ค์ด๊ฐ ์ ์์ต๋๋ค. Cache Poisoning ์ ์ด ์ ์ ์๊ณ ์์ด์ผ, Self ์บ์๋๋ ์ํฉ์์ Global ์บ์๋ก ๋ฒ์๋ฅผ ํ์ฅํ ์ ์์ต๋๋ค.
Unkeyed inputs
Unkeyed inputs์ Cache Key์ ๋ค๋ฅด๊ฒ Cache์ ์ง์ ์ ์ธ ์ํฅ์ ๋ผ์น์ง ์์ผ๋ฉด์, Response์๋ง ์ํฅ์ ๋ผ์น๋ ํญ๋ชฉ์ ์๋ฏธํฉ๋๋ค. ๋งจ ์์ Cache Poisoning ์์์์ X-Location ๊ฐ์ด Unkeyed inputs์ด ๋ฉ๋๋ค.
GET /?cache_busting=1234 HTTP/1.1
Host: example.com
X-Location: https://www.hahwul.com
HTTP/1.1 200 OK
Location: https://www.hahwul.com
Detect flow
๋ณดํต 3๊ฐ์ง์ ํ๋ก์ฐ๋ก Cache Poisoning์ ์ฌ๋ถ๋ฅผ ์๋ณํ ์ ์์ต๋๋ค.
- Identify and evaluate unkeyed inputs (unkeyed inputs๋ฅผ ์ฐพ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ํฅ๋ ฅ ๊ฒ์ฆ)
- Elicit a harmful response from the back-end server (๋ฐฑ์๋ ์๋ฒ์์ ์ ์์ ์ธ Response๋ฅผ ์ ๋ํฉ๋๋ค.)
- Get the response cached (์ดํ ํด๋น Response๊ฐ ์บ์๋๋์ง ํ์ธํฉ๋๋ค)
Header Mining
Cache poisoning์ ์ฝ๊ฒ ์๋ณํ๊ธฐ ์ํด์ Param mining๊ณผ ๊ฐ์ด Header mining์ํ๋ ๊ฒ์ด ํจ๊ณผ์ ์ ๋๋ค. HTTP Header wordlist๋ฅผ ๊ธฐ์ค์ผ๋ก ํด๋น ์๋ฒ์์ Response์ ์ํฅ์ ๋ผ์น ์ ์๋ ํค๋๋ฅผ ์ฐพ๋ ๊ฒ์ด ์ข์ต๋๋ค.
GET /?cache_busting=1234 HTTP/1.1
Host: example.com
X-Location: 1234
X-Forwarded-For: 1234
X-Origin: 1234
X-URL-Rewrite: 1234
....
- https://developer.mozilla.org/ko/docs/Web/HTTP/Headers
- https://github.com/danielmiessler/SecLists/blob/e017d54a22f230e15b8a5f51e9fc4292537b374b/Miscellaneous/web/http-request-headers/http-request-headers-fields-large.txt
๋ํ์ ์ผ๋ก BurpSuite์ Param Minior, ZAP์ Fuzzer๋ฅผ ์ฌ์ฉํ๊ณ , ์ผ๋ถ Param mining์ด ๊ฐ๋ฅํ ๋๊ตฌ๋ก๋ ํ ์คํธํ ์ ์์ต๋๋ค. wordlist๋ ์ SecLists์ http-request-header-s-fields-large.txt๋ฅผ ์ฌ์ฉํ์๋ฉด ๋๋ค์ ํค๋์ ๋ํด ํ ์คํธํ์ค ์ ์์ต๋๋ค.
Cache Busting
Cache busting์ URL Query ๋ฑ์ ํน์ ํ ๊ฐ์ ์ถ๊ฐํ์ฌ ํด๋น ๊ฒฝ๋ก๋ก ์ง์ ์ ๊ทผํ ์ฌ์ฉ์๋ง ์ํฅ๋ฐ๋๋ก ํ ์ ์๋ ๊ธฐ๋ฒ์ ๋๋ค. ๋ณดํต Cache Poisoning, HTTP Request Smuggling ๋ฑ ๊ด๋ฒ์ํ ๋์์ ์ฌ์ฉ์์๊ฒ ์ํฅ์ ๋ผ์น ์ ์๋ ๊ณต๊ฒฉ๋ค์ ํ ์คํธํ ๋ ์์ฃผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
์์ธํ ๋ด์ฉ์ ์๋ ๊ธ์ ์ฐธ๊ณ ํด์ฃผ์ธ์.
https://www.hahwul.com/2021/08/28/cache-busting/
Exploitation
์บ์๋ฅผ ํตํด HTTP Response ํค๋์ ์ํฅ์ ๋ผ์น ์ ์๋ค๋ฉด ์ด๋ฅผ ํตํด ๊ฐ๋ฅํ ๋ชจ๋ ๊ณต๊ฒฉ์ด Exploit์ ํฌ์ธํธ๊ฐ ๋ฉ๋๋ค. ์ํฉ์ ๋ฐ๋ผ ๋๋ฌด ๋ง์ ๊ฒฝ์ฐ์ ์๊ฐ ์์ง๋ง ๋์ฒด์ ์ผ๋ก Client-Side์์ ๋ฐ์ํ ์ ์๋ ๋ชจ๋ ์ด์์ ์ฐ๊ด์ด ์์ต๋๋ค.
- XSS
- DOS
- CSRF (bypass protection)
- Open Redirect
- Smuggling
- Etcโฆ
More technic
PortSwigger์ ๊ธ์์ ์ ์ ๋ฆฌ๋์ด ์์ต๋๋ค. ์๋ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
- https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws
- https://portswigger.net/web-security/web-cache-poisoning/exploiting-design-flaws
๐ก Defensive techniques
Disable Cache
์บ์๊ฐ ํ์ํ์ง ์์ ์๋ฒ์์ ์บ์๋ฅผ ๊บผ๋๋ ๊ฒ์ด ๊ฐ์ฅ ์ข์ต๋๋ค. (๋ฆฌ์์ค ์บ์ ๋ฑ์ CDN์์ ์ฒ๋ฆฌ)
Protect unkeyed inputs
unkeyed inputs์ ์ด ๊ณต๊ฒฉ์ ํต์ฌ์ด ๋๋ ์ค๋ธ์ ํธ ์ค ํ๋์ ๋๋ค. Cache๊ฐ ๊ฐ๋ฅํ ์๋ฒ์์ ์ฌ์ฉ์ฑ์ ์ง์ ์ ์ธ ์ํฅ์ ๋ผ์น ์ ์๋ Header๋ฑ์ unkeyed inputs๋ ๊ณต๊ฒฉ์๊ฐ ์์๋ก ์บ์ํ์ง ๋ชปํ๋๋ก๊ณ ์ ํํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
Using Vary Header
Vary ํค๋๋ PC์น ํ๊ฒฝ๊ณผ ๋ชจ๋ฐ์ผ ์น ํ๊ฒฝ ๊ตฌ๋ณ์ ์ํด ๋ง์ด ์ฌ์ฉํ๋ ํค๋์ ๋๋ค. ์ด๋ฅผ ํตํด Cache Poisoning์ด ๋ฐ์ํ๋๋ผ๋, ์ฌ๋ฌ ์ฌ์ฉ์๊ฐ ์ํฅ๋ฐ์ง ์๋๋ก ์ํํ ์ ์์ต๋๋ค.
Vary: User-Agent
์ ์ผ์ด์ค์์ ๋์ผ UA๊ฐ ์๋๋ฉด ์ํฅ๋ฐ์ง ์๊ฒ ๋๊ฒ ๋ค์.
๐น Tools
- BurpSuite Scanner
- ZAP Fuzzer
- https://github.com/tismayil/fockcache
- https://github.com/fngoo/web_cache_poison
๐ Articles
- https://www.hahwul.com/2018/12/31/web-cache-poisoning-attack-with-header-xss/
- https://www.hahwul.com/2021/08/28/cache-busting/