protostar stack4

assb
|2020. 10. 29. 19:53

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

 

Stack 4 - 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)
{
  char buffer[64];

  gets(buffer);
}

 stack4의 소스코드이다. buffer 값을 입력받는데, 다른 변수는 존재하지 않는다. 따라서 return address를 변조시켜서 win 함수를 실행해야 한다. 

 

 

 gdb로 프로그램을 분석하여 이를 기반으로 stack 구조를 그려보았다. 64byte의 buffer과 8byte의 dummy, ebp, 그리고 그 아래에 return address가 존재한다. 따라서 buffer을 overflow 시켜서 return address를 변조해야 한다. 

 

2020/10/29 - [CTF/시스템] - protostar stack0

 

protostar stack0

old.liveoverflow.com/binary_hacking/protostar/stack0.html Stack 0 - LiveOverflow Bruteforcing stack canary, stack guard, stack cookie with a C program. old.liveoverflow.com #include #include #includ..

assb.tistory.com

 

 dummy는 <main+3>에서 esp에 and 연산을 하면서 생긴다. 

 

 따라서 64byte+8byte(dummy)+4byte(ebp)+4byte(return address) 형식으로 채워주면 된다. 이때 return address는 win의 주소를 넣어준다. 

 

 win 함수의 주소를 기억한다. 

 

 임의의 76byte(buffer+dummy+ebp)와 win 주소를 입력하면 문제를 해결할 수 있다. 

728x90

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

protostar stack6  (0) 2020.10.29
protostar stack5  (0) 2020.10.29
protostar stack3  (0) 2020.10.29
protostar stack2  (0) 2020.10.29
protostar stack1  (0) 2020.10.29