본문 바로가기

Security/System Hacking42

[Dreamhack System Hacking] STAGE 12 - tcache_dup [혼자실습] tcache_dup // gcc -o tcache_dup tcache_dup.c -no-pie #include #include #include #include char *ptr[10]; void alarm_handler() { exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(60); } int create(int cnt) { int size; if(cnt > 10) { return -1; } printf("Size: "); scanf("%d", &size); ptr[cnt] = malloc(size.. 2022. 4. 5.
[Dreamhack System Hacking] STAGE 12 - tcache_dup2 [혼자실습] tcache_dup2 #include #include #include #include char *ptr[7]; void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); } void create_heap(int idx) { size_t size; if( idx >= 7 ) exit(0); printf("Size: "); scanf("%ld", &size); ptr[idx] = malloc(size); if(!ptr[idx]) exit(0); printf("Data: "); read(0, ptr[idx], size-1); } void modify_heap() { size_t size, idx; pr.. 2022. 4. 5.
[Dreamhack System Hacking] STAGE 12 - 함께실습 [Exploit Tech: Tcache Poisoning] 1. Tcache Poisoning 1) Tcache Poisoning - tcache를 조작하여 임의 주소에 청크를 할당시키는 공격 기법 - 중복으로 연결된 청크를 재할당하면, 그 청크가 해제된 청크인 동시에, 할당된 청크라는 특징을 이용한 공격 - 이런 중첩 상태를 이용하면, 임의 주소에 청크를 할당할 수 있으며, 그 청크를 이용하여 임의 주소의 데이터를 읽거나 조작할 수 있음 - 실습 코드 // Name: tcache_poison.c // Compile: gcc -o tcache_poison tcache_poison.c -no-pie -Wl,-z,relro,-z,now #include #include #include int main() { .. 2022. 4. 5.
[Dreamhack System Hacking] STAGE 12 Backgorund: ptmalloc2 1. ptmalloc2 1) ptmalloc2 (pthread malloc 2) - 리눅스에서 사용됨 - GLibc에 구현되어 있음 - 사용 목표 : 메모리의 효율적인 관리 ① 메모리 낭비 방지 ② 빠른 메모리 재사용 ③ 메모리 단편화 방지 2) 메모리 낭비 방지 - 메모리의 동적 할당과 해제는 매우 빈번하게 발생하지만 컴퓨터 전체 메모리는 한정적이므로 메모리를 무한히 할당할 수 없음 - 메모리 할당 요청이 발생 시, ptmalloc은 먼저 해제된 메모리 공간 중에서 재사용할 수 있는 공간이 있는지 탐색함 - 해제된 메모리 공간 중에서 요청된 크기와 같은 크기의 메모리 공간이 있다면 이를 그대로 재사용 3) 빠른 메모리 재사용 - 가상 메모리 공간은 매우 넓어, 특.. 2022. 4. 5.
[Dreamhack System Hacking] STAGE 11 - 함께실습 Exploit Tech : Use After Free 1. 서론 - UAF 취약점이 있는 코드를 사용해 공격하여 셸을 획득하는 실습 - 예제 코드 // Name: uaf_overwrite.c // Compile: gcc -o uaf_overwrite uaf_overwrite.c #include #include #include #include struct Human { char name[16]; int weight; long age; }; struct Robot { char name[16]; int weight; void (*fptr)(); }; struct Human *human; struct Robot *robot; char *custom[10]; int c_idx; void print_name() {.. 2022. 4. 1.
[Dreamhack System Hacking] STAGE 11 Memory Corruption : Use After Free 1. 서론 - Use After Free란? - 메모리 참조에 사용한 포인터를 메모리 해제 후에 적절히 초기화하지 않아서 발생하는 취약점 - 해제한 메모리를 초기화하지 않고 다음 청크에 재할당해주면서 발생하는 취약점 - ptmalloc2 함수를 이용하여 메모리 관리할 때 주의 필요 2. Use After Free 1) Dangling Pointer - 유효하지 않은 메모리 영역을 가리키는 포인터 - 해제된 메모리를 가리키고 있는 포인터 - UAF가 발생하는 원인이 될 수 있음 - 일반적으로 malloc 함수로 메모리를 할당하고 free 함수로 메모리를 해제하는데, free 함수는 청크를 ptmalloc에 반환하기만 할 뿐, 청크의 주소를 담고.. 2022. 4. 1.
[Dreamhack System Hacking] STAGE 10 - basic_exploitation_003 보호되어 있는 글 입니다. 2022. 2. 19.
[Dreamhack System Hacking] STAGE 10 - basic_exploitation_002 보호되어 있는 글 입니다. 2022. 2. 19.
[Dreamhack System Hacking] STAGE 10 - 함께실습 [함께실습] Exploit Tech: Format String Bug 1. Format String Bug 1) Format String Bug - printf 함수 등 포맷 스트링을 사용하는 모든 함수는 해당 버그가 발생할 수 있음 (fprintf, sprintf 등) 2) 예제 코드 - 목표 : changeme의 값을 1337로 바꾸기 // Name: fsb_overwrite.c // Compile: gcc -o fsb_overwrite fsb_overwrite.c #include #include #include void get_string(char *buf, size_t size) { ssize_t i = read(0, buf, size); if (i == -1) { perror("read"); e.. 2022. 2. 19.