protostar stack7

assb
|2020. 10. 29. 19:56

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

 

Stack 7 - 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>

char *getpath()
{
  char buffer[64];
  unsigned int ret;

  printf("input path please: "); fflush(stdout);

  gets(buffer);

  ret = __builtin_return_address(0);

  if((ret & 0xb0000000) == 0xb0000000) {
      printf("bzzzt (%p)
", ret);
      _exit(1);
  }

  printf("got path %s
", buffer);
  return strdup(buffer);
}

int main(int argc, char **argv)
{

  getpath();

}

 이 문제는 stack6 문제와 유사하다. 소스코드를 살펴보면 main에서 getpath 함수를 호출한다. getpath 함수에서는 buffer 변수를 오버플로우 시켜야 하는데, 이때 주의해야 할 점은 ret 값이다. __builtin_return_address(0)을 사용하면 현재 함수의 리턴 주소를 가져올 수 있다. ret & 0xb0000000이 0xb0000000일 경우 함수가 종료되는데, 이는 리턴주소가 b로 시작하지 않음을 의미한다. 

 

 stack6에서 사용한 ret2libc는 system 함수가 b로 시작한다. 따라서 ret2libc 대신 다른 방법을 사용해야 한다. 이번 경우에는 ROP를 사용했다. 

 

 objdump을 사용해서 gadget에서 ret를 찾아줬다. 

 

 stack7의 스택 구조는 stack6과 동일하다. 

 

 쉘 코드를 환경변수로 설정하고, 해당 환경변수의 주소를 구한다. 

 

 위에서 얻은 두 주소를 기억해서 80byte dummy + ret + env address를 입력하면 문제를 해결할 수 있다.

(python -c 'print "A"*80+ret+"\x90"*4+env address';cat)|./stack6

 

 

728x90

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

protostar format1  (0) 2020.11.05
protostar format0  (0) 2020.11.01
protostar stack6  (0) 2020.10.29
protostar stack5  (0) 2020.10.29
protostar stack4  (0) 2020.10.29