pico CTF

[pico CTF] Forbidden Paths

skyepodium 2022. 6. 4. 20:37

1. 개요

file traversal 문제

https://play.picoctf.org/practice?category=1&page=1&search=Forbidden%20Paths 

 

2. 분석

 

read.php를 입력하면 현재 코드를 읽을 수 있습니다.

$firstChar = $_POST['filename'][0];

if( strcmp($firstChar, '/') == 0 )
{
echo "Not Authorized";
}
else
{
if (file_exists($_POST['filename'])) {

$file = fopen($_POST['filename'], 'r');

while(! feof($file))
{
$line = fgets($file);
echo $line. "
";
}

fclose($file);
} else {
echo "File does not exist";
}
}
?>

코드를 보니

 

flag.txt를 넣었을 때 File does not exist

 

이 나타났던 이유는 현재 디렉토리에 flag.txt 파일이 없었기 때문입니다.

 

경로를 상승하면서, 올라가봅니다.

 

3. exploit

../../../../flag.txt