Description
RecruitCTF - layer0
Approach
Pull image rồi run với lệnh sau:
docker run --name recruitctf_layer0 ghcr.io/compsec-hcmus/recruitctf-2024/layer0
Container exit ngay lập tức. Điều này có thể là do container đã kết thúc câu lệnh. Chúng ta cần một cách để cho container luôn chạy:
docker run --name recruitctf_layer0 ghcr.io/compsec-hcmus/recruitctf-2024/layer0 /bin/sh -c "echo 'hello world'; sleep infinity"
Dùng lệnh sau để xem lịch sử build của image:
docker history --no-trunc ghcr.io/compsec-hcmus/recruitctf-2024/layer0
Output:
IMAGE CREATED CREATED BY SIZE COMMENT
sha256:05f4928ed685fb133ab29bb8d8b8c5e2f2ca3116496c5a483bbc5a30e187efa3 11 days ago CMD ["/bin/sh"] 0B buildkit.dockerfile.v0
<missing> 11 days ago ENV flag=not_flag_either 0B buildkit.dockerfile.v0
<missing> 11 days ago RUN /bin/sh -c echo "not_flag" > /flag.txt # buildkit 9B buildkit.dockerfile.v0
<missing> 11 days ago RUN /bin/sh -c touch /root/select_correct_folder # buildkit 0B buildkit.dockerfile.v0
<missing> 11 days ago RUN /bin/sh -c sh -c "for i in \$(seq 1 256); do mkdir /root/\$(head -c 32 /dev/urandom | od -A n -v -t x1 | tr -d ' \n'); done;" # buildkit 0B buildkit.dockerfile.v0
<missing> 11 days ago RUN /bin/sh -c sh -c "export P=$(head -c 32 /dev/urandom | od -A n -v -t x1 | tr -d ' \n'); mkdir /root/\$P; mv /root/flag.txt /root/\$P" # buildkit 32B buildkit.dockerfile.v0
<missing> 11 days ago COPY flag.txt /root # buildkit 32B buildkit.dockerfile.v0
<missing> 5 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ADD file:a25798f31219000d6a82d2c9258743926b1a400530d12dbb1eadf2c2519f9888 in / 72.8MB
<missing> 5 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.image.version=20.04 0B
<missing> 5 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.image.ref.name=ubuntu 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ARG LAUNCHPAD_BUILD_ARCH 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ARG RELEASE 0B
Có thể thấy, flag được sinh ra khi build image. Thư mục của flag là một thư mục con có tên ngẫu nhiên trong thư mục /root
.
Truy cập vào container:
docker exec -it recruitctf_layer0 bash
Truy cập vào thư mục root
rồi dùng lệnh sau để tìm flag:
find . "*.txt"
Flag
Success
BPCTF{deep_inside_multi_l4yered}