diff --git a/README.md b/README.md index 597d197..3a7e975 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,21 @@ #### Difficulty : easy ---- +## Running the challenge. + +You can run the challenge using docker. + +### with Docker compose + +``` +cd docker +sudo docker compose up --build +``` + ## Writeup - - +### Enum diff --git a/config/base.sql b/config/base.sql new file mode 100644 index 0000000..b279f4d --- /dev/null +++ b/config/base.sql @@ -0,0 +1,17 @@ +CREATE DATABASE IF NOT EXISTS app; +USE app; + +CREATE USER 'ctf'@'%' IDENTIFIED WITH mysql_native_password BY '39gknzLD'; +GRANT ALL PRIVILEGES ON app.* TO 'ctf'@'%'; +FLUSH PRIVILEGES; + +CREATE TABLE users +( + user_id INT PRIMARY KEY AUTO_INCREMENT, + username VARCHAR(25) NOT NULL, + pass VARCHAR(80) NOT NULL +); + +-- cleartext pass ? but why of course +INSERT INTO users (user_id,username,pass) +VALUES (0,'admin','X82v7>P./~vC'); \ No newline at end of file diff --git a/config/codes.txt b/config/codes.txt new file mode 100644 index 0000000..28fba20 --- /dev/null +++ b/config/codes.txt @@ -0,0 +1 @@ +ODQxOTU= \ No newline at end of file diff --git a/config/creds.txt b/config/creds.txt new file mode 100644 index 0000000..1e6f0e1 --- /dev/null +++ b/config/creds.txt @@ -0,0 +1 @@ +agent:1c0b76fce779f78f51be339c49445c49 \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 67c8ac7..92b9696 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,9 @@ FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive +ENV MYSQL_ROOT_PASSWORD=39gknzLD +ENV MYSQL_DATABASE=app + RUN apt update && apt upgrade -y && \ apt install -y \ @@ -11,28 +14,43 @@ RUN apt update && apt upgrade -y && \ supervisor \ openssh-server \ sudo \ + php-mysql\ cowsay \ + php \ + iputils-ping \ && rm -rf /var/lib/apt/lists/* # the user players will need to have access as -RUN useradd -m -s /bin/bash l33t \ -&& echo "l33t:h4x0r" | chpasswd +RUN useradd -m -s /bin/bash agent \ +&& echo "agent:secure" | chpasswd -# foothold user with no sudo perms. Only access to the l33t user home directory. +# apache2 config to change default 80 port to 8080 -RUN useradd webmaster +RUN sed -i 's/^Listen 80/Listen 8080/' /etc/apache2/ports.conf -# apache2 config to change default 80 port to 31337 +RUN sed -i 's///' /etc/apache2/sites-available/000-default.conf -RUN sed -i 's/^Listen 80/Listen 31337/' /etc/apache2/ports.conf +# remove default apache2 index.html -RUN sed -i 's///' /etc/apache2/sites-available/000-default.conf +RUN rm /var/www/html/index.html + +# enable php module +RUN ls /etc/apache2/mods-enabled/ +RUN a2enmod php* # copy the app -#COPY ./app/ /var/www/html/ +COPY ./www/ /var/www/html/ + +# give upload permissions to the www-data user + +RUN chown -R www-data:www-data /var/www/html/confidential/uploads && chmod -R 755 /var/www/html/confidential/uploads + +# give permissions to access the agent user to www-data + +RUN usermod -aG agent www-data && chmod 750 /home/agent RUN mkdir /var/run/sshd @@ -40,14 +58,25 @@ RUN mkdir /var/run/sshd # for the privesc, cowsay allowed to be ran with sudo without password # https://gtfobins.github.io/gtfobins/cowsay/ -RUN printf 'l33t ALL=(ALL) NOPASSWD: /usr/games/cowsay, /usr/bin/sudo -l\n' > /etc/sudoers.d/l33t && \ - chmod 0440 /etc/sudoers.d/l33t && \ - visudo -cf /etc/sudoers.d/l33t +RUN printf 'agent ALL=(ALL) NOPASSWD: /usr/games/cowsay, /usr/bin/sudo -l\n' > /etc/sudoers.d/agent && \ + chmod 0440 /etc/sudoers.d/agent && \ + visudo -cf /etc/sudoers.d/agent -# 22 port -> ssh, 31337 port (suggestion) -> vulnerable webserver players need to find using nmap port scans +# copy the agent user creds and set 777 suid + +COPY ./config/creds.txt /home/agent/ +RUN chmod 777 /home/agent/creds.txt + +# copy the secret codes and set suid + +COPY ./config/codes.txt /root/ + +RUN chown root:root /root/codes.txt + +# 22 port -> ssh, 8080 port -> webserver EXPOSE 22 -EXPOSE 31337 +EXPOSE 8080 # config of supervisord to have both apache2 and sshd services running diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e69de29..7068372 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -0,0 +1,24 @@ +services: + db: + image: mysql:8.1 + environment: + MYSQL_ROOT_PASSWORD: 39gknzLD + MYSQL_DATABASE: app + volumes: + - ../config/base.sql:/docker-entrypoint-initdb.d/base.sql:ro + ports: + - "3306:3306" + app: + hostname: srv1prod + build: + context: .. + dockerfile: docker/Dockerfile + container_name: "ji-ctf-dockerized" + environment: + MYSQL_ROOT_PASSWORD: 39gknzLD + MYSQL_DATABASE: app + ports: + - "22:22" + - "31337:31337" + depends_on: + - db \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100644 index f682536..0000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/bash - diff --git a/fiveserver.config.js b/fiveserver.config.js new file mode 100644 index 0000000..23b68d3 --- /dev/null +++ b/fiveserver.config.js @@ -0,0 +1,3 @@ +module.exports = { + php: "/usr/bin/php" +} \ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess new file mode 100644 index 0000000..2f6aa62 --- /dev/null +++ b/www/.htaccess @@ -0,0 +1 @@ +DirectoryIndex index.php \ No newline at end of file diff --git a/www/admin/loadnote.php b/www/admin/loadnote.php new file mode 100644 index 0000000..8fe5be7 --- /dev/null +++ b/www/admin/loadnote.php @@ -0,0 +1,23 @@ + diff --git a/www/admin/securenotes.php b/www/admin/securenotes.php new file mode 100644 index 0000000..7e794a4 --- /dev/null +++ b/www/admin/securenotes.php @@ -0,0 +1,129 @@ + + + + + + + +NFD | SECURE NOTES + + + + + + +
+ +
+

