当前位置:网站首页>web安全之目录遍历
web安全之目录遍历
2022-08-02 03:25:00 【CHIAJ176】
什么是目录遍历?
目录遍历(也称为文件路径遍历)是一个 Web 安全漏洞,允许攻击者读取运行应用程序的服务器上的任意文件。这可能包括应用程序代码和数据、后端系统的凭据以及敏感的操作系统文件。在某些情况下,攻击者可能能够写入服务器上的任意文件,从而允许他们修改应用程序数据或行为,并最终完全控制服务器。
思路来源:
考虑一个显示待售商品图像的购物应用程序。图像通过一些HTML加载,如下所示:
<img src="/loadImage?filename=218.png">
URL 采用一个参数并返回指定文件的内容。映像文件本身存储在磁盘上的位置 。要返回图像,应用程序会将请求的文件名追加到此基目录,并使用文件系统 API 读取文件的内容。在上述情况下,应用程序从以下文件路径读取:loadImagefilename/var/www/images/
/var/www/images/218.png
应用程序不实现对目录遍历攻击的防御,因此攻击者可以请求以下 URL 从服务器的文件系统中检索任意文件:
https://insecure-website.com/loadImage?filename=../../../etc/passwd
这将导致应用程序从以下文件路径中读取:
/var/www/images/../../../etc/passwd
该序列在文件路径中有效,意味着在目录结构中提升一个级别。三个连续的序列从文件系统根目录递增,因此实际读取的文件是:../..//var/www/images/
/etc/passwd
在基于 Unix 的操作系统上,这是一个标准文件,其中包含在服务器上注册的用户的详细信息。
在 Windows 上,和 都是有效的目录遍历序列,检索标准操作系统文件的等效攻击将是:../..\
https://insecure-website.com/loadImage?filename=..\..\..\windows\win.ini
简单的大小写
通过"../" 能够对目录进行遍历
ps:filename=../../etc/passwd
用绝对路径旁路阻止的遍历序列
许多将用户输入放入文件路径的应用程序都实现了针对路径遍历攻击的某种防御,而这些攻击通常可以规避。如果应用程序从用户提供的文件名中剥离或阻止目录遍历序列,则可以使用各种技术绕过防御。您可以使用文件系统根目录的绝对路径(如 )直接引用文件,而无需使用任何遍历序列。
ps:filename=/etc/passwd
总之一句话:若阻止遍历,可以尝试绝对路径读取
非递归剥离的遍历序列
您可能能够使用嵌套遍历序列,例如 或 ,当剥离内部序列时,它将恢复为简单的遍历序列。....//....\/。当../与..\被替换成空时,上面就变成了../../,因此也可以实现遍历。
ps:filename=....//....//....//etc/passwd
遍历序列被多余的URL解码剥离
在某些上下文中,例如在 URL 路径或请求的参数中,Web 服务器可能会在将输入传递到应用程序之前剥离任何目录遍历序列。您有时可以通过URL编码,甚至双URL编码来绕过这种清理,从而产生或分别产生。
ps:filename=..%252f..%252f..%252fetc/passwd
验证路径的起点
如果应用程序要求用户提供的文件名必须以预期的基文件夹开头,例如 ,则可以包含所需的基文件夹,后跟合适的遍历序列。例如:/var/www/images
ps:filename=/var/www/images/../../../etc/passwd
使用空字节旁路验证文件的
如果应用程序要求用户提供的文件名必须以预期的文件扩展名(如 )结尾,则可以使用空字节在所需扩展名之前有效地终止文件路径。例如:.png
ps:filename=../../../etc/passwd%00.png
加密型传递的参数
filename=aW1hZ2UxLmpwZw== 参数file的数据采用Base64加密,而攻击中只需要将数据进行相应的解密即可入侵,采用一些常见、规律性的加密方式也是不安全的。
常见系统文件路径
Windows:
C:\boot.ini //查看系统版本
C:\Windows\System32\inetsrv\MetaBase.xml //IIS配置文件
C:\Windows\repair\sam //存储系统初次安装的密码
C:\Program Files\mysql\my.ini //Mysql配置
C:\Program Files\mysql\data\mysql\user.MYD //Mysql root
C:\Windows\php.ini //php配置信息
C:\Windows\my.ini //Mysql配置信息
Linux:
/etc/passwd #查看用户文件
/etc/shadow #查看密码文件,如果能读取该文件说明是root权限
/etc/httpd/conf/httpd.conf #查看apache的配置文件
/root/.bash_history #查看历史命令
/var/lib/mlocate/mlocate.db #本地所有文件信息
/etc/ssh/sshd_config #ssh配置文件,如果对外开放可看到端口
/proc/self/fd/fd[0-9]*(文件标识符)
/proc/mounts
/root/.ssh/known_hosts
边栏推荐
- 2. PHP variables, output, EOF, conditional statements
- Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
- 14. JS Statements and Comments, Variables and Data Types
- Stable and easy-to-use short connection generation platform, supporting API batch generation
- c语言用栈实现计算中缀表达式
- 4. PHP array and array sorting
- hackmyvm: kitty walkthrough
- [league/flysystem] An elegant and highly supported file operation interface
- web渗透必玩的靶场——DVWA靶场 1(centos8.2+phpstudy安装环境)
- (8) requests、os、sys、re、_thread
猜你喜欢

12. What is JS

Smart Tips for Frida Scripting in Kali Environment

Phonebook

(5) 模块与包、编码格式、文件操作、目录操作

一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用

Orasi: 1 vulnhub walkthrough

hackmyvm: kitty walkthrough

DVWA drone installation tutorial

hackmyvm-hopper预排
![[sebastian/diff] A historical change extension library for comparing two texts](/img/c7/ea79db7a5003523ece7cf4f39e4987.png)
[sebastian/diff] A historical change extension library for comparing two texts
随机推荐
[phpunit/php-timer] A timer for code execution time
PHP8.2 version release administrator and release plan
13. JS output content and syntax
hackmyvm: may walkthrough
Query the indexes of all tables in the database and parse them into sql
命令执行漏洞
CTF之xxe
hackmyvm-bunny walkthrough
Scrapy crawler encounters redirection 301/302 problem solution
(2) Thinkphp6 template engine ** tag
Batch replace file fonts, Simplified -> Traditional
(2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets
Introduction to PHP (self-study notes)
hackmyvm: again walkthrough
QR code generation API interface, which can be directly connected as an A tag
3. PHP data types, constants, strings and operators
16.JS事件, 字符串和运算符
12. What is JS
php函数漏洞总结
Turn trendsoft/capital amount of Chinese capital library