달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

'nebula level04'에 해당되는 글 1

  1. 2017.07.15 [문제풀이] Nebula, Level00, Level01, Level02, Level03, Level04
본 문제에 대한 문제풀이를 하기 전에 간단히 워게임 특성을 말하자면~ 
이 워게임은 권한있는 사용자로 "/bin/getflag" 명령어를 실행하면 된다. 
(권한있는 사용자 ? flag00, flag01, .... flag19)

간단하지만 왜 설명하냐면, 나는 처음에 이해를 못했으니까 -ㅅ-
난 처음엔 다른 워겜처럼 다음 계정의 패스워드나 이런게 나올 줄 알았당.

그럼 롸이럽 시작해보도록 하겠다. 
간단한건 여러개 묶어서 간단하게 하고 넘어가겠다. 



※ LEVEL 00 

Q. This level requires you to find a Set User ID program that will run as the “flag00” account. You could also find this by carefully looking in top level directories in / for suspicious looking directories.

A. SetUID로 검색하던가 그냥 사용자로 검색하던가 편한대로 검색하면 된다. 

[그림 1] Level 00 미션 성공




※ Level 01 

Q. There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
 
int main(int argc, char **argv, char **envp)
{
  gid_t gid;
  uid_t uid;
  gid = getegid();
  uid = geteuid();
 
  setresgid(gid, gid, gid);
  setresuid(uid, uid, uid);
 
  system("/usr/bin/env echo and now what?");
}
cs



A. 심볼릭 링크를 걸고 PATH 환경 변수를 조작해주면 된다. 


[그림 2] flag01 파일 실행 시 


[그림 3] 심볼릭 링크 설정 


[그림 4] PATH 환경 변수 설정 후 문제 실행 





※ LEVEL 02


Q. There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
 
int main(int argc, char **argv, char **envp)
{
  char *buffer;
 
  gid_t gid;
  uid_t uid;
 
  gid = getegid();
  uid = geteuid();
 
  setresgid(gid, gid, gid);
  setresuid(uid, uid, uid);
 
  buffer = NULL;
 
  asprintf(&buffer, "/bin/echo %s is cool", getenv("USER"));
  printf("about to call system(\"%s\")\n", buffer);
  
  system(buffer);
}
cs


A. 환경변수를 통한 명령어 인젝션 공격이다. Let's inject !!


[그림 5] 인젝션 및 flag 획득





※ LEVEL 03


Q. Check the home directory of flag03 and take note of the files there. There is a crontab that is called every couple of minutes.


[그림 6] crontab 에 등록되어 있는 스크립트 


A. crontab에 flag03 사용자 권한으로 해당 쉘 스크립트를 동작시키는 작업이 스케쥴되어 있다는 문제다. 나는 나보고 돌리라는 줄 알고 -ㅅ-.. 삽질했넹 


[그림 7] 해당 경로에 스크립트 작성


[그림 8] 동작되는 스크립트 내용 


[그림 9] 스케줄링 된 작업이 동작하면서 획득한 플래그 




※ LEVEL 04


Q. This level requires you to read the token file, but the code restricts the files that can be read. Find a way to bypass it :)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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);
}
cs


A. 이 문제도 심볼릭 링크로 해결할 수 있다. 단 이번 문제는 token 파일에 들어있는 값을 flag04 계정의 패스워드로 활용하면 된다. 

[그림 10] 심볼릭 링크 후 플래그 획득 / 로그인 성공




이것으로 Level 00 ~ Level 04 까지의 문제풀이를 마치겠다. 


:
Posted by einai