Upload notes securely here from each operation.

+ Notes must be in .txt +
+ + +

+ +
+ + +
+ +
+ + +
+ isDot() || $file->isDir()) continue; + $fileName = $file->getFilename(); + if (!preg_match('/\.(txt|php)$/i', $fileName)) continue; + ?> +
+ Note Icon +
+
+ +
+ +
+ + + + + + + + + diff --git a/www/admin/uploadnote.php b/www/admin/uploadnote.php new file mode 100644 index 0000000..4a7c309 --- /dev/null +++ b/www/admin/uploadnote.php @@ -0,0 +1,28 @@ +File uploaded!"; + } else { + $status = "
An error occurred.
"; + } + } else { + $status = "
An error occurred.
"; + } + } else { + $status = "
Invalid file type!
"; + } +} + +echo $status; +?> diff --git a/www/confidential/uploads/OperationAlpha.txt b/www/confidential/uploads/OperationAlpha.txt new file mode 100644 index 0000000..f6ea049 --- /dev/null +++ b/www/confidential/uploads/OperationAlpha.txt @@ -0,0 +1 @@ +foobar \ No newline at end of file diff --git a/www/confidential/uploads/OperationBravo.txt b/www/confidential/uploads/OperationBravo.txt new file mode 100644 index 0000000..f6ea049 --- /dev/null +++ b/www/confidential/uploads/OperationBravo.txt @@ -0,0 +1 @@ +foobar \ No newline at end of file diff --git a/www/confidential/uploads/OperationTourniquet.txt b/www/confidential/uploads/OperationTourniquet.txt new file mode 100644 index 0000000..f6ea049 --- /dev/null +++ b/www/confidential/uploads/OperationTourniquet.txt @@ -0,0 +1 @@ +foobar \ No newline at end of file diff --git a/www/gallery.php b/www/gallery.php new file mode 100644 index 0000000..d652182 --- /dev/null +++ b/www/gallery.php @@ -0,0 +1,49 @@ + + + + + + + Tux gallery ! + + + + + + +
+
+

Tux gallery

+

Tux is awesome ! So I made this extremely secure gallery app.

+ + You can also add tux pictures to the gallery, first login and then you should be able to upload a new image of tux. + + First navigate to the upload.php page and upload your tux image from there! + +
+
+ +
+ + + + \ No newline at end of file diff --git a/www/include/nav.php b/www/include/nav.php new file mode 100644 index 0000000..342f7a2 --- /dev/null +++ b/www/include/nav.php @@ -0,0 +1,18 @@ + + diff --git a/www/index.html b/www/index.html deleted file mode 100644 index 8b1652e..0000000 --- a/www/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - Tux gallery ! - - - - -
-
- -
-
- - - \ No newline at end of file diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..e249638 --- /dev/null +++ b/www/index.php @@ -0,0 +1,63 @@ + + + + + + + NDF | LOGIN + + + + +
+
+
+

NDF ACCESS

+ + + + + + + + Username is empty.
'; + } else { + $servername = "db"; + $username = "ctf"; + $password_db = "39gknzLD"; + $dbname = "app"; + $conn = new mysqli($servername, $username, $password_db, $dbname); + $sql = "SELECT username, pass FROM users WHERE username='$name' AND pass='$password'"; + $result = $conn->query($sql); + if ($result->num_rows > 0) { + session_regenerate_id(true); + $_SESSION['username'] = $name; + header('Location: /admin/securenotes.php'); + exit(); + } else { + echo '
Wrong username or password!
'; + } + } + } + ?> + + + + + + diff --git a/www/logout.php b/www/logout.php new file mode 100644 index 0000000..f8fceb5 --- /dev/null +++ b/www/logout.php @@ -0,0 +1,14 @@ +