Pwnable/Tech

Heap - House of Force

Kon4 2021. 10. 27. 15:19

House of Force 기법은 top chunk의 size를 조작함으로써 임의의 주소에 힙 청크를 할당 할 수 있는 공격기법이다.

 

이 기법을 사용하기 위해서는 공격자가 top chunk의 size를 조작하고, 원하는 크기의 힙 청크를 할당 할 수 있어야 합니다.

 

top chunk를 처리하는 _int_malloc코드의 설명입니다.

 

static void *

_int_malloc(mstate av, size_t bytes){

  INTERNAL_SIZE_T nb;

  mchunkptr remainder;

  unsigned long remainder_size;

  

  victim = av->top;

  size = chunksize(victim);

  if(size >= (nb+MINSIZE)){

    remainder_size = size - nb;

    remainder = chunk_at_offset(victim, nb);

    av -> top = remainder;

    set_head(victim, nb|PREV_INUSE|(av != &main_arena ? NON_MAIN_ARENA : 0));

    set_head(remainder, remainder_size | PREV_INUSE);

    check_malloced_chunk(av, victim, nb);

    void *p = chunk2mem(victim);

    alloc_perturb(p, bytes);

    return p;

  }

 

}