본문 바로가기

how2heap

(5)
06. [How2Heap] - unsafe_unlink.c #include #include #include #include #include uint64_t *chunk0_ptr;int main(){ setbuf(stdout, NULL); printf("Welcome to unsafe unlink 2.0!\n"); printf("Tested in Ubuntu 20.04 64bit.\n"); printf("This technique can be used when you have a pointer at a known location to a region you can call unlink on.\n"); printf("The most common scenario is a vulnerable buffer t..
05. [How2Heap] fastbin_dup_consolidate.c #include #include #include /*Original reference: https://valsamaras.medium.com/the-toddlers-introduction-to-heap-exploitation-fastbin-dup-consolidate-part-4-2-ce6d68136aa8This document is mostly used to demonstrate malloc_consolidate and how it can be leveraged with adouble free to gain two pointers to the same large-sized chunk, which is usually difficult to dodirectly due to the previnuse chec..
-01.first_fit.c 서론first_fit.c를 공부 하였지만, 추가적인 학습이 필요하다 생각하였다. 따라서 개념에 대한 정리를 하려한다. 본론힙이란?프로세스가 실행되는 동안 프로그램이 동적으로(실행 중에) 메모리를 할당하고 해제하는 영역이라고 한다. 쉽게 말하자면프로그램이 실행중일 때 크기가 정해지지 않은 데이터를 저장할 때 힙 영역에서 메모리를 할당하고, 데이터를 더이상 안쓸때 해제한다는 뜻이다. 동적할당, 정적할당, 자동할당?힙은 동적할당이다. 동적할당이란프로그램이 실행중에 메모리를 할당하고 해제하는 것이다.여기서 메모리를 할당한다는 말은 코드로 표현하면 malloc() 을 뜻한다.또한 해제를 뜻하는 코드 free(), delete() 이다.이는 힙 영역에 저장된다. 정적할당은 뭘까?정적할당은 전역변수나, static ..
02.How2Heap - calc_tcache_idx.c 서론이번에는 calc_tcache_idx.c을 해볼 것이다.설명은Demonstrating glibc's tcache index calculation.glibc의 tcache 인덱스 계산 방식을 시연라고 되어있다.본론우선 이 학습에서는 tcache 인덱스 계산 방식을 이해하는 것이다.우분투를 켜보겠다.다음을 입력하면 다음과 같이 결과가 출력된다.이 파일을 보면 우리가 알고싶은 것이 malloc(x)를 했을 때 그 청크는 tcache[idx]중 어디로 들어가는가? 가 중요한 포인트인 것을 알 수 있다.malloc(x)에서 x는 유저가 요청한 크기를 말한다. 하지만 힙 내부에는 크기와 정렬 보정이 추가된다. 따라서 실제 할당 크기(CHUNKSIZE)가 된다.CHUNKSIZE의 공식은CHUNKSIZE = ( x..
01.How2Heap - first_fit.c 서론ChatGPT에 조언에 따라 Heap을 공부해 보겠다. Heap을 공부하기 위해 how2heap라는 힙 익스플로잇 기법 실습하며 학습할 수 있 오픈소스를 이용해 공부할 것이다.본론사전 설치우선 how2heap을 설치하겠다.git clone https://github.com/shellphish/how2heap.gitcd how2heap이를 하고 ls 를 입력하면다음과 같이 파일이 설치된다. 실행실행하기 전에 first_fit.c의 설명을 보자면Demonstrating glibc malloc's first-fit behaviorglibc malloc의 first-fit 동작을 보여줍니다.라고 되어있다. 코드를 분석하기 위해 cat first_fit.c 를 해보겠다.#include #include #inc..