Wargame
send_sig
1. intro 2. code 및 분석 2.1 code 이번 문제는 코드가 별도로 제공되지 않고, 문제 파일과 dockerfile만 제공된다. 그래서 IDA로 디스어셈블 해보았다. void __noreturn start() { setvbuf(stdout, 0LL, 2, 0LL); setvbuf(stdin, 0LL, 1, 0LL); write(1, "++++++++++++++++++Welcome to dreamhack++++++++++++++++++\n", 0x39uLL); write(1, "+ You can send a signal to dreamhack server. +\n", 0x39uLL); write(1, "++++++++++++++++++++++++++++++++++++++++++++++++++..
SigReturn-Oriented Programming
1. intro 2. code 및 분석 2.1 code // Name: srop.c // Compile: gcc -o srop srop.c -fno-stack-protector -no-pie #include int gadget() { asm("pop %rax;" "syscall;" "ret" ); } int main() { char buf[16]; read(0, buf ,1024); } ┌──(kali㉿kali)-[~/Downloads] └─$ checksec srop [*] '/home/kali/Downloads/srop' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x40000..
rtld
1. intro 2. code 및 분석 2.1 code // gcc -o rtld rtld.c -fPIC -pie #include #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); } void get_shell() { system("/bin/sh"); } int main() { long addr; long value; initialize(); printf("stdout..
__environ
1. intro 2. code 및 분석 2.1 code // Name: environ.c // Compile: gcc -o environ environ.c #include #include #include #include #include void sig_handle() { exit(0); } void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); signal(SIGALRM, sig_handle); alarm(5); } void read_file() { char file_buf[4096]; int fd = open("/home/environ_exercise/flag", O_RDONLY); read(fd, file_buf, sizeof(file_bu..
Overwrite _rtld_global
1. intro 2. code 및 분석 2.1 code // Name: ow_rtld.c // Compile: gcc -o ow_rtld ow_rtld.c #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { long addr; long data; int idx; init(); printf("stdout: %p\n", stdout); while (1) { printf("> "); scanf("%d", &idx); switch (idx) { case 1: printf("addr: "); scanf("%ld", &addr); printf("data: "); scanf("%ld", &dat..
master_canary
1. intro 2. code 및 분석 2.1 code // gcc -o master master.c -pthread #include #include #include #include #include char *global_buffer; 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); } void get_shell() { system("/bin/sh"); } void *thread_routine() { char buf[256]; g..
Master Canary
1. intro 2. code & 분석 // Name: mc_thread.c // Compile: gcc -o mc_thread mc_thread.c -pthread -no-pie #include #include #include #include void giveshell() { execve("/bin/sh", 0, 0); } void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int read_bytes (char *buf, int len) { int idx = 0; int read_len = 0; for (idx = 0; idx < len; idx++) { int ret; ret = read(0, buf+idx, 1); if (ret <..
seccomp
// gcc -o seccomp seccomp.cq #include #include #include #include #include #include #include #include #include #include #include #include int mode = SECCOMP_MODE_STRICT; 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 syscall_filter() { #define syscall_nr (o..
Bypass SECCOMP-1
코드부터 보자. // Name: bypass_syscall.c // Compile: gcc -o bypass_syscall bypass_syscall.c -lseccomp #include #include #include #include #include #include #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } void sandbox() { scmp_filter_ctx ctx; ctx = seccomp_init(SCMP_ACT_ALLOW); if (ctx == NULL) { exit(0); } seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(open), 0); se..
validator
드디어 마지막 문제! 오랜만에 코드 없는 문제를 본다. 문제 파일을 다운로드 및 압축을 해제하면 두개의 파일이 나온다. 사실 코드가 없기에 ida와 같이 디스어셈블러 프로그램 사용법을 먼저 익힌 후 푸는 것이 맞는 것 같다. 사실 디스어셈블러 프로그램은 코드를 해석하기 편하게 만들어놓은 것이라 어셈블리어를 알고 있다면 굳이 사용할 필요는 없다. 개인적으로 어셈블리어 실력이 그렇게 좋지 않기 때문에, 핸드레이까지는 어렵고, 어느정도 해석만 가능한 수준이라 시간이 너무 오래 걸려 ida를 쓰기로 했다. 우선 varidator_dist 파일의 보안 기법을 확인. ┌──(kali㉿kali)-[~/Downloads] └─$ checksec validator_dist [*] '/home/kali/Downloads/..