[문제풀이] Nebula, Level00, Level01, Level02, Level03, Level04 Wargames/e-exercises.com2017. 7. 15. 14:48
[그림 1] Level 00 미션 성공
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 |
[그림 10] 심볼릭 링크 후 플래그 획득 / 로그인 성공
'Wargames > e-exercises.com' 카테고리의 다른 글
[문제풀이] Nebula, Level15 (0) | 2017.07.25 |
---|---|
[문제풀이] Nebula, Level13, Level14 (0) | 2017.07.23 |
[문제풀이] Nebula, Level11, Level12 (0) | 2017.07.21 |
[문제풀이] Nebula, Level09, Level10 (0) | 2017.07.19 |
[문제풀이] Nebula, Level05, Level06, Level07, Level08 (0) | 2017.07.16 |