Libc Heap

Tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporte o HackTricks

Conceitos Básicos do Heap

O heap é basicamente o local onde um programa pode armazenar dados quando os solicita chamando funções como malloc, calloc… Além disso, quando essa memória não é mais necessária ela fica disponível ao chamar a função free.

Como mostrado, ele fica logo após onde o binário é carregado na memória (veja a seção [heap]):

Alocação Básica de Chunk

Quando alguns dados são solicitados para serem armazenados no heap, algum espaço do heap é alocado para eles. Esse espaço pertencerá a um bin e somente os dados solicitados + o espaço dos headers do bin + o deslocamento de tamanho mínimo do bin serão reservados para o chunk. O objetivo é reservar o mínimo de memória possível sem tornar complicado localizar cada chunk. Para isso, as informações de metadados do chunk são usadas para saber onde cada chunk usado/livre está.

Existem diferentes formas de reservar o espaço dependendo principalmente do bin usado, mas uma metodologia geral é a seguinte:

  • O programa começa solicitando uma certa quantidade de memória.
  • Se na lista de chunks houver algum disponível grande o suficiente para satisfazer a solicitação, ele será usado.
  • Isso pode até significar que parte do chunk disponível será usada para essa solicitação e o restante será adicionado à lista de chunks.
  • Se não houver nenhum chunk disponível na lista, mas ainda houver espaço na memória do heap já alocada, o gerenciador de heap cria um novo chunk.
  • Se não houver espaço suficiente no heap para alocar o novo chunk, o gerenciador do heap pede ao kernel para expandir a memória alocada ao heap e então usa essa memória para gerar o novo chunk.
  • Se tudo falhar, malloc retorna null.

Note que se a memória solicitada ultrapassar um limiar, mmap será usado para mapear a memória solicitada.

Arenas

Em aplicações multithread, o gerenciador de heap deve prevenir condições de corrida que poderiam levar a crashes. Inicialmente, isso era feito usando um mutex global para garantir que apenas uma thread pudesse acessar o heap por vez, mas isso causava problemas de performance devido ao gargalo induzido pelo mutex.

Para resolver isso, o alocador ptmalloc2 introduziu “arenas”, onde cada arena atua como um heap separado com suas próprias estruturas de dados e mutex, permitindo que múltiplas threads realizem operações de heap sem interferir umas nas outras, desde que usem arenas diferentes.

A arena “main” padrão lida com operações de heap para aplicações single-thread. Quando novas threads são adicionadas, o gerenciador de heap as atribui a arenas secundárias para reduzir contenção. Ele tenta primeiramente anexar cada nova thread a uma arena não utilizada, criando novas se necessário, até um limite de 2 vezes o número de núcleos de CPU para sistemas 32-bit e 8 vezes para sistemas 64-bit. Uma vez atingido o limite, as threads devem compartilhar arenas, levando a possível contenção.

Ao contrário da main arena, que expande usando a chamada de sistema brk, arenas secundárias criam “subheaps” usando mmap e mprotect para simular o comportamento do heap, permitindo flexibilidade no gerenciamento de memória para operações multithread.

Subheaps

Subheaps servem como reservas de memória para arenas secundárias em aplicações multithread, permitindo que elas cresçam e gerenciem suas próprias regiões de heap separadamente do heap inicial. Aqui está como os subheaps diferem do heap inicial e como eles operam:

  1. Inicial Heap vs. Subheaps:
  • O heap inicial está localizado diretamente após o binário do programa na memória, e ele se expande usando a chamada de sistema sbrk.
  • Subheaps, usados por arenas secundárias, são criados através de mmap, uma chamada de sistema que mapeia uma região de memória especificada.
  1. Reserva de Memória com mmap:
  • Quando o gerenciador de heap cria um subheap, ele reserva um grande bloco de memória através de mmap. Essa reserva não aloca memória imediatamente; ela simplesmente designa uma região que outros processos do sistema ou alocações não devem usar.
  • Por padrão, o tamanho reservado para um subheap é de 1 MB para processos 32-bit e 64 MB para processos 64-bit.
  1. Expansão Gradual com mprotect:
  • A região de memória reservada é inicialmente marcada como PROT_NONE, indicando que o kernel não precisa alocar memória física para esse espaço ainda.
  • Para “crescer” o subheap, o gerenciador de heap usa mprotect para mudar as permissões de página de PROT_NONE para PROT_READ | PROT_WRITE, forçando o kernel a alocar memória física para os endereços previamente reservados. Essa abordagem passo a passo permite que o subheap expanda conforme necessário.
  • Uma vez que todo o subheap esteja esgotado, o gerenciador de heap cria um novo subheap para continuar a alocação.

