Donut
Description
nc pwn.ctf.uscybergames.com 5000
Solution
Decompile with your favorite decompiler or https://dogbolt.org/?id=9d3b3f31-5de2-40ee-a205-727743976140#Hex-Rays=280

Copy Hex-Rays code and ask ChatGPT to kindly rewrite the code into what programmer would normally write:
Our target is admin_maintenance function, because it contains system call which is controlled by the very first input in program; This leads to RCE so nom nom nom.
However it's not easy to reach the function, donuts count must be equal to ADMIN_MAGIC (-889275714) and we can't buy negative donuts. Ideally somewhere there should be integer overflow, or overwrite the address with gets.
The exploit is pretty easy, we just have to overwrite the variable on stack to get into the admin panel and inject RCE.
The variables timezone, money, and donuts are declared in global scope, and are laid out in memory consecutively (as is often the case in simple ELF binaries).
So if timezone is 32 bytes long, to overwrite donuts you need to overflow past timezone and money:
timezone: 32 bytesmoney: 4 bytes (standardint)
So to reach donuts, you must overflow:
Script:
Flag: SVBGR{my_fav0rIte_fl4vor_1s_Or3o_54ac91c0}
Last updated