0x.Heap Tutorial
-
0x09.How2heap - house_of_einherjar0x.Heap Tutorial 2018. 11. 22. 00:51
0x09.How2heap - house_of_einherjar 진짜 오랜만에 작성하는 듯하다. 근데 매 글의 윗 부분에 이 내용이 있긴 하지만.. combination을 풀겸해서 복습이닷. #include #include #include #include #include /* Credit to st4g3r for publishing this technique The House of Enherjar uses an off-by-one overflow with a null byte to control the pointers returned by malloc() This technique may result in a more powerful primitive than the Poison Null Byte, b..
-
0x08.How2heap - unsafe_unlink0x.Heap Tutorial 2018. 4. 10. 00:08
0x07.How2heap - unsafe_unlink 오랜만에 how2heap에 대한 문서를 작성한다. 근데 unsafe_unlink에 대해 설명하자니 글로 너무 복잡하다. ㅋㅋ 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869#include #include #include #include uint64_t *chunk0_ptr; int main(){ fprintf(stderr, "Welcome to unsafe unlink 2.0!\n"); fprintf(stderr, "Tested in Ubuntu 14.04/16.04 6..
-
0x07.How2heap - fastbin_dup_consolidate0x.Heap Tutorial 2018. 4. 9. 19:15
How2heap - fastbin_dup_consolidate 최근에 how2heap에 추가된 취약점인데, 조금 신기하기도 한 취약점이다. #include #include #include int main() { void* p1 = malloc(0x40); void* p2 = malloc(0x40); fprintf(stderr, "Allocated two fastbins: p1=%p p2=%p\n", p1, p2); fprintf(stderr, "Now free p1!\n"); free(p1); void* p3 = malloc(0x400); fprintf(stderr, "Allocated large bin to trigger malloc_consolidate(): p3=%p\n", p3); fpri..
-
0x06.Malloc hook0x.Heap Tutorial 2018. 3. 19. 17:17
0x06.Malloc hook GNU C library에서는 hook이라는 놈을 제공하는데, 이 놈의 값을 변경가능하도록 하여 디버깅을 수월하게 할 수 있도록 설계되었지만, Heap Overflow를 익스할 때 주로 악용되기도 한다. 예로 malloc이 프로그램이 실행됨에 의해 호출되면 C 라이브러리가 hook이 존재하는지를 확인하고 만약 존재하면 그 hook 버전을 부른다. 만약 이 hook이 기존의 malloc을 호출한다면 malloc이 실행될 것이고, system을 실행하면 시스템이 실행될 것이다. void *(*__malloc_hook)(size_t SIZE, const void *CALLER); void *(*__realloc_hook)(void *PTR, size_t SIZE, const vo..
-
0x05.How2heap - fastbin_dup_into_stack0x.Heap Tutorial 2018. 3. 12. 17:29
0x05. How2heap - fastbin_dup_into_stack fastbin 취약점의 응용 단계로 *fd의 값을 stack으로 변환시켜 fake_chunk를 할당하는 방법에 대한 설명이다.#include #include int main() { fprintf(stderr, "This file extends on fastbin_dup.c by tricking malloc into\n" "returning a pointer to a controlled location (in this case, the stack).\n"); unsigned long long stack_var; fprintf(stderr, "The address we want malloc() to return is %p.\n..
-
0x04.How2heap - fastbin_dup0x.Heap Tutorial 2018. 3. 8. 14:18
0x04.How2heap - fastbin_dup 이번에는 fastbin의 취약점이다.#include #include int main() { fprintf(stderr, "This file demonstrates a simple double-free attack with fastbins.\n"); fprintf(stderr, "Allocating 3 buffers.\n"); int *a = malloc(8); int *b = malloc(8); int *c = malloc(8); fprintf(stderr, "1st malloc(8): %p\n", a); fprintf(stderr, "2nd malloc(8): %p\n", b); fprintf(stderr, "3rd malloc(8): %p\..
-
0x03.How2heap - first_fit0x.Heap Tutorial 2018. 3. 8. 13:43
0x03.How2heap - first_fit 자 이제 Heap Exploit에 대한 공부를 시작하도록 한다.#include #include #include int main() { fprintf(stderr, "This file doesn't demonstrate an attack, but shows the nature of glibc's allocator.\n"); fprintf(stderr, "glibc uses a first-fit algorithm to select a free chunk.\n"); fprintf(stderr, "If a chunk is free and large enough, malloc will select this chunk.\n"); fprintf(stderr, "Thi..
-
0x02.Arena and Chunk0x.Heap Tutorial 2018. 3. 7. 17:34
0x02. Arena and Chunk 이번에는 아레나와 청크를 다뤄보겠다. Arena아레나는 malloc()에서 메모리 관리 부분을 포함한 영역을 뜻한다. MMAPPED 부분은 아레나에 포함이 되지 않는다.malloc.c의 struct malloc_state 구조체를 살펴보자면 아래와 같은데,struct malloc_state { /* Serialize access. */ mutex_t mutex; /* Flags (formerly in max_fast). */ int flags; /* Fastbins */ mfastbinptr fastbinsY[NFASTBINS]; /* Base of the topmost chunk -- not otherwise kept in a bin */ mchunkptr top..