Search K
Appearance
Appearance
Other ways to support HackTricks:
Having just access to a 1B overflow allows an attacker to modify the pre_in_use
bit from the next chunk and as the current chunk won't be in use, the end of the chunk becomes the previous chunk size metadata information.
This allows to tamper which chunks are actually freed, potentially generating a chunk that contains another legit chunk.
There are 2 types of off by one vulnerabilities:
// From https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/off_by_one/
int main(void)
{
char buffer[40]="";
void *chunk1;
chunk1 = malloc(24);
puts("Get Input");
gets(buffer);
if(strlen(buffer)==24)
{
strcpy(chunk1,buffer);
}
return 0;
}
Among other checks, now whenever a chunk is free the previous size is compared with the size configured in the metadata's chunk, making this attack fairly complex from version 2.28.
malloc(): invalid next size (unsorted)
b + b->size
never updates the c chunk because the pointed address is smaller than it should. c - c->prev_size
still points to b (b1 now), both are consolidated in one chunk. However, b2 is still inside in between b1 and c.This image explains perfectly the attack:
getline
function that reads user input lines. This function is used to read the "key" of the content and not the content.[ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ]
0x4e0
. 0x4e0
: hex(0x1f8 + 0x10 + 0x68 + 0x10 + 0x50 + 0x10 + 0x200) = 0x4e0
[ 0x4e0 Chunk 1-2-5-3 (free) ] [ 0xf0 Chunk 4 (corrupted) ] [ 0x400 Chunk defense ]
[ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ]
0x200
bytes are allocated filling the original chunk 1 fd
of the fast bin chunk of chunk5 pointing it to __malloc_hook
__malloc_hook
is the following fast bin chunk__malloc_hook
is overwritten with a one_gadget
addressOther ways to support HackTricks: