Skip to content

Commit 6a851fb

Browse files
authored
Merge pull request #5 from ShayNehmad/docker
Docker
2 parents 04a7e52 + 781ee27 commit 6a851fb

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
# For vim
13+
*.swp

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from ubuntu:latest
2+
3+
# Install dependencies.
4+
RUN apt update -y
5+
RUN DEBIAN_FRONTEND="noninteractive" apt install -y tzdata
6+
RUN apt install -y \
7+
git-all \
8+
vim \
9+
nano \
10+
whois \
11+
openssh-server \
12+
curl \
13+
apt-utils \
14+
iputils-ping \
15+
zsh \
16+
tmux
17+
18+
# Create the required users. The game master is the `git` account, and the player is the user's account
19+
RUN useradd --comment "GameMaster account" --create-home --password $(mkpasswd -m sha-512 94+wings+STRONG+mountain+35) gamemaster
20+
RUN useradd --comment "Player account" --create-home --password $(mkpasswd -m sha-512 player) --shell $(which zsh) player
21+
22+
# Set up the player's SSH keys and copy the public key to /tmp
23+
COPY build/player_entrypoint.sh /home/player
24+
RUN chown player:player /home/player/player_entrypoint.sh
25+
RUN chmod 770 /home/player/player_entrypoint.sh
26+
RUN su -c "/home/player/player_entrypoint.sh" - player
27+
COPY build/player_zshrc.sh /home/player/.zshrc
28+
RUN chown player:player /home/player/.zshrc
29+
RUN chmod 770 /home/player/.zshrc
30+
31+
RUN mkdir /var/run/sshd
32+
RUN echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
33+
RUN echo 'ClientAliveCountMax 10' >> /etc/ssh/sshd_config
34+
COPY build/login_banner.txt /etc/motd
35+
36+
# Set up the git server so that the player can run git clone gamemaster@localhost:/home/gamemaster/ctf-repo
37+
RUN git clone --bare https://github.com/ShayNehmad/make-git-better-levels.git /home/gamemaster/ctf-repo
38+
# This file adds the player's ssh public key from before
39+
COPY build/gamemaster_entrypoint.sh /home/gamemaster
40+
RUN chown gamemaster:gamemaster /home/gamemaster/gamemaster_entrypoint.sh
41+
RUN chmod 770 /home/gamemaster/gamemaster_entrypoint.sh
42+
RUN su -c "/home/gamemaster/gamemaster_entrypoint.sh" - gamemaster
43+
# Set up the hooks for the actual gameplay in the repo
44+
COPY levels/checkers /home/gamemaster/ctf-repo/hooks/checkers
45+
COPY scripts/generate-pre-receive-hook/output/pre-receive /home/gamemaster/ctf-repo/hooks
46+
# Make sure that gamemaster owns all of their files
47+
RUN chown -R gamemaster:gamemaster /home/gamemaster
48+
49+
# Now that we're done with gamemaster's setup we can change their shell to git shell and block their home directory
50+
RUN chsh gamemaster -s $(which git-shell)
51+
RUN chmod 700 -R /home/gamemaster
52+
53+
# Cleanup
54+
RUN rm -rf /tmp/*
55+
RUN rm -rf /home/player/player_entrypoint.sh
56+
57+
EXPOSE 22
58+
CMD ["/usr/sbin/sshd", "-D"]
59+

build/gamemaster_entrypoint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
if [[ ! $(whoami) == "gamemaster" ]]
4+
then echo "I'm not the gamemaster"; exit 1;
5+
fi
6+
7+
if [[ ! -f /tmp/id_rsa.player.pub ]]
8+
then echo "Not public key file found"; exit 1;
9+
fi
10+
11+
# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
12+
cd
13+
pwd
14+
mkdir .ssh && chmod 700 .ssh
15+
cat /tmp/id_rsa.player.pub >> ~/.ssh/authorized_keys
16+

build/login_banner.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
_ _ _
2+
_ __ __ _ | |__ ___ __ _ (_) | |_
3+
| ' \ / _` | | / / / -_) / _` | | | | _|
4+
|_|_|_| \__,_| |_\_\ \___| \__, | |_| \__|
5+
|___/
6+
___ ___ ___
7+
_____ / /\ ___ ___ / /\ / /\
8+
/ /::\ / /:/_ / /\ / /\ / /:/_ / /::\
9+
/ /:/\:\ / /:/ /\ / /:/ / /:/ / /:/ /\ / /:/\:\
10+
/ /:/~/::\ / /:/ /:/_ / /:/ / /:/ / /:/ /:/_ / /:/~/:/
11+
/__/:/ /:/\:| /__/:/ /:/ /\ / /::\ / /::\ /__/:/ /:/ /\ /__/:/ /:/___
12+
\ \:\/:/~/:/ \ \:\/:/ /:/ /__/:/\:\ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:::::/
13+
\ \::/ /:/ \ \::/ /:/ \__\/ \:\ \__\/ \:\ \ \::/ /:/ \ \::/~~~~
14+
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\
15+
\ \::/ \ \::/ \__\/ \__\/ \ \::/ \ \:\
16+
\__\/ \__\/ \__\/ \__\/
17+
18+
19+
A git CTF challenge by Shay Nehmad
20+
Visit https://mrnice.dev
21+
22+
This is a game server. Please try to not mess it up ¯\_(ツ)_/¯
23+
If you find any issues, let me know @ShayNehmad on Twitter.
24+
25+
To start playing, clone the game repository by running:
26+
27+
git clone gamemaster@localhost:~/ctf-repo
28+

build/player_entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/zsh
2+
3+
if [[ ! $(whoami) == "player" ]]
4+
then echo "I'm not the player"; exit 1;
5+
fi
6+
7+
# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
8+
cd
9+
pwd
10+
ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa 2>/dev/null <<< y >/dev/null
11+
12+
cat ~/.ssh/id_rsa.pub >> /tmp/id_rsa.player.pub
13+
14+
echo "Setting up zsh"
15+
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
16+
17+
18+
git config --global user.email "[email protected]"
19+
git config --global user.name "CTF player"
20+

build/player_zshrc.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export ZSH="/home/player/.oh-my-zsh"
2+
ZSH_THEME="juanghurtado"
3+
plugins=(git)
4+
5+
source $ZSH/oh-my-zsh.sh
6+

0 commit comments

Comments
 (0)