Natas Wargame Level 9 Writeup(bash injection)

sourcedode中的关键代码:

 

 1 <?
 2 $key = "";
 3 
 4 if(array_key_exists("needle", $_REQUEST)) {
 5     $key = $_REQUEST["needle"];
 6 }
 7 
 8 if($key != "") {
 9     passthru("grep -i $key dictionary.txt");
10 }
11 ?>

 

 

 

此处的关键在于passthru()执行的系统命令,以下是passthru()的相关介绍:

---------------------------------------------------------------------------------------------------------

void passthru ( string $command [, int &$return_var ] )

exec() 函数类似, passthru() 函数 也是用来执行外部命令(command)的。 当所执行的 Unix 命令输出二进制数据, 并且需要直接传送到浏览器的时候, 需要用此函数来替代 exec()system() 函数。 常用来执行诸如 pbmplus 之类的可以直接输出图像流的命令。 通过设置 Content-type 为 image/gif, 然后调用 pbmplus 程序输出 gif 文件, 就可以从 PHP 脚本中直接输出图像到浏览器。

Warning

当用户提供的数据传入此函数,使用 escapeshellarg()escapeshellcmd() 来确保用户欺骗系统从而执行任意命令。

-------------------------------------------------------------------------------

输入.*,出现当前目录下的dictionary文件,没有意义。结合Natas首页的信息“Each level has access to the password of the next level. Your job is to somehow obtain that next password and level up. All passwords are also stored in /etc/natas_webpass/. E.g. the password for natas5 is stored in the file /etc/natas_webpass/natas5 and only readable by natas4 and natas5.”可以得知输出etc/natas_webpass/natas10即可。

于是执行“xxx ; cat etc/natas_webpass/natas10 #”,其中xxx无用,与前面的grep -i 结合,随后的分号作为另一条命令的分隔,输出etc/natas_webpass/natas10,#将末尾的dictionary注释掉。

得到flag:nOpp1igQAkUzaI1GUUjzn1bFVj7xCNzu

 

posted @ 2017-05-12 15:58  QiuhaoLi  阅读(235)  评论(0编辑  收藏  举报