[stypr] tofukimchi

2017. 6. 12. 21:22

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

How 2 heap - fastbin_dup.c

System 2017. 5. 16. 13:11

원문 : https://github.com/shellphish/how2heap/blob/master/fastbin_dup.c



#include 
#include 

int main()
{
	printf("이 파일은 fastbins을 통한 double-free 공격을 간단하게 보여줄 겁니다.\n");

	printf("3개의 버퍼를 할당하도록 하죠.\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("제일 처음것을 할당해제를 하고...\n");
	free(a);

	printf("만약 %p 를 다시 해제한다면 크래쉬가 날텐데, %p가 free list의 제일 위에 있기 때문이죠.\n", a, a);
	// free(a);

	printf("그러므로 대신 %p를 할당해제 합시다..\n", b);
	free(b);

	printf("그럼 이제 %p를 할당해제 할수 있습니다. free list의 처음 노드가 아니기 때문이죠.\n", a);
	free(a);

	printf("free list는 현재 [ %p, %p, %p ] 입니다. 우리가 3회 할당하면, %p를 2번 얻게 될 겁니다.\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));
}


'System' 카테고리의 다른 글

How 2 heap - first_fit.c  (0) 2017.05.15
LLVM -3  (2) 2016.08.24
LLVM - 2  (0) 2016.08.17
LLVM - 1  (0) 2016.08.12
프로그램에서 일어날수 있는 레이스컨디션의 예제  (8) 2015.04.01
Posted by IzayoiSakuya
,

How 2 heap - first_fit.c

System 2017. 5. 15. 16:47

원문 : https://github.com/shellphish/how2heap/blob/master/first_fit.c 

#include 
#include 
#include 

int main()
{
	printf("이 파일은 POC는 아닙니다. 하지만 glibc's allocator의 본모습을 보여주게 될것입니다.\n");
	printf("glibc 비어있는 청크에서 최초적합 알고리즘을 사용하여 선택후, 가져옵니다.\n");
	printf("만약 청크가 비어있고 충분히 크다면, malloc은 그 청크를 선택하고 가져오겠죠.\n");
	printf("이는 Use-after-free 상황이며 공격 당할 수 있습니다\n");

	printf("2개의 버퍼를 할당합시다. fastbin이 아니도록 충분히 커야만 합니다.\n");
	char* a = malloc(512);
	char* b = malloc(256);
	char* c;

	printf("1st malloc(512): %p\n", a);
	printf("2nd malloc(256): %p\n", b);
	printf("우리는 여기에 더 할당 할 수 있습니다.\n");
	printf("문자열을 할당하여 읽을수 있게 합니다. \"this is A!\"를 버퍼에 넣도록 합시다.\n");
	strcpy(a, "this is A!");
	printf("첫 할당된 메모리 %p, 내용은 %s\n", a, a);

	printf("첫번째 것을 할당 해제 합시다.\n");
	free(a);

	printf("다시 다른것을 할당해제 할 필요는 없습니다. 512 보다 작게 할당하는 한, %p에서 그칠테니까요.\n", a);

	printf("그렇다면, 500 바이트를 할당 해 봅시다\n");
	c = malloc(500);
	printf("3rd malloc(500): %p\n", c);
	printf("여긴 다른 문자열을 넣도록 하죠.\"this is C!\" 이걸로.\n");
	strcpy(c, "this is C!");
	printf("세번째 할당된 메모리는 %p, 내용은 %s\n", c, c);
	printf("최초 할당된 메모리는 %p, 내용은 %s\n", a, a);
	printf("만약 첫번째 할당을 재사용하게 되면 3번째 할당에 사용된 데이터를 가지게 될겁니다.");
}

'System' 카테고리의 다른 글

How 2 heap - fastbin_dup.c  (0) 2017.05.16
LLVM -3  (2) 2016.08.24
LLVM - 2  (0) 2016.08.17
LLVM - 1  (0) 2016.08.12
프로그램에서 일어날수 있는 레이스컨디션의 예제  (8) 2015.04.01
Posted by IzayoiSakuya
,