Web/webhacking.kr

Webhacking.kr old-18

cloudnaaam 2025. 3. 17. 18:44

 

진짜 오랜만에 보는 SQL Injection 문제다. 

 

소스 코드를 함 볼까?

<?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>

 

필터링이 빡세게 되어 있다.

 

공백을 비롯해서 다양한 문자들이 필터링 된다.

 

일단 페이로드는

'' or no=2

를 넣으면 되는데

 

공백이 필터링 중이다.

 

\도 필터링 중이라서 \t \v 같은 것도 못쓴다.

 

근데 소스 코드를 보니까 id값을 GET으로 받는다.

 

그래서 url 인코딩을 통해 풀기로 했다.

''%09or%09no=2

을 url을 통해 넣자.

 

풀었다!

'Web > webhacking.kr' 카테고리의 다른 글

Webhacking.kr old-10  (0) 2025.03.18
Webhacking.kr old-54  (0) 2025.03.18
Webhacking.kr old-26  (0) 2025.03.17
Webhacking.kr old-06  (0) 2025.03.17
Webhacking.kr old-24  (0) 2025.03.17