rosieblue
article thumbnail
[드림핵(Dreamhack)] tcache_dup
Linux Exploitation/Wargame 2023. 6. 27. 12:52

문제코드 // gcc -o tcache_dup tcache_dup.c -no-pie #include #include #include #include char *ptr[10]; void alarm_handler() { exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(60); } int create(int cnt) { int size; if (cnt > 10) { return -1; } printf("Size: "); scanf("%d", &size); ptr[cnt] = malloc(size); if (!ptr[..

article thumbnail
[Heap] Exploitation : tcache dup
Linux Exploitation/Heap 2023. 6. 27. 09:02

배경지식 : Double Free Bug [Heap] Exploitation : Double Free Bug [Heap] Exploitation : Double Free Bug Double Free Bug Double Free Bug(DFB)는 free(ptr1); free(ptr1);처럼 같은 메모리를 여러번 free했을 때 나타나는 버그이다. 이게 왜 문제인지는 아래에서 설명할 것임 free(ptr1); free(ptr1); free 함수는 포인터를 초 hannahsecurity.tistory.com Duble Free Bug에 대해 모르는 분들은 위 글 꼭읽고 오기! 다시 한번 DFB에 대해 복습해보자. Double Free Bug은 free등으로 동일한 힙 메모리를 중복으로 해제했을 때 일어나는 ..

article thumbnail
[드림핵(Dreamhack)] uaf_overwrite
Linux Exploitation/Wargame 2023. 6. 20. 20:10

⬇ 사용한 배경지식 ⬇ [Heap] Memory Corruption : Use After Free(UAF) (1) [Heap] Exploitation : Unsorted Bin Memory Leak // Name: uaf_overwrite.c // Compile: gcc -o uaf_overwrite uaf_overwrite.c #include #include #include #include struct Human { char name[16]; int weight; long age; }; struct Robot { char name[16]; int weight; void (*fptr)(); }; //Human 구조체와 Robot 구조체 크기 동일 //전역변수 human,romot,custom,c_idx ..

article thumbnail
[Heap] Exploitation : fastbin dup & poisoning
Linux Exploitation/Heap 2023. 6. 16. 12:06

이번 포스트는 [Heap] Exploitation : Double Free Bug을 알아야 읽을 수 있다. Fastbin dup & poisoning Fastbin dup fastbin dup은 double free bug을 통해 이미 할당된 청크에 다른 청크를 또 할당하는 기법이다. 아까 위에서 재할당을 통해서 ptr3만 0x602030을 가리키게 했지만 만약 추가적으로 ptr4,ptr5로 두번이나 재할당하게 되면 ptr5또한 0x602030을 가리키게 된다. 그래서 0x602030에 두개의 청크가 할당되게된다. Fastbin Poisoning fastbin poisoning은 이미 해제된 힙 청크의 fd를 조작하여 임의의 주소에 힙 청크를 할당할 수 있게 하는 공격이다. 아까 위에서 ptr3이 0x6..

article thumbnail
[Heap] Exploitation : Poison NULL Byte
Linux Exploitation/Heap 2023. 6. 15. 15:27

Poison NULL Byte 이 공격은 인접한 청크의 메타 데이터를 조작하는 방법으로 size의 하위 1바이트를 overwrite하는 기법이다. 데이터 영역과 다음 청크 size의 flag부분은 바로 붙어있으므로 입력한 값이 조금만 넘쳐도 overwrite하게 된다. 이를 통해 다른 공격과 연계할 수 있다. 이 버그를 트리거하는 함수로는 readdata,strncat,fgets 등이 있다. 꼭 힙이 아니더라도 Off-by-one 등 다른 공격으로도 이어질 수 있다. // gcc -o null1 null1.c #include #include #include int readdata(char *buf, int len){ read(0, buf, len); *(char *)(buf + len) = '\x00';..

article thumbnail
[Heap] Exploitation : Double Free Bug
Linux Exploitation/Heap 2023. 6. 15. 00:51

Double Free Bug Double Free Bug(DFB)는 free(ptr1); free(ptr1);처럼 같은 메모리를 여러번 free했을 때 나타나는 버그이다. 이게 왜 문제인지는 아래에서 설명할 것임 free(ptr1); free(ptr1); free 함수는 포인터를 초기화하지 않는다. 따라서 free를 여러번 하게 되면, freelist에 동일한 주소가 여러번 적히게 된다.(free는 freelist에 노드를 '추가'하는 것과 같다) 원래는 위 코드처럼 연달아 해도 아무 문제 없었는데, freelist에서 연속한 청크가 같은 주소이면(ptr1->ptr1 이런식으로 리스트가 연결되면) 에러 내뿜고 죽는다. 그래서 아래처럼 해주면 우회할 수 있다. free(ptr1); free(ptr2); f..