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

2 ๋ถ„ ์†Œ์š”

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

๋ฌธ์ œ

image

Enumeration

โ”Œโ”€โ”€(rootใ‰ฟkali)-[/home/kali/Desktop]
โ””โ”€ nmap -sV -p - 10.129.227.233 -vv --min-rate 3000

Nmap scan report for 10.129.227.233
Host is up, received echo-reply ttl 63 (0.081s latency).
Scanned at 2023-02-11 09:24:39 EST for 122s
Not shown: 65532 closed tcp ports (reset)
PORT     STATE SERVICE  REASON         VERSION
22/tcp   open  ssh      syn-ack ttl 63 OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
80/tcp   open  http     syn-ack ttl 63 nginx 1.23.1
9093/tcp open  copycat? syn-ack ttl 63
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Nmap done: 1 IP address (1 host up) scanned in 122.20 seconds
           Raw packets sent: 65540 (2.884MB) | Rcvd: 65536 (2.621MB)
                                                                            

์ด 3๊ฐœ์˜ ์„œ๋น„์Šค๊ฐ€ ์—ด๋ ค์žˆ์Šต๋‹ˆ๋‹ค. http(80) ์„œ๋น„์Šค์™€ , ์–ด๋–ค ์„œ๋น„์Šค ์ธ์ง€๋Š” ๋ชจ๋ฅด์ง€๋งŒ 9093 ํฌํŠธ๋กœ ์ ‘์†์„ ํ•ด๋ด…๋‹ˆ๋‹ค.

image

์œ„์™€๊ฐ™์€ ๋ฐ์ดํ„ฐ๋“ค์ด ๋‚˜์˜ค๊ณ , ์ผ๋ถ€ ํ•ญ๋ชฉ๋“ค์„ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด๋ฉด ํ•ด๋‹น ํŽ˜์ด์ง€๋Š” prometheus ๋ผ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํŽ˜์ด์ง€ ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ œ๋ฅผ ๋‹ค ํ’€์–ด๋ณธ ๊ฒฐ๊ณผ ํ•ด๋‹น ํŽ˜์ด์ง€๋Š” ๋ฌธ์ œํ’€์ด์™€ ์—ฐ๊ด€์ด ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€์ ์ธ ์„ค๋ช…์€ ํ•˜์ง€ ์•Š๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ทธ ๋‹ค์Œ์€ ์›น์„œ๋น„์Šค ์ž…๋‹ˆ๋‹ค.

image

/etc/hosts ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋„๋ฉ”์ธ์„ ๋“ฑ๋กํ•ด ์ฃผ๊ณ  ๋‹ค์‹œ ์ ‘์†์„ ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# /etc/hosts 
10.129.227.233 shoppy.htb

image

์‚ฌ์ดํŠธ๋ฅผ ๋‘˜๋Ÿฌ๋ด๋„ ํŠน๋ณ„ํ•œ ๊ธฐ๋Šฅ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

subdomain / subdirectory ๋ฆฌ์ŠคํŒ…์„ ์ˆ˜ํ–‰ํ•ด ๋ด…๋‹ˆ๋‹ค.

# subdirectory
wfuzz -c --hc 404 -w /usr/share/wordlists/dirb/commont.txt 'http://shoppy.htb/FUZZ'

# subdomain
wfuzz -c -w /usr/share/seclists/Discovery/DNS/bitquark-subdomains-top100000.txt -u shoppy.htb -H "Host: FUZZ.shoppy.htb" --hc 301

๋จผ์ € subdirectory์˜ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

image

admin ๊ฒฝ๋กœ๋กœ ์ ‘์†์„ ํ•ด๋ด…๋‹ˆ๋‹ค.

SQL Injection

image

๊ณ„์ • ์ธ์ ์…˜์„ ์ˆ˜ํ–‰ํ•ด๋ณธ ๊ฒฐ๊ณผ, ๋ฐฑ์—”๋“œ์—์„œ MongoDB๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ถ”์ธก๋˜๊ณ  ๊ณ„์ •์˜ ๊ฒ€์ฆ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ถ€๋ถ„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ์ผ ๊ฒƒ์œผ๋กœ ์ถ”์ธกํ•˜์˜€์Šต๋‹ˆ๋‹ค.

db.user.find({$where: `this.username=='${req.query.username}'&&this.password=='${req.query.password}'`});

๋”ฐ๋ผ์„œ ์ธ์ ์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

