DeepSpace

Binary Exploitation/Pwn

Given a zip file that contains an ELF file and its libc and ldd. Then we proceed to decompile the ELF file and got:

main:

int __fastcall main(int argc, const char **argv, const char **envp)
{
  init();
  start_challenge();
}

start_challenge:

in short:

  • There are two RW (Read/Write) mmap allocations:

    • v3 = mmap(...,0x1375, PROT_READ|PROT_WRITE, ...): eventually populated with the flag (Menu 2).

    • buf = mmap(..., 0x169, PROT_READ|PROT_WRITE, ...): the I/O buffer (Menu 1 & 3).

    • (Both are rounded up to the page size: v3 ≈ 0x2000, buf ≈ 0x1000.)

  • Menu 5 prints the addresses of v3 and buf (providing an ASLR leak).

  • Menu 2 reads ./flag into v3 (0x64 bytes).

  • Menu 3 executes write(1, buf, nbytes) WITHOUT limits -> this allows an OOB (Out-Of-Bounds) read starting from buf and continuing to higher addresses.

Linux typically places anonymous mmaps "downwards" (meaning the first mapping is at a higher address). Since v3 is allocated first, address(v3) > address(buf), and they are usually located on adjacent pages. Therefore, if we request nbytes = (v3 - buf) + 0x64, the "Full Diagnostic Log" output will read past buf, cross the page boundary into v3, and capture the 0x64 bytes of the flag.

solver.py:

if we run it, we get the flag:

Flag: SCH25{Kur4ng_T4hU_Ju9A_Y4H_muNgKiN_SuaTu_s4At_b4KaL_When_Yh}

Last updated