TigerDemon
webhacking.kr 18번 본문
https://webhacking.kr/challenge/web-32/
Challenge 18
webhacking.kr
위 링크로 들어가면 아래 사진이 뜹니다.

그중 view-source로 들어가면 아래 처럼 코드가 뜹니다.
<?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>
admin을 입력하면 url에 아래 사진처럼 뜹니다.

코드 해석
if(preg_match("/ |\/|\(|\)|\||&|select|from|0x/i",$_GET['no'])) exit("no hack");
위 코드의 의미
| 필터 | 의미 |
| 공백 " " | 띄어쓰기 |
| / | 슬래시 |
| ( ) | 괄호 |
| ` | ` |
| & | AND 연산자 |
| select | SQL SELECT |
| from | SQL FROM |
| 0x | HEX 표현 |
띄어쓰기가 필터링 되어 있어서 tab인 %09를 사용하고 or 뒤에 참으로 만들어서 문제를 풀기 위해서 no를 아예 다른 숫자인 0으로 만듭니다.


'2026-SWLUG > 웹해킹' 카테고리의 다른 글
| Webhacking.kr 39번 문제 풀이 (0) | 2026.06.30 |
|---|---|
| WEBHACKING.KR 7번 풀기 (0) | 2026.05.24 |
| webhacking.kr 27번 (0) | 2026.05.06 |
| WEBHACKING.kr 26번 풀이 (0) | 2026.05.06 |
| Webhacking.kr 17번 풀기 (0) | 2026.04.29 |
