CTF/Solved

TJCTF 2023 - pwn/flip-out

wyv3rn 2023. 5. 29. 11:56
728x90
반응형

1. intro

2. code 및 분석

2.1.  code

int __cdecl main(int argc, const char **argv, const char **envp)
{
  int result; // eax
  int v4; // [rsp+4h] [rbp-BCh]
  FILE *stream; // [rsp+8h] [rbp-B8h]
  char nptr[48]; // [rsp+10h] [rbp-B0h] BYREF
  __int64 v7; // [rsp+40h] [rbp-80h]
  __int64 v8; // [rsp+48h] [rbp-78h]
  __int64 v9; // [rsp+50h] [rbp-70h]
  __int64 v10; // [rsp+58h] [rbp-68h]
  __int64 v11; // [rsp+60h] [rbp-60h]
  __int64 v12; // [rsp+68h] [rbp-58h]
  __int64 v13; // [rsp+70h] [rbp-50h]
  __int64 v14; // [rsp+78h] [rbp-48h]
  __int64 v15; // [rsp+80h] [rbp-40h]
  __int64 v16; // [rsp+88h] [rbp-38h]
  __int64 v17; // [rsp+90h] [rbp-30h] BYREF
  char v18[9]; // [rsp+98h] [rbp-28h]
  __int64 v19; // [rsp+A1h] [rbp-1Fh]
  unsigned __int64 v20; // [rsp+B8h] [rbp-8h]

  v20 = __readfsqword(0x28u);
  setbuf(_bss_start, 0LL);
  strcpy(nptr, "Nothing to see here... Nothing to see here...");
  v7 = 0LL;
  v8 = 0LL;
  v9 = 0LL;
  v10 = 0LL;
  v11 = 0LL;
  v12 = 0LL;
  v13 = 0LL;
  v14 = 0LL;
  v15 = 0LL;
  v16 = 0LL;
  v17 = 0LL;
  v18[0] = 0;
  *(_QWORD *)&v18[1] = 0LL;
  v19 = 0LL;
  stream = fopen("flag.txt", "r");
  if ( stream )
  {
    fgets((char *)&v17, 25, stream);
    fclose(stream);
    printf("Input: ");
    __isoc99_scanf("%15s", nptr);
    v4 = atoi(nptr);
    if ( v4 <= 128 )
      printf("%s", &nptr[(unsigned __int8)v4]);
    result = 0;
  }
  else
  {
    printf("Cannot find flag.txt.");
    result = 1;
  }
  return result;
}

2.2. 분석

입력 값을 정수로 변환하고, 0x80이면 플래그를 출력해준다.

 

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

3.1. 취약점

걍 플래그 출력기임 ㄷㄷㄷ

3.2. 공격 준비

준비할게 없...

 

4. exploit

접속 후 128을 입력하면 플래그가 따단.

728x90
반응형