Search K
Appearance
Appearance
Other ways to support HackTricks:
malloc(): corrupted top size
If an attacker wants to allocate a chunk in the address P to overwrite a value here, he can start by overwriting the top chunk size with -1
. This ensures that malloc won't be using mmap for any allocation as the Top chunk will always have enough space.
Then, calculate the distance between the address of the top chunk and the target space to allocate. This is because a malloc with that size will be performed in order to move the top chunk to that position. This is how the difference/size can be easily calculated:
// From https://github.com/shellphish/how2heap/blob/master/glibc_2.27/house_of_force.c#L59C2-L67C5
/*
* The evil_size is calulcated as (nb is the number of bytes requested + space for metadata):
* new_top = old_top + nb
* nb = new_top - old_top
* req + 2sizeof(long) = new_top - old_top
* req = new_top - old_top - 2sizeof(long)
* req = target - 2sizeof(long) - old_top - 2sizeof(long)
* req = target - old_top - 4*sizeof(long)
*/
Therefore, allocing a size of target - old_top - 4*sizeof(long)
(the 4 longs are because of the metadata of the top chunk and of the new chunk when alloced) will move the top chunk to the address we want to overwrite.
Then, do another malloc to get a chunk containing the at the beginning of the data to write the target address.
malloc
Input your name:
there is an initial vulnerability that allows to leak an address from the heapOrg:
and Host:
functionality its possible to fill the 64B of the s
pointer when asked for the org name, which in the stack is followed by the address of v2, which is then followed by the indicated host name. As then, strcpy is going to be copying the contents of s to a chunk of size 64B, it's possible to overwrite the size of the top chunk with the data put inside the host name.atoi
's GOT was overwritten to the address of printf. the it as possible to leak the address of IO_2_1_stderr
with %24$p
. And with this libc leak it was possible to overwrite atoi
's GOT again with the address to system
and call it passing as param /bin/sh
free
with puts
, and then add the address of atoi@got
, in the pointer that will be later freed so it's leaked and with this leak overwrite again atoi@got
with system
and call it with /bin/sh
.Other ways to support HackTricks: