tcache_dup2
·
Wargame/Dreamhack
문제 파일 압축을 풀어보면 이번에는 libc 버전이 2.30이다. 아래 링크에서 설명한 것과 같이 2.29 버전부터는 패치되어 다른 방법을 사용해야한다. https://wyv3rn.tistory.com/75 heap tcache poisoning & double free tcache libc > 2.25 이후부터 적용된 heap 관리 방법이며, 2.29부터는 패치 되었다. 사실 아래 내용 다 필요 없이 같은 공간에 free가 두번 들어가며, free 시 앞에 사용한 heap 영역의 주소를 가져오기 때문 wyv3rn.tistory.com 더불어 libc에 맞는 ld 파일을 찾아야하므로 아래 사이트에서 찾아보자. http://old-releases.ubuntu.com/ubuntu/pool/main/g/gli..
Tcache Poisoning
·
Wargame/Dreamhack
// Name: tcache_poison.c // Compile: gcc -o tcache_poison tcache_poison.c -no-pie -Wl,-z,relro,-z,now #include #include #include int main() { void *chunk = NULL; unsigned int size; int idx; setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); while (1) { printf("1. Allocate\n"); printf("2. Free\n"); printf("3. Print\n"); printf("4. Edit\n"); scanf("%d", &idx); switch (idx) { case 1: printf("Size: ..
heap tcache poisoning & double free
·
Tips & theory
tcache libc > 2.25 이후부터 적용된 heap 관리 방법이며, 2.29부터는 패치 되었다. 사실 아래 내용 다 필요 없이 같은 공간에 free가 두번 들어가며, free 시 앞에 사용한 heap 영역의 주소를 가져오기 때문에 tcache 영역에 임의의 주소를 덮어씌울 수 있다. 우선 두번의 32 byte heap 영역 할당을 통해 아래와 같이 데이터가 들어있다고 가정하자. gef➤ heap chunks Chunk(addr=0x602010, size=0x290, flags=PREV_INUSE) [0x0000000000602010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................] Chunk(addr=0x6022a0, size=0..
heap tcache & main_arena
·
Tips & theory
tcache(thread local cache) heap 관리를 빠르게 하기 위해 glibc 2.26 이상부터 적용되는 기술. fast bin과 유사하지만 다른 성격을 가짐. tcache는 heap 영역에 존재함. 32 bit 에서는 516 byte 이하의 사이즈, 64 bit 에서는 1032 byte 이하의 사이즈가 할당되었을때 tcache를 사용함. 예제로 256 byte로 4개를 할당하고 첫번째 영역을 free 해서 fd, bk 값을 보면 다시 heap 영역을 가르키고 있으며, gef➤ x/40gx 0x555555603000 0x555555603000: 0x0000000000000000 0x0000000000000291 0x555555603010: 0x0000000000000000 0x0000000..
uaf_overwrite
·
Wargame/Dreamhack
// Name: uaf_overwrite.c // Compile: gcc -o uaf_overwrite uaf_overwrite.c #include #include #include #include struct Human { char name[16]; int weight; long age; }; struct Robot { char name[16]; int weight; void (*fptr)(); }; struct Human *human; struct Robot *robot; char *custom[10]; int c_idx; void print_name() { printf("Name: %s\n", robot->name); } void menu() { printf("1. Human\n"); printf("..