ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [HackerSchool] Level3
    오래된/HackerSchool 2011. 4. 26. 08:45

    [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 hint ]
    이전과 같이 find 명령을 이용하여 autodig 파일을 찾거나, whereis 명령을 이용해서 파일을 찾는다.

    [level3@ftz level3]$ whereis find
    find: /usr/bin/find /usr/share/man/man1/find.1.gz
    [ find 명령 검색 ]

    1. WHEREIS

    PATH 환경변수에 등록된 디렉토리에서 파일을 찾을 때에는 find 명령보다 whereis 명령이 유용하다.

    http://www.google.com/cse?cx=partner-pub-6915143203050178%3A3221174078&ie=UTF-8&q=whereis

    2. STRCAT

    C언어 함수로 왼쪽 변수에 문자열 끝에 오른쪽 변수의 값을 추가하여 기록 한다.

    char buf[] = "12345" => [ 1 2 3 4 5 ]
    strcat( buf, "6789a" ) =>[ 1 2 3 4 5 6 7 8 9 a ]

    http://www.google.com/cse?cx=partner-pub-6915143203050178%3A3221174078&ie=UTF-8&q=strcat

    3. SYSTEM

    리눅스 명령을 실행 시킬 수 있게 해주는 C 언어 함수.

    http://www.google.com/cse?cx=partner-pub-6915143203050178%3A3221174078&ie=UTF-8&q=system

    system( "ls" );

    4. 문제 해설

    이번 문제는 autodig 프로그램 내부에 존재하는 취약점으로 인한 권한 상승 문제 이다.

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

    system( cmd );
    [ autodig 소스에서 문제가 되는 부분 ]

    문제는 프로그램 인자로 입력 받은 값을 그대로 cmd 변수에 넣어 실행 하는데에 있다.
    메모리 내용을 예상해보면 다음과 같을 것이다.

    [ dig @ argv[1] version.bind chaos txt ]

    system 함수는 리눅스 명령을 실행 시켜준다고 위에서 설명 했었는데, 위를 보면 우리가 입력한 인자값이 그대로 cmd 변수에
    들어가 system 함수에 의해 실행되고 있으므로, 인자값에 우리가 실행 시키고자 하는 명령을 넣으면 되는데,
    문제는 앞의 명령과 뒤의 명령을 구분지어 주는 특수한 문자가 필요하다는 것이다.

    즉, dig @ 을 실행 시키고 argv[1] 을 실행시키고 version.bind chaos txt 를 실행 시키도록 하는 방법을 찾아내면 되겠다.

    '오래된 > HackerSchool' 카테고리의 다른 글

    [HackerSchool] Level6  (0) 2011.04.27
    [HackerSchool] Level5  (0) 2011.04.27
    [HackerSchool] Level4  (0) 2011.04.27
    [HackerSchool] Level2  (0) 2011.04.26
    [HackerSchool] Level1  (0) 2011.04.26

    댓글

Designed by Tistory.