๐ Introduction
RFD(Remote File Download)๋ ํ์ฅ์, ํ์ผ ๋ด์ฉ์ ๋ํด ํต์ ๊ฐ๋ฅํ ๋ค์ด๋ก๋ ๊ธฐ๋ฅ์ ์ด์ฉํ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ผ๋ก ์ ๋ขฐ ๋๋ฉ์ธ์์ ์ฌ์ฉ์๊ฐ ๊ณต๊ฒฉ์ฝ๋๊ฐ ํฌํจ๋ ํ์ผ์ ๋ค์ด๋ก๋ํ๊ณ ์คํํ๋๋ก ์ ๋ํ์ฌ ์ฌ์ฉ์๋จ ์์ญ์์ ๋ช ๋ น์ ์คํํ ์ ์์ต๋๋ค.
์คํ์ ์ ๋ํ๋ค๋ ์ ์์ ๋ง์น ํผ์ฑ ๊ณต๊ฒฉ๊ณผ ๋น์ทํด๋ณด์ด์ง๋ง ์ ๋ขฐ ๋๋ฉ์ธ์ ์ฌ์ฉํ๋ค๋ ์ , ์ด๋ก์ธํ ๊ฒฐ๊ณผ๊ฐ ๋ช ๋ น ์คํ์ด๋ผ๋ ์ ์์ CSV Injection๊ณผ ๋งค์ฐ ์ ์ฌํ ํํ์ ๊ณต๊ฒฉ์ ๋๋ค.
๐ก Offensive techniques
Detect
RFD ๊ณต๊ฒฉ ์ฑ๊ณต์ ์ํด์ ํ์ ์กฐ๊ฑด์ด ์กด์ฌํ๋ฉฐ, ์ด๋ RFD ์ทจ์ฝ์ ์ ์๋ณํ๋๋ฐ ์์ด์ ๊ฐ์ฅ ์ฐ์ ์ฒดํฌ๋์ด์ผํ ๋ถ๋ถ์ ๋๋ค.
Content-Disposition: attachment
RFD๋ ์ฌ์ฉ์๊ฐ ์ ๋ขฐ ๋๋ฉ์ธ์์์ ๋งํฌ๋ก ์ธํด ํ์ผ์ ๋ค์ด๋ก๋ํ๊ณ , ์คํํ๋๋ก ์ ๋ํ๋ ๊ณต๊ฒฉ์ด๊ธฐ ๋๋ฌธ์ ์ ๋ขฐ ๋๋ฉ์ธ ๋ด ํ์ด์ง์์ ํ์ผ ๋ค์ด๋ก๋๊ฐ ์ผ์ด๋์ผ ํฉ๋๋ค.
์น ์๋น์ค์์ Content-Disposition ํค๋๋ฅผ ํตํด ํ์ผ ๋ด์ฉ์ด ์ด๋ป๊ฒ ์ฒ๋ฆฌ๋ ์ง ๋ช ์ํ๊ณ , ์ด ๊ฐ์ด attachment์ธ ๊ฒฝ์ฐ ๋ค์ด๋ก๋๋ฅผ ์คํํ๊ธฐ ๋๋ฌธ์ Response header ๋ด ํด๋น ํค๋๊ฐ ์๋์ง ์ฒดํฌ๊ฐ ํ์ํฉ๋๋ค.
Content-Disposition: attachment
ํ์ผ ํ์ฅ์๋ฅผ ์ปจํธ๋กคํ ์ ์์ด์ผ ํจ
์ฌ์ฉ์๋จ์์ ํ์ผ์ ์คํํ์ฌ ๋ช ๋ น์ ์คํํ๊ธฐ ๋๋ฌธ์ ๋ค์ด๋ก๋๋๋ ํ์ผ์ ํ์ฅ์๋ฅผ ์ปจํธ๋กคํ ์ ์์ด์ผ ํฉ๋๋ค.
Response๋ฅผ ์ปจํธ๋กคํ ์ ์์ด์ผํจ
ํ์ผ ๋ค์ด๋ก๋ ํ ์คํ ์ ๋ช ๋ น ์คํ์ ์ํ ์ฝ๋๋ฅผ ์ฝ์ ํ๊ธฐ ์ํด์ Response body๋ฅผ ์ปจํธ๋กคํ ์ ์์ด์ผ ํฉ๋๋ค. ์ด๋ Reflected XSS์ ์ ํ์กฐ๊ฑด์ด ๋น์ทํฉ๋๋ค.
Exploitation
MacOS and Linux
Request
GET /s;/install.sh;?q=hwul\"`ls` HTTP/1.1
Host: example.com
Response
HTTP/1.1 200 OK
Content-Type: application/json;
Content-Disposition: attachment
{"result":["q","hwul\"`ls`","zzzz"]}
Windows
Request
GET /s;/install.bat;?q=hwul\"||calc|| HTTP/1.1
Host: example.com
Response
HTTP/1.1 200 OK
Content-Type: application/json;
Content-Disposition: attachment
{"result":["q","hwul\"||calc||","zzzz"]}
Bypass protection
Bypass filename protection
- /get_user_profile.bat
- /get_user_profile;setup.bat
- /get_user_profile/setup.bat
- /get_user_profile;/setup.bat
- /get_user_profile;/setup.bat;
Bypass command
๋ช ๋ น์ด ์คํ๋๋ ๊ตฌ๊ฐ์ด ์ฌ์ฉ์ ๊ตฌ๊ฐ์ผ ๋ฟ์ด์ง ์ ๋ฐ์ ์ธ ๋ฉ์ปค๋์ฆ์ Command Injection๊ณผ ๋์ผํฉ๋๋ค. ๋ง์ฝ ์๋น์ค์์ ํน์๋ฌธ์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฐจ๋จํ๋ค๋ฉด Command Injection ์ฐํ์ ์ ์ฌํ ๋ฐฉ๋ฒ์ผ๋ก ๊ณต๊ฒฉ์ ์๋ํด๋ณผ ์ ์์ต๋๋ค.
https://www.hahwul.com/cullinan/command-injection/#bypass-protection
Chain attack
ํด๋น ์ทจ์ฝ์ ์ด ๊ณต๊ฐ๋ 2014๋ ๋น์์๋ ๋จ์ํ ๋งํฌ๋ฅผ ์ด์ฉํ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ด์์ง๋ง, ํ์ฌ(2021๊ธฐ์ค) Web Cache Poisoning, HTTP Request Smuggling ๋ฑ ๊ด๋ฒ์์ ์ฌ์ฉ์๋ฅผ ๋์์ผ๋ก ๊ณต๊ฒฉ์๊ฐ ์๋ํ Response๋ฅผ ์ ๋ฌํ ์ ์๋ ๊ณต๊ฒฉ ๋ฐฉ๋ฒ์ด ๋ง์ด ๋์์๋ ์ํ๋ผ ๋ค๋ฅธ ์ทจ์ฝ์ ๊ณผ ์ฐ๊ณ์ ํ๊ธ๋ ฅ์ ์ฝ๊ฒ ์ฌ๋ฆด ์ ์์ต๋๋ค.
- Web Cache Poisoning
- Web Cache Deception
- HTTP Request Smuggling
- H2C Smuggling
- Etcโฆ
๐ก Defensive techniques
Protect user-controlled filename
File Download ๊ตฌ๊ฐ(Content-Disposition์ ์ฌ์ฉํ๋ ๊ตฌ๊ฐ)์์ ์ฌ์ฉ์๊ฐ filename์ ์ปจํธ๋กคํ ์ ์๋๋ก staticํ๊ฒ ์ ํํฉ๋๋ค. ๋ง์ฝ filename์ ํต์ ๊ถ์ ์ ๊ณตํด์ผ ํ๋ ๊ฒฝ์ฐ ์ ์์ ์ธ filename(e.g .sh .bat)์ ์ฌ์ฉํ ์ ์๋๋ก ์ ํ์ด ํ์ํฉ๋๋ค.
Using auth header
ํด๋น ๊ธฐ๋ฅ์ด API์ธ ๊ฒฝ์ฐ ๋ณ๋์ ์ธ์ฆ ํค๋ ๋ฑ์ ํตํด ๊ฒ์ฆํ๋ ๊ฒ์ด ์ข์ต๋๋ค. RFD๋ Reflected XSS, Open Redirect์ ๊ฐ์ด URL์ ๊ธฐ๋ฐ์ผ๋ก ํ ๊ณต๊ฒฉ์ด๋ผ ํค๋ ๊ธฐ๋ฐ์ผ๋ก API Key ๋ฑ์ ๊ฒ์ฆํ๊ฒ ๋๋ฉด ํด๋น ์์ฒญ์ผ๋ก ํ ์ฌ์ฉ์์๊ฒ ์ํฅ์ ๋ผ์น ์ ์๊ฒ ๋ฉ๋๋ค.
CrossSite, CrossOrigin protection
SOP, CSRF Token, Referer Check ๋ฑ Cross-site, Cross-origin์์์ ๋ณด์ ์ ์ฑ ๋ค์ ์ด์ฉํ์ฌ ๋ฐฉ์ดํ ์ ์์ต๋๋ค. ๋ฉ์ปค๋์ฆ์ ์ด๊ฒ์ด ์ ์์ ์ธ ํ์ด์ง๋ก ๋ถํฐ ๋ฐ์ํ ์์ฒญ์ธ์ง ๊ฒ์ฆํ๋ ํํ์ ๋๋ค.