From 1c90463e2a7190583cb806372d2c0c224cd12661 Mon Sep 17 00:00:00 2001 From: Spencer Pogorzelski <34356756+Scoder12@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:11:01 -0700 Subject: [PATCH] Add help for some /home/hacker footguns to init scripts (#331) * refactor: move some initialization code to a .sh this script was already being called the line above there's not really much reason for it to live in docker.py * fix home directory permissions on init (#103, #253) * Add low disk space warning to bash.bashrc --------- Co-authored-by: Yan Shoshitaishvili --- challenge/bash.bashrc | 10 ++++++++++ challenge/docker-initialize.sh | 7 +++++++ dojo_plugin/api/v1/docker.py | 8 +------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/challenge/bash.bashrc b/challenge/bash.bashrc index d41b8edac..ab2098402 100755 --- a/challenge/bash.bashrc +++ b/challenge/bash.bashrc @@ -16,4 +16,14 @@ if [ -e "/challenge/README.md" ] && [ ! -e "/tmp/.dojo/readme-once" ]; then touch /tmp/.dojo/readme-once fi +AVAILABLE_M="$(df --block-size=1M --output=avail /home/hacker | tail -n +2 | head -n1)" +if [[ "$AVAILABLE_M" -lt 512 ]]; then + echo 'Note: Your home directory is running low on storage:' + df -h /home/hacker + echo '' + echo 'Filling your home directory completely could cause you to lose access to the workspace and/or desktop.' + echo 'You can view a list of the largest files and directories using the command:' + echo ' du -sh /home/hacker/* | sort -h' +fi + [ -f "/challenge/.bashrc" ] && source /challenge/.bashrc diff --git a/challenge/docker-initialize.sh b/challenge/docker-initialize.sh index 1a2485251..a55f58710 100755 --- a/challenge/docker-initialize.sh +++ b/challenge/docker-initialize.sh @@ -1 +1,8 @@ #!/bin/sh + +chown hacker:hacker /home/hacker +chmod 755 /home/hacker + +if [ -x "/challenge/.init" ]; then + /challenge/.init +fi diff --git a/dojo_plugin/api/v1/docker.py b/dojo_plugin/api/v1/docker.py index a7e03b046..d8990ca49 100644 --- a/dojo_plugin/api/v1/docker.py +++ b/dojo_plugin/api/v1/docker.py @@ -184,14 +184,8 @@ def insert_auth_token(auth_token): def initialize_container(): exec_run( f""" - /opt/pwn.college/docker-initialize.sh - export DOJO_PRIVILEGED={"1" if practice else "0"} - - if [ -x "/challenge/.init" ]; then - /challenge/.init - fi - + /opt/pwn.college/docker-initialize.sh touch /opt/pwn.college/.initialized """, shell=True