note

보호기법

Pasted image 20240828102035.png

GOT overwrite 가능
PIE 비활성화, 매핑되는 주소는 일정

기능

Pasted image 20240828103456.png

함수

Pasted image 20240828103525.png
Pasted image 20240828103620.png

Pasted image 20240828103727.png

calloc과 free
4 delete -> free
1 create -> calloc

calloc size는 0x70 미만
idx는 0xA 미만이니 최대가 10개의 노트

Pasted image 20240828105426.png

이런 식으로 들어감

Pasted image 20240828105544.png

data: *((void **)&unk_4040B0 + 2 * (int)v2
size: *((_QWORD *)&unk_4040A8 + 2 * (int)v2)

struct note_t {
    size_t size;
    char *data;
};

이런식으로 생겻다고 유추가능

취약점

Pasted image 20240828105918.png

data 포인터를 free하지만 null로 초기화하지 않음. -> dangling pointer
read를 통해 해제된 청크를 읽을 수 있음

배경지식

fastbin dup into stack

https://infosecwriteups.com/the-toddlers-introduction-to-heap-exploitation-fastbin-dup-to-stack-part-4-1-425592a2870b

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

https://blog.sechack.kr/34

그리고 이번 익스플로잇에서 가장 핵심적이고 중요한 내용을 알아보자면 calloc함수는 tcache를 사용하지 않는다. tcache bin을 꽉채우더라도 tcache bin을 재활용하지 않고 fastbin에 chunk가 있으면 그걸 재활용하게 된다

익스 시날

Pasted image 20240828113348.png

[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하는 순간 쉘 무한실행되고 쾅 하고 터짐
(친구가 나중에 이런거 읽으면 재밌대서 써놓음)

6abbfb9a3f3bb7ad861e33c6bdd9311a.jpg REDACTED! NOTHING TO SEE!