From b3cba936417b1bbf24960b8f0c37e2377af7733e Mon Sep 17 00:00:00 2001 From: Connor Nelson Date: Mon, 6 Jan 2025 14:19:56 -0700 Subject: [PATCH] Update challenges for simple challenge image --- hello/apple/apple | 2 +- hello/banana/banana | 2 +- world/earth/.init | 2 +- world/earth/earth | 2 +- world/mars/orbit | 2 +- world/venus/.init | 11 +++++------ world/venus/README.md | 6 +++--- world/venus/launch.j2 | 8 -------- world/venus/launch.template | 8 ++++++++ 9 files changed, 21 insertions(+), 22 deletions(-) delete mode 100644 world/venus/launch.j2 create mode 100644 world/venus/launch.template diff --git a/hello/apple/apple b/hello/apple/apple index 3410e30..46e3818 100644 --- a/hello/apple/apple +++ b/hello/apple/apple @@ -1,4 +1,4 @@ -#!/opt/pwn.college/python +#!/usr/bin/exec-suid -- /usr/local/bin/python -I with open("/flag") as f: print(f.read()) diff --git a/hello/banana/banana b/hello/banana/banana index 6dc0f6b..adf8483 100644 --- a/hello/banana/banana +++ b/hello/banana/banana @@ -1,4 +1,4 @@ -#!/opt/pwn.college/python +#!/usr/bin/exec-suid -- /usr/local/bin/python -I import pathlib diff --git a/world/earth/.init b/world/earth/.init index 693e3ab..c8e0b8c 100644 --- a/world/earth/.init +++ b/world/earth/.init @@ -1,4 +1,4 @@ -#!/opt/pwn.college/python +#!/usr/local/bin/python import pathlib diff --git a/world/earth/earth b/world/earth/earth index 3410e30..46e3818 100644 --- a/world/earth/earth +++ b/world/earth/earth @@ -1,4 +1,4 @@ -#!/opt/pwn.college/python +#!/usr/bin/exec-suid -- /usr/local/bin/python -I with open("/flag") as f: print(f.read()) diff --git a/world/mars/orbit b/world/mars/orbit index b70344a..b8efdb5 100644 --- a/world/mars/orbit +++ b/world/mars/orbit @@ -1,4 +1,4 @@ -#!/opt/pwn.college/python +#!/usr/bin/exec-suid -- /usr/local/bin/python -I import pathlib import random diff --git a/world/venus/.init b/world/venus/.init index 5d8d1b0..3865bec 100644 --- a/world/venus/.init +++ b/world/venus/.init @@ -1,9 +1,8 @@ -#!/opt/pwn.college/python +#!/usr/local/bin/python import pathlib import random - -import jinja2 +import string with open("/flag") as f: random.seed(f.read()) @@ -11,12 +10,12 @@ with open("/flag") as f: init_path = pathlib.Path(__file__) planets_path = (pathlib.Path(__file__).parent / "planets.txt") launch_path = (pathlib.Path(__file__).parent / "launch") -launch_template_path = (pathlib.Path(__file__).parent / "launch.j2") +launch_template_path = (pathlib.Path(__file__).parent / "launch.template") planet = random.choice(planets_path.read_text().strip().splitlines()) -template = jinja2.Template(launch_template_path) -launch_path.write_text(template.render(planet=planet)) +template = string.Template(launch_template_path.read_text()) +launch_path.write_text(template.safe_substitute(planet=planet)) launch_template_path.unlink() planets_path.unlink() diff --git a/world/venus/README.md b/world/venus/README.md index 159de01..b107a0a 100644 --- a/world/venus/README.md +++ b/world/venus/README.md @@ -9,9 +9,9 @@ When users start this challenge, their environment will have: - `/challenge/launch` In this challenge, `takeoff` is a statically instanced file. -There is also files `.init`, `planets.txt`, and `launch.j2` which students will never see. -At run time, `.init` reads in `planets.txt` to construct `launch` from the templated file `launch.j2`. +There is also files `.init`, `planets.txt`, and `launch.template` which students will never see. +At run time, `.init` reads in `planets.txt` to construct `launch` from the templated file `launch.template`. This gives the challenge static instancing dependent upon the flag. In general, it is best to define a pool of static instanced files prior, so that this setup does not need to be performed at runtime every challenge start. However, for simple cases, this may be acceptable. -It is important to note, however, that the results of these static instances are still dependent upon the flag, which means running the challenge with a different flag (e.g. with a practice flag), will fundamentally change the instance. +It is important to note, however, that the results of these static instances are still dependent upon the flag, which means running the challenge with a different flag (e.g. with a practice flag), will change the behavior of the instance. diff --git a/world/venus/launch.j2 b/world/venus/launch.j2 deleted file mode 100644 index be95e5d..0000000 --- a/world/venus/launch.j2 +++ /dev/null @@ -1,8 +0,0 @@ -#!/opt/pwn.college/python - -import subprocess - -subprocess.run(["/challenge/takeoff", "{{ planet }}"]) - -with open("/flag") as f: - print(f.read()) diff --git a/world/venus/launch.template b/world/venus/launch.template new file mode 100644 index 0000000..30a1f5c --- /dev/null +++ b/world/venus/launch.template @@ -0,0 +1,8 @@ +#!/usr/bin/exec-suid -- /usr/local/bin/python -I + +import subprocess + +subprocess.run(["/challenge/takeoff", "${planet}"]) + +with open("/flag") as f: + print(f.read())