..

How To Run Any CLI Program Over a TCP Socket, or How To Run a CTF?

If you want to run a CTF sometimes you'd like to give telnet access to a program to the participants. How do people do that?

Well here's the gist of it. Run the following docker build file using docker compose build and you'll be done. The binary file chal, and flag.txt should be in the same directory.

FROM debian:latest
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && \
    apt-get install -y socat && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN useradd -u 1001 -d /home/user -s /bin/bash user

WORKDIR /home/user

COPY chall /home/user/
COPY flag.txt /home/user/

RUN chmod 111 /home/user/chall
RUN chmod 444 /home/user/flag.txt
RUN chmod -R 555 /home/user

EXPOSE 1337
ENTRYPOINT ["socat", "TCP-LISTEN:1337,reuseaddr,fork,nodelay,su=user", "EXEC:'timeout 180 ./chall'"]

You could change ./chall part to yes for example and see that any client that connects to that socket over telnet sees a lot of "y"s :)