note
보호기법
GOT overwrite 가능
PIE 비활성화, 매핑되는 주소는 일정
기능
함수
calloc과 free
4 delete -> free
1 create -> calloc
calloc size는 0x70 미만
idx는 0xA 미만이니 최대가 10개의 노트
이런 식으로 들어감
data: *((void **)&unk_4040B0 + 2 * (int)v2
size: *((_QWORD *)&unk_4040A8 + 2 * (int)v2)
struct note_t {
size_t size;
char *data;
};
이런식으로 생겻다고 유추가능
취약점
data 포인터를 free하지만 null로 초기화하지 않음. -> dangling pointer
read를 통해 해제된 청크를 읽을 수 있음
배경지식
fastbin dup into stack
safe linking
https://velog.io/@msh1307/Heap-Safe-linking
https://github.com/comed-ian/word_games/?ref=margin.re
https://github.com/n132/Dec-Safe-Linking/blob/main/sol.py
It’s important to note that our attacker doesn’t know where the heap is located, as the heap’s base address is randomized together with the
mmap_base
by the ASLR (more on this topic in the next section).
calloc
그리고 이번 익스플로잇에서 가장 핵심적이고 중요한 내용을 알아보자면 calloc함수는 tcache를 사용하지 않는다. tcache bin을 꽉채우더라도 tcache bin을 재활용하지 않고 fastbin에 chunk가 있으면 그걸 재활용하게 된다
익스 시날
[1] 0x30 * 7 하면 그 다음부터는 fastbin로 관리
[2] read 부분의 leak을 통해 heap의 base addr 알면 pointer를 decode 가능
[3] malicious chunk을 .data안에
[4] update 부분을 통해 딴 노트 data 변조 -> exit으로
[5] update 부분을 통해 딴 노트 data 변조 2 -> exit을 win으로
[6] exit을 부르면 쉘따짐
익스
처음에 아무생각없이 read got썼다가 cat flag하는 순간 쉘 무한실행되고 쾅 하고 터짐
(친구가 나중에 이런거 읽으면 재밌대서 써놓음)
REDACTED! NOTHING TO SEE!