๐๏ธ Access
php๋ก ์์ฑ๋ ํ์ด์ง์ ๋๋ค.
์๋ง์ Id๊ณผ Password๋ฅผ ์ ๋ ฅํ์ฌ ํ๋๊ทธ๋ฅผ ํ๋ํ์ธ์.
ํ๋๊ทธ์ ํ์์ 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>Type c-j</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="/">Type c-j</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">index page</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container">
<div class="box">
<h4>Enter the correct ID & Password.</h4>
<p>
<form method="post" action="/check.php">
<input type="text" placeholder="Id" name="input1">
<input type="text" placeholder="Password" 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>Type c-j</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="/">Type c-j</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Index page</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container">
<?php
function getRandStr($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[mt_rand(0, $charactersLength - 1)];
}
return $randomString;
}
require_once('flag.php');
error_reporting(0);
$id = getRandStr();
$pw = sha1("1");
// POST request
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input_id = $_POST["input1"] ? $_POST["input1"] : "";
$input_pw = $_POST["input2"] ? $_POST["input2"] : "";
sleep(1);
if((int)$input_id == $id && strlen($input_id) === 10){
echo '<h4>ID pass.</h4><br>';
if((int)$input_pw == $pw && strlen($input_pw) === 8){
echo "<pre>FLAG\n";
echo $flag;
echo "</pre>";
}
} else{
echo '<h4>Try again.</h4><br>';
}
}else {
echo '<h3>Fail...</h3>';
}
?>
</div>
</body>
</html>
#1
: '/' ํ์ด์ง์์ id์ password๋ฅผ ์ ๋ ฅ ํ ์ ์ถํ๋ฉด ๊ฐ์ ํ์ธํ ์ ์์ ๊ฒ์ผ๋ก ์์๋๋ค.
: ๊ทธ๋ฌ๋ ์ด๋ค ๊ฐ์ ์ ๋ ฅํ์ฌ๋ "Try again."์ด๋ผ๋ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋์ด์ ์ฝ๋๋ฅผ ๋ถ์ํ๋ค.
#2
...
$id = getRandStr();
$pw = sha1("1");
...
: id๋ getRandStr() ํจ์๋ฅผ ๋ถ์ํ๋ฉด ๋ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
: pw๋ sha1 ํจ์๋ SHA-1 16์ง์ 40์๋ฆฌ๋ก ๋ ๋๋ง๋๋ ์ํธํ ํด์ฌ ํจ์๋ก ๋ณด์ธ๋ค.
function getRandStr($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[mt_rand(0, $charactersLength - 1)];
}
return $randomString;
}
require_once('flag.php');
error_reporting(0);
$id = getRandStr();
$pw = sha1("1");
// POST request
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input_id = $_POST["input1"] ? $_POST["input1"] : "";
$input_pw = $_POST["input2"] ? $_POST["input2"] : "";
sleep(1);
if((int)$input_id == $id && strlen($input_id) === 10){
echo '<h4>ID pass.</h4><br>';
if((int)$input_pw == $pw && strlen($input_pw) === 8){
echo "<pre>FLAG\n";
echo $flag;
echo "</pre>";
}
} else{
echo '<h4>Try again.</h4><br>';
}
}else {
echo '<h3>Fail...</h3>';
}
: ๋ถ์ ๊ฒฐ๊ณผ if((int)$input_id == $id && strlen($input_id) === 10), $input_id๋ (int)๋ฅผ ํตํด ์ ์๋ก ํ๋ณํ ๋ ํ์ $id์ ๋น๊ต๋๊ณ , ๊ธธ์ด๋ 10์ด๋ค.
: ์ฌ๊ธฐ์ PHP ์์์ ์ฐ์ฐ์ ์ทจ์ฝ์ '==' ์ด ์ทจ์ฝํ ์ ์๋ค๋ ๊ฒ์ ์ ์ ์๋ค.(Loose Comparison)
: '==' ์ฐ์ฐ์๋ PHP๋ฌธ์์ $a์ $b๊ฐ ๊ฐ์ผ๋ฉด true, '===' ์ฐ์ฐ์๋ $a์ $b๊ฐ ๊ฐ๊ณ , ๋์ผํ ์๋ฃํ์ผ ์ true
: ์ฆ, '==' ์ฐ์ฐ์๋ ๋ฌธ์์ด๊ณผ ์ ์๋ฅผ ๋น๊ตํ์ ๋, ๋ฌธ์์ด์ด ์ ์(int) ํน์ ์ค์(float)์ผ๋ก ๋ฐ๋๊ฒ ๋๋ค.
๐Analysis and results for obtaining the Flag DH{…}
// ๊ธธ์ด 10
// 0e ๋ค๋ก ์ซ์ ๋๋คํ๊ฒ ๊ฐ๋ฅ
// ๋ฌธ์์ด์ ์ ์๋ก ํ ๋ณํํ ๋๋ ๋ฌธ์์ด์ ์ ๋ถ๋ถ๋ถํฐ ์ซ์๊ฐ ์๋ ๋ฌธ์๋ฅผ ๋ง๋ ๋๊น์ง ์ซ์๋ฅผ ์ถ์ถํ์ฌ ๋ณํ
(int) $input_id = 0e12345678 → 0 * ... → 0
(int) $input_id = 0e1234567a → 0 * ... → 0
...
: ์ด๋ฅผ ํ์ฉํด ๋งค์งํด์ฌ(0e: ์ด๊ฒ์ผ๋ก ์์ํ๋ ๋ฌธ์์ด ๋ค๊ฐ ๋ชจ๋ ์ซ์๋ฉด floatํํ๋ก ์ธ์ํ๋ค)๋ฅผ '==' ์ฐ์ฐ์์ ํจ๊ป ์ ์ฉํ ๊ฒฝ์ฐ ์ทจ์ฝํ ์ ์๋ค.
// ๊ธธ์ด 8
$input_pw = 356A192B
: $pw์ ๊ฒฝ์ฐ๋ https://www.convertstring.com/ko/Hash/SHA1 ํด๋น ์ฌ์ดํธ์์ SHA-1 ํด์ํ๊ณ ์ ํ๋ ํ ์คํธ์ธ "1"์ ์ ๋ ฅํ์๋๋ "356A192B7913B04C54574D18C28D46E6395428AB" ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์๋ค.
'[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: baby-union (2) | 2024.02.02 |
[Dreamhack] CTF Season 5 Round #2 - php7cmp4re (0) | 2024.01.28 |