Don't like this style? Click here to change it! blue.css
OK so the next part of our flow chart is the fastbins.
They act very similarly to the tcache bins with a few exceptions:
main_arena
Here is the main arena in pictures:
I'd like you to trigger errors using a debug version of glibc so you can learn how to see what security checks you trigger.
I'd like you to get as comfy with the main_arena as you were with tcache (at least for the fastbin part).
I'd like you create a fast_bin dup using a double free free(a); free(b); free(a);
OK so I made this for you in order to let you navigate the flow chart with ease.
This playground gives you way too much rope and you can see it suffers from Use After Free
,
but not heap smashing (the ability to overflow your intended area), well except by one single null byte (which is often enough).
We can use this template to try many different exploits with any number of distinct glibc copies.
So in my /glibcs directory with all of the various
glibcs there is a special folder called malloc
which has a single source file malloc.c
.
If, when you copy the library into your directory you also bring a copy of malloc.c
we can see what lines of malloc.c are causing problems for us.
OK here's my instructions for seeing the double-free protection in fastbins with your own eyes:
gcc heapvuln.c -o playground
glibc_2.27_no-tcache
(so we don't have to fill the tcache to see fastbins)ld.so.2
libc.so.6
and malloc.c
into the same directory as playground
patchelf --set-interpreter ./ld.so.2 --set-rpath . playground
gdb ./playground
run
f 4
context code
Being able to see and debug your exact error in the exact source code is the best way to discover the security checks you will trigger as you go about making exploits!
Now technically there can be more than one arena, hence the name main_arena
for the one that always exists.
The main_arena is the struct, just like the tcache struct. That lives inside of glibc and holds the heads of all of the bins/linked lists (it also holds other cool meta data)
So let's see it in action.
Start again with gdb ./playground
and make a small chunk then free it. Let's see it in two ways:
bins
and dq &main_arena 16
OK, now we can inspect the true main_arena and validate the way that the ascii struct diagram works:
Let's manufacture a glibc leak using the unsorted bins
telescope your_leak_here
to see what the offset into main_arena is.OK now finally get around the security check by doing a free(smallchunk) free(anothersmallchunk) free(smallchunk)
We will explore just how deadly this is next time.
fastbin dup works like this:
A = malloc(somefixedsize);
B = malloc(somefixedsize);
free(A);
free(B);
free(A);
C = malloc(somefixedsize)//will be A
fgets(C, 8, stdin)//send target to C
D = malloc(somefixedsize)//D will be B
E = malloc(somefixedsize)//will be A again
F = malloc(somefixedsize)//will be target!