๋ฌธ์ ์ค๋ช
์ฌ์ดํธ์ ๋ค์ด๊ฐ ๋ณด๋ฉด
์ด๋ ๊ฒ Step 1๊ณผ Step 2๋ฅผ ํด๊ฒฐํด์ผ๋ง flag๋ฅผ ์ฐพ์ ์ ์๋ ํ์์ธ ๊ฒ ๊ฐ๋ค.
๋ฌธ์ ํ์ผ์ ๋ค์ด๋ก๋ํด ๋ดค๋ค.
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>PHPreg</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="/">PHPreg</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Step 1</a></li>
<li><a href="/step2.php">Step 2</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container">
<div class="box">
<!-- PHP code -->
<?php
// POST request
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input_name = $_POST["input1"] ? $_POST["input1"] : "";
$input_pw = $_POST["input2"] ? $_POST["input2"] : "";
// pw filtering
if (preg_match("/[a-zA-Z]/", $input_pw)) {
echo "alphabet in the pw :(";
}
else{
$name = preg_replace("/nyang/i", "", $input_name);
$pw = preg_replace("/\d*\@\d{2,3}(31)+[^0-8\"]\!/", "d4y0r50ng", $input_pw);
if ($name === "dnyang0310" && $pw === "d4y0r50ng+1+13") {
echo '<h4>Step 2 : Almost done...</h4><div class="door_box"><div class="door_black"></div><div class="door"><div class="door_cir"></div></div></div>';
$cmd = $_POST["cmd"] ? $_POST["cmd"] : "";
if ($cmd === "") {
echo '
<p><form method="post" action="/step2.php">
<input type="hidden" name="input1" value="'.$input_name.'">
<input type="hidden" name="input2" value="'.$input_pw.'">
<input type="text" placeholder="Command" name="cmd">
<input type="submit" value="์ ์ถ"><br/><br/>
</form></p>
';
}
// cmd filtering
else if (preg_match("/flag/i", $cmd)) {
echo "<pre>Error!</pre>";
}
else{
echo "<pre>--Output--\n";
system($cmd);
echo "</pre>";
}
}
else{
echo "Wrong nickname or pw";
}
}
}
// GET request
else{
echo "Not GET request";
}
?>
</div>
</div>
<style type="text/css">
h4 {
color: rgb(84, 84, 84);
}
.box{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
pre {
width: 80%;
}
.door_box {
position: relative;
width: 240px;
height: 180px;
margin: 20px 0px;
}
.door_black {
position: absolute;
width: 140px;
height: 180px;
background-color: black;
border-radius: 10px;
right:0px;
}
.door {
z-index: 2;
position: absolute;
width: 140px;
height: 180px;
background-color: #b9abf7;
border-radius: 10px;
right: 100px;
}
.door_cir{
z-index: 3;
position: absolute;
border-radius: 50%;
width: 20px;
height: 20px;
border: 2px solid rgba(255, 222, 113, 0.873);
background-color: #ffea98;
top: calc( 180px / 2 - 10px );
right: 10px;
}
</style>
</body>
</html>
step2.php
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>PHPreg</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="/">PHPreg</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Step 1</a></li>
<li><a href="/step2.php">Step 2</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container">
<div class="box">
<h4>Step 1 : Open the door & Go to Step 2 !!</h4>
<div class="door"><div class="door_cir"></div></div>
<p>
<form method="post" action="/step2.php">
<input type="text" placeholder="Nickname" name="input1">
<input type="text" placeholder="Password" name="input2">
<input type="submit" value="์ ์ถ">
</form>
</p>
</div>
</div>
<style type="text/css">
h4 {
color: rgb(84, 84, 84);
}
.box{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.door {
position: relative;
margin: 20px 0px;
width: 140px;
height: 180px;
background-color: #b9abf7;
border-radius: 10px;
}
.door_cir{
position: absolute;
border-radius: 50%;
width: 20px;
height: 20px;
border: 2px solid rgba(255, 222, 113, 0.873);
background-color: #ffea98;
top: calc( 180px / 2 - 10px );
right: 10px;
}
</style>
</body>
</html>
index.php
step1.php๋ ์ ์๋ ๊ฑด์ง ์๋ฌธ์ด๊ธด ํ์ง๋ง.. ์ฐ์ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ๊ทธ๋ฌ๋ฏ์ด index.php ํ์ผ์๋ ์ ์ฉํ ์ ๋ณด๊ฐ ์๋ ๊ฒ ๊ฐ๋ค.
step2.php๋ฅผ ์ดํด ๋ณด๋, ๊ฐ๊ฐ Nickname๊ณผ Password์ ๋ค์ด๊ฐ์ผ ํ๋ ๊ฐ์ ์ง์ ์ ์ผ๋ก ๋ณด์ฌ์ฃผ๊ณ ์๋ ๊ฒ์ ํ์ธํ๋ค.
else{
$name = preg_replace("/nyang/i", "", $input_name);
$pw = preg_replace("/\d*\@\d{2,3}(31)+[^0-8\"]\!/", "d4y0r50ng", $input_pw);
if ($name === "dnyang0310" && $pw === "d4y0r50ng+1+13") {
echo '<h4>Step 2 : Almost done...</h4><div class="door_box"><div class="door_black"></div><div class="door"><div class="door_cir"></div></div></div>';
$cmd = $_POST["cmd"] ? $_POST["cmd"] : "";
name์ด "dnyang0310", pw๊ฐ "d4y0r50ng+1+13"์ด๋ฉด step2๋ก ๋์ด๊ฐ ์ ์๋ค.
๊ทธ๋ฌ๋, ์ ๋ ฅ๊ฐ์ ํํฐ๋ง์ด ๊ฑธ๋ ค์๋ ๊ฒ ์ญ์ ์ฝ๋์์ ์ฐพ์๋ณผ ์ ์๋ค.
์ ์ฝ๋๋ฅผ ๋ณด๋ฉด ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ name๊ฐ์์ nyang์ ๋น ๋ฌธ์์ด๋ก ํํฐ๋งํ๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ name๊ฐ์ dnyangnyang0310์ ์ ๋ ฅํด nyang์ด ์ ์์ ์ผ๋ก ๋ค์ด๊ฐ๋๋ก ํด์ผ ํ๋ค.
// pw filtering
if (preg_match("/[a-zA-Z]/", $input_pw)) {
echo "alphabet in the pw :(";
์ํ๋ฒณ ๋์๋ฌธ์ ๋ชจ๋ ์ ๋ ฅ ์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ๋ฌ๋ค๋ ๊ฒ์ด๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ์ด๋ฆ๋๋ก php ์ ๊ท์์ ์ด์ฉํ์ฌ ํด๊ฒฐํด์ผ ๋๋ ๊ฒ ๊ฐ๋ค.
pw์ ์ ๊ท ํํ์์ ํ๋์ฉ ํด์ฒดํด ๋ณด๋ฉด,
\d* : 0~9 ์ฌ์ด ์ซ์๊ฐ 0๊ฐ ์ด์ ๋ํ๋์ผ ํจ
\@ : @
\d{2, 3}(31) : 0~9 ์ฌ์ด์ ์ซ์ 2~3ํ ํ์ 31์ ์
+ : ์ง๊ธ๊น์ง์ ํํ์ 1ํ ์ด์ ๋ฐ๋ณต
[^0-8] : 0~8 ์ด์ธ์ ๋ฌธ์๊ฐ ์์ผ๋ฉด ํจํด์ด ๋งค์นญ
! : !
๋ชจ๋ ์์๋ฅผ ์กฐํฉํด ๋ณด๋ฉด 1@12319!๋ผ๋ ๋ฌธ์์ด์ ๋ง๋ค ์ ์๋ค.
๋น๋ฐ๋ฒํธ๋ d4y0r50ng+1+13์ด ๋์ด์ผ ํด์ 1@12319!+1+13์ ๋น๋ฐ๋ฒํธ์ ์ ๋ ฅํด ๋ณด์.
Step2๋ก ๋์ด๊ฐ๋ ๊ฒ์ ์ฑ๊ณตํ๋ค.
์ด ์ญ์ step2.php ์ฝ๋์์ ์ ๋ ฅ๊ฐ์ ๋ํ ํํฐ๋ง์ด ์ ์ฉ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
// cmd filtering
else if (preg_match("/flag/i", $cmd)) {
echo "<pre>Error!</pre>";
}
else{
echo "<pre>--Output--\n";
system($cmd);
echo "</pre>";
}
}
else{
echo "Wrong nickname or pw";
}
}
์ด๋ฅผ ์ ์ํด์ ๋ช ๋ น์ด๋ฅผ ์์ฑํด ๋ณด๋ฉด,
cat ../dream/f?ag.txt
๋ฅผ ๋ฃ์ ์ ์๋ค. ํด๋น command๋ฅผ ์ ๋ ฅํด ๋ดค๋๋,
ํ๋๊ทธ ํ๋์ ์ฑ๊ณตํ๋ค!
'SWUFORCE > ์๊ฒ์ ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Dreamhack] web-misconf-1 (web) (0) | 2024.05.14 |
---|---|
[Dreamhack] devtools-sources (web) (0) | 2024.05.14 |
[Dreamhack] php7cmp4re (web) (0) | 2024.05.07 |
[Dreamhack] Carve Party (web) (0) | 2024.05.01 |
[Dreamhack] simple-web-request (web) (0) | 2024.05.01 |