heap_info

Esta struct aloca informações relevantes do heap. Além disso, a memória do heap pode não ser contínua após mais alocações; essa struct também armazenará essa informação.

// From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/arena.c#L837

typedef struct _heap_info
{
mstate ar_ptr; /* Arena for this heap. */
struct _heap_info *prev; /* Previous heap. */
size_t size;   /* Current size in bytes. */
size_t mprotect_size; /* Size in bytes that has been mprotected
PROT_READ|PROT_WRITE.  */
size_t pagesize; /* Page size used when allocating the arena.  */
/* Make sure the following data is properly aligned, particularly
that sizeof (heap_info) + 2 * SIZE_SZ is a multiple of
MALLOC_ALIGNMENT. */
char pad[-3 * SIZE_SZ & MALLOC_ALIGN_MASK];
} heap_info;

malloc_state

Each heap (main arena or other threads arenas) has a malloc_state structure.
É importante notar que a estrutura malloc_state da main arena é uma variável global na libc (portanto localizada no espaço de memória da libc).
No caso das estruturas malloc_state dos heaps de threads, elas estão localizadas dentro do próprio heap da thread.

Há algumas coisas interessantes a notar sobre esta estrutura (veja o código C abaixo):

  • __libc_lock_define (, mutex); Está aí para garantir que esta estrutura do heap seja acessada por 1 thread por vez

  • Flags:

#define NONCONTIGUOUS_BIT (2U)

#define contiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) == 0) #define noncontiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) != 0) #define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT) #define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT)


