Wechall PHP - Local File Inclusion
本地文件包含(Local File Inclusion)
本地文件包含(LFI)类似于远程文件包含漏洞,但不包括远程文件,只能包括当前服务器上的本地文件(即执行中的文件)。此问题仍可以通过包含包含攻击者控制的数据(如 Web 服务器的访问日志)的文件来导致远程代码执行。
题目
wechall的LFI题
分析
题目要求为显示 …/solution.php 文件
相关代码:
GeSHi`ed PHP code
$filename = 'pages/'.(isset($_GET["file"])?$_GET["file"]:"welcome").'.html';
include $filename;
第一行代码表示 filename 变量= pages/ + 通过get方法传递 file 参数。如果有file参数传递则 file传递的参数.html,没有则为 welcome.html
第二行代码表示 包含 filename 内容
解题
- 观察题目页面,可以看到包含文件显示的区域如图所示:
此页的URL链接
http://www.wechall.net/challenge/training/php/lfi/up/index.php
题目中有提示
Here are a few examples of the script in action (in the box below):
index.php?file=welcome
index.php?file=news
index.php?file=forums
- 测试,将提示内的字符串与网页链接拼合,看看网页的变化
http://www.wechall.net/challenge/training/php/lfi/up/index.php?file=welcome
与原页面一致
http://www.wechall.net/challenge/training/php/lfi/up/index.php?file=news
出现变化,如图所示:
http://www.wechall.net/challenge/training/php/lfi/up/index.php?file=
出现错误提示,如图所示:
根据这个图片可以看出目前包含文件显示的区域的路径 为 ‘/home/wechall/www/wc5/www/challenge/training/php/lfi/up/pages/.html’。根据题意可以得出 …/solution.php 与 /up 是同一级,那么要通过 filename 变量传递参数就应该为 …/…/solution.php。
又因为在代码中有 '.html’对所有输入参数默认添加,所以需要排除这个干扰,使用 %00 对其进行截断。
exp
up/index.php?file=../../solution.php%00
- 验证,如图所示:
参考链接:
维基百科
关于文件包含相关链接:
PHP文件包含小总结
Web安全实战系列:文件包含漏洞
浅谈文件包含漏洞