<?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>
SQL Injection 문제입니다!
이 문제는 no에 필터링이 되어있는데 제가 필터링걸린건 0x와 공백문자였습니다!
문제 풀이는 밑에!
더보기



일단 문제를 풀어보기위해 소스를 봤는데 admin의 no는 2라고 합니다

no가 1일땐 guest이구요!
일단 SQL문을 보면
select id from chall18 where id='guest' and no=$_GET[no]
인것을 보면 no와 id가 일치할 때 hi ~ 라고 나오는 걸 알 수 있습니다!
그러면 일단 id가 guest인 것은 픽스된거니까 저걸 없애기 위해 no를 1말고 아무숫자를 넣고 OR로 no에 들어갈 문장을 써보면!
3 OR no=2
를 써주면 될 거 같은데여
0x랑 공백이 막혔으니까 저는

이걸 이용해서 풀어보겠습니다!
그럼 다시 써보면
?no=333%09OR%09no=2
이렇게 해주면 될 거 같은데요!
주소창에 입력해보겠습니당

그럼 이렇게 뜨게됩니다~!
끝!
'Hacking' 카테고리의 다른 글
Bandit 과제~_~(Bandit5까지 로그인) (0) | 2020.10.10 |
---|---|
ctf-d.com GrrCON 2015 #1 ~ #2 (0) | 2020.08.30 |
SuNiNaTaS Web - 3 (0) | 2020.08.16 |
Webhacking.kr - Challenge 16 (0) | 2020.08.16 |
Webhacking.kr - Challenge 17 (0) | 2020.08.16 |