247CTF - The Flag Bootloader
Can you unlock the secret boot sequence hidden within our flag bootloader to recover the flag?
Analysis
1 | ❯ file flag.com |
This is a 512-byte boot sector image. The following xxd
excerpts show offsets 0x00..0x1f and
0x1f0..0x1ff only:
1 | 00000000: eb21 b800 10cd 16c3 60b4 0e8a 043c 0074 .!......`....<.t |
Final 16 bytes:
1 | 000001f0: 0000 0000 0000 0000 0000 0000 0000 55aa ..............U. |
The 55 aa signature at the end confirms it is a standard
boot sector.
Boot Sector Fundamentals
When a computer powers on and completes the Power-On Self-Test
(POST), the BIOS reads the first sector (512 bytes) of the disk into
physical memory between 0x7C00 and
0x7DFF. It then sets the CPU's Instruction Pointer
(IP) to 0x7C00 to begin execution.
Therefore, the base address of this program in
memory is 0x7C00. When performing static
analysis or debugging, any hardcoded physical addresses must have
0x7C00 subtracted to find their corresponding file
offset.
Static Analysis and Memory Mapping
Analyzing the assembly code reveals two critical memory locations:
1. Flag Ciphertext Area
(0x7DAA)
Calculate the file offset: \[0x7DAA -
0x7C00 = 0x01AA\] Looking at the hex dump at 0x01AA:
1
000001a0: 6420 636f 6465 210a 0d00 3234 3743 5446 d code!...247CTF
247CTF{ prefix.
2. Input Buffer (0x7DEC)
Calculate the file offset: \[0x7DEC -
0x7C00 = 0x01EC\] The region of null bytes before the
55 aa signature is used directly as a buffer for keyboard
input.
Core Logic Deconstruction
Focusing on sub_1016A in IDA (the primary decryption
logic):
1 | seg000:016B mov bx, 7DECh ; BX points to the input buffer |
Logic Summary: 1. The program requires a 16-character unlock code. 2. Each character is validated via arithmetic/logical operations (XOR, ADD, SUB). 3. Validated characters serve as XOR keys to decrypt the subsequent ciphertext region. 4. Each key character decrypts 2 bytes of ciphertext.
Solution Script
The script evaluates the retained validation constants and 32
ciphertext bytes. It reproduces their XOR result offline; without
flag.com, the complete instruction sequence and original
byte offsets cannot be rechecked.
1 | #!/usr/bin/env python3 |