Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 프로그래밍
- 정보보안
- webhacking.kr
- lord of sqlinjection
- XSS GAME
- Over The Wire
- CTF
- burp suite
- sql injection bypass
- system hacking
- 인공지능
- web hacking
- hackthissite
- geminipro
- 개발자
- 웹해킹 기초
- Wargame
- SQL Injection
- web-server
- Bandit
- write up
- WebHacking
- 코딩
- root me
- 웹해킹
- 웹개발
- overthewire
- 사이버보안
- pythonprogramming
- 테크트렌드
Archives
- Today
- Total
컴맹에서 컴공 그리고 화이트 해커가 되는 그날까지
Pearfect Markdown (dreamhack) write up 본문
반응형
VM에 접속하면 이렇게 생긴 화면이 나온다.
코드를 다운로드 받아서 코드를 살펴보자.
index.php 파일
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Markdown Editor</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="container">
<h1>Upload and Edit Markdown Files</h1>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Choose Markdown file:</label>
<input type="file" name="file" id="file" accept=".md">
<input type="submit" value="Upload">
</form>
<div class="preview-container">
<h2>Example Markdown Preview</h2>
<div class="markdown-preview" id="preview"></div>
</div>
<?php
$uploads_dir = 'uploads/';
if ($handle = opendir($uploads_dir)) {
echo "<h2>Uploaded Files</h2><ul>";
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<li><a href='edit.php?file=" . urlencode($entry) . "'>" . htmlspecialchars($entry) . "</a></li>";
}
}
closedir($handle);
echo "</ul>";
}
?>
</div>
<script>
fetch('post_handler.php')
.then(response => response.text())
.then(data => {
document.getElementById('preview').innerHTML = marked.parse(data);
});
</script>
</body>
</html>
사용자가 .md 파일을 업로드 할 수 있도록 해줌
uploads/ 디렉터리 내 파일을 목록으로 표시하고
Markdown 미리보기 기능을 제공한다. 그렇기 때문에 첫 페이지에서 Example Markdown Preview를 볼 수 있는 것이었다.
취약점
<?php
$uploads_dir = 'uploads/';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$file = $_GET['file'] ?? 'example.md';
$path = $uploads_dir . $file;
include($path);
} else {
echo "Use GET method!!";
}
?>
이 문제의 취약점은 바로 post_handler.php에 있었다.
PHP 코드에서 다른 PHP 파일을 포함할 때 사용하는 include($path);를 사용하여 .md 파일은 원래 PHP 코드가 포함되지 않은 문서 파일이어야 하지만, .md 파일 안의 PHP 코드가 그대로 실행되게 된다.
그렇기 때문에 .md 파일 안에 <?php system("ls -al"); ?> 과 같은 PHP 코드가 포함되어 있으면 실행되게 되는 것이다.
익스플로잇
우리의 목적은 flag.txt 파일을 읽는 것이다. 읽는 것은 cat!!! flag 파일은 루트 디랙토리에 위치해 있다. 따라서
cat /*flag 명령어는 리눅스 시스템에서 특정 파일의 내용을 출력하려는 시도이다.
예를 들어, /flag.txt, /flag123, /flag_secret 같은 파일이 있다면 cat /*flag는 해당 파일들의 내용을 출력하려고 명령하는 것이다.
컷!!!
반응형
'해킹 > Web hacking' 카테고리의 다른 글
webhacking.kr old-49 Write Up (0) | 2025.03.06 |
---|---|
webhacking.kr old-42 Write Up (0) | 2025.03.05 |
Cross-Site Scripting (XSS) 완벽 가이드: 기초부터 고급 방어 기법까지 (0) | 2025.02.23 |
OverTheWire: Natas 클리어!!! (0) | 2025.01.29 |
Root Me[web-server] : HTTP - Headers Write up (0) | 2024.09.19 |