본문 바로가기

Dreamhack

(22)
[Wargame] uaf_overwrite 1. 실습 코드 C 코드, 바이너리 파일, libc-2.27.so가 주어진다. // 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() { printf("Name: %s\n", robot->name); } ..
[Practice] Use After Free 1. Use After Free (UAF) 해제된 메모리에 접근할 수 있는 취약점으로, 메모리에 남아있던 데이터를 유출하거나 사용할 수 있다. 참고 : 2022.08.20 - [Dreamhack/Lecture & Practice] - [Lecture] Use After Free 2. 실습 코드 // 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 ..
[Lecture] Use After Free 1. Use-After-Free 메모리 참조에 사용한 포인터를 메모리 해제 후, 제대로 초기화하지 않아 발생하는 취약점이다. 해제한 메모리를 초기화하지 않고 다음 청크에 재할당해주기 때문이다. 즉, 해제된 메모리에 접근할 수 있을 때, 발생하는 취약점이다. Chunk(청크) 란? • malloc에 메모리 할당을 요청하면, 넓은 메모리의 영역을 다양한 크기의 덩어리(chunk)로 나눈다. • chunk는 사용중인 덩어리, 해제된 덩어리, Top 덩어리, Last Remainder 덩어리가 있다. • 위에서 말하고 있는 청크는 "해제된 덩어리"로 응용프로그램에서 시스템에 반환한 덩어리를 의미하는 것이다. 2. Dangling Pointer 2-1. 정의 컴퓨터 과학에서 'Dangling Pointer'는 유..
[Practice] 64bit_FSB (Format String Bug) 1. Format String Bug (FSB) 포맷스트링을 사용하는 함수에서 발생할 수 있는 취약점이다. 리눅스 라이브러리 함수에서는 printf, fprintf, sprintf와 같은 함수들에서 발생한다. 참고 : 2022.08.10 - [Dreamhack/Lecture & Practice] - [Lecture] Format String Bug (FSB) 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 ..
[Wargame] basic_exploitation_003 1. 실습 코드 #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } void get_shell() { system("/bin/sh"); } int main(int argc, char *argv[]) { char *heap_buf = (char *)malloc(0x80); char stack_buf[0x90] = {}; initialize(); read(0, heap_..
[Wargame] basic_exploitation_002 1. 실습 코드 #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } void get_shell() { system("/bin/sh"); } int main(int argc, char *argv[]) { char buf[0x80]; initialize(); read(0, buf, 0x80); printf(buf); exit(0); } 2. 코드 분석 initialize..
[Lecture] Format String Bug (FSB) 1. 포맷 스트링 버그 (Format String Bug, FSB) 포맷 스트링을 인자로 사용하는 함수는 대표적으로 scanf, fprintf, fscanf, sprintf, sscanf가 있다. 포맷 스트링을 채울 값들은 레지스터나, 스택에서 가져온다. 하지만, 포맷 스트링을 사용하는 함수의 내부에는 필요로 하는 인자 개수와 함수에 전달된 인자의 개수를 비교하는 루틴이 존재하지 않는다. 포맷 스트링을 사용자가 입력할 수 있을 때, 공격자는 레지스터와 스택을 읽을 수 있고, 임의 주소 읽기 및 쓰기를 할 수 있다. 포맷 스트링 함수를 잘못 사용하여, 발생하는 버그를 "포맷 스트링 버그"라고 한다. 2. 레지스터 및 스택 읽기 2-1. 실습 코드 사용자가 임의의 포맷 스트링을 입력할 수 있는 코드이다. s..
[Wargame] out_of_bound 1. 실습 코드 #include #include #include #include #include char name[16]; char *command[10] = { "cat", "ls", "id", "ps", "file ./oob" }; void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } int main() { int idx; initialize(); printf("Admin name: "); read(0, name, sizeof(..