Post

The House of Spirit

The House of Spirit

stack overflowstack에 있는 포인터 변수 hptr을fake\_chunk addr로 overwrite. 이후 free(hptr)하면 fastbin에는 fake\_chunkaddr이 추가되므로, 그 다음 반환 chunk는 ` fake_chunk`

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/\* set fake\_chunk \*/
fake\_chunk[1] = arbitrary\_size;
/\* set next chunk size \*/
...

  

void \*hptr = malloc(SIZE);
char buf[4];
strcpy(buf, argv[1]);     // stack overflow

  

free(hptr)          // fake chunk is added in fastbin
fake = malloc(SIZE) // return fake chunk

[free] MINSIZE check
fake\_chunk->size 채워주어야 한다.

[free] next size check (fast)
일반적인 경우 top chunk size가 존재하기 때문에 알아서 pass하지만, fake\_chunk는 그렇지 못하기 때문에

반드시 fake_chunk 뒤쪽에 next chunk의 size field를 넣어주어야 한다. 이 check만 통과하면 되므로 fake chunk’s size와 같을 필요는 없으며 알맞은 위치에 size만 넣어주면 된다.

This post is licensed under CC BY 4.0 by the author.