본문 바로가기
드림핵

[드림핵][wargame.kr] type confusion 풀이

by jwcs 2024. 1. 10.
728x90

https://dreamhack.io/wargame/challenges/329

 

[wargame.kr] type confusion

Description Simple Compare Challenge. hint? you can see the title of this challenge. :D

dreamhack.io

 

php에서 발생하는 느슨한 비교 문제이다.

 

/

첫 화면이다. 바로 view-source를 확인해보겠다.

 

<?php
 if (isset($_GET['view-source'])) {
     show_source(__FILE__);
    exit();
 }
 if (isset($_POST['json'])) {
     usleep(500000);
     require("./lib.php"); // include for FLAG.
    $json = json_decode($_POST['json']);
    $key = gen_key();
    if ($json->key == $key) {
        $ret = ["code" => true, "flag" => $FLAG];
    } 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>

문제에서 제공하는 소스 코드이다. 서버에서 $key 변수를 선언한다. "welcome to wargame.kr!_" 라는 문자열에 uniqid() 함수를 실행시키고 sha1()으로 해싱한다.

여기서 uniqid()는 유일한 ID를 생성하는 데 사용된다. 이 함수는 주로 파일명, 데이터베이스 레코드, 세션 변수 등에서 중복을 방지하기 위한 목적으로 사용된다. uniqid()는 현재의 시간을 기반으로 하여 문자열을 생성한다.

uniqid()는 두 개의 파라미터를 받는다.

uniqid()의 설명 출처:https://www.php.net/manual/en/function.uniqid.php

 

이런 식이다.

more_entropy false
more_entropy true 비교 1
more_entropy true 비교 2

이를 통해 비교하는 $key의 값이 항상 달라질 것이다.

 

이 $key 변수를 우리가 입력하는 값과 == 비교한다. 이를 느슨한 비교라고 한다. 여기서 취약점이 발생한다.

느슨한 비교표  출처:  https://www.php.net/manual/en/types.comparisons.php

우리가 비교하는 값은 문자열이다. 이 문자열이 true와 비교하면 true가 된다. 따라서 우리는 true를 입력해주면 flag를 얻을 수 있을 것이다.

 

burpsuite 수정 전

버프 스위트로 잡아서 코드를 수정해주자. %221%22 이 부분은 url encode 되어 있는 부분이다. 해석 해보면 "1"이므로 이 부분을 true로 바꿔주자.

burpsuite 수정 후
flag

짜잔

728x90
반응형

'드림핵' 카테고리의 다른 글

[드림핵] baby-sqlite 풀이  (2) 2024.01.10
[드림핵] out of money 풀이  (0) 2024.01.10
[드림핵] web-misconf-1 풀이  (0) 2024.01.08
[드림핵] proxy-1 풀이  (0) 2024.01.08
[드림핵] session 풀이  (4) 2024.01.05