Hack
-
[BlackHat Heap] malloc_state structureHack/Pwnable 2016. 11. 29. 22:18
12345678910111213141516171819struct malloc_state { mutex_t mutex; /* Serialize access. */int flags; /* Flags (formerly in max_fast). */#if THREAD_STATS/* Statistics for locking. Only used if THREAD_STATS is defined. */ long stat_lock_direct, stat_lock_loop, stat_lock_wait;#endif mfastbinptr fastbins[NFASTBINS]; /* Fastbins */mchunkptr top;mchunkptr last_remainder;mchunkptr bins[NBIS*2];unsigned ..
-
[BlackHat Heap] heap_info structureHack/Pwnable 2016. 11. 29. 21:40
glibc에서 다루는 힙은 다음과 같은 구조체로 구현되어있다. 1234567typedef struct _heap_info { mstate ar_ptr; /* Arena for this heap. */struct _heap_info *prev; /* Previous heap. */size_t size; /* Current size in bytes. */char pad[-5 * SIZE_SZ & MALLOC_ALIGN_MASK];} heap_info;Colored by Color Scriptercs ar_ptr : heap arena의 포인터, 힙과 아레나 사이를 얘기함 struct _heap_info *prev : 이전 heap_info 구조체에 대한 포인터, heap_info 구조체는 싱글 링크드 리스트..
-
Allocate Heap with fgetsHack/Pwnable 2016. 11. 17. 05:35
fgets 는 누구나 알고있듯이 파일 등에서 문자열을 읽어들인다. 3번쨰인자에서 stream을 설정할 수 있는데, 여기서는 fgets에 함수를 사용해서 어떻게 할당되는지를 볼것이다. stack에 변수를 할당하고 이곳에 값을 담는 코드이다. 12345678910#include int main(){ char p[25] = {0,}; printf("Input: "); fgets(p,24,stdin); printf("p: %p",p); return 0;}cs 그냥 배열을 생성하고, fgets로 입력을 받는다. B를 입력해주고나서 스택과 힙의 상황을 확인해볼것이다. 스포를 하자면 heap이 존재한다. heap을 확인해보자 p: p스택주소가 담겨있다. 힙영역에 이값이 쓰이고, 저 스택을 확인해보면 우리가입력한값이 ..
-
[Heap Exploit] Unsafe_unlink - how2heap verHack/Pwnable 2016. 11. 8. 02:31
12345678910111213141516171819202122232425262728293031323334#include #include #include #include uint64_t *chunk0_ptr; int main(){ int malloc_size = 0x80; //we want to be big enough not to use fastbins int header_size = 2; chunk0_ptr = (uint64_t*) malloc(malloc_size); //chunk0 uint64_t *chunk1_ptr = (uint64_t*) malloc(malloc_size); //chunk1 chunk0_ptr[2] = (uint64_t) &chunk0_ptr-(sizeof(uint64_t)*..
-
heap 문제 시나리오들..Hack/Pwnable 2016. 11. 8. 00:31
아직 힙을 자유자재로 다루고 그럴 익스능력은 안되지만 어느 대회나보면 익스 시나리오는 비슷하다 unsorted bin에서 libc 를 릭하고, free를 통해 fd,bk 를 릭해서 heap 주소 릭하고... 좀 더 어려워지는 문제라면 double free bug가 기본적으로 패치된 상황일땐, fake chunk를 만들되 fd와 bk는 malloc 포인터에 잘 맞게 해주고 두개청크에서 size chunk의 prev_inuse 를 0으로 만들어 병합되게만든후 unlink 매크로를 호출해 그 이후로 double free bug가 발생하게 만드는문제들... 릭은 거의 UAF 로 릭하고 overwrite는 double free bug로 하는 문제들이 대다수인거같다.
-
-
[Heap exploit] fastbin unlinkHack/Pwnable 2016. 10. 19. 05:25
12345678910111213141516171819202122232425262728293031323334353637383940414243#include #include void leave() { puts("exiting..."); }void jackpot() { puts("jackpot!"); } void (*p)() = leave; int main(){ printf("&p = %p\n", &p); char *p1 = malloc(0x20); char *p2 = malloc(0x40); printf("p1 = %p\n", p1); printf("p2 = %p\n", p2); puts("\n[+] free p2"); free(p2); puts("\n[+] modify &p-0x8"); char *p_ta..
-
[Heap exploit] unsafe_unlinkHack/Pwnable 2016. 10. 18. 15:52
123456789101112131415161718192021222324252627282930313233343536373839#include #include void jackpot() { puts("jackpot!"); } char *p; int main(){ printf("&p = %p\n", &p); p = malloc(0x40); char *p1 = malloc(0x80); printf("p = %p\n", p); printf("p1 = %p\n", p1); printf("p1->prev_size = %p\n", *(void **)(p1-0x10)); printf("p1->size = %p\n", *(void **)(p1-0x8)); puts("\n[+] abuse p overflow"); *(voi..