Myspace2

a ret2win with canary bypass pwn challenge

given an ELF file.

we see here the ELF file has a stack canary. Then we run the program

then we decompile the program using ghidra

main:

this ELF has two vulnerabilities. one at edit_friend and another at display_friend.

now for the exploit part. first we leak canary by exploiting arbitrary read vuln at display_friend then we ret2win by exploiting buffer overflow vuln at edit_friend.

we then use gdb to see the memory offsets

this might seem confusing, but when we combine with ghidra decompile info, we know that main <+82> is where 'friends' array started and it is stored in rbp-0x70. We can also see where the canary is located, which is main <+21> and is stored in rbp-0x8.

Now we can calculate the offsets:

  • friends to canary:

    Offset = (Canary addr) - (Friends beginning addr)

    Offset = (rbp-0x8) - (rbp-0x70)

    Offset = -0x8 + 0x70 = 0x68 bytes (104 in decimal)

  • Canary leak:

    • Display_friend() function reads address from friends_addr + index * 8.

      Canary_addr = friends_addr + index * 8

      (friends_addr) + 0x68 = (friends_addr) + index * 8

      0x68 = index * 8

      index = 0x68/8 = 104/8 = 13

now after we got all the offsets we construct our exploit:

Flag: idek{b4bys_1st_c00k1e_leak_yayyy!}

Last updated