username='||1||'&password=123

image

๊ฒ€์ƒ‰๊ธฐ๋Šฅ ์—ญ์‹œ ์ธ์ ์…˜์ด ๊ฐ€๋Šฅํ•˜์—ฌ ๋™์ผํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ธ์ ์…˜์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

image

admin ๊ณ„์ •๊ณผ, josh ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ•ด์‹œ๊ฐ’์„ ์–ป์„ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

Crack MD5

hash-identifier ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด๋ณธ ๊ฒฐ๊ณผ md5 ์ธ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

๋‘ ๊ณ„์ • ๋ชจ๋‘ rockyou.txt ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ํฌ๋ž˜ํ‚น์„ ์‹œ๋„ํ•ด ๋ด…๋‹ˆ๋‹ค. ์‹œ๋„ ๊ฒฐ๊ณผ admin ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์–ป์ง€ ๋ชปํ•˜์˜€๊ณ , josh ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์–ป์„ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

image

id : josh 
pw : remembermethisway

์ด์ „์— ์‹คํ–‰ํ•ด๋†“์€ wfuzz ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด, subdomain์œผ๋กœ mattermost ๊ฐ€ ์กด์žฌํ•จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

image

ํš๋“ํ•œ josh ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ์„ ํ•ฉ๋‹ˆ๋‹ค.

์ฑ„ํŒ… ๋‚ด์—ญ์—์„œ jaeger ๊ณ„์ •์ •๋ณด๋ฅผ ํš๋“ํ•ฉ๋‹ˆ๋‹ค.

image

user ๊ณ„์ •์˜ flag๋ฅผ ํš๋“ํ•ฉ๋‹ˆ๋‹ค.

image

/home ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋ณด๋ฉด deploy ๊ณ„์ •์ด ์กด์žฌํ•จ์„ ์•Œ ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

image

ํ•ด๋‹น ํ™ˆ๋””๋ ‰ํ„ฐ๋ฆฌ์— password-manager ํŒŒ์ผ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์‹คํ–‰ ๊ถŒํ•œ์€ ์—†๊ณ  ์‹คํ–‰ํŒŒ์ผ์— ์ฝ๊ธฐ ๊ถŒํ•œ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ kali linux ๋กœ์ปฌ์—์„œ ๋ฆฌ๋ฒ„์‹ฑ ํ•ด๋ด…๋‹ˆ๋‹ค.

๋ฆฌ๋ฒ„์‹ฑ์€ ghidra๋กœ ์ˆ˜ํ–‰ํ•˜์˜€์œผ๋ฉฐ, ๊ทธ ๊ฒฐ๊ณผ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo -l ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด๋ณด๋ฉด, jaeger ๊ณ„์ •์œผ๋กœ deploy ๊ถŒํ•œ์œผ๋กœ password-manager ํ”„๋กœ๊ทธ๋žจ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

image

deploy ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•Œ์•„๋ƒˆ์Šต๋‹ˆ๋‹ค.

Docker Breakout

image

deploy ๊ณ„์ •์— docker ๊ทธ๋ฃน๊ถŒํ•œ์ด ์ฃผ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. docker breakout ๊ธฐ์ˆ ์„ ์ด์šฉํ•ด์„œ root ๊ถŒํ•œ ํƒˆ์ทจ๋ฅผ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

image

docker iamges ๋ช…๋ น์–ด ์ˆ˜ํ–‰๊ฒฐ๊ณผ alpine ์ด๋ฏธ์ง€๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด --privileged๊ถŒํ•œ์„ ์ค˜์„œ breakout์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋„์ปค ํ™˜๊ฒฝ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

image

--privileged ๊ถŒํ•œ์ด ์ฃผ์–ด์ง€๋ฉด, ํ˜ธ์ŠคํŠธ ๋จธ์‹ ์œผ๋กœ mount๊ฐ€ ๊ฐ€๋Šฅํ•ด ์ง‘๋‹ˆ๋‹ค. host ๋จธ์‹ ์˜ ํ•˜๋“œ์ธ /dev/sda1 ๋กœ ๋‹ค์‹œ mount๋ฅผ ํ•˜์—ฌ ์ „์ฒด ํŒŒ์ผ์‹œ์Šคํ…œ์˜ ์ ‘๊ทผ๊ถŒํ•œ์„ ํš๋“ํ•ฉ๋‹ˆ๋‹ค.

image

image

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