System Hacking - format_pistol

2023. 7. 1. 15:41·Wargame/H4C
728x90
반응형

1. intro

2. code 및 분석

2.1.  code

init

int init()
{
  int result; // eax
  int fd; // [rsp+8h] [rbp-8h]

  result = open("/dev/null", 1);
  fd = result;
  if ( result != -1 )
  {
    result = dup2(result, 1);
    if ( result != -1 )
    {
      result = dup2(fd, 2);
      if ( result != -1 )
        result = close(fd);
    }
  }
  return result;
}

format_f

unsigned __int64 format_f()
{
  char format[56]; // [rsp+10h] [rbp-40h] BYREF
  unsigned __int64 v2; // [rsp+48h] [rbp-8h]
  void *retaddr; // [rsp+58h] [rbp+8h]

  v2 = __readfsqword(0x28u);
  LODWORD(retaddr) = 0;
  __isoc99_scanf("%16s", format);
  printf(format);
  return __readfsqword(0x28u) ^ v2;
}

2.2. 분석

init 함수에서는 표준 출력과 표준 에러를 /dev/null으로 돌려버린다.

즉 아무것도 출력이 안된다는 소리.

format_f 함수에서는 16글자를 받아 출력하는데 여기서 포맷스트링이 발생한다.

다만 format_f 함수에서 main으로 돌아오는 return address의 뒷부분 4 byte를 0으로 날려버리기에 무조건 seg.fault가 발생한다.

 

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

3.1. 취약점

format string bug

3.2. 공격 준비

format string bug의 새로운 점을 배울 수 있었던 문제.

머릿속으로만 특정 값을 스택이나 메모리에서 가져와서 %n의 인자(?)로 쓸 수 없나? 하는 고민을 많이 했는데

역시나 있었다.

이는 별도로 정리해둬야겠다.

더불어 표준 출력을 날려버리기에 shell을 획득한 이후에도 이 설정이 유지되어 아무것도 출력되지 않는데,

리눅스 명령어가 약해서 이를 어떻게 출력할 수 있을지 다소 고민했다.

 

솔직히 H4C pwnable 문제 중에 제일 배울 것이 있었던 문제였지 않나 생각한다.

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

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

System Hacking - Simple_VM  (0) 2023.07.01
System Hacking - Notepad  (0) 2023.07.01
System Hacking - apple pie  (0) 2023.07.01
System Hacking - bof  (0) 2023.07.01
System Hacking - Qualification  (0) 2023.07.01
'Wargame/H4C' 카테고리의 다른 글
  • System Hacking - Simple_VM
  • System Hacking - Notepad
  • System Hacking - apple pie
  • System Hacking - bof
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (502) N
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (79) N
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • 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)
        • Solved (39)
        • Unsolved (2)
      • Script (0)
      • RubiyaLap (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

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

  • 태그

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

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
System Hacking - format_pistol
상단으로

티스토리툴바