FROM ubuntu:25.04

ENV DEBIAN_FRONTEND=noninteractive


RUN apt-get update \
 && apt-get install -y --no-install-recommends \
     openssh-server sudo ca-certificates nano file htop vim locales \
     python3 python3-pip procps cron libpam-modules \
 && locale-gen en_US.UTF-8 \
 && update-locale LANG=en_US.UTF-8 \
 && rm -rf /var/lib/apt/lists/* \
 && echo escape-room > /etc/hostname


RUN mkdir -p /var/run/sshd

RUN useradd -m -s /bin/bash crime1
RUN useradd -m -s /bin/bash crime2
RUN useradd -m -s /bin/bash crime3 
RUN useradd -m -s /bin/bash crime4
RUN useradd -m -s /bin/bash crime5 

RUN mkdir -p /home/crime1
RUN chown -R crime1:crime1 /home/crime1
RUN mkdir -p /home/crime2
RUN chown -R crime2:crime2 /home/crime2
RUN mkdir -p /home/crime3
RUN chown -R crime3:crime3 /home/crime3
RUN mkdir -p /home/crime4
RUN chown -R crime4:crime4 /home/crime4
RUN mkdir -p /home/crime5
RUN chown -R crime5:crime5 /home/crime5

RUN echo "crime1:crime1" | chpasswd
RUN echo "crime2:&Vs@gSfdC+SPh!{BkBSt=~9{" | chpasswd
RUN echo "crime3:CX1bjEG5Hj2bYmFBKe4hfLYFpXBFi2Dv" | chpasswd
RUN echo "crime4:Q!w2e3r4T5z6U7i8O9p0A#sD" | chpasswd
RUN echo "crime5:vG7kLp9!xQ2zW4eR6tY8uI0" | chpasswd

# SSH
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' /etc/ssh/sshd_config

RUN sed -i 's/^session.*pam_lastlog.so/#&/' /etc/pam.d/sshd \
 && sed -i 's/^session.*pam_lastlog.so/#&/' /etc/pam.d/login

# Level4
RUN mkdir -p /home/crime4
COPY Level/Level4/_geheim /home/crime4/_geheim
RUN chown crime4:crime4 /home/crime4/_geheim && chmod 600 /home/crime4/_geheim
RUN echo "Q!w2e3r4T5z6U7i8O9p0A#sD" > /home/crime4/_geheim
RUN echo "Q!w2e3r4T5z6U7i8O9p0A#sD" > /home/crime4/_geheim
COPY Level/Level3/geheim.txt /home/crime3/geheim.txt
RUN chown crime3:crime3 /home/crime3/geheim.txt && chmod 600 /home/crime3/geheim.txt


RUN mkdir -p /home/crime5
COPY Level/Level5/systemd-hdtob.py /usr/local/bin/systemd-hdtob.py
RUN chmod +x /usr/local/bin/systemd-hdtob.py

COPY Level/Level5/watchdog.py /root/watchdog.py
RUN chmod 700 /root/watchdog.py

RUN mkdir -p /home/crime5/.timer \
    && chown crime5:crime5 /home/crime5/.timer

COPY guide/crime5/win-message.sh /root/win-message.sh
RUN chmod +x /root/win-message.sh

COPY Level/Level5/start_level5.sh /usr/local/bin/start_level5.sh
RUN chmod +x /usr/local/bin/start_level5.sh

COPY Level/Level5/login_wrapper.sh /usr/local/bin/login_wrapper.sh
RUN chmod +x /usr/local/bin/login_wrapper.sh

RUN printf "\nMatch User crime5\n    ForceCommand /usr/local/bin/login_wrapper.sh\n" >> /etc/ssh/sshd_config

RUN apt-get update && apt-get install -y bash psmisc

COPY Level/Level5/hduzgfizgfiz.sh /usr/local/bin/hduzgfizgfiz.sh
RUN chmod +x /usr/local/bin/hduzgfizgfiz.sh





# motd
RUN rm -fr /etc/update-motd.d/*
RUN mkdir -p /guide

RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" > /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\e[37m✧ Ein unfreundliches Willkommen im Escape Room ✧\e[0m\n" >> /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\033[37mACHTUNG!\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37mIn wenigen Augenblicken wird dein PC ausgelöscht\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37mes sei denn, du bestehst diese Prüfung. Vor dir liegen\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37m5 Level, und in jedem musst du in einer unheimlichen\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37mLinux-Umgebung ein verborgenes Passwort finden.\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37mNur dann kannst du deinen PC retten.\033[0m\n" >> /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\033[37mAktuelles Level: 1\033[0m\n" >> /guide/crime1.txt
RUN printf "\033[37mTipp: Finde das Password\033[0m\n" >> /guide/crime1.txt
RUN printf "\n" >> /guide/crime1.txt
RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" >> /guide/crime1.txt

RUN echo "crime2" > /guide/crime2.txt

RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" > /guide/crime3.txt
RUN printf "\n" >> /guide/crime3.txt
RUN printf "\e[37m✧ Level 3 – Entschlüsselung ✧\e[0m\n" >> /guide/crime3.txt
RUN printf "\n" >> /guide/crime3.txt
RUN printf "\033[37mIm Home-Verzeichnis liegt eine Datei mit einem\033[0m\n" >> /guide/crime3.txt
RUN printf "\033[37mverschlüsselten Inhalt. Finde heraus, wie sie\033[0m\n" >> /guide/crime3.txt
RUN printf "\033[37mcodiert wurde und entschlüssle das Passwort.\033[0m\n" >> /guide/crime3.txt
RUN printf "\n" >> /guide/crime3.txt
RUN printf "\033[37mAktuelles Level: 3\033[0m\n" >> /guide/crime3.txt
RUN printf "\033[37mTipp: base64 -d\033[0m\n" >> /guide/crime3.txt
RUN printf "\n" >> /guide/crime3.txt
RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" >> /guide/crime3.txt

RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" > /guide/crime4.txt
RUN printf "\n" >> /guide/crime4.txt
RUN printf "\e[37m✧ Level 4 – Versteckte Datei ✧\e[0m\n" >> /guide/crime4.txt
RUN printf "\n" >> /guide/crime4.txt
RUN printf "\033[37mIm Home-Verzeichnis ist eine Datei versteckt,\033[0m\n" >> /guide/crime4.txt
RUN printf "\033[37mdie nicht sofort sichtbar ist. Schau genau hin!\033[0m\n" >> /guide/crime4.txt
RUN printf "\n" >> /guide/crime4.txt
RUN printf "\033[37mAktuelles Level: 4\033[0m\n" >> /guide/crime4.txt
RUN printf "\033[37mTipp: ls -la\033[0m\n" >> /guide/crime4.txt
RUN printf "\n" >> /guide/crime4.txt
RUN printf "\e[37m↚ ↜ ↞ ↤ ↫ ↭ ↬ ↦ ↣ ↝ ↛ ↮ ↛ ↝ ↣ ↦ ↬ ↭ ↫ ↤ ↞ ↜ ↚\e[0m\n" >> /guide/crime4.txt

RUN echo 'if [ -f "/guide/$(whoami).txt" ]; then cat "/guide/$(whoami).txt"; fi' >> /etc/bash.bashrc

COPY guide/crime5/typewrite.sh /usr/local/bin/typewrite.sh
RUN chmod +x /usr/local/bin/typewrite.sh

RUN echo 'if [ "$(whoami)" = "crime5" ]; then /usr/local/bin/typewrite.sh; fi' >> /home/crime5/.bashrc \
 && chown crime5:crime5 /home/crime5/.bashrc

RUN echo 'export PS1="\u@$(hostname):\\$ "' >> /etc/profile

RUN rm -f /etc/legal
RUN sed -i 's/^session\s\+optional\s\+pam_motd/#session optional pam_motd/' /etc/pam.d/sshd


EXPOSE 22

COPY start.sh /start.sh
RUN chmod +x /start.sh
CMD ["/start.sh"]
