Skip to content

Commit 24aebf6

Browse files
committed
linux-luminarium: add hidden disk doomsday test
1 parent 23f3c08 commit 24aebf6

7 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
The available space in `/home/hacker` in this container is deliberately limited.
2+
In this level you will clog up `/home/hacker` with so much junk that even a tiny 1 megabyte file can't be created.
3+
When this happens, your workspace becomes unusable.
4+
We'll practice inducing this in this challenge, and then expand on it a bit later.
5+
6+
How to fill the disk?
7+
There are so many ways.
8+
Here, we'll teach you the `yes` command!
9+
10+
```
11+
hacker@dojo:~$ yes | head
12+
y
13+
y
14+
y
15+
y
16+
y
17+
y
18+
y
19+
y
20+
y
21+
y
22+
hacker@dojo:~$
23+
```
24+
25+
The `yes` outputs `y` over and over forever.
26+
The typical usage is to automate confirmation prompts ("Are you sure you want to delete this file?") using piping, but we'll use it here to make a massive file full of "y" lines.
27+
Just redirect `yes` to a file in your home directory, and you'll fill your disk!
28+
29+
This challenge forces you to fill the disk and then clean up.
30+
The process:
31+
32+
1. Fill your disk.
33+
2. Run `/challenge/check`. It will attempt to create a 1 megabyte temporary file. If that fails, you pass the first stage and the checker will ask you to free the space.
34+
3. Delete the file you made (with `rm`) to clear up the space.
35+
4. Run `/challenge/check` a second time. If it can now create the temporary file (i.e., you successfully cleaned up your home directory), you’ll receive the flag.
36+
37+
----
38+
**Why two stages?**
39+
For local runs, this challenge gives you a temporary, size-limited home directory for the exercise.
40+
On pwn.college, your home directory persists across challenge instances.
41+
If we let you keep it full, your pwn.college will stop working.
42+
This is _by far_ the most common cause of weird issues on pwn.college!
43+
44+
**HELP IT BROKE!**
45+
If you fill the disk and don't clean it up afterwards, you'll need to `ssh` in to fix things (by removing that file).
46+
This is a bit tricky, but we describe how to do it under "Connecting over SSH" in the [Getting Started](/welcome/welcome) module.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
privileged: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Bound the disposable pwnshop home without hiding a deployed persistent home.
5+
if [ "$(findmnt -n -o TARGET -T /home/hacker)" = "/" ]; then
6+
mount -t tmpfs -o size=64M,mode=0755,nosuid,nodev tmpfs /home/hacker
7+
chown hacker:hacker /home/hacker
8+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "../../../common/Dockerfile.j2" %}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/exec-suid -- /usr/bin/python3 -I
2+
3+
import errno
4+
import os
5+
import sys
6+
import tempfile
7+
8+
MARKER = "/run/disk_doomsday_phase1"
9+
TEST_SIZE = 1 * 1024 * 1024
10+
11+
12+
def try_create():
13+
fd = None
14+
path = None
15+
try:
16+
fd, path = tempfile.mkstemp(prefix=".space_test.", dir="/home/hacker")
17+
os.posix_fallocate(fd, 0, TEST_SIZE)
18+
except OSError as error:
19+
if error.errno in (errno.EDQUOT, errno.ENOSPC):
20+
return False
21+
print("Unexpected failure creating temporary file.")
22+
sys.exit(1)
23+
finally:
24+
if fd is not None:
25+
os.close(fd)
26+
if path is not None:
27+
try:
28+
os.remove(path)
29+
except FileNotFoundError:
30+
pass
31+
return True
32+
33+
34+
can_create = try_create()
35+
36+
if not os.path.exists(MARKER):
37+
if can_create:
38+
print(
39+
"Plenty of space remains. Fill up /home/hacker until a 1 MB file cannot be created "
40+
"and run this checker again."
41+
)
42+
else:
43+
open(MARKER, "w").close()
44+
print(
45+
"Well done, you clogged the disk. Now free that space (remove the file you created) "
46+
"and run /challenge/check again to prove you cleaned up!"
47+
)
48+
elif not can_create:
49+
print("Still no space left. Clean up more and try again!")
50+
else:
51+
print("Disk space restored. Here is your flag:")
52+
print(open("/flag").read().strip())
Binary file not shown.

challenges/linux-luminarium/destruction/module.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ resources:
77
- type: challenge
88
id: disk-doomsday
99
name: Disk-Space Doomsday
10+
- type: challenge
11+
id: disk-doomsday-test
12+
name: Disk-Space Doomsday (Test)
13+
required: false
14+
visibility:
15+
start: "2099-01-01T00:00:00+00:00"
1016
- type: challenge
1117
id: rm-rf-root
1218
name: rm -rf /

0 commit comments

Comments
 (0)