본문 바로가기

Dreamhack/Wargame

(12)
[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); } ..
[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..
[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(..
[Wargame] hook 1. 실습 코드 // gcc -o init_fini_array init_fini_array.c -Wl,-z,norelro #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(60); } int main(int argc, char *argv[]) { long *ptr; size_t size; initialize(); printf("stdout: %p\n", stdout); prin..
[Wargame] oneshot 1. 실습 코드 // gcc -o oneshot1 oneshot1.c -fno-stack-protector -fPIC -pie #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(60); } int main(int argc, char *argv[]) { char msg[16]; size_t check = 0; initialize(); printf("stdout: %p\n", st..
[Wargame] fho 해당 문제는 강의에 기반한 문제로, 자세한 풀이는 아래 주소를 참고하세요. 2022.07.14 - [Dreamhack/Lecture & Practice] - [Practice] Hook Overwrite 1. 실습 코드 // Name: fho.c // Compile: gcc -o fho fho.c #include #include #include int main() { char buf[0x30]; unsigned long long *addr; unsigned long long value; setvbuf(stdin, 0, _IONBF, 0); setvbuf(stdout, 0, _IONBF, 0); puts("[1] Stack buffer overflow"); printf("Buf: "); read(0, bu..
[Wargame] basic_rop_x86 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); } int main(int argc, char *argv[]) { char buf[0x40] = {}; initialize(); read(0, buf, 0x400); write(1, buf, sizeof(buf)); return 0; } 2. 풀이 ① checksec을 이용하여, 메모리 보호기법을 확인한..