protostar stack3

assb
|2020. 10. 29. 19:52

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

 

Stack 3 - LiveOverflow

This video introduces http://exploit-exercises.com, how to connect to the VM with ssh and explains what setuid binaries are.

old.liveoverflow.com

 

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

void win()
{
  printf("code flow successfully changed\n");
}

int main(int argc, char **argv)
{
  volatile int (*fp)();
  char buffer[64];

  fp = 0;

  gets(buffer);

  if(fp) {
      printf("calling function pointer, jumping to 0x%08x\n", fp);
      fp();
  }
}

 소스코드는 위의 사이트에서 얻을 수 있다. buffer을 입력받으며 fp 변수를 위조해 win 함수를 호출해야 한다. 

 

 

 프로그램을 gdb로 실행하여 stack 구조를 그려보았다. 

 

 buffer과 fp 사이의 간격을 확인했으니 다음은 win 함수의 시작 주소를 확인했다. 

 

 임의의 64바이트와 win 함수의 주소인 "\x08048424"를 입력하면 win 함수가 호출되며 문제가 해결된다. 

728x90

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

protostar stack5  (0) 2020.10.29
protostar stack4  (0) 2020.10.29
protostar stack2  (0) 2020.10.29
protostar stack1  (0) 2020.10.29
protostar stack0  (0) 2020.10.29