Skip to content

Commit

Permalink
Add help for some /home/hacker footguns to init scripts (pwncollege#331)
Browse files Browse the repository at this point in the history
* 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 (pwncollege#103, pwncollege#253)

* Add low disk space warning to bash.bashrc

---------

Co-authored-by: Yan Shoshitaishvili <[email protected]>
  • Loading branch information
2 people authored and mudongliang committed Mar 19, 2024
1 parent 37364be commit 1c90463
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 10 additions & 0 deletions challenge/bash.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions challenge/docker-initialize.sh
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
#!/bin/sh

chown hacker:hacker /home/hacker
chmod 755 /home/hacker

if [ -x "/challenge/.init" ]; then
/challenge/.init
fi
8 changes: 1 addition & 7 deletions dojo_plugin/api/v1/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c90463

Please sign in to comment.