- The `mchunkptr bins[NBINS * 2 - 2];` contém ponteiros para o primeiro e o último chunk dos bins small, large e unsorted (o -2 é porque o índice 0 não é usado)
- Portanto, o primeiro chunk desses bins terá um ponteiro para trás para esta estrutura e o último chunk desses bins terá um ponteiro para frente para esta estrutura. O que basicamente significa que se você puder l**eak these addresses in the main arena** você terá um ponteiro para a estrutura na **libc**.
- As structs `struct malloc_state *next;` e `struct malloc_state *next_free;` são listas ligadas de arenas
- O chunk `top` é o último "chunk", que basicamente representa todo o espaço restante do heap. Uma vez que o top chunk esteja "vazio", o heap está completamente usado e precisa requisitar mais espaço.
- O chunk `last reminder` surge em casos onde um chunk de tamanho exato não está disponível e, portanto, um chunk maior é dividido; a parte restante é colocada aqui.
```c
// From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1812

struct malloc_state
{
/* Serialize access.  */
__libc_lock_define (, mutex);

/* Flags (formerly in max_fast).  */
int flags;

/* Set if the fastbin chunks contain recently inserted free blocks.  */
/* Note this is a bool but not all targets support atomics on booleans.  */
int have_fastchunks;

/* Fastbins */
mfastbinptr fastbinsY[NFASTBINS];

/* Base of the topmost chunk -- not otherwise kept in a bin */
mchunkptr top;

/* The remainder from the most recent split of a small request */
mchunkptr last_remainder;

/* Normal bins packed as described above */
mchunkptr bins[NBINS * 2 - 2];

/* Bitmap of bins */
unsigned int binmap[BINMAPSIZE];

/* Linked list */
struct malloc_state *next;

/* Linked list for free arenas.  Access to this field is serialized
by free_list_lock in arena.c.  */
struct malloc_state *next_free;

/* Number of threads attached to this arena.  0 if the arena is on
the free list.  Access to this field is serialized by
free_list_lock in arena.c.  */
INTERNAL_SIZE_T attached_threads;

/* Memory allocated from the system in this arena.  */
INTERNAL_SIZE_T system_mem;
INTERNAL_SIZE_T max_system_mem;
};

malloc_chunk

Esta estrutura representa um chunk específico de memória. Os vários campos têm significados diferentes para chunks alocados e não alocados.

// https://github.com/bminor/glibc/blob/master/malloc/malloc.c
struct malloc_chunk {
INTERNAL_SIZE_T      mchunk_prev_size;  /* Size of previous chunk, if it is free. */
INTERNAL_SIZE_T      mchunk_size;       /* Size in bytes, including overhead. */
struct malloc_chunk* fd;                /* double links -- used only if this chunk is free. */
struct malloc_chunk* bk;
/* Only used for large blocks: pointer to next larger size.  */
struct malloc_chunk* fd_nextsize; /* double links -- used only if this chunk is free. */
struct malloc_chunk* bk_nextsize;
};

typedef struct malloc_chunk* mchunkptr;

Como comentado anteriormente, esses chunks também possuem alguns metadados, muito bem representados nesta imagem:

https://azeria-labs.com/wp-content/uploads/2019/03/chunk-allocated-CS.png

Os metadados são tipicamente 0x08B indicando o tamanho atual do chunk, usando os últimos 3 bits para indicar:

  • A: Se 1, vem de um subheap; se 0, está na main arena
  • M: Se 1, este chunk faz parte de um espaço alocado com mmap e não faz parte de um heap
  • P: Se 1, o chunk anterior está em uso

Em seguida, o espaço para os dados do usuário, e finalmente 0x08B para indicar o tamanho do chunk anterior quando o chunk está disponível (ou para armazenar dados do usuário quando está alocado).

Além disso, quando disponível, os dados do usuário também são usados para conter alguns campos:

  • fd: Ponteiro para o próximo chunk
  • bk: Ponteiro para o chunk anterior
  • fd_nextsize: Ponteiro para o primeiro chunk na lista que é menor que ele
  • bk_nextsize: Ponteiro para o primeiro chunk na lista que é maior que ele

https://azeria-labs.com/wp-content/uploads/2019/03/chunk-allocated-CS.png

Tip

Observe como encadear a lista dessa forma evita a necessidade de ter um array onde cada chunk é registrado.

Chunk Pointers

When malloc is used a pointer to the content that can be written is returned (just after the headers), however, when managing chunks, it’s needed a pointer to the begining of the headers (metadata).
For these conversions these functions are used:

// https://github.com/bminor/glibc/blob/master/malloc/malloc.c

/* Convert a chunk address to a user mem pointer without correcting the tag.  */
#define chunk2mem(p) ((void*)((char*)(p) + CHUNK_HDR_SZ))

/* Convert a user mem pointer to a chunk address and extract the right tag.  */
#define mem2chunk(mem) ((mchunkptr)tag_at (((char*)(mem) - CHUNK_HDR_SZ)))

/* The smallest possible chunk */
#define MIN_CHUNK_SIZE        (offsetof(struct malloc_chunk, fd_nextsize))

/* The smallest size we can malloc is an aligned minimal chunk */

#define MINSIZE  \
(unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK))

Alinhamento & tamanho mínimo

O ponteiro para o chunk e 0x0f devem ser 0.

// From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/sysdeps/generic/malloc-size.h#L61
#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)

// https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/sysdeps/i386/malloc-alignment.h
#define MALLOC_ALIGNMENT 16


// https://github.com/bminor/glibc/blob/master/malloc/malloc.c
/* Check if m has acceptable alignment */
#define aligned_OK(m)  (((unsigned long)(m) & MALLOC_ALIGN_MASK) == 0)

#define misaligned_chunk(p) \
((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2mem (p)) \
& MALLOC_ALIGN_MASK)


/* pad request bytes into a usable size -- internal version */
/* Note: This must be a macro that evaluates to a compile time constant
if passed a literal constant.  */
#define request2size(req)                                         \
(((req) + SIZE_SZ + MALLOC_ALIGN_MASK < MINSIZE)  ?             \
MINSIZE :                                                      \
((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)

/* Check if REQ overflows when padded and aligned and if the resulting
value is less than PTRDIFF_T.  Returns the requested size or
MINSIZE in case the value is less than MINSIZE, or 0 if any of the
previous checks fail.  */
static inline size_t
checked_request2size (size_t req) __nonnull (1)
{
if (__glibc_unlikely (req > PTRDIFF_MAX))
return 0;

/* When using tagged memory, we cannot share the end of the user
block with the header for the next chunk, so ensure that we
allocate blocks that are rounded up to the granule size.  Take
care not to overflow from close to MAX_SIZE_T to a small
number.  Ideally, this would be part of request2size(), but that
must be a macro that produces a compile time constant if passed
a constant literal.  */
if (__glibc_unlikely (mtag_enabled))
{
/* Ensure this is not evaluated if !mtag_enabled, see gcc PR 99551.  */
asm ("");

req = (req + (__MTAG_GRANULE_SIZE - 1)) &
~(size_t)(__MTAG_GRANULE_SIZE - 1);
}

return request2size (req);
}

Observe que, ao calcular o espaço total necessário, SIZE_SZ é adicionado apenas 1 vez porque o campo prev_size pode ser usado para armazenar dados; portanto, apenas o cabeçalho inicial é necessário.

Obter dados do Chunk e alterar metadados

Essas funções recebem um ponteiro para um chunk e são úteis para verificar/definir metadados:

  • Verificar flags do chunk
// From https://github.com/bminor/glibc/blob/master/malloc/malloc.c


/* size field is or'ed with PREV_INUSE when previous adjacent chunk in use */
#define PREV_INUSE 0x1

/* extract inuse bit of previous chunk */
#define prev_inuse(p)       ((p)->mchunk_size & PREV_INUSE)


/* size field is or'ed with IS_MMAPPED if the chunk was obtained with mmap() */
#define IS_MMAPPED 0x2

/* check for mmap()'ed chunk */
#define chunk_is_mmapped(p) ((p)->mchunk_size & IS_MMAPPED)


/* size field is or'ed with NON_MAIN_ARENA if the chunk was obtained
from a non-main arena.  This is only set immediately before handing
the chunk to the user, if necessary.  */
#define NON_MAIN_ARENA 0x4

/* Check for chunk from main arena.  */
#define chunk_main_arena(p) (((p)->mchunk_size & NON_MAIN_ARENA) == 0)

/* Mark a chunk as not being on the main arena.  */
#define set_non_main_arena(p) ((p)->mchunk_size |= NON_MAIN_ARENA)
  • Tamanhos e ponteiros para outros chunks
/*
Bits to mask off when extracting size

Note: IS_MMAPPED is intentionally not masked off from size field in
macros for which mmapped chunks should never be seen. This should
cause helpful core dumps to occur if it is tried by accident by
people extending or adapting this malloc.
*/
#define SIZE_BITS (PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA)

/* Get size, ignoring use bits */
#define chunksize(p) (chunksize_nomask (p) & ~(SIZE_BITS))

/* Like chunksize, but do not mask SIZE_BITS.  */
#define chunksize_nomask(p)         ((p)->mchunk_size)

/* Ptr to next physical malloc_chunk. */
#define next_chunk(p) ((mchunkptr) (((char *) (p)) + chunksize (p)))

/* Size of the chunk below P.  Only valid if !prev_inuse (P).  */
#define prev_size(p) ((p)->mchunk_prev_size)

/* Set the size of the chunk below P.  Only valid if !prev_inuse (P).  */
#define set_prev_size(p, sz) ((p)->mchunk_prev_size = (sz))

/* Ptr to previous physical malloc_chunk.  Only valid if !prev_inuse (P).  */
#define prev_chunk(p) ((mchunkptr) (((char *) (p)) - prev_size (p)))

/* Treat space at ptr + offset as a chunk */
#define chunk_at_offset(p, s)  ((mchunkptr) (((char *) (p)) + (s)))
  • bit resultante
/* extract p's inuse bit */
#define inuse(p)							      \
((((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size) & PREV_INUSE)

/* set/clear chunk as being inuse without otherwise disturbing */
#define set_inuse(p)							      \
((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size |= PREV_INUSE

#define clear_inuse(p)							      \
((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size &= ~(PREV_INUSE)


/* check/set/clear inuse bits in known places */
#define inuse_bit_at_offset(p, s)					      \
(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size & PREV_INUSE)

#define set_inuse_bit_at_offset(p, s)					      \
(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size |= PREV_INUSE)

#define clear_inuse_bit_at_offset(p, s)					      \
(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size &= ~(PREV_INUSE))
  • Definir head e footer (quando chunk nos estiverem em uso)
/* Set size at head, without disturbing its use bit */
#define set_head_size(p, s)  ((p)->mchunk_size = (((p)->mchunk_size & SIZE_BITS) | (s)))

/* Set size/use field */
#define set_head(p, s)       ((p)->mchunk_size = (s))

/* Set size at footer (only when chunk is not in use) */
#define set_foot(p, s)       (((mchunkptr) ((char *) (p) + (s)))->mchunk_prev_size = (s))
  • Obter o tamanho dos dados realmente utilizáveis dentro do chunk
#pragma GCC poison mchunk_size
#pragma GCC poison mchunk_prev_size

/* This is the size of the real usable data in the chunk.  Not valid for
dumped heap chunks.  */
#define memsize(p)                                                    \
(__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \
chunksize (p) - CHUNK_HDR_SZ :                                    \
chunksize (p) - CHUNK_HDR_SZ + (chunk_is_mmapped (p) ? 0 : SIZE_SZ))

/* If memory tagging is enabled the layout changes to accommodate the granule
size, this is wasteful for small allocations so not done by default.
Both the chunk header and user data has to be granule aligned.  */
_Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ,
"memory tagging is not supported with large granule.");

static __always_inline void *
tag_new_usable (void *ptr)
{
if (__glibc_unlikely (mtag_enabled) && ptr)
{
mchunkptr cp = mem2chunk(ptr);
ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), memsize (cp));
}
return ptr;
}

Exemplos

Exemplo Rápido de Heap

Exemplo rápido de heap de https://guyinatuxedo.github.io/25-heap/index.html mas em arm64:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(void)
{
char *ptr;
ptr = malloc(0x10);
strcpy(ptr, "panda");
}

Coloque um breakpoint no final da função main e vamos descobrir onde a informação foi armazenada:

É possível ver que a string panda foi armazenada em 0xaaaaaaac12a0 (que foi o endereço retornado por malloc dentro de x0). Verificando 0x10 bytes antes, é possível ver que o 0x0 representa que o chunk anterior não está em uso (comprimento 0) e que o tamanho deste chunk é 0x21.

Os espaços extras reservados (0x21-0x10=0x11) vêm dos cabeçalhos adicionados (0x10) e 0x1 não significa que foi reservado 0x21B, mas sim que os últimos 3 bits do comprimento do cabeçalho atual têm alguns significados especiais. Como o comprimento é sempre alinhado a 16 bytes (em máquinas 64 bits), esses bits na prática nunca são usados pelo valor do comprimento.

0x1:     Previous in Use     - Specifies that the chunk before it in memory is in use
0x2:     Is MMAPPED          - Specifies that the chunk was obtained with mmap()
0x4:     Non Main Arena      - Specifies that the chunk was obtained from outside of the main arena

Exemplo de Multithreading

Multithread ```c #include #include #include #include #include

