# NOTE: This hash is for the version at the time of the original CTF.
FROM ubuntu:20.04@sha256:c9820a44b950956a790c354700c1166a7ec648bc0d215fa438d3a339812f1d01

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -y update --fix-missing
RUN apt-get -y install xinetd wget

RUN groupadd -r admin && useradd -r -g admin admin
RUN groupadd pwn && useradd -g pwn pwn
RUN printf "/bin/bash\n" | chsh pwn

RUN echo '#!/bin/bash\n\
service xinetd restart && /bin/sleep infinity' > /etc/init.sh
RUN echo 'service pwn\n\
{\n\
  type = UNLISTED\n\
  disable = no\n\
  socket_type = stream\n\
  protocol = tcp\n\
  wait = no\n\
  user = pwn\n\
  bind = 0.0.0.0\n\
  port = 9999\n\
  server = /bin/bash\n\
  server_args = -i\n\
}' > /etc/xinetd.d/pwn
RUN chmod 500 /etc/init.sh
RUN chmod 444 /etc/xinetd.d/pwn

WORKDIR /home/pwn
RUN chown -R pwn:admin .
RUN chmod 775 .

ADD sharr .
RUN chown admin:root sharr
RUN chmod 4555 sharr

# Add flag
RUN echo "nek0pts{*** REDACTED ***}" > flag.txt
RUN chmod 440 /home/pwn/flag.txt
RUN chown admin:root /home/pwn/flag.txt
RUN mv flag.txt flag-$(md5sum flag.txt | awk '{print $1}').txt

RUN service xinetd restart
