๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[Dreamhack]WebHacking/Wargame&CTF

[Dreamhack] Level1: [wargame.kr] strcmp

by Yun2๐Ÿ‘ 2024. 2. 25.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธ Access

if you can bypass the strcmp function, you get the flag.

 

 

๐Ÿ‘พ Exploit Algorithm & Payload

 > view-source

๋”๋ณด๊ธฐ
<?php
    require("./lib.php"); // for FLA

    $password = sha1(md5(rand().rand().rand()).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>" . $FLAG ."</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>

 

 

#1


: '/' ํŽ˜์ด์ง€์—์„œ password๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ํผ์ด ์žˆ๊ณ  'chk' ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ํŒจ์Šค์›Œ๋“œ๊ฐ€ ํ‹€๋ฆฐ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

: '/?view-sourc' ํŽ˜์ด์ง€์—์„œ๋Š” PHP ์›น ํŽ˜์ด์ง€์˜ ์ผ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

: strcmp ์ทจ์•ฝ์ ์„ ์ด์šฉํ•˜๋ฉด ํ’€๋ฆด ๊ฒƒ์ด๋ผ๋Š” ๊ฒƒ์„ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

#2


strcmp(): ๋‘ ๋ฌธ์ž์—ด์ด ๊ฐ™์œผ๋ฉด 0์„, ๊ฐ™์ง€ ์•Š์œผ๋ฉด 0์ด ์•„๋‹Œ ๊ฐ’์„ ๋ฐ˜ํ™˜
strncmp(): ๋‘ ๋ฌธ์ž์—ด์˜ ์›ํ•˜๋Š” ๊ธธ์ด๋งŒํผ ๊ฐ™์œผ๋ฉด 0์„ ๊ฐ™์ง€ ์•Š์œผ๋ฉด 0์ด ์•„๋‹Œ ๊ฐ’์„ ๋ฐ˜ํ™˜

: strcmp($a, $b)๋ฅผ ์‹คํ–‰ ํ•  ๋•Œ, $a๊ฐ€ ์ž‘์œผ๋ฉด ์Œ์ˆ˜, $b๊ฐ€ ์ž‘์œผ๋ฉด ์–‘์ˆ˜, $a์™€ $b๊ฐ€ ๊ฐ™์œผ๋ฉด 0์ด ๋ฐ˜ํ™˜๋œ๋‹ค. ํ•˜์ง€๋งŒ PHP ํŠน์ • ๋ฒ„์ „์—์„œ ์ž…๋ ฅ ๊ฐ’์œผ๋กœ ๋ฐฐ์—ด์„ ๋„ฃ์œผ๋ฉด strcmp ํ•จ์ˆ˜๊ฐ€ 0์„ ๋ฆฌํ„ดํ•˜๋Š” ์ทจ์•ฝ์ ์ด ์กด์žฌํ•œ๋‹ค.

: ์˜ˆ๋กœ $a = Array("a")๊ณ  $b = '0ab12..'์—ฌ๋„ strcmp($a, $b)==0์€ True๋‹ค.

 

: ๊ฒŒ๋‹ค๊ฐ€ ํ˜„์žฌ "==" ๋Š์Šจํ•œ ๋น„๊ต๋ฅผ ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— NULL == 0(True)๊ฐ€ ๋˜์–ด๋ฒ„๋ฆฐ๋‹ค.

("===" ์œผ๋กœ ์—„๊ฒฉํ•œ ๋น„๊ต๋ฅผ ํ•œ ๊ฒฐ๊ณผ NULL == 0 (False))

 

 

๐Ÿ”‘Analysis and results for obtaining the Flag DH{…}


๋ฐ˜์‘ํ˜•

'[Dreamhack]WebHacking > Wargame&CTF' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dreamhack] Level1: simple-ssti  (0) 2024.03.24
[Dreamhack] Level1: random-test  (2) 2024.03.04
[Dreamhack] Level2: login-1  (2) 2024.02.25
[Dreamhack] CTF Season 5 Round #4 - BypassIF  (1) 2024.02.25
[Dreamhack] Level2: baby-sqlite  (0) 2024.02.23