다음은 natas13의 페이지 화면이다.
아무 파일을 업로드해본 결과 다음과 같이 떴다.
View sourcecode를 통해 소스코드를 확인해주었다.
<html>
<head>
<!-- This stuff in the header has nothing to do with the level -->
<link rel="stylesheet" type="text/css" href="http://natas.labs.overthewire.org/css/level.css">
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/jquery-ui.css" />
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/wechall.css" />
<script src="http://natas.labs.overthewire.org/js/jquery-1.9.1.js"></script>
<script src="http://natas.labs.overthewire.org/js/jquery-ui.js"></script>
<script src=http://natas.labs.overthewire.org/js/wechall-data.js></script><script src="http://natas.labs.overthewire.org/js/wechall.js"></script>
<script>var wechallinfo = { "level": "natas13", "pass": "<censored>" };</script></head>
<body>
<h1>natas13</h1>
<div id="content">
For security reasons, we now only accept image files!<br/><br/>
<?
function genRandomString() {
$length = 10;
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters)-1)];
}
return $string;
}
function makeRandomPath($dir, $ext) {
do {
$path = $dir."/".genRandomString().".".$ext;
} while(file_exists($path));
return $path;
}
function makeRandomPathFromFilename($dir, $fn) {
$ext = pathinfo($fn, PATHINFO_EXTENSION);
return makeRandomPath($dir, $ext);
}
if(array_key_exists("filename", $_POST)) {
$target_path = makeRandomPathFromFilename("upload", $_POST["filename"]);
$err=$_FILES['uploadedfile']['error'];
if($err){
if($err === 2){
echo "The uploaded file exceeds MAX_FILE_SIZE";
} else{
echo "Something went wrong :/";
}
} else if(filesize($_FILES['uploadedfile']['tmp_name']) > 1000) {
echo "File is too big";
} else if (! exif_imagetype($_FILES['uploadedfile']['tmp_name'])) {
echo "File is not an image";
} else {
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file <a href=\"$target_path\">$target_path</a> has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
} else {
?>
<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
<input type="hidden" name="filename" value="<? print genRandomString(); ?>.jpg" />
Choose a JPEG to upload (max 1KB):<br/>
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<? } ?>
<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>
exif_imagetype함수를 통해 이미지파일만 업로드 가능하도록 하였다.
이전 단계와 동일하게 php파일을 작성해주어 비밀번호를 찾을 수 있도록 하였다.
그리고 이를 업로드해주었더니 아직은 jpg파일이 아니기 때문에 아래와 같이 jpg가 아니라고 뜬다.
그래서 이를 burp suite를 통해 jpg를 php로 변경해주었다.
그리고 파일 시그니처인 GIF89a를 추가해주었다.
그랬더니 아래와 같은 화면이 나타났다.
파일을 눌러주었더니 아래와 같이 비밀번호를 획득할 수 있었다.
GIF89aLg96M10TdfaPyVBkJdjymbllQ5L6qdl1
'Web Hacking > Natas' 카테고리의 다른 글
[Natas] Level 14 > Level 15 (0) | 2022.06.25 |
---|---|
[Natas] Level 13 > Level 14 (0) | 2022.06.19 |
[Natas] Level 11 > Level 12 (0) | 2022.05.27 |
[Natas] Level 10 > Level 11 (0) | 2022.05.27 |
[Natas] Level 9 > Level 10 (0) | 2022.05.21 |