#include "stdio.h"
#include "stdlib.h"

int main()
{
	printf("This file demonstrates a simple double-free attack with fastbins.\n");

	printf("Allocating 3 buffers.\n");
	int *a = malloc(8);
	int *b = malloc(8);
	int *c = malloc(8);

	printf("1st malloc(8): %p\n", a);
	printf("2nd malloc(8): %p\n", b);
	printf("3rd malloc(8): %p\n", c);

	printf("Freeing the first one...\n");
	free(a);

	printf("If we free %p again, things will crash because %p is at the top of the free list.\n", a, a);
	// free(a);

	printf("So, instead, we'll free %p.\n", b);
	free(b);

	printf("Now, we can free %p again, since it's not the head of the free list.\n", a);
	free(a);

	printf("Now the free list has [ %p, %p, %p ]. If we malloc 3 times, we'll get %p twice!\n", a, b, a, a);
	printf("1st malloc(8): %p\n", malloc(8));
	printf("2nd malloc(8): %p\n", malloc(8));
	printf("3rd malloc(8): %p\n", malloc(8));
}


This file demonstrates a simple double-free attack with fastbins.

이 파일은 fastbin에서의 간단한 double-free attack을 설명한다


Allocating 3 buffers.

3개의 버퍼를 할당

int *a = malloc(8);
int *b = malloc(8);
int *c = malloc(8);

1st malloc(8): 0x2145420

2nd malloc(8): 0x2145440

3rd malloc(8): 0x2145460


Freeing the first one...

첫번째를 free한다 

free(a);

If we free 0x2145420(a) again, things will crash because 0x2145420(a) is at the top of the free list.

만약 우리가 a를 다시 free한다면 crash가 일어난다. a가 free list의 top에 있기 때문이다.


So, instead, we'll free 0x2145440(b).

그래서 대신 우리는 b를 free할 것이다

free(b);

Now, we can free 0x2145420(a) again, since it's not the head of the free list.

이제 우리는 a를 다시 free할 수 있다. 왜냐하면 a는 더이상 free list의 head가 아니기 때문이다

free(a);

Now the free list has [ 0x2145420(a), 0x2145440(b), 0x2145420(a) ]. If we malloc 3 times, we'll get 0x2145420(a) twice!

이제 free list는 [ 0x2145420(a), 0x2145440(b), 0x2145420(a) ] 를 가진다. 만약 우리가 3번 malloc한다면 우리는 0x2145420을 두번가진다


1st malloc(8): 0x2145420

2nd malloc(8): 0x2145440

3rd malloc(8): 0x2145420



'시스템 > how2heap시리즈' 카테고리의 다른 글

[how2heap정리]fist_fit  (0) 2017.01.14
[how2heap 정리]fast_bin_dup_into_stack  (0) 2017.01.07
[how2heap정리] unsorted_bin_attack  (0) 2016.12.28
[how2heap]unsafe_unlink  (0) 2016.12.16
[how2heap정리]house of spirit  (0) 2016.12.16

+ Recent posts