본문 바로가기

Wargame/Exploit Exercises Nebula

Exploit Exercises Nebula Level04

https://exploit-exercises.com/nebula/level04/

level04 문제이다. 해당 링크에서 문제를 확인해보자.



token 파일을 읽어라. 하지만 코드상으로 token을 읽을 수 없다. 우회를 해라.

ID : level04 P/W : level04 로 로그인하여라. /home/flag04 에 필요한 파일들이 있다.



로그인 후에 /home/flag04 디렉토리를 확인해보면 

flag04 라는 실행 파일과 token 이라는 텍스트 파일이 존재한다.

flag04 파일은 stickybit가 권한이 설정되어 있고, token 파일은 권한이 없어 읽을 수 없다.


level4.c

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys types.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc, char **argv, char **envp)
{
  char buf[1024];
  int fd, rc;

  if(argc == 1) {
      printf("%s [file to read]\n", argv[0]);
      exit(EXIT_FAILURE);
  }

  if(strstr(argv[1], "token") != NULL) {
      printf("You may not access '%s'\n", argv[1]);
      exit(EXIT_FAILURE);
  }

  fd = open(argv[1], O_RDONLY);
  if(fd == -1) {
      err(EXIT_FAILURE, "Unable to open %s", argv[1]);
  }

  rc = read(fd, buf, sizeof(buf));
  
  if(rc == -1) {
      err(EXIT_FAILURE, "Unable to read fd %d", fd);
  }

  write(1, buf, rc);
}

level4의 문제 소스코드이다.

13번 코드를 확인하면 argv[1] 인자 값은 하나이어야만 한다.

18번 코드를 확인하면 token이라는 문자열이 들어갈 경우 에러메세지를 출력한다.

이후 파일을 불러와 읽은 후에 화면에 읽은 파일을 출력한다.


문제를 해결하기 위해서 token 파일을 우회하여 읽어야 한다.

하지만 권한이 없어 cp 명령어로 token 파일을 복사할 수도 없다.


그렇기 때문에 심볼릭 링크로 해당 파일의 바로가기 파일을 

/tmp 디렉토리에 생성하여 우회하면 된다. ※ 단, token 파일을 절대 경로로 작성해주어야한다.



위의 사진과 같이 명령어를 입력하면 된다.

'Wargame > Exploit Exercises Nebula' 카테고리의 다른 글

Exploit Exercises Nebula Level03  (0) 2017.04.01
Exploit Exercises Nebula Level02  (0) 2017.03.31
Exploit Exercises Nebula Level01  (0) 2017.02.08
Exploit Exercises Nebula Level00  (0) 2016.12.29