목표 :SQLi 공백 우회
시작부터 나 SQLi 라고 자랑하고 있다.
소스를 보자
<?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>
PHP
복사
정규식으로
공백 / ( ) | & select from 16진수 를 필터링한다.
id가 admin이면 된다.
그런데 admin의 no은 2라고 주석에 친절하게 표시해놨다.
select id from chall18 where id='guest' and no=$_GET[no]
PHP
복사
참이면 되므로 뒤 내용이 999 or no=2 일경우
select id from chall18 where id='guest' and no=999 or no=2
PHP
복사
뒤 내용만 참인 걸 찾게 되므로 and로 묶인 앞은 거짓이 되고 뒤 no=2인 admin을 찾게 된다.
공백의 입력이 불가능하므로 아래 중 하나를 택한다.
공백 우회 방법
•
%09 (tab)
•
%0a (\n)
•
%0d (\r)
•
/**/ (주석)
•
() (괄호)
•
+ (더하기)
999%0dor%0dno%3D2
를 uri에 인자로 직접 넣었다.