protostar stack2

assb
|2020. 10. 29. 19:46

 문제를 실행하면 environment variable GREENIE를 설정해달라고 한다. 

 

 환경변수로 GREENIE를 생성하고 임의의 값을 대입한 후 실행하면 다시 시도하라고 뜬다.  

 

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

 

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

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

  variable = getenv("GREENIE");

  if(variable == NULL) {
      errx(1, "please set the GREENIE environment variable\n");
  }

  modified = 0;

  strcpy(buffer, variable);

  if(modified == 0x0d0a0d0a) {
      printf("you have correctly modified the variable\n");
  } else {
      printf("Try again, you got 0x%08x\n", modified);
  }

}

 위의 사이트에 들어가면 소스코드를 얻을 수 있다. 

 

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

 

 

 위에서 그린 스택 구조를 살펴보면 buffer 64byte 아래에 바로 modified가 존재한다. 따라서 64바이트 이상의 값을 대입하면 modified의 값을 변경할 수 있다. 문제를 해결하기 위해 환경변수를 임의의 64바이트와 "\x0d0a0d0a"로 설정해주면 문제가 해결된다. 

728x90

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

protostar stack4  (0) 2020.10.29
protostar stack3  (0) 2020.10.29
protostar stack1  (0) 2020.10.29
protostar stack0  (0) 2020.10.29
해커스쿨 FTZ level18  (0) 2020.10.29