<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": "natas12", "pass": "<censored>" };</script></head> 
<body> 
<h1>natas12</h1> 
<div id="content"> 
<?  

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"]); 


        if(filesize($_FILES['uploadedfile']['tmp_name']) > 1000) { 
        echo "File is too big"; 
    } 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> 

form으로 보내는 부분에서 jpg 확장자를 추가하는것 외엔 필터링 하는 부분이 없습니다.










'Wargame > Natas:OverTheWire' 카테고리의 다른 글

[Natas] Level14  (0) 2016.10.23
[Natas] Level13  (0) 2016.10.23
[Natas] Level11  (0) 2016.10.22
[Natas] Level10  (0) 2016.10.22
[Natas] Level9  (0) 2016.10.22
OverTheWire_Wargame Bandit

[ level12 -> level13 ]




이번 문제는 data.txt파일이 hexdump로 제공되며, 압축이 연속적으로 걸려있다고 하네요. 이를 /tmp에 새 이름으로 폴더를 만든 후 거기서 문제를 진행하라고 합니다. 그대로 따라해주도록 하죠.



/tmp/fstr3am 아래에 data.txt 파일을 넣어주었습니다.



data.txt 파일의 hexdump입니다. 헤더를 보면 1f8b 0808로 시작하는 것을 알 수 있는데, 이는 gzip의 파일 포맷입니다. hexdump를 바이너리화 시켜주면서 파일명의 뒤에 .gz을 불여주도록 하죠. 이 때 사용하는 툴은 xxd입니다. -d 옵션을 주어 출력해주면 바이너리 파일이 생성됩니다.


생성된 data.txt.gz을 gzip -d 옵션으로 압축 해제를 해주면 다시 data.txt 파일이 나타납니다.

이러한 형식으로 다중 압축이 되어 있는데, 이 문제 같은 경우 3가지의 압축 방법이 적용되어 있습니다.

위에서 설명한 헤더를 가지고 있는 gzip,

그리고 바로 아래 그림에서 볼 수 있는 425a 헤더를 가지고 있는 bzip2,



마지막으로 헤더에 파일명을 가지고 있으며, 아래 섹션에서는 해당 파일 hex값이 나타나는 tar 압축입니다.



이런식으로 하나하나 압축을 풀어 나가다 보면 마지막에는 data8.bin이 남게 되며, 이 파일을 읽어내면 key값을 얻어 낼 수 있습니다.






P.S - xxd로 파일 헤더를 볼 필요 없이, file 명령어를 이용하면 어떤 압축 포맷인지 바로 알 수 있다고 합니다.... 쮸륵..


OverTheWire_Wargame Bandit

[ level11 -> level12 ]



이번 문제도 이전 레벨과 동일하게 data.txt에 패스워드가 들어있다고 합니다. 하지만 소문자와 대문자 알파벳이 13의 간격을 두고 바뀌어 있다고 하네요.

파이썬이나 다른 언어로 13씩 앞/뒤로 당겨 출력하면 key값을 구할 수 있을 것입니다.


위 값이 13의 크기만큼 rotatation 된 문자열입니다. 이를 바꿔보도록 하죠.






이를 출력하면 키값을 구할 수 있습니다.

+ Recent posts