웹 해킹/webhacking.kr

webhacking.kr 41번

sonysame 2018. 2. 12. 21:41

소스코드는 다음과 같다.



<html>
<head>
<title>Challenge 41</title>
</head>
<body>

<form method=post action=index.php enctype="multipart/form-data">
<input type=file name=up><input type=submit value='upload'>
</form>
</body>
</html>

<!-- index.phps -->



주석에 index.phps가 있으니, index.phps를 살펴보자!


<html>
<head>
<title>Challenge 41</title>
</head>
<body>

<?
$hidden_dir
="???";

$pw="???";

if(
$_FILES[up])
{
$fn=$_FILES[up][name];
$fn=str_replace(".","",$fn);
if(
eregi("/",$fn)) exit("no");
if(
eregi("\.",$fn)) exit("no");
if(
eregi("htaccess",$fn)) exit("no");
if(
eregi(".htaccess",$fn)) exit("no");
if(
strlen($fn)>10) exit("no");
$fn=str_replace("<","",$fn);
$fn=str_replace(">","",$fn);
$cp=$_FILES[up][tmp_name];

copy($cp,"$hidden_dir/$fn");

$f=@fopen("$hidden_dir/$fn","w");
@
fwrite($f,"$pw");
@
fclose($f);

echo(
"Done~");

}


?>

<form method=post action=index.php enctype="multipart/form-data">
<input type=file name=up><input type=submit value='upload'>
</form>
</body>
</html>


파일명에 

.사라짐


/ \. htaccess .htaccess 길이가 10보다 길면 exit("no")!

<와 >는 널로!



파일명이 > 이나 < 이면 널이 된다!

파일명에 > 이나 < 이 들어갈 수 없으므로 버프 수트를 이용해서 고쳐주었다.

copy($cp,"$hidden_dir/$fn");

그러면 이 부분에서 에러가 난다!


hidden_dir을 알아냈다!



이제 정상적인 파일을 업로드 하여

URL을 완성시켜준다!


http://webhacking.kr/challenge/web/web-19/dkanehdkftndjqtsmsdlfmadmlvhfejzzzzzzzzzkkkkkkkkggggggggg/010png

4cef331a6b10d6a8a6a9b8cd80fde0b9