• [BDSec CTF 2022] Awesome Note Keeping

    2022. 7. 22.

    by. hackintoanetwork


    문제에 들어가면 위와 같은 페이지를 볼 수 있는데


    크롬 개발자 도구를 열어보면 index.php.bak 이라는 백업 파일을 다운로드 할 수 있다고 한다.


    다운로드하고 .bak을 지우면 아래와 같은 소스코드를 얻을 수 있다.

    <!DOCTYPE html>
    <html>
    
    <head>
        <title>Awesome Note Keeping</title>
    </head>
    
    <body style="padding: 100px; background: #000000; color: #09b576">
    
        <h1>Welcome to Awesome Note Keeping</h1>
        <?php
        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);
        if (isset($_POST["note"]) && isset($_POST["note_title"])) {
            if (empty($_POST["note"]) || empty($_POST["note_title"])) {
                echo "All fields are required.";
            } else if (strlen($_POST["note_title"]) >= 13) {
                echo "Note title is too long.";
            } else if (strlen($_POST["note"]) >= 40) {
                echo "Note is too long.";
            } else {
                $note_title = str_replace("flag", "", $_POST["note_title"]);
                if (!empty($note_title)) {
                    if (file_exists($note_title . ".txt")) {
                        echo "There is already a note with that title and the note is <br>";
                        $note_title = str_replace("flag", "", $note_title);
                        $myNote = fopen($note_title . ".txt", "r");
                        echo fread($myNote, filesize($note_title . ".txt"));
                        fclose($myNote);
                    } else {
                        $myNote = fopen($note_title . ".txt", "w");
                        fwrite($myNote, $_POST["note"]);
                        fclose($myNote);
                        echo "Your note has been saved.";
                    }
                } else {
                    echo "Sorry ! You can't create flag note.";
                }
            }
        }
    
    
        if (isset($_GET["note_title"]) && !empty($_GET["note_title"]) && $_GET["note_title"] != "flag") {
            if (file_exists($_GET["note_title"] . ".txt")) {
                $myNote = fopen($_GET["note_title"] . ".txt", "r");
                echo fread($myNote, filesize($_GET["note_title"] . ".txt"));
                fclose($myNote);
            } else {
                echo "Sorry ! Couldn't find any note with that title.";
            }
        }
    
        ?>
        <br>
        <h5>Create a Note</h5>
        <form action="" method="POST">
            <table>
                <tr>
                    <td><label>Note Title : </label></td>
                    <td><input type="text" name="note_title" /></td>
                </tr>
                <tr>
                    <td><label>Note : </label></td>
                    <td><textarea name="note"></textarea></td>
                </tr>
            </table>
            <input type="submit" value="Save" />
        </form>
    
        <h5>Read a Note</h5>
        <form action="" method="GET">
            <table>
                <tr>
                    <td><label>Note Title : </label></td>
                    <td><input type="text" name="note_title" /></td>
                </tr>
            </table>
            <input type="submit" value="Read" />
        </form>
        <!-- Hi Seli, I have created this awesome note keeping web app today. I have saved a backup file index.php.bak for you. Download it and check it out.  -->
    </body>
    
    </html>

     

    코드를 보면 POST 방식으로 입력 받아 flag라는 문자열이 있으면 위,아래에서 두번 삭제하고 있는 것을 확인할 수 있다.


    이 경우 flflflagagag 를 입력하면 flag라는 문자열이 두번 필터링 되어 없어지면서 최종적으로 flag라는 문자열이 완성된다.

    flflflagagag를 한번 저장해주고 flflflagagag를 다시 한번 더 저장하면

    이미 존재하는 note라면서 아래와 같이 flag가 노출되는 것을 볼 수 있었다.

    다른 사람들이 푼 걸 보니까 

    http://206.189.236.145:9000/?note_title=./flag

    이런식으로도 풀 수 있다고 한다.

    Flag : BDSEC{tHe_n0t3_K33p1n6_4W350M3_N5}

     

     

    'CTF > BDSec CTF 2022' 카테고리의 다른 글

    [BDSec CTF 2022] Awesome Calculator  (0) 2022.07.22
    [BDSec CTF 2022] Knight Squad Shop  (0) 2022.07.22
    [BDSec CTF 2022] Jungle Templating  (0) 2022.07.22

    댓글