Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# For vim
*.swp
63 changes: 63 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from ubuntu:latest

# Install dependencies.
RUN apt update -y
RUN DEBIAN_FRONTEND="noninteractive" apt install -y tzdata
RUN apt install -y \
git-all \
vim \
nano \
whois \
openssh-server \
curl \
apt-utils \
iputils-ping \
zsh \
tmux

# Create the required users. The game master is the `git` account, and the player is the user's account
# TODO - change the gamemaster password?
# TODO - change the gamemaster username to git?
RUN useradd --comment "GameMaster account" --create-home --password $(mkpasswd -m sha-512 gamemaster) gamemaster
RUN useradd --comment "Player account" --create-home --password $(mkpasswd -m sha-512 player) --shell /bin/zsh player
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it /usr/bin/zsh?
Anyways, probably better to use $(which zsh)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


# Set up the player's SSH keys and copy the public key to /tmp
COPY build/player_entrypoint.sh /home/player
RUN ls -Rla /home/player
RUN chown player:player /home/player/player_entrypoint.sh
RUN chmod 770 /home/player/player_entrypoint.sh
RUN ls -Rla /home/player
RUN su -c "/home/player/player_entrypoint.sh" - player

RUN mkdir /var/run/sshd
RUN echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
RUN echo 'ClientAliveCountMax 10' >> /etc/ssh/sshd_config
COPY build/ssh_banner.txt /etc/banner
RUN echo 'Banner /etc/banner' >> /etc/ssh/sshd_config

# Set up the git server so that the player can run git clone gamemaster@localhost:/home/gamemaster/game-repo
RUN git clone --bare https://github.com/ShayNehmad/make-git-better-levels.git /home/gamemaster/game-repo
# This file adds the player's ssh public key from before
COPY build/gamemaster_entrypoint.sh /home/gamemaster
RUN chown gamemaster:gamemaster /home/gamemaster/gamemaster_entrypoint.sh
RUN chmod 770 /home/gamemaster/gamemaster_entrypoint.sh
RUN su -c "/home/gamemaster/gamemaster_entrypoint.sh" - gamemaster
# Set up the hooks for the actual gameplay in the repo
COPY levels/checkers /home/gamemaster/game-repo/hooks/checkers
COPY scripts/generate-pre-receive-hook/output/pre-receive /home/gamemaster/game-repo/hooks
# Make sure that gamemaster owns all of their files
RUN chown -R gamemaster:gamemaster /home/gamemaster

# Now that we're done with gamemaster's setup we can change his shell to git shell
RUN chsh gamemaster -s $(which git-shell)

# Cleanup
RUN rm -rf /tmp/*
RUN rm -rf /home/player/player_entrypoint.sh

# Some debug messages
RUN ls -Rla /home

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

16 changes: 16 additions & 0 deletions build/gamemaster_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

if [[ ! $(whoami) == "gamemaster" ]]
then echo "I'm not the gamemaster"; exit 1;
fi

if [[ ! -f /tmp/id_rsa.player.pub ]]
then echo "Not public key file found"; exit 1;
fi

# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
cd
pwd
mkdir .ssh && chmod 700 .ssh
cat /tmp/id_rsa.player.pub >> ~/.ssh/authorized_keys

21 changes: 21 additions & 0 deletions build/player_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/zsh

if [[ ! $(whoami) == "player" ]]
then echo "I'm not the player"; exit 1;
fi

# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
cd
pwd
ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa 2>/dev/null <<< y >/dev/null

cat ~/.ssh/id_rsa.pub >> /tmp/id_rsa.player.pub

echo "Setting up zsh"
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
echo "ZSH_THEME=\"agnoster\"" >> ~/.zshrc
echo "plugins=( git )" >> ~/.zshrc

git config --global user.email "[email protected]"
git config --global user.name "CTF player"

24 changes: 24 additions & 0 deletions build/ssh_banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
_ _ _
_ __ __ _ | |__ ___ __ _ (_) | |_
| ' \ / _` | | / / / -_) / _` | | | | _|
|_|_|_| \__,_| |_\_\ \___| \__, | |_| \__|
|___/
___ ___ ___
_____ / /\ ___ ___ / /\ / /\
/ /::\ / /:/_ / /\ / /\ / /:/_ / /::\
/ /:/\:\ / /:/ /\ / /:/ / /:/ / /:/ /\ / /:/\:\
/ /:/~/::\ / /:/ /:/_ / /:/ / /:/ / /:/ /:/_ / /:/~/:/
/__/:/ /:/\:| /__/:/ /:/ /\ / /::\ / /::\ /__/:/ /:/ /\ /__/:/ /:/___
\ \:\/:/~/:/ \ \:\/:/ /:/ /__/:/\:\ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:::::/
\ \::/ /:/ \ \::/ /:/ \__\/ \:\ \__\/ \:\ \ \::/ /:/ \ \::/~~~~
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\
\ \::/ \ \::/ \__\/ \__\/ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/


A CTF challenge by Shay Nehmad
Visit https://mrnice.dev

This is a game server. Please try to not mess it up ¯\_(ツ)_/¯
If you find any issues, let me know @ShayNehmad on Twitter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some notes about the server config?
"Your shell is ZSH with oh-my-zsh etc."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be on the site. No need to see each login