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

[Dreamhack] CTF Season 5 Round #2 - php7cmp4re

by Yun2๐Ÿ‘ 2024. 1. 28.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธ Access

php 7.4๋กœ ์ž‘์„ฑ๋œ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.
์•Œ๋งž์€ Input ๊ฐ’์„ ์ž…๋ ฅํ•˜๊ณ  ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•˜์„ธ์š”.
ํ”Œ๋ž˜๊ทธ ํ˜•์‹์€ DH{} ์ž…๋‹ˆ๋‹ค.

 

 

๐Ÿ‘พ Exploit Algorithm & Payload

> index.php

๋”๋ณด๊ธฐ
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>php7cmp4re</title>
</head>
<body>
    <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-stop">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" href="/">php7cmp4re</a>
        </div>
        <div id="navbar">
          <ul class="nav navbar-nav">
            <li><a href="/">index page</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
    <div class="container">
      <div class="box">
      <h4>Enter the correct Input.</h4>
        <p>
          <form method="post" action="/check.php">
              <input type="text" placeholder="input1" name="input1">
              <input type="text" placeholder="input2" name="input2">
              <input type="submit" value="์ œ์ถœ">
          </form>
        </p>
      </div>

    <?php
        require_once('flag.php');
        error_reporting(0);
    ?> 
    </div> 
</body>
</html>

> check.php

๋”๋ณด๊ธฐ
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>php7cmp4re</title>
</head>
<body>
    <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" href="/">php7cmp4re</a>
        </div>
        <div id="navbar">
          <ul class="nav navbar-nav">
            <li><a href="/">Index page</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
    <div class="container">
    <?php
    require_once('flag.php');
    error_reporting(0);
    // POST request
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
      $input_1 = $_POST["input1"] ? $_POST["input1"] : "";
      $input_2 = $_POST["input2"] ? $_POST["input2"] : "";
      sleep(1);

      if($input_1 != "" && $input_2 != ""){
        if(strlen($input_1) < 4){
          if($input_1 < "8" && $input_1 < "7.A" && $input_1 > "7.9"){
            if(strlen($input_2) < 3 && strlen($input_2) > 1){
              if($input_2 < 74 && $input_2 > "74"){
                echo "</br></br></br><pre>FLAG\n";
                echo $flag;
                echo "</pre>";
              } else echo "<br><br><br><h4>Good try.</h4>";
            } else echo "<br><br><br><h4>Good try.</h4><br>";
          } else echo "<br><br><br><h4>Try again.</h4><br>";
        } else echo "<br><br><br><h4>Try again.</h4><br>";
      } else{
        echo '<br><br><br><h4>Fill the input box.</h4>';
      }
    } else echo "<br><br><br><h3>WHat??!</h3>";
    ?> 
    </div> 
</body>
</html>

> flag.php

๋”๋ณด๊ธฐ
<?php
    $flag = 'flag{**Sample**}'
?>

 

 

#1


: '/' ํŽ˜์ด์ง€์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด input1๊ณผ input2์— ์ž…๋ ฅ ํ›„ ์ œ์ถœํ•˜๋ฉด ๊ฐ’์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋œ๋‹ค.

: ๊ทธ๋Ÿฌ๋‚˜ ์–ด๋–ค ๊ฐ’์„ ์ž…๋ ฅํ•˜์—ฌ๋„ "Try again."์ด๋ผ๋Š” ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜์–ด์„œ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ–ˆ๋‹ค.

 

 

#2


