Don't like this style? Click here to change it! blue.css

LOGIN:
Welcome .... Click here to logout

Tales from the heap: main_arena, fastbins, debug flags

OK so the next part of our flow chart is the fastbins.

They act very similarly to the tcache bins with a few exceptions:

Here is the main arena in pictures:

My goals for the day:

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);

Heap Vulnerability Playground

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.

Traceback: glibc with debug symbols

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:

CONGRATS!! This is the best heap learning tool I can give you

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!

fastbins and the main_arena

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:

Aside: making a leak

Let's manufacture a glibc leak using the unsorted bins

fastbin-dup / double-free

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!