๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[Dreamhack]WebHacking/Wargame&CTF

[Dreamhack] Level1:Beginner blue-whale

by Yun2๐Ÿ‘ 2024. 2. 7.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธ Access

๋ณด์ฝ”๊ฐ€ ์—ฌ๋Ÿฌ๋ถ„์—๊ฒŒ ๋„์›€์„ ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค. 
"๋ถ„๋ช… ํ”Œ๋ž˜๊ทธ ํŒŒ์ผ์ด ์žˆ์—ˆ๋Š”๋ฐ์š”... ์—†์–ด์กŒ์–ด์š”."

Docker hub์˜ dreamhackofficial/blue-whale ๋ ˆํฌ์ง€ํ† ๋ฆฌ (TAG:1) ์—์„œ ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋ถ„์„ํ•˜์—ฌ ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•˜์„ธ์š”.
์ฃผ์–ด์ง„ Dockerfile์€ ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•  ๋•Œ ์‚ฌ์šฉํ•œ ํŒŒ์ผ๋กœ, ํ’€์ด์ž๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

ํ”Œ๋ž˜๊ทธ ํ˜•์‹์€ DH{...} ์ž…๋‹ˆ๋‹ค.

 

 

๐Ÿ‘พ Exploit Algorithm & Payload

> Dokerfile

๋”๋ณด๊ธฐ
FROM ubuntu:22.04@sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9

ENV user chall
ENV chall_port 31337

RUN apt-get update
RUN apt-get install -y python3

RUN adduser $user

COPY ./deploy/flag /home/$user/flag

RUN chown -R root:$user /home/$user

WORKDIR /home/chall
RUN touch `python3 -c "print(open('./flag', 'r').read())"`
RUN rm *

WORKDIR /home
USER $user
EXPOSE $chall_port

 

 

#1


cd Dockerfile
docker pull dreamhackofficial/blue-whale:1
docker images

: ํ•ด๋‹น Dokerfile์„ ํ™•์ธํ–ˆ๋‹ค.

: ./deploy/flag ํŒŒ์ผ์„ /home/$user/flag(/home/chall/flag)์— ๋ณต์‚ฌ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

: ์ญ‰ ๋ณด๋‹ค๊ฐ€ touch ๋ช…๋ น์–ด์—์„œ ./flagํŒŒ์ผ์„ ์—ด๊ณ  flagํŒŒ์ผ ๋‚ด์šฉ์„ ์ฝ์—ˆ๊ณ  ์ถœ๋ ฅ์ด ๋œ ๊ฒƒ์„ ํŒŒ์ด์ฌ ๋ช…๋ น์–ด๋กœ ์‹คํ–‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์œ„์น˜ ๋‚ด์šฉ์„ ๋ณธ๋‹ค๋ฉด FLAG๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋œ๋‹ค.

: ๊ทธ๋‹ค์Œ *rm ๋ช…๋ น์–ด๋กœ ์‚ญ์ œ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— docker run -it [image ID] /bin/bash๋กœ bash-shell์„ ์—ด๊ณ  flag ์œ„์น˜์—(/home/chall/...) flag๊ฐ€ ์—†๋Š” ๊ฒƒ์ด๋‹ค.

 

: ์—ฌ๊ธฐ๊นŒ์ง€ ํŒŒ์ผ์„ ํ•ด์„ํ•˜๊ณ  ๋„์ปค ํŒŒ์ผ์„ ์ด๋ฏธ์ง€๋กœ ๋‚ด๋ ค๋ฐ›์•„ IMAGE ID๋ฅผ ํ™•์ธํ–ˆ๋‹ค.

 

 

#2


https://github.com/wagoodman/dive

 

GitHub - wagoodman/dive: A tool for exploring each layer in a docker image

A tool for exploring each layer in a docker image. Contribute to wagoodman/dive development by creating an account on GitHub.

github.com

: 'dive'๋ฅผ ํ†ตํ•ด ํƒ์ƒ‰ํ•  ์ด๋ฏธ์ง€์˜ ๋ ˆ์ด์–ด๋ฅผ ํŠธ๋ฆฌํ˜•ํƒœ๋กœ ๋ณด์—ฌ์ฃผ์–ด ํ›จ์”ฌ ์ž์„ธํ•œ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

: README.mdํŒŒ์ผ์—์„œ ์„ค์น˜ ๊ณผ์ • ํ™•์ธํ–ˆ๋‹ค.

 

dive [image ID]

: ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž์„ธํ•œ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

๐Ÿ”‘Analysis and results for obtaining the Flag DH{…}

 


: *rm์ „์˜ ๋ช…๋ น์–ด(touch ...)๋Š” ํ•ด๋‹น ์œ„์น˜์˜ ํŒŒ์ผ์ด ์•„์ง ์‚ญ์ œ๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— FLAG๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

[+] Additional Checks


docker pull [image address:TAG] - ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
docker images - ์ด๋ฏธ์ง€ ํ™•์ธ
docker rmi -f [image ID] - ์ด๋ฏธ์ง€ ์‚ญ์ œ
docker run -it [image ID] /bin/bash - ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
dive [image ID] - ์ด๋ฏธ์ง€ ๋ถ„์„ ๋„๊ตฌ

...

 

-Dokerfile ๋‚ด์šฉ ๋ถ„์„-

FROM - ๋ฒ ์ด์Šค ์ด๋ฏธ์ง€
: ์–ด๋Š ์ด๋ฏธ์ง€์—์„œ ์‹œ์ž‘ํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์˜๋ฏธ
: [image address:TAG]

 

MAINTAINER - ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•œ ๊ฐœ๋ฐœ์ž์˜ ์ •๋ณด (1.13.0 ์ดํ›„ ์‚ฌ์šฉ X)

ENV - ์ด๋ฏธ์ง€์—์„œ ์‚ฌ์šฉํ•  ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ง€์ •
: port

WORKDIR - ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •. ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ
: ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •ํ•˜๋ฉด ๊ทธ ์ดํ›„ ๋ช…๋ น์–ด๋Š” ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋™์ž‘
: cd ๋ช…๋ น์–ด์™€ ๋™์ผ

CMD/ENTRYPOINT - ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑ ๋ฐ ์‹คํ–‰ํ•  ๋•Œ ์‹คํ–‰ํ•  ๋ช…๋ น์–ด
| CMD
: ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ๋งŒ ์‹คํ–‰ (doker run)
: ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ์‹œ, ์ถ”๊ฐ€์ ์ธ ๋ช…๋ น์–ด์— ๋”ฐ๋ผ ์„ค์ •ํ•œ ๋ช…๋ น์–ด๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Œ

| ENTRYPOINT
: ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ๋งˆ๋‹ค ์‹คํ–‰ (docker start)
: ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ ์‹œ, ์ถ”๊ฐ€์ ์ธ ๋ช…๋ น์–ด ์กด์žฌ ์—ฌ๋ถ€์™€ ์ƒ๊ด€์—†์ด ๋ฌด์กฐ๊ฑด ์‹คํ–‰๋จ

 

๋ฐ˜์‘ํ˜•

'[Dreamhack]WebHacking > Wargame&CTF' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dreamhack] Level2: baby-sqlite  (0) 2024.02.23
[Dreamhack] Level4: KeyCat  (0) 2024.02.23
[Dreamhack] Level2: Dream Gallery  (0) 2024.02.03
[Dreamhack] Level2: filestorage  (0) 2024.02.02
[Dreamhack] Level1: Type c-j  (2) 2024.02.02