문제에 접속하면 하나의 입력창과 함께 소스코드를 확인할 수 있다.
<?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>
"select 1 from member where length(id)<14 and id='{$_POST['id']}" 이 값이 존재한다면 문제를 해결할 수 있다는 것을 알 수 있다.admin 인 값이 분명 하나는 존재할 것으로 추측하고, admin’을 입력한다면 결과를 확인할 수 있지만, 코드에서 ‘를 ‘’로 치환하기 때문에 어려울 수 있다. 그러나 substr함수를 보면 0번째 문자열에서 15번째 문자열까지만 출력하기 때문에, admin이후에 공백을 14번째까지 넣고 15번째에 ‘를 넣어준다면 ‘’로 바뀌더라도 마지막 글자는 짤려 결과적으로 admin’을 입력할 수 있다.