Simple Compare Challenge. hint? you can see the title of this challenge. :D
type.. 사실 PHP같은 스크립트 기반 언어에서 type을 신경써본적이 '거의'없다. 무슨 문제일지 궁금하긴하다.
<?php
if (isset($_GET['view-source'])) {
show_source(__FILE__);
exit();
}
if (isset($_POST['json'])) {
usleep(500000);
require("../lib.php"); // include for auth_code function.
$json = json_decode($_POST['json']);
$key = gen_key();
if ($json->key == $key) {
$ret = ["code" => true, "flag" => auth_code("type confusion")];
} else {
$ret = ["code" => false];
}
die(json_encode($ret));
}
function gen_key(){
$key = uniqid("welcome to wargame.kr!_", true);
$key = sha1($key);
return $key;
}
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="./util.js"></script>
</head>
<body>
<form onsubmit="return submit_check(this);">
<input type="text" name="key" />
<input type="submit" value="check" />
</form>
<a href="./?view-source">view-source</a>
</body>
</html>
일단 gen_key는 uniqid기때문에 내가 어떤값을 넣어서 보낸다고 해도 별로 소용이 없다.
그래서 다른 방법을 찾아야 할 것 같아보였다. 무조건 값을 참으로 만들어야 하는데 $json->key를 그대로 사용하고 있다.
json은 true와 false의 경우 "true"나 "false"처럼 string으로 캐스팅하지 않고 그대로 사용하고, 형을 보존해서 보내기때문에
key에 true 값을 줘서 보내면 문제를 패스하게 된다
요컨데 이런식이다
json={"key":true}