아래는 페이지 소스 보기.
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="./css/style.css" rel="stylesheet">
<title>Code Inj. & File Inc. #1</title>
</head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="./js/main.js"></script>
<body>
<div class="container d-block">
<div class="mt-5 d-flex justify-content-center">
<div class="terminal-form">
<div id="terminal">
<p>
Welcome to HSPACE Ping Terminal!<br />
<span>•</span> This terminal provides testing ping to arbitrary IP host (including IPv6!)<br/>
<span>•</span> Note that our Ping needs some time after you type the command. (about 5 seconds) <br />
<span>•</span> To check usage, type the command <span class="orange">help</span> and press enter!<br />
</p>
<p>
<span class="orange">player@HSPACE</span> <span class="grey">$</span> <span class="user-input">help</span><textarea id="user-text" autofocus></textarea>
</p>
</div>
</div>
</div>
</div>
</body>
</html>
커맨드 인젝션 문제이다.
help를 입력하면 hint가 나온다.
hint를 입력하면 링크가 나온다.
link를 누르면 다음과 같은 화면으로 이동한다.
<?php
if(isset($_GET["hint"])) {
show_source(__FILE__);
die();
}
//flag is in $flag
include "flag.php";
header("Content-Type: application/json");
include "tool.php";
$t = $_POST["target"] ?? "";
if(!preg_match("/(\d+\.\d+\.\d+\.\d+|[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+)/", $t)){
echo error("no ip address");
die();
}
$result = shell_exec("ping -c 3 \"{$t}\"");
//$result = shell_exec("id");
echo success(array(
"result" => $result
));
$_POST를 target으로 값을 받아오고,
표현식에 match되는 문자열이 없으면 error를 반환하고, die.
문자열이 있으면 shell_exec로 값을 뽑아낸다.
ip 1.1.1.1 이나 8.8.8.8 을 넣어주면 1 match라고 뜬다.
포함만 하면 그 뒤에 무슨 문자열이 오든 상관 없다.
'CTF > SWING CTF 2023' 카테고리의 다른 글
[Misc] Eagles (0) | 2023.08.30 |
---|---|
[Forensic] HSpace Backdoor 3 (0) | 2023.08.30 |
[Forensic] HSpace Backdoor 2 (0) | 2023.08.05 |
[Forensic] HSpace Backdoor 1 (0) | 2023.08.05 |
[Misc] Can U guess? (0) | 2023.08.05 |