# NOTE: This hash is pinned to avoid version and environment differences.
FROM debian@sha256:c71b05eac0b20adb4cdcc9f7b052227efd7da381ad10bb92f972e8eae7c6cdc9
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update --fix-missing && \
    apt-get -y install xinetd qemu-system-x86
RUN groupadd -r pwn && useradd -r -g pwn 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 = /home/pwn/run.sh\n\
}' > /etc/xinetd.d/pwn
RUN chmod 500 /etc/init.sh
RUN chmod 444 /etc/xinetd.d/pwn

WORKDIR /home/pwn
ADD --chmod=644 rootfs.cpio.gz .
ADD --chmod=644 flag .
ADD --chmod=644 bzImage     .
ADD --chmod=550 run.sh      .

RUN chown -R root:pwn /home/pwn
RUN service xinetd restart