void* threadFuncMalloc(void* arg) { printf(“Hello from thread 1\n”); char* addr = (char*) malloc(1000); printf(“After malloc and before free in thread 1\n”); free(addr); printf(“After free in thread 1\n”); }

void* threadFuncNoMalloc(void* arg) { printf(“Hello from thread 2\n”); }

int main() { pthread_t t1; void* s; int ret; char* addr;

printf(“Before creating thread 1\n”); getchar(); ret = pthread_create(&t1, NULL, threadFuncMalloc, NULL); getchar();

printf(“Before creating thread 2\n”); ret = pthread_create(&t1, NULL, threadFuncNoMalloc, NULL);

printf(“Before exit\n”); getchar();

return 0; }

</details>

Depurando o exemplo anterior, é possível ver como, no início, existe apenas 1 arena:

<figure><img src="../../images/image (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

Then, after calling the first thread, the one that calls malloc, a new arena is created:

<figure><img src="../../images/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

e dentro dela alguns chunks podem ser encontrados:

<figure><img src="../../images/image (2) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

## Bins & Memory Allocations/Frees

Verifique quais são os bins, como eles estão organizados e como a memória é alocada e liberada em:


<a class="content_ref" href="bins-and-memory-allocations.md"><span class="content_ref_label">Bins & Memory Allocations</span></a>

