Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Git CTF 🚩 but good this time.
- [make-git-better-2](#make-git-better-2)
- [Dependencies](#dependencies)
- [Build](#build)
- [How to build the challenge Docker](#how-to-build-the-challenge-docker)
- [Ansible](#ansible)
- [How to build the challenge Docker manually](#how-to-build-the-challenge-docker-manually)
- [Create the hook script](#create-the-hook-script)
- [powershell](#powershell)
- [sh](#sh)
Expand All @@ -28,10 +29,23 @@ Git CTF 🚩 but good this time.
- Rust
- Docker
- Python 3.6 (for docker TCP switchboard)
- Ansible (optional)

## Build

### How to build the challenge Docker
### Ansible

Using Ansible, you can build and deploy the game server from nothing.

```bash
cd build/ansible
sed -i 's/ctf.mrnice.dev/your.server.com/g' hosts
ansible-playbook -v -i hosts build.yaml
```

Make sure that you have Ansible configured correctly with your SSH keys.

### How to build the challenge Docker manually

#### Create the hook script

Expand Down
55 changes: 55 additions & 0 deletions build/ansible/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
- hosts: ctfservers
tasks:
- name: Pull CTF repo
git:
repo: "https://github.com/TheCoreMan/make-git-better-2.git"
dest: /home/{{ ansible_facts['user_id'] }}/make-git-better-2
version: dev
accept_hostkey: yes

- name: Compile rust
command: /home/{{ ansible_facts['user_id'] }}/.cargo/bin/cargo run --bin generate-pre-receive-hook -- --verbose /home/{{ ansible_facts['user_id'] }}/make-git-better-2/levels/game-config.toml src/bin/templates/hook.tmpl
args:
chdir: /home/{{ ansible_facts['user_id'] }}/make-git-better-2/scripts

- name: Build Docker image
shell: docker build --tag mgb:0.1 --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .
args:
chdir: /home/{{ ansible_facts['user_id'] }}/make-git-better-2

- name: Clone docker-tcp-switchboard
git:
repo: "https://github.com/OverTheWireOrg/docker-tcp-switchboard.git"
dest: /home/{{ ansible_facts['user_id'] }}/docker-tcp-switchboard
accept_hostkey: yes

- name: Install docker-tcp-switchboard requirements
pip:
requirements: /home/{{ ansible_facts['user_id'] }}/docker-tcp-switchboard/requirements.txt
executable: pip3

- name: Create switchboard log
file:
path: /var/log/docker-tcp-switchboard.log
mode: a+w
state: touch
become: yes

- name: Copy our switchboard conf to /etc
copy:
src: /home/{{ ansible_facts['user_id'] }}/make-git-better-2/build/docker-tcp-switchboard.conf
dest: /etc/docker-tcp-switchboard.conf
remote_src: yes
become: yes

- name: Kill docker-tcp-switchboard
command: pkill -f "python3 .*docker-tcp-switchboard.py"
ignore_errors: true
become: yes

- name: Start docker-tcp-switchboard
shell: nohup python3 /home/{{ ansible_facts['user_id'] }}/docker-tcp-switchboard/docker-tcp-switchboard.py </dev/null >/dev/null 2>&1 &
# This shell line is required because Ansible sends a kill signal to Python
# when it finishes running. The nohup is there to prevent it, and the redirections
# prevent breaking the process.
become: yes
3 changes: 3 additions & 0 deletions build/ansible/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ctfservers]
[email protected]