summaryrefslogtreecommitdiffstats
path: root/chall
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2024-05-10 20:02:22 +0200
committerLouis Burda <quent.burda@gmail.com>2024-05-10 20:02:22 +0200
commitd443cc3152fc206e4393e9809f282722200308ca (patch)
tree20d97961c3ef9f2d62a85238d76165eb40757f08 /chall
downloadseccon2022-txtchecker-master.tar.gz
seccon2022-txtchecker-master.zip
Add solutionHEADmaster
Diffstat (limited to 'chall')
-rw-r--r--chall/Dockerfile25
-rw-r--r--chall/checker.sh9
-rw-r--r--chall/docker-compose.yml8
-rw-r--r--chall/flag.txt1
4 files changed, 43 insertions, 0 deletions
diff --git a/chall/Dockerfile b/chall/Dockerfile
new file mode 100644
index 0000000..9606414
--- /dev/null
+++ b/chall/Dockerfile
@@ -0,0 +1,25 @@
+FROM ubuntu:jammy
+
+RUN apt-get update && apt-get -y install openssh-server file procps
+
+WORKDIR /app
+
+RUN groupadd -r ctf && useradd -m -r -g ctf ctf
+RUN echo "ctf:ctf" | chpasswd
+
+RUN echo 'ForceCommand "/app/checker.sh"' >> /etc/ssh/sshd_config
+RUN echo 'Port 2022' >> /etc/ssh/sshd_config
+RUN mkdir /var/run/sshd
+
+COPY flag.txt /
+COPY checker.sh /app/
+
+RUN chmod 444 /flag.txt
+RUN chmod 555 /app/checker.sh
+
+CMD while true; do \
+ # kill long running processes for ssh
+ ps -eo comm,pid,etimes | awk '/^checker.sh/ {if ($3 > 10) { print $2 }}' | xargs --no-run-if-empty kill -9; \
+ sleep 5s; \
+ done & \
+ /sbin/sshd -D
diff --git a/chall/checker.sh b/chall/checker.sh
new file mode 100644
index 0000000..45f7942
--- /dev/null
+++ b/chall/checker.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+read -p "Input a file path: " filepath
+file $filepath 2>/dev/null | grep -q "ASCII text" 2>/dev/null
+
+# TODO: print the result the above command.
+# $? == 0 -> It's a text file.
+# $? != 0 -> It's not a text file.
+exit 0
diff --git a/chall/docker-compose.yml b/chall/docker-compose.yml
new file mode 100644
index 0000000..c13f708
--- /dev/null
+++ b/chall/docker-compose.yml
@@ -0,0 +1,8 @@
+version: "3"
+
+services:
+ challenge:
+ build: .
+ restart: always
+ ports:
+ - 2022:2022
diff --git a/chall/flag.txt b/chall/flag.txt
new file mode 100644
index 0000000..8671e48
--- /dev/null
+++ b/chall/flag.txt
@@ -0,0 +1 @@
+SECCON{dummy}