malloc()
returns chunks (blocks of memory)
mixing metadata (control) & user data?
a bunch of other metadata
free()
after a chunk is
free()
’d, information about it is stored in a ‘bin’
used to store information about small chunks
chunks are stored in size-specific bins
a fast-bin is a singly-linked list
malloc()
thread-local cache each bin can only store 7 chunks
we’re attacking heap implementation, not bad programming. So you’ll need to use the right version
free()
detected.docker run -d --rm -h banana --name banana -v .:/ctf/work --cap-add=SYS_PTRACE skysider/pwndocker
docker exec -it banana /bin/bash
free()
workfree()
’dnothing, we can still use the pointer
it gets replaced with that metadata
if we modified the metadata (e.g. the next chunk ptr), then malloc(…) would return memory we tell it to.
free(chunk) // bin: chunk -> NULL
*chunk = "AAAA" // bin: chunk -> 0x41414141 -> ????
malloc(...) // bin: 0x41414141 -> ????
malloc(...) // bin: ????
// the second call to malloc returns 0x41414141
free()
’d a chunk twice?doesn’t really work this easily anymore, but can still be used sometimes
free(chunk) // bin: chunk -> NULL
free(chunk) // bin: chunk -> chunk -> NULL
malloc(...) // bin: chunk -> NULL
malloc(...) // bin: NULL
both calls to malloc()
return the same chunk?
there’s basic protections against double free()
s, and it’ll SIGABORT
when detected
but what if you just…
free(chunk_1)
free(chunk_2)
free(chunk_1)
vis_heap_chunks
bins
heap
arena