취약점분석/Pwnable

[Pwnable] tcache_dup

poiri3r 2025. 11. 7. 14:52

안녕하세요 오늘은 how2heap에서 제공하는 tcache_dup.c 코드를 살펴보겠습니다.

tcache_dup은 사실 저번에 작성한 tcache poisoning의 기초적인 부분으로 DFB가 발생하는 과정을 보여주는 코드입니다

 

https://github.com/shellphish/how2heap/blob/master/obsolete/glibc_2.27/tcache_dup.c

 

how2heap/obsolete/glibc_2.27/tcache_dup.c at master · shellphish/how2heap

A repository for learning various heap exploitation techniques. - shellphish/how2heap

github.com

해당 깃허브 주소에서 확인할 수 있습니다.

 

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int main()
{
	printf("This file demonstrates a simple double-free attack with tcache.\n");

	printf("Allocating buffer.\n");
	int *a = malloc(8);

	printf("malloc(8): %p\n", a);
	printf("Freeing twice...\n");
	free(a);
	free(a);

	printf("Now the free list has [ %p, %p ].\n", a, a);
	void *b = malloc(8);
	void *c = malloc(8);
	printf("Next allocated buffers will be same: [ %p, %p ].\n", b, c);

	assert((long)b == (long)c);
	return 0;
}

 

assert(조건문)은 조건문이 True가 아닐 시 프로그램을 크래시합니다.

 

a를 malloc으로 할당하고 free를 두번해줍니다 -> DFB가 발생합니다.

이때 tcache의 free list에는 a의 주소가 두개 들어가게 됩니다.

이 상황에서 b와 c를 할당하게 되면, free list에 있던 a가 b와 c에 둘 다 할당되게 됩니다.

 

실제로 실습 코드를 만들어서 해보고 싶은데, 맥북으로 포스팅을 하고 있는데 맥북 사용법을 몰라서.. 쉽지 않네요 ..

다음 포스팅 때 Tcache dup 드림핵 문제를 풀이하면서 실습해보도록 하겠습니다.

짧은글이지만 읽어주셔서 감사합니다.

'취약점분석 > Pwnable' 카테고리의 다른 글

[Pwnable]Tcache_dup2 write-up  (0) 2025.11.09
[Pwnable] Tcache_dup write-up  (0) 2025.11.08
[Pwnable] tcache_poison write-up  (0) 2025.11.06
[Pwnable] Tcache Poisoning  (0) 2025.11.05
[Pwnable] Double Free Bug (Memory Corruption)  (0) 2025.11.03