[极客大挑战 2020]Greatphp
[极客大挑战 2020]Greatphp
考点
利用PHP内置类Error和Exception反序列化绕过hash
利用PHP内置类Error和Exception反序列化命令执行
取反绕过代码执行黑名单
wp
PHP内置类Error和Exception反序列化利用
<?php
error_reporting(0);
class SYCLOVER {
public $syc;
public $lover;
public function __wakeup(){
if( ($this->syc != $this->lover) && (md5($this->syc) === md5($this->lover)) && (sha1($this->syc)=== sha1($this->lover)) ){
if(!preg_match("/\<\?php|\(|\)|\"|\'/", $this->syc, $match)){
eval($this->syc);
} else {
die("Try Hard !!");
}
}
}
}
if (isset($_GET['great'])){
unserialize($_GET['great']);
} else {
highlight_file(__FILE__);
}
?>md5()和sha1()会触发类的__toString()函数,对于这个hash碰撞可以使用Error或Exception类绕过
得到的结果如下,并且输入也原封不动的返回了。那么如果在输入中闭合PHP语句,就能让eval($ex1)执行任意代码
闭合语句可以使用__HALT_COMPILER() 终止对后面语句的编译,也可以使用?><?php ?> 闭合语句
使用Error类的方法如下
结果
简化的题目如下
那么最后可以执行代码的payload
回到本题,绕过hash之后需要绕过正则if(!preg_match("/\<\?php|\(|\)|\"|\'/", $this->syc, $match)) ,即传入的参数不能有<?php 和()"' 而PHP里面可以不用括号执行的只要文件包含,又不能带单双引号,那就只能通过编码绕过了,就只剩下了取反绕过
小结
if(!preg_match("/\<\?php|\(|\)|\"|\'/", $this->syc, $match)){eval($this->syc);}这种使用include+取反
最后更新于