AfterLife
Problem
Just pwn this program and get a flag. It's also found in /problems/afterlife_2_049150f2f8b03c16dc0382de6e2e2215 on the shell server. Source.
Solution
This problem is nearly identical to the "SecondLife" challenge. I recommend reading that write-up first since it covers the concepts needed to understand the following steps. Compared to "SecondLife," instead of freeing the first chunk twice, this program simply writes to the first chunk on lines 32 and 33 after it has been freed on line 29. This is known as a use-after-free exploit. The setup is exactly the same as the double-free exploit. The call to
malloc()
on line 34 replaces the GOT address ofexit()
with the address of the shellcode, and the call toexit()
on line 35 invokes the shellcode.Use-after-free vulnerability:
We can use the same payload code as before:
We add 8 bytes to address (which is the base address of the
first
buffer) since that's where we located our shellcode, right afterp32(exe.got["exit"] - 12) + p32(address + 8)
.Note: Line 25 in this challenge is different than in "SecondLife".
fgets(first, LINE_BUFFER_SIZE, stdin);
was changed tostrncpy(first,argv[1],LINE_BUFFER_SIZE);
. So we need to specify and argument to the process when we launch it from the command line to get past line 25. Previously we just sent a single enter sincefgets
was used instead ofstrncpy
.Run the script.py
python script.py USER=<username> PASSWORD=<password>
:
Flag
picoCTF{what5_Aft3r_187f3d9a}
Last updated