๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Web Hacking/Dreamhack

[Dreamhack] php-1 ๋“œ๋ฆผํ•ต ์›Œ๊ฒŒ์ž„ ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2022. 11. 8.

6 - 0 - 2. php - 1 ๋“œ๋ฆผํ•ต ๋ฌธ์ œ ํ’€์ด

 

 

 

# php - 1 ๋“œ๋ฆผํ•ต ๋ฌธ์ œ ํ’€์ด

1. ๋ฌธ์ œ ํ™•์ธ ํ›„ ๋ฌธ์ œ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

+ LFI(=Local File Inclusion) ์ทจ์•ฝ์ ์ด๋ž€?

: ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์ด๋‚˜ ์š”์†Œ๋ฅผ '๊ฒฝ๋กœ'์— ์ถ”๊ฐ€ํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ทจ์•ฝ์ ์œผ๋กœ, ์ฃผ๋กœ php๋กœ ๋งŒ๋“ค์–ด์ง„ ์›น์‚ฌ์ดํŠธ๊ฐ€ ํŠน์ • ํ•จ์ˆ˜(include,require,fopen)๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฐœ์ƒํ•œ๋‹ค.

-->  ์„œ๋ฒ„ ์•ˆ์— ์กด์žฌํ•˜๋Š” ํŒŒ์ผ์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ์‹์„ ํ†ตํ•ด ๊ณต๊ฒฉ ๊ฐ€๋Šฅ

 

 

 

 

2. ๋ฌธ์ œ ํŒŒ์ผ(index.php, list.php, main.php, view.php) ๋ถ„์„

index.php

+ << Line 23 ~ 26 >>

: include ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ GET ๋ฐฉ์‹์œผ๋กœ ๋ณ€์ˆ˜ page์— php๋ช…์„ ์ž…๋ ฅ๋ฐ›๊ณ , ์ด์— ๋Œ€ํ•œ main.php๋ฅผ ํ˜ธ์ถœ

 

 

 

list.php

 

 

 

main.php

 

 

 

view.php

+ << Line 4 >>

: ๋ณ€์ˆ˜ file์— ๊ฒฝ๋กœ๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ณผ์ •์—์„œ flag ๋ฌธ์ž์—ด์„ ํ•„ํ„ฐ๋งํ•˜์—ฌ ์ ‘์† ์ œํ•œ  

-->  ์ ‘์† ์ •๋ณด์˜ ๋งํฌ์—์„œ flag.php๋ฅผ ํด๋ฆญ ์‹œ ์ ‘๊ทผ ๊ฑฐ๋ถ€ ๋ฉ”์‹œ์ง€๊ฐ€ ๋œจ๋Š” ์ด์œ ๋กœ, flag ํ•„ํ„ฐ๋ง ์šฐํšŒ ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ flag ์— ์ ‘๊ทผํ•ด์•ผ ํ•จ

 

 

 

 

3. ์ ‘์† ์ •๋ณด ํ™•์ธ ํ›„ ์•ˆ๋‚ด๋œ ๋งํฌ๋กœ ์ ‘์†

 

 

 

 

 

4. List ํŽ˜์ด์ง€๋กœ ์ด๋™ ํ›„ flag.php์™€ hello.json ํด๋ฆญ

 

flag.php ํด๋ฆญ ์‹œ

 

hello.json ํด๋ฆญ ์‹œ

 

 

 

 

5. Home ํŽ˜์ด์ง€์—์„œ PHP Wrapper ์ข…๋ฅ˜ ์ค‘ ํ•˜๋‚˜์ธ php://filter ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ๋‹จ์˜ url ๋ž€์— http://host3.dreamhack.games:18527/?page=php://filter/convert.base64-encode/resource=/var/www/uploads/flag ์ž…๋ ฅ

 

url ์ž…๋ ฅ ํ›„ ๋ฐ˜์ฏค ์ž˜๋ ค์ง„ ์ƒํƒœ์˜ base64๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ฝ”๋“œ๊ฐ€ ์ถœ๋ ฅ

+ ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์œ„ํ•ด PHP Wrapper ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜์ธ php://filter Wrapper์„ ์ด์šฉ

PHP Wrapper์˜ ์ข…๋ฅ˜
expect:// php://filter zip:// php://stdout php://input php://fd/[fd ์ˆซ์ž]

-->  php.filter Wrapper

:์ธ์ฝ”๋”ฉ๊ณผ ๋””์ฝ”๋”ฉ ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ ์„œ๋ฒ„ ์•ˆ์˜ ๋ฌธ์„œ(=flag ๊ฐ’) ์—ด๋žŒ ๊ฐ€๋Šฅ

 

-->  resource/

: ํ•„ํ„ฐ๋งํ•  ์ŠคํŠธ๋ฆผ(stream)์„ ๋‚˜ํƒ€๋ƒ„

 

-->  convert.base64-encode

: ๋ฐ์ดํ„ฐ๋ฅผ base64๋กœ ์ธ์ฝ”๋”ฉ

 

 

 

 

6. Base64 ๋””์ฝ”๋”๋ฅผ ํ†ตํ•ด ์ธ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด์„ ๋””์ฝ”๋”ฉ

 

Flag๋Š”&nbsp;DH{bb9db1f303cacf0f3c91e0abca1221ff}

+ Flag๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ถœ๋ ฅ๋จ์„ ํ™•์ธ

 

 

 

 

+ ์ž๋ฃŒ ์ฐธ๊ณ 

https://watchout31337.tistory.com/148#:~:text=wrapper/

https://hevton.tistory.com/140