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

For security reasons, we now filter even more on certain characters<br/><br/>
<form>
Find words containing: <input name=needle><input type=submit name=submit value=Search><br><br>
</form>


Output:
<pre>
<?
$key = "";

if(array_key_exists("needle", $_REQUEST)) {
    $key = $_REQUEST["needle"];
}

if($key != "") {
    if(preg_match('/[;|&`\'"]/',$key)) {
        print "Input contains an illegal character!";
    } else {
        passthru("grep -i \"$key\" dictionary.txt");
    }
}
?>
</pre>

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

소스를 보니 이전에 했던 정규표현식 문제와 비슷합니다.

그러나 이번에는 key 부분에 double quotation으로 묶여있다는 점과 필터링이 강화되었다는 차이가 있네요.

여기서 생각 할 수 있는 것은 dictionary.txt를 무조건 참조할수밖에 없다는 것인데, 정규표현식에서는 if와 같이 조건을 걸어 줄 수 있습니다.

따라서 이를 이용하여 blind SQLi와 비스무리한 기법으로 패스워드를 찾아낼 수 있습니다.






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

[Natas] Level18  (0) 2016.10.24
[Natas] Level17  (0) 2016.10.23
[Natas] Level15  (0) 2016.10.23
[Natas] Level14  (0) 2016.10.23
[Natas] Level13  (0) 2016.10.23

OverTheWire_Wargame Bandit

[ level16 -> level17 ]



이번 레벨은 31000~32000 사이에 있는 포트 중 하나에서 다음 레벨로 갈 수 있는 키를 얻을 수 있다고 합니다.

먼저, 이 포트들 사이에서 listening 하고 있는 포트를 찾고, SSL 통신을 하는 지 안하는 지 확인을 합니다. 그리고 추려 낸 SSL 통신 중 오직 1개의 서버만이 다음 레벨로 갈 수 있는 key값을 뱉어준다고 하네요.

그럼 nmap으로 포트스캔을 해 봅시다.


31000, 31046, 31518, 31691, 31790, 31960으로 총 6개의 포트가 listening 하고 있는 것을 알 수 있습니다.



31518, 31790 두 개의 포트에서만 SSL 통신을 하고 있었습니다.

OpenSSL 버전은 1.0.1f이므로, HEARTBLEED 취약점이 발생하는 것을 알 수 있습니다.


openssl s_client -connect localhost:31518 -ign_eof

openssl s_client -connect localhost:31790 -ign_eof


위 두 명령어로 현 레벨의 key값을 보내 주면 31790 포트에서 다음 레벨로 갈 수 있는 RSA_private key값을 얻을 수 있습니다.


이 RSA key값을 putty keygen을 이용하여 SSH_RSA key값으로 변경 해 준 후, bandit17로 연결하면 정상접속 되는 것을 확인 할수 있습니다.

OverTheWire_Wargame Bandit

[ level15 -> level16 ]




이번 레벨에서는 openssl의 heartbleed 취약점을 이용한 풀이입니다.

openssl로 localhost의 30001 포트로 접속 한 후 B를 입력 했을 때 HEARTBEATING 응답이 올 경우 취약점이 존재합니다.

또한, openssl 버전을 확인했을 때 1.0.1 ~ 1.0.1f까지의 버전을 사용할 경우 취약점이 발생합니다.

아래 그림은 openssl s_client -connect localhost:30001 로 연결을 시도 후, B를 입력하였을 때 나타나는 응답값입니다.



HEARTBEATING 응답값이 나오는 것을 확인 할 수 있으며, 현 환경의 openssl 버전은 1.0.1f입니다.

파일의 끝(EOF)에 도달하여도 프로그램이 중단되는것을 방지하기 위해 -ign_eof 옵션을 걸어주고 openssl 연결을 시도하였습니다.

만약 -ign_eof 옵션을 걸어주지 않고 현 레벨의 key값을 넘겨주게 되면 'B'만 인식하여 HEARTBEATING 응답이 나오게 됩니다.

연결 후 이전 레벨의 key값을 넘겨주면 다음 레벨로 갈 수 있는 key값을 넘겨받을 수 있습니다.



+ Recent posts