Heap 디버깅을 할 때 유용한 명령어들을 정리해보겠다. 디버거는 gef를 사용하였다.
#include <stdlib.h>
int main(){
char *ptr[10];
for (int i = 0; i< 10; i++)
ptr[i] = malloc(0x20);
char *ptr_s1 = malloc(0x300);
malloc(0x20);
char *ptr_s2 = malloc(0x300);
malloc(0x20);
char *ptr_s3 = malloc(0x300);
malloc(0x20);
char *ptr_b1 = malloc(0x500);
malloc(0x20);
char *ptr_b2 = malloc(0x500);
malloc(0x20);
char *ptr_b3 = malloc(0x600);
malloc(0x20);
char *ptr_b4 = malloc(0x600);
malloc(0x20);
for (int j = 0; j< 10; j++)
free(ptr[j]);
free(ptr_s1);
free(ptr_s2);
free(ptr_s3);
free(ptr_b1);
free(ptr_b2);
free(ptr_b3);
free(ptr_b4);
malloc(0x700);
return 0;
}
간단한 테스트 코드다.
return 0 직전에 breakpoint를 걸어보자.
heap chunks
heap에 존재하는 할당/해제 된 청크들을 보여준다.
heap chunk
특정 청크에 대한 정보를 보여준다
heap bins
현재 heap bins의 상태를 볼 수 있다.
p main_arena
library에 존재하는 main_arena 를 보여준다.
이정도면 디버깅 하기에는 충분할 것이다.
'포너블 > Heap' 카테고리의 다른 글
Heap single list safe linking (0) | 2025.04.14 |
---|---|
heap exploit 공부하기 좋은 곳 (1) | 2024.12.10 |
Tcache memory leak (0) | 2024.12.10 |
Tcache House of Spirit (0) | 2024.12.10 |
breaking calloc (0) | 2024.10.12 |