반응형

type confusion

Simple Compare Challenge.

hint? you can see the title of this challenge.

:D

 

 

와 간단 비교 챌린지!

 

힌트는 이 문제의 제목이라고 한다. type confusion 타입을 혼동

 

 

 

페이지 소스

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
27
28
29
30
31
32
33
34
35
36
37
38
<?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>
cs

 

usleep(500000); == sleep(0.5);

 

 

$key값은 sha1( welcome to wargame.kr!_[마이크로초단위의 타임스탬프] ) 이다.

 

$key값을 맞출 수는 없다.

 

 

 

 

11행을 보면  == 느슨한 비교를 하고 있다.

 

true == "string" 는 true다.

 

php 느슨한 비교 라고 검색을 해보면 ture false 표가 나온다. 참고하자.

 

 

 

 

 

우리는 $json->key 값에 true를 보내면 된다.

첫 페이지 소스를 보면, check 버튼을 누르면, submit_check(this); 함수를 호출한다.

해당 함수는 http://wargame.kr:8080/type_confusion/util.js에 정의되어있다.

 

 

 

정의된 함수를 가져와서 key값에 true가 들어가도록 재정의 해주었다. 크롬 개발자도구 콘솔창을 이용하면 된다.

 

 

25행 수정

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
27
28
29
30
31
32
33
34
35
var lock = false;
function submit_check(f){
    if (lock) {
        alert("waiting..");
        return false;
    }
    lock = true;
    var key = f.key.value;
    if (key == "") {
        alert("please fill the input box.");
        lock = false;
        return false;
    }
 
    submit(key);
 
    return false;
}
 
function submit(key){
    $.ajax({
        type : "POST",
        async : false,
        url : "./index.php",
        data : {json:JSON.stringify({key: true})},
        dataType : 'json'
    }).done(function(result){
        if (result['code'== true) {
            document.write("Congratulations! flag is " + result['flag']);
        } else {
            alert("nope...");
        }
        lock = false;
    });
}
cs

 

그러면 입력란에 아무거나 입력하고 check를 누르면 flag를 얻을 수 있다.

 

 

 

 

 

 

 

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [php? c?] 풀이  (0) 2019.12.31
Wargame.kr [img recovery] 풀이  (0) 2019.12.31
Wargame.kr [tmitter] 풀이  (0) 2019.12.31
Wargame.kr [fly me to the moon] 풀이  (0) 2019.12.24
Wargame.kr [DB is really GOOD] 풀이  (0) 2019.12.24

+ Recent posts