문제 서버에 접속하면 위와 같이 입력창이 있다. 코드는 아래와 같다.
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?><html>
<head>
<title>Chellenge 39</title>
</head>
<body>
<?php
$db = dbconnect();
if($_POST['id']){
$_POST['id'] = str_replace("\\","",$_POST['id']);
$_POST['id'] = str_replace("'","''",$_POST['id']);
$_POST['id'] = substr($_POST['id'],0,15);
$result = mysqli_fetch_array(mysqli_query($db,"select 1 from member where length(id)<14 and id='{$_POST['id']}"));
if($result[0] == 1){
solve(39);
}
}
?>
<form method=post action=index.php>
<input type=text name=id maxlength=15 size=30>
<input type=submit>
</form>
<a href=?view_source=1>view-source</a>
</body>
</html>
sql 문을 보면 select 1 from member where length(id)<14 and id='{_POST['id']} 으로 되어있는데 작은 따옴표가 하나 빠진 것을 찾으면 쉽게 문제를 해결할 수 있다.
$_POST['id'] = substr($_POST['id'],0,15);
substr은 id의 0인덱스에서 15개의 문자를 가져오므로 {admin '}를 입력하면 '이 ''로 바뀌더라도 잘리기 때문에 그대로 admin '이 입력된다. php에서는 {'admin'}과 {'admin '} 똑같이 취급된다고 한다. 따라서 해당 값을 입력하면 플래그를 획득할 수 있다.
'웹 해킹 > Webhacking.kr' 카테고리의 다른 글
[Webhacking.kr] old-19 (0) | 2021.09.07 |
---|---|
[Webhacking.kr] old-25 (0) | 2021.09.07 |
[Webhacking.kr] old-54 (0) | 2021.09.06 |
[Webhacking.kr] old-38 (0) | 2021.09.05 |
[Webhacking.kr] old-26 (0) | 2021.09.05 |
댓글