Continuous free bug (double free bug)
·
Tips & theory
* 서론 솔직히 이건 double free라고 하지말고 continuous free나 heap free unlink bug라던지라고 불러야하는게 맞지 않나? double free는 동일 heap 영역에 대한 free를 이야기해야되는거 아니야? 나만그래...? *원리 - 전제 조건 및 기본 원리 double free bug는 기본적으로 heap overflow를 기본으로 한다. 즉, P flag가 수정 가능해야하기에 heap overflow가 필수적이다. heap 영역은 free 될 때 다음에 사용할 주소를 fd 영역에 저장한다. 더불어 heap 영역이 초기화될 때 heap 영역들 사이에 빈 공간이 있다면 합쳐주며, 이는 unlink 함수를 통해 이루어진다. 이는 heap 영역을 효율적으로 사용하려함에 있..
Tcache Poisoning
·
Wargame/Dreamhack
// Name: tcache_poison.c // Compile: gcc -o tcache_poison tcache_poison.c -no-pie -Wl,-z,relro,-z,now #include #include #include int main() { void *chunk = NULL; unsigned int size; int idx; setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); while (1) { printf("1. Allocate\n"); printf("2. Free\n"); printf("3. Print\n"); printf("4. Edit\n"); scanf("%d", &idx); switch (idx) { case 1: printf("Size: ..
heap tcache poisoning & double free
·
Tips & theory
tcache libc > 2.25 이후부터 적용된 heap 관리 방법이며, 2.29부터는 패치 되었다. 사실 아래 내용 다 필요 없이 같은 공간에 free가 두번 들어가며, free 시 앞에 사용한 heap 영역의 주소를 가져오기 때문에 tcache 영역에 임의의 주소를 덮어씌울 수 있다. 우선 두번의 32 byte heap 영역 할당을 통해 아래와 같이 데이터가 들어있다고 가정하자. gef➤ heap chunks Chunk(addr=0x602010, size=0x290, flags=PREV_INUSE) [0x0000000000602010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................] Chunk(addr=0x6022a0, size=0..
[App-System] ELF x64 - Double free
·
Wargame/Root me
1. intro 2. code 및 분석 2.1. code #include #include #include #include struct Zombie { int hp; void (*hurt)(); void (*eatBody)(); void (*attack)(); int living; }; struct Human { int hp; void (*fire)(int); void (*prayChuckToGiveAMiracle)(); void (*suicide)(); int living; }; struct Zombie *zombies[3]; struct Human *human = NULL; void fire(int zombieIndex) { struct Zombie *zombie = zombies[zombieIndex..