Skip to content

Instantly share code, notes, and snippets.

@jaybosamiya
Created November 5, 2018 20:49
Show Gist options
  • Save jaybosamiya/cfd7c745b813531e6c5bb35793e5ad06 to your computer and use it in GitHub Desktop.
Save jaybosamiya/cfd7c745b813531e6c5bb35793e5ad06 to your computer and use it in GitHub Desktop.
CODE BLUE CTF '18
# Makefile to simplify Docker stuff for CODE BLUE CTF
# Author: Jay Bosamiya (f0xtr0t)
PROBLEM_NAME=todo
TEAM_USN=todo
TEAM_PASS=todo
TEST_FLAG="testing{flagtest}"
SUBMIT_TO_PROBLEM_NAME=$(PROBLEM_NAME)
all:
@echo "Problem Name: $(PROBLEM_NAME)"
@echo " make challenge-shell -> Opens a shell inside the challenge container"
@echo " make exploit-template -> Generates a template for exploit Dockerfile"
@echo " make test -> Tests exploit"
@echo " make exploit-shell -> Opens a shell inside the exploit container"
@echo " make submit-exploit -> Submits exploit"
login:
@echo "[ ] Logging in"
@docker login registry.finals.ctf.codeblue.jp:5000 -u $(TEAM_USN) -p $(TEAM_PASS)
@echo "[+] Logged In"
pull: login
@echo "[ ] Pulling problem"
@docker pull registry.finals.ctf.codeblue.jp:5000/problems/$(PROBLEM_NAME)
@echo "[+] Pulled problem"
ephemeral:
@echo "[!] Container created for testing is ephemeral, and "
@echo " all data except inside /connect will be lost upon "
@echo " closing shell."
challenge-shell: ephemeral docker-compose.yml pull
@echo "[ ] Spinning up shell for challenge"
@docker-compose run \
--rm -u 0 \
-v "$(shell pwd):/connect" \
problem /bin/bash
@echo "[+] Shell spun down"
challenge-shell-run: ephemeral docker-compose.yml pull
@echo "[ ] Spinning up shell for challenge"
@docker run -it \
--rm -u 0 \
-v "$(shell pwd):/connect" \
--cap-add=SYS_PTRACE \
registry.finals.ctf.codeblue.jp:5000/problems/$(PROBLEM_NAME) /bin/bash
@echo "[+] Shell spun down"
exploit-shell: ephemeral docker-compose.yml build tag
@echo "[ ] Spinning up shell for exploit"
@docker-compose run \
--rm -u 0 \
-v "$(shell pwd):/connect" \
exploit /bin/bash
@echo "[+] Shell spun down"
exploit-template:
@mv Dockerfile Dockerfile.old 2>/dev/null || true
@echo "[+] Moved Dockerfile (if it exists) to Dockerfile.old"
@echo 'FROM ubuntu:latest' >> Dockerfile
@echo '' >> Dockerfile
@echo 'RUN apt-get update && apt-get -y upgrade' >> Dockerfile
@echo 'RUN apt install -y python python-pip gcc build-essential' >> Dockerfile
@echo 'RUN pip install pwntools' >> Dockerfile
@echo '' >> Dockerfile
@echo 'ENV TERM=linux' >> Dockerfile
@echo 'ENV TERMINFO=/etc/terminfo' >> Dockerfile
@echo '' >> Dockerfile
@echo 'WORKDIR /' >> Dockerfile
@echo 'COPY . .' >> Dockerfile
@echo '' >> Dockerfile
@echo 'CMD ["python", "solve.py"]' >> Dockerfile
@echo "[+] Done generating Dockerfile"
@touch 'solve.py'
@echo "[+] Solution needs to go into solve.py"
Dockerfile:
@echo "[-] Dockerfile not found. Maybe do a [make exploit-template] first"
@false
docker-compose.yml:
@echo "[-] docker-compose.yml not found. Please pull this from web interface"
@false
build: Dockerfile
@docker build --tag $(TEAM_USN):$(SUBMIT_TO_PROBLEM_NAME) .
@echo "[+] Built problem"
tag: Dockerfile build
@docker tag $(TEAM_USN):$(SUBMIT_TO_PROBLEM_NAME) registry.finals.ctf.codeblue.jp:5000/$(TEAM_USN)/$(SUBMIT_TO_PROBLEM_NAME)
test: Dockerfile docker-compose.yml pull build tag
@echo $(TEST_FLAG) > flag
@echo "[+] Created test flag"
@echo "" > submitted-flag
@echo "[+] Cleared submitted-flag"
@echo "[ ] Spinning up exploit"
@docker-compose up --abort-on-container-exit
@echo "[+] Done running exploit"
@test "$$(cat submitted-flag)" = "$(TEST_FLAG)" && echo "[+] Test passed" || (echo "[-] Test failed" && false)
submit-exploit: Dockerfile build login test tag
@docker push registry.finals.ctf.codeblue.jp:5000/$(TEAM_USN)/$(SUBMIT_TO_PROBLEM_NAME)
@echo "[+] Pushed exploit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment