The binary provides a menu that lets you enter a message. The small-message path contains a classic stack overflow in small_message(int) because it reads up to 0x100 bytes into a 0x18-byte stack buffer. A throw/catch path in big_message(int) returns cleanly to the menu and avoids stack-canary checks, enabling a controlled stack pivot and a final return-address overwrite to jump to win().
chall (ELF64, no PIE, Full RELRO, Canary, NX)libc.so.6, ld-linux-x86-64.so.2small_message(int) does read(0, buf, 0x100) and then puts(buf).puts leaks adjacent stack data.A’s are the saved rbp of enter_message.small_message would normally trip the stack canary on return.big_message and the top-level try/catch in main prints “Error occurred try again!” and then loops the menu. This path returns to the loop without rechecking the corrupted canary state, letting us continue with a modified stack frame.main uses scanf("%d", &choice) each loop. The return address for scanf is stored at [rbp - 0x1c] in the main frame.rbp to point into the small_message buffer, then scanf will write into our buffer, letting us overwrite its own return address.main.rbp = enter_message.rbp + 0x24.enter_message saved rbp
Enter message, size 24.A’s; read output until the menu prints again.As to get enter_message.rbp.small_message to pivot main.rbp
Enter message, size 1 (still uses small_message).small_message saved rbp and saved rip (avoid crashing).enter_message saved rbp with enter_message.rbp + 0x24.enter_message saved rip so execution returns to the loop.scanf return address with win()
win() address (0x401773).main.rbp is pivoted, scanf writes to [rbp - 0x1c] in our buffer, replacing its own return address.win(), which prints the flag from flag.txt.small_message buffer start: rbp - 0x30small_message saved rbp: +0x30small_message saved rip: +0x38enter_message saved rbp: +0x50enter_message saved rip: +0x58main.rbp = enter_message.rbp + 0x24See solve.py for a full working exploit that:
rbp via the exception path.scanf return address with win().0xL4ugh{ch0p_ch0p_fr33_th3_p41nful_sp1r1t_ch0p_11a6464501114e55}