## Heap Functions Security Checks

Funções relacionadas ao heap realizam certas verificações antes de executar suas ações, tentando garantir que o heap não foi corrompido:


<a class="content_ref" href="heap-memory-functions/heap-functions-security-checks.md"><span class="content_ref_label">Heap Functions Security Checks</span></a>

## musl mallocng exploitation notes (Alpine)

- **Slab group/slot grooming for huge linear copies:** mallocng sizeclasses use mmap()'d groups whose slots are fully `munmap()`'d when empty. Para cópias lineares longas (~0x15555555 bytes), mantenha o span mapeado (evite buracos de grupos liberados) e posicione a alocação vítima adjacente ao slot de origem.
- **Cycling offset mitigation:** On slot reuse mallocng may advance the user-data start by `UNIT` (0x10) multiples when slack fits an extra 4-byte header. Isso desloca os deslocamentos de sobrescrita (por exemplo, acertos de ponteiro LSB) a menos que você controle as contagens de reutilização ou mantenha passos sem slack (por exemplo, objetos Lua `Table` em stride 0x50 mostram offset 0). Inspecione os deslocamentos com muslheap’s `mchunkinfo`:
```gdb
pwndbg> mchunkinfo 0x7ffff7a94e40
... stride: 0x140
... cycling offset : 0x1 (userdata --> 0x7ffff7a94e40)
  • Prefira corrupção de objetos em tempo de execução em vez de metadata do allocator: mallocng mixes cookies/guarded out-of-band metadata, so target higher-level objects. In Redis’s Lua 5.1, Table->array points to an array of TValue tagged values; overwriting the LSB of a pointer in TValue->value (e.g., with the JSON terminator byte 0x22) can pivot references without touching malloc metadata.
  • Depuração de Lua stripped/static no Alpine: Compile uma Lua compatível, liste símbolos com readelf -Ws, remova símbolos de função via objcopy --strip-symbol para expor layouts de struct no GDB, então use pretty-printers com suporte a Lua (GdbLuaExtension para Lua 5.1) além do muslheap para verificar os valores de stride/reserved/cycling-offset antes de acionar o overflow.

Estudos de Caso

Estude primitivos específicos do allocator derivados de bugs do mundo real:

Virtualbox Slirp Nat Packet Heap Exploitation

Gnu Obstack Function Pointer Hijack

Referências

Tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporte o HackTricks