WebHacking/Wargame.kr

Wargame.kr strcmp

HSr00t 2018. 2. 25. 06:35

이번 문제는 strcmp함수 문제인것같다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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>
cs


== 함수에서 NULL과 0은 같다.


php 5.3버전에서는 str과 배열을 비교할때 NULL을 반환 시켜주는데 위에 적어 놓은 것처럼 NULL은 0과 같으니 $_POST['password']가 배열이라면 NULL을 반환 할 것이고 플래그를 얻을 수 있을 것 이다.