[How2Heap] Tcache_House_of_spirit

Tcache_House_of_spirit

tcache_house_of_spirit.c

the house of spirit attack on tcache.
기존의 house of spirit과 비슷한 방식으로 작동하지만
free될 fake chunk 뒤에 fake chunk를 만들 필요가 없다.
malloc.c의 _int_free 함수에서 tcache_put이 다음 chunk의 prev_inuse가 정상인지 확인하지 않고 호출되는 것을 알 수 있다.
(Search for strings “invalid next size” and “double free or corruption”)

malloc()을 한 번 호출해서 메모리를 세팅한다.
fake chunk 영역을 가리키기 위해 1 pointer를 overwrite할 것이라고 생각해보자.
이 영역에는 하나의 fake chunk가 있다. 크기 필드는 0x7fff15cd5518에 위치한다.
이 chunk 크기는 tcache 범주에 속해야 한다.
(chunk 크기 <= 0x410; x64: malloc arg <= 0x408)

prev_inuse(lsb) bit는 tcache chunk의 경우 free로 무시되지만
is_mmapped(두번째 lsb)와 non_main_arena(세번째 lsb) 비트는 문제를 일으킨다.
이제 첫번째 fake chunk안에 있는 0x7fff15cd5518를 fake영역의 주소에 pointer를 overwrite할 것이다.

overwrite된 pointer를 free한다.
-------free(a)-------
이제 다음 malloc은 0x7fff15cd5518에서 fake chunk의 영역을 반환할 것이다. 그것은 0x7fff15cd5520일 것이다.
malloc(0x30): 0x7fff15cd5520

공유하기