background/linux

    [how2heap] Fastbin dup into stack (glibc 2.35)

    https://github.com/shellphish/how2heap/blob/master/glibc_2.35/fastbin_dup_into_stack.c #include #include #include int main(){ fprintf(stderr, "이 파일은 calloc을 속이는 방법으로 fastbin_dup.c를 확장합니다.\n" "(이 경우 스택에 제어된 위치를 가리키는 포인터를 반환합니다).\n"); fprintf(stderr,"먼저 tcache를 채웁니다.\n"); void *ptrs[7]; for (int i=0; i> 12) ^ ptr; /*취약점*/ fprintf(stderr, "3번째 calloc(1,8): %p, 스택 주소를 free list에 넣음\n", calloc..

    [how2heap] Fastbin dup (glibc 2.35)

    https://github.com/shellphish/how2heap/blob/master/glibc_2.35/fastbin_dup.c #include #include #include int main(){ setbuf(stdout, NULL); printf("이 파일은 fastbins를 사용한 간단한 double-free 공격을 보여줍니다.\n"); printf("먼저 tcache를 채웁니다.\n"); void *ptrs[8]; for (int i=0; i 이 파일은 fastbins를 사용한 간단한 double-free 공격을 보여줍니다.먼저 tcache를 채웁니다.버퍼 3개를 할당합니다.첫 번째 calloc(1, 8): 0x55db240313a0두 번째 calloc(1, 8): 0x55db240313c..

    stack pivoting

    stack pivoting

    stack pivoting 가젯을 활용해 스택의 흐름을 변경해서 익스플로잇을 수행하는 공격 기법이다. 쓰기 가능한 영역(.bss 영역 등)을 활용해서 fake stack을 구성한 뒤 ROP 체이닝에 활용하는 식으로 공격을 수행할 수 있다. 일반적으로 사용하는 gadget은 다음과 같다. gadget 종류 add esp, offset; ret; sub esp, offset; ret; call register; push register; pop esp; ret; xchg register, esp; ret; mov esp, register; ret; leave; ret; mov register,[ebp+0c]; call register; mov reg, dword ptr fs:[0]; …; ret; 여기서 주..

    [how2heap] House of Lore (glibc 2.35)

    [how2heap] House of Lore (glibc 2.35)

    how2heap의 예제를 활용한 house of lore 공격 분석 bins bins은 사용이 끝난 청크들이 저장되는 객체이다. 메모리의 낭비를 막고, 해제된 청크를 빠르게 재사용할 수 있게 한다. bin에는 unsorted bin, small bin, large bin이 있으며 small bin에서 특정 크기 이하 청크는 fast bin으로 관리된다. malloc 요청이 들어오면 먼저 tcache를 검색하고 없으면, unsorted bin을 찾으며 unsorted bin에도 없으면 fast, small, large bin순으로 크기 범위에 맞는 bin을 찾아 탐색한다. 이는 해제된 free 상태의 청크가 저장되는 순서와도 동일한데, free 함수로 할당 받은 청크를 해제하면 청크는 tcache에 우선적..

    [how2heap] Tcache House of Spirit (glibc 2.35)

    [how2heap] Tcache House of Spirit (glibc 2.35)

    house of spirit은 free 함수의 인자를 조작해 임의의 주소를 해제하여 해당 주소에 쓰기가 가능해지는 공격이다.free 함수의 인자를 조작할 수 있어야 하며 오버라이트 하고자 하는 타겟의 주소를 알아야 한다.해당 영역에 값을 쓸 수 있다면 스택 내에 존재하는 다른 지역변수나 리턴 주소를 조작할 수 있다.가상의 익스플로잇 시나리오를 만들어 보면1. 먼저 버퍼 등에 fake chunk header를 작성한다.(청크 구조를 고려해 0x8 또는 0x10단위로 작성)2. 최초 malloc 호출을 통해 힙 영역을 세팅한 뒤 free 함수로 buffer + 0x10을 해제힌다.  (0x10을 더하는 이유는 fake chunk header를 작성한 부분을 헤더로 인식하도록 하기 위함)3. 다시 malloc..