본문 바로가기
Systemhacking/Base info

small bin attack

by reindeer002 2023. 6. 4.
728x90

House of Lore 라고도 불리우는 small bin attack에 대해 알아보자.

이는 free된 후 small bin에 들어간 chunk의 bk를 조작해, 원하는 chunk를 small bin에 넣는 공격이다.
이때 원하는 chunk는 free된 것으로 설정해도 가능하고, 이미 malloc을 통해 할당 받은 것도 가능하다.

그러나, small bin size의 chunk는 free된 후 unsorted bin에 우선적으로 들어가므로,
더 큰 크기의 chunk를 할당받아, unsorted bin의 free chunk를 small bin으로 이동시켜야 한다.

아래는 small bin의 free chunk 체크 로직을 우회하기 위한 방법이다.

  • real_chunk→bk = fake_chunk
  • fake_chunk→fd = real_chunk
  • fake_chunk→bk = another_chunk
  • another_chunk→fd = fake_chunk
if (in_smallbin_range (nb))
  {
    idx = smallbin_index (nb);
    bin = bin_at (av, idx);
 
    if ((victim = last (bin)) != bin)
      {
        if (victim == 0) /* initialization check */
          malloc_consolidate (av);
        else
          {
            bck = victim->bk;
  if (__glibc_unlikely (bck->fd != victim))
              {
                errstr = "malloc(): smallbin double linked list corrupted";
                goto errout;
              }
            set_inuse_bit_at_offset (victim, nb);
            bin->bk = bck;
            bck->fd = bin;
 
            if (av != &main_arena)
              victim->size |= NON_MAIN_ARENA;
            check_malloced_chunk (av, victim, nb);
            void *p = chunk2mem (victim);
            alloc_perturb (p, bytes);
            return p;
          }
      }
  }

 

우리는 해당 기법을 통해 원하는 chunk를 bin에 삽입하여 UAF와 같은 공격으로 발전시킬 수 있을 것이다.

 

Refer:
https://heap-exploitation.dhavalkapil.com/attacks/house_of_lore
https://dokydoky.tistory.com/461

728x90

'Systemhacking > Base info' 카테고리의 다른 글

IO_buf_end attack  (0) 2023.07.19
malloc consolidate with Fastbin_Dup Consolidate  (1) 2023.06.04
unsorted bin attack  (0) 2023.06.02
unsafe Unlink in heap  (0) 2022.11.07
Fastbin Double Free  (0) 2021.04.04

댓글