1) input_1๊ณผ input_2๋Š” ๊ณต๋ฐฑ์ด์—ฌ์„œ๋Š” ์•ˆ๋œ๋‹ค
2) input_1์˜ ๋ฌธ์ž์—ด ๊ธธ์ด๋Š” 4 ๋ฏธ๋งŒ์ด์–ด์•ผ ํ•œ๋‹ค
3) input_1์€ ๋ฌธ์ž์—ด ๊ฐ’ "8" ๋ณด๋‹ค ์ž‘๊ณ  "7.A"๋ณด๋‹ค ์ž‘์œผ๋ฉฐ ๋™์‹œ์— "7.9"๋ณด๋‹ค ์ปค์•ผ ํ•œ๋‹ค.
4) input_2๋Š” ๋ฌธ์ž์—ด ๊ธธ์ด๋Š” 3 ๋ฏธ๋งŒ, 1 ์ดˆ๊ณผ์ด์–ด์•ผ ํ•˜๊ณ (3 > input_2 > 1),
    ๊ฒฐ๊ณผ๊ฐ’์€ ์ˆซ์ž 74 > input_2, ๋ฌธ์ž์—ด "74" < input_2 ์ด์–ด์•ผ ํ•œ๋‹ค.

: check.php ์กฐ๊ฑด๋ฌธ ํ•ด์„์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

 

 

#3


 

: input_1์€ ๋ฌธ์ž์—ด ๊ฐ’ "8"๋ณด๋‹ค ์ž‘๊ณ , "7.9"๋ณด๋‹ค ํฌ๋ฉฐ, "7.A"๋ณด๋‹ค ์ž‘์•„์•ผ ํ•œ๋‹ค.

: ๋˜ํ•œ ๋ฌธ์ž์—ด ๊ธธ์ด๊ฐ€ 4๋ฏธ๋งŒ์ด์–ด์•ผ ํ•˜๊ธฐ์— ASCII ์ฝ”๋“œ๋ฅผ ์ด์šฉํ–ˆ๋‹ค.

: "7." ๋’ค์— ์˜ค๋Š” ๋ฌธ์ž๋Š” "9"๋ณด๋‹ค ํฌ๊ณ  "A"๋ณด๋‹ค ์ž‘์•„์•ผ ํ•œ๋‹ค. ๋•Œ๋ฌธ์— ๋งŒ์กฑํ•˜๋Š” ๊ฐ’์€ 7.: ~ 7.@ ์ด๋‹ค.

: ๋”ฐ๋ผ์„œ input1์— ๊ฐ’์„ ์ž‘์„ฑํ•˜๋ฉด "Good Try."๋ฅผ ๋งŒ๋‚  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

#4


: input_2๋Š” 3 > strlen($input_2 )> 1, 74 > input_2 > "74" ์ด๋‹ค.

: PHP์—์„œ๋Š” ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ™œ ๋•Œ, ๊ฐ€๋Šฅํ•œ ๊ฐ€์žฅ ๊ธด ์ˆซ์ž๋ฅผ ์ฐพ๋Š”๋‹ค.

: ์ฆ‰, ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ๋งŒ๋‚  ๋•Œ๊นŒ์ง€ ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

: ์˜ˆ๋ฅผ๋“ค๋ฉด "7a", "7A", "7#", ...์˜ ๋ฌธ์ž์—ด์€ ์ˆซ์ž๋กœ ํ•ด์„๋  ๋•Œ, ์ˆซ์ž 74๋ณด๋‹ค ์ž‘๊ฒŒ ๋˜๊ณ , ๋ฌธ์ž์—ด 74๋ณด๋‹ค๋Š” ํฌ๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

: ๋•Œ๋ฌธ์— ๋งŒ์กฑํ•˜๋Š” ๊ฐ’์€ 7: ~ ...(๋’ค์— ASCII ๋ฌธ์ž๋“ค ๋“ฑ๋“ฑ ๋‹ค์–‘ํ•˜๊ฒŒ ๊ฐ€๋Šฅ)

 

 

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


๋ฐ˜์‘ํ˜•

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

[Dreamhack] Level1:Beginner blue-whale  (1) 2024.02.07
[Dreamhack] Level2: Dream Gallery  (0) 2024.02.03
[Dreamhack] Level2: filestorage  (0) 2024.02.02
[Dreamhack] Level1: Type c-j  (2) 2024.02.02
[Dreamhack] Level1: baby-union  (2) 2024.02.02