Wargame
cmd_center
앞선 문제도 그렇고, 조금 쉬어가는 코너 같은 느낌이다. (사실, 문제 파일이 있다는 것을 망각하고 무작정 서버에 접속해서 아무 명령어나 넣어보고 있었음... 근데 아무런 반응이 없어서 이런식으로 문제 만들면 어떻게 풀라고 하는거지라는 생각을 하며...) 우선 코드를 보자. #include #include #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { char cmd_ip[256] = "ifconfig"; int dummy; char center_name[24]; init(); printf("Center name: "); read(0, center_name, 100); if( ..
sint
#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() { char buf[256]; int size; initialize(); signal(SIGSEGV, get_shell); printf("Size: "); scanf("%d", &size); if (size > 256 || s..
tcache_dup2
문제 파일 압축을 풀어보면 이번에는 libc 버전이 2.30이다. 아래 링크에서 설명한 것과 같이 2.29 버전부터는 패치되어 다른 방법을 사용해야한다. https://wyv3rn.tistory.com/75 heap tcache poisoning & double free tcache libc > 2.25 이후부터 적용된 heap 관리 방법이며, 2.29부터는 패치 되었다. 사실 아래 내용 다 필요 없이 같은 공간에 free가 두번 들어가며, free 시 앞에 사용한 heap 영역의 주소를 가져오기 때문 wyv3rn.tistory.com 더불어 libc에 맞는 ld 파일을 찾아야하므로 아래 사이트에서 찾아보자. http://old-releases.ubuntu.com/ubuntu/pool/main/g/gli..
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); if(!ptr[cnt]) {..
Tcache Poisoning
// Name: tcache_poison.c // Compile: gcc -o tcache_poison tcache_poison.c -no-pie -Wl,-z,relro,-z,now #include #include #include int main() { void *chunk = NULL; unsigned int size; int idx; setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); while (1) { printf("1. Allocate\n"); printf("2. Free\n"); printf("3. Print\n"); printf("4. Edit\n"); scanf("%d", &idx); switch (idx) { case 1: printf("Size: ..
uaf_overwrite
// 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); } void menu() { printf("1. Human\n"); printf("..
basic_exploitation_003
#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_buf, 0x80..
basic_exploitation_002
#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); } 32 bit format string bug 문제이..
out_of_bound
#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(name)); p..
oneshot
// 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", stdout); pr..