writeups/Web
strcmp
m4tta
2019. 11. 23. 23:02
Description
Category: Web
Source: wargame.kr
Points: 229
Author: Jisoon Park(js00n.park)
Description:
if you can bypass the strcmp function, you get the flag.
Write-up
password를 입력 할 수 있고, 문제의 소스가 제공된다.
소스 코드를 살펴보자.
<?php
require("../lib.php"); // for auth_code function
$password = sha1(md5(rand().file_get_contents("/var/lib/dummy_file")).rand());
if (isset($_GET['view-source'])) {
show_source(__FILE__);
exit();
}else if(isset($_POST['password'])){
sleep(1); // do not brute force!
if (strcmp($_POST['password'], $password) == 0) {
echo "Congratulations! Flag is <b>" . auth_code("strcmp") ."</b>";
exit();
} else {
echo "Wrong password..";
}
}
?>
<br />
<br />
<form method="POST">
password : <input type="text" name="password" /> <input type="submit" value="chk">
</form>
<br />
<a href="?view-source">view-source</a>
strcmp() 함수가 0을 리턴하도록 해야 하는데, $password 변수는 예측할 수가 없다.
strcmp() 함수의 오래된 취약점(일부 버전에서만 동작한다.)인 type confusion을 이용해서 공격해보자.
취약점이 있는 strcmp 함수는 문자열과 배열을 비교할 경우 NULL을 리턴하고, == 연산자는 NULL == 0을 true로 인식한다.
burp suite를 이용해서, password 파라미터를 배열로 전송해보자.

성공적으로 if 문을 통과하여 flag를 얻을 수 있다.

Flag : 03361f76c1f4e2c3bca7c5351f48be854adee710