Security Study

[WEB] natas8 -> natas9

PreGoogler 2019. 8. 2. 01:29

이번에는 https://overthewire.org/wargames/ 사이트의 워게임 중 하나인 Natas라는 웹 워게임의 8단계의 풀이과정을 설명해드리겠습니다.

 

우선 문제를 보면

와 같이 secret값을 입력하여 다음 스테이지로 향하는 비밀번호를 얻는 문제인 것 같습니다.

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": "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>

와 같은 소스가 나오게 됩니다.

소스코드를 간단히 해석하면

encodeSecret 값과 입력한 secret값을 encodeSecret함수에 넣은 값을 서로 비교하는 소스코드 입니다.

encodeSecret함수는 입력한 secret값을 base64로 인코딩 한 후 인코딩된 문자를 뒤집은 후 16진수로 바꿔주는 함수입니다.

 

그러면 역으로 16진수인 encodeSecret값을 문자로 바꿔준 후 문자를 뒤집고 base64로 디코드하면 우리가 입력해야 할 문자가 나오겠죠??

 

따라서 소스코드를

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<?php
	$encodedSecret = "3d3d516343746d4d6d6c315669563362";
	$decode = strrev(pack("H*", $encodedSecret));
	echo "$decode";
?>

</body>
</html>

와 같이 작성해 주면 결과값으로 b3ViV1lmMmtCcQ== 가 나오게 되므로 base64로 디코딩해주면 oubWYf2kBq가 결과값으로 나와서 이 값을 문제의 Input secret에 넣어주면 

와 같이 패스워드가 나오게 됩니다.

끄읕~!