반응형

overthewire.org 문제 풀이 / Natas Level 7 → Level 8

 

 

admin을 입력하면 아래와 같이 Wrong secret가 출력됩니다. 

View sourcecode 링크를 클릭해 보겠습니다. 

 

아래와 같은 코드가 생성됩니다. 

아래 구문을 보면 $encodedSecret 값과 입력란의 값을 encodeSecret 함수의 인자로 넣어 반환된 값과 동일하면 natas9 패스워드를 확인할 수 있습니다. 

 

encodeSecret 함수를 전달인자를 base64로 인코딩한 값을 strrev() 함수로 문자열을 뒤집습니다. 

또한 그 값을 bin2hex 함수로 hex 코드로 변환하였습니다. 

 

$encodedSecret의 값을 encodeSecret 함수에서 진행한 것을 역순으로 진행하여, 어떠한 값을 입력란에 넣어야 하는지 찾아 보겠습니다. 

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

<?

$encodedSecret = "3d3d516343746d4d6d6c315669563362";

function encodeSecret($secret) {
    return bin2hex(strrev(base64_encode($secret)));
}

if(array_key_exists("submit", $_POST)) {
    if(encodeSecret($_POST['secret']) == $encodedSecret) {
    print "Access granted. The password for natas9 is <censored>";
    } else {
    print "Wrong secret";
    }
}
?>

<form method=post>
Input secret: <input name=secret><br>
<input type=submit name=submit>
</form>

<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>

아래 사이트에서 php 구문을 입력하여 보았습니다. 

$encodedSecret의 값을 encodeSecret 함수에서 진행한 것을 역순으로 진행하였을 때, 생성된 코드를 입력란에 넣었습니다.

생성된 코드를 입력란에 넣고 제출하면 natas9의 패스워드를 확인할 수 있습니다.

반응형

+ Recent posts