Large_bin attack

keto·2024년 8월 13일

heap_exploit

목록 보기
2/2

glibc 2.3부터
if (__glibc_unlikely (fwd->bk_nextsize->fd_nextsize != fwd))
if (bck->fd != fwd)
두가지가 추가되었다.

하지만 fwd->bk_nextsize->fd_nextsize != fwd 같은 경우 가장 작은 chunk가 들어올 때는 검사하지 않기에 bypass 할 수 있다.

방법은 다음과 같다.
1. large chunk p1을 alloc하고 consolidate되지 않도록 사이에 chunk를 끼워준다.
2. large chuk p2도 똑같이 해준다. (단, p1이 p2보다 size가 커야한다.)
3. p1을 free한다.
4. p1보다 큰 chunk를 alloc한다. (p1을 large bin으로)
5. p2를 free한다.
6. p1->bk_nextsize에 원하는 주소 -0x20 를 넣는다.
7. p2보다 큰 chunk를 alloc한다. (p2를 large bin으로)

if ((unsigned long) (size) < (unsigned long) chunksize_nomask (bck->bk))
  {
    fwd = bck; // fwd = p1
    bck = bck->bk; // bck = p1->bk 

    victim->fd_nextsize = fwd->fd; // p2->fd_nextsize = p1->fd (Note that p1->fd is p1 as it's the only chunk)
    victim->bk_nextsize = fwd->fd->bk_nextsize; // p2->bk_nextsize = p1->fd->bk_nextsize
    fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim; // p1->fd->bk_nextsize->fd_nextsize = p2
  }

를 보면 알 수 있듯이 원하는 주소에 chunk의 주소가 들어가게 된다.

profile
meme

0개의 댓글