源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

详解PHP中pathinfo()函数导致的安全问题

  • 时间:2020-02-06 06:18 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:详解PHP中pathinfo()函数导致的安全问题
[b]定义和用法[/b] pathinfo() 函数以数组或字符串的形式返回关于文件路径的信息。 [b]返回的数组元素如下:[/b] [list=1] [*][dirname]:返回文件路径中的目录部分[/*] [*][basename]:返回文件路径中文件名的部分[/*] [*][extension]:返回文件路径中文件的类型的部分 [/*] [/list] [b]语法[/b] [code]pathinfo(path,options) [/code] [b]参数[/b] [list=1] [*]path: 必需。规定要检查的路径。[/*] [*]options 可选。规定要返回的数组元素。默认是 all。[/*] [/list] [b]可能的值:[/b] [list=1] [*]PATHINFO_DIRNAME - 只返回 dirname[/*] [*]PATHINFO_BASENAME - 只返回 basename[/*] [*]PATHINFO_EXTENSION - 只返回 extension [/*] [/list] [b]提示和注释[/b] 注释:如果不是请求所有的元素,则 pathinfo() 函数返回字符串。 php开启pathinfo 路由模式:pathinfo 模式 需要 php.ini 开启下面这个参数 [code]cgi.fix_pathinfo=1 [/code] path_info模式:http://www.xxx.com/index.php/模块/方法 [b]实例 1[/b]
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
上面的代码将输出:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
[b]实例 2[/b]
<?php
var_dump(pathinfo("/testweb/test.txt",PATHINFO_DIRNAME));
var_dump(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
var_dump(pathinfo("/testweb/test.txt",PATHINFO_EXTENSION));
?>
上面的代码将输出:
string(8)"/testweb"
string(8)"test.txt"
string(3)"txt"
[b]应用[/b] 目录不可控没有执行权限 [img]http://files.jb51.net/file_images/article/201701/201715152853298.png?20170515292[/img] pathinfo, 一种伪静态的用法,path_info 模式:http://www.xxx.com/index.php / 模块 / 方法: [img]http://files.jb51.net/file_images/article/201701/201715152924102.png?201705152932[/img] sb.txt 被当成了模块,实际上请求的还是 6.php [img]http://files.jb51.net/file_images/article/201701/201715152949819.png?201705152958[/img] 一句话就执行了。 [b]过 WAF 注入[/b] 本地安装 apache 安全狗 已知在开启 pathinfo 的情况下 (默认开启) 可以这样访问 [img]http://files.jb51.net/file_images/article/201701/201715153018408.png?201705153026[/img] 常用注入语句被拦截 [img]http://files.jb51.net/file_images/article/201701/201715153049934.png?201705153059[/img] pathinfo 模式不拦截 [img]http://files.jb51.net/file_images/article/201701/201715153127815.png?201705153135[/img] [b]总结[/b] 以上就是这篇文章的全部内容了,本文也算是抛砖引玉,更多用途请自测!希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部