
https://dreamhack.io/wargame/challenges/46
php로 작성된 Back Office 서비스입니다.
LFI 취약점을 이용해 플래그를 획득하는 문제입니다. 플래그는 /var/www/uploads/flag.php에 있습니다.
../../../../etc/passwd 를 입력하면 민감한 파일인 비밀번호 정보를 열람할 수 있는 것입니다.php://filter – 소스 코드 보기http://example.com/index.php?page=php://filter/convert.base64-encode/resource=[파일 이름]=> [파일 이름] 파일의 내용을 Base64로 인코딩해서 출력하게 합니다. 보통 PHP 설정에서 display_source = Off 되어 있으면 직접 소스코드가 안 보이는데, 우회할 수 있는 방법입니다.zip:// – 압축 파일 안의 파일 접근http://example.com/index.php?page=zip://uploads/something.zip#shell.php=> something.zip 의 압축을 풀고, 안에 있는 shell.php를 실행시킵니다./var/www/uploads/flag.php에 플래그가 있다는 문제 설명을 보고, 바로 http://host1.dreamhack.games:9132/var/www/uploads/flag.php 로 접근을 시도하였지만 404 오류가 떴습니다. 역시 다른 방법이 필요함을 알 수 있습니다.

주어진 index.php를 확인해 보았습니다.
<?php
include $_GET['page'] ? $_GET['page'] . '.php' : 'main.php';
?>
page 라는 GET 파라미터를 넣으면 include '입력값.php' 을, page 파라미터가 없으면 include 'main.php'을 싫행합니다.view.php 를 확인해 보았습니다.
<?php
$file = $_GET['file'] ? $_GET['file'] : '';
if(preg_match('/flag|:/i', $file)){
file_get_contents()로 파일 내용을 읽어서 화면에 출력합니다.file_get_contents() 에서 flag와 : 를 필터링 했지만, 우회 가능하기에 LFI 취약점이 발생합니다.문제에서 LFI 취약점 을 이용하라는 힌트가 있었기에, 활용하여 문제를 풀어줍니다. 위에서 설명한 PHP Wrapper 를 사용하면 flag를 획득할 수 있습니다.
플래그 값을 구해야 하기에, Base64 형태로 소스코드를 볼 수 있는 php://filter 를 이용합니다.
http://host1.dreamhack.games:9132/index.php?page=php://filter/convert.base64-encode/resource=/var/www/uploads/flag
http://example.com/index.php?page=php://filter/convert.base64-encode/resource=[파일 이름] 형식에서 [파일 이름] 에 flag값이 있는 /var/www/uploads/flag.php 에 이동할 수 있도록 경로를 설정합니다.파일의 내용을 Base64로 인코딩 한 상태가 나타났습니다.

Base64 변환 프로그램을 통해 플래그를 획득할 수 있었습니다.

page) is directly included as a PHP file using include, enabling arbitrary file inclusion.view.php) uses file_get_contents() with minimal filtering (flag and :), still allowing for bypass.php://filter/convert.base64-encode/resource=[file] allowed viewing the contents of /var/www/uploads/flag.php as base64.