해킹&보안/웹해킹

[웹 해킹 : 나타스(Natas 워게임] Level 9 -> 10(웹 해킹 / 보안)

yamaeking 2025. 4. 6. 20:21

Natas wargame Level 9 -> 10 로그인 정보와 URL 은 아래와 같다.

 

OverTheWire

We're hackers, and we are good-looking. We are the 1%. <!-- Please read and accept the Rules! --> Username: natas1 URL: http://natas1.natas.labs.overthewire.org

overthewire.org

 

 

1. 문제 풀이

 > Natas URL로 접속하면 아래 화면이 나온다

 

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

For security reasons, we now filter 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>

 

이번 문제에서는필터링을 이용하여 아래와 같이 [;|& 문자들이 들어가 있으면 illegal character 를 보여주고 끝나게 된다. 즉 이전 문제에서 얘기하였던 화이트리스트를 이용하여 보안을 좀 더 신경쓴 것이 보이기는 한데, 이 문자들만 막는다고 필터를 우회할 수 없는 것은 아니다.

 

grep -i 에서 $key를 입력 받으니, . /etc/natas_webpass/natas11 # 이걸 인자로 넘겨보면 아래와 같이 비밀번호를 얻을 수 있다.  위 경로에 있는 파일을 읽어서 화면에 나타내고, 그리고 #을 붙여줌으로써 뒤에 dictionary.txt 를 주석처리 해버리는 것이다.

즉 grep -i .etc/natas_webpass/natas11  명령어가 실행된거임ㅇㅇ;

 

 

 

2. 요약

☞ 화이트리스트로 문자열 필터링 하더라도 우회할 수 있는 방법이 여러 가지 있을 수 있다.