System/FTZ
-
[FTZ Level19 풀이]System/FTZ 2018. 2. 17. 01:20
[Level19 Code]12345678#include void main(){ char buf[20]; gets(buf); printf("%s\n",buf);} cs코드는 굉장히 심플하다.gets( )에서 BOF취약점이 발생하니까, 이 점을 이용해서 RTL공격으로 쉘을 따도록 하겠다.RTL에 대해서는 블로그에 정리해두었으니, 참고하길 바란다.[RTL 정리글] RTL공격을 하기 위해서는 System( )주소, /bin/sh의 문자열 위치, RET까지의 offset을 구해야 한다.우선 attackme가 사용하는 libc버전을 확인해보자 [ldd attackme]ldd명령어로 libc버전이 /lib/tls에 위치한 so.6버전임을 알아냈다.libc버전을 알아냈으니 이제 System( )와 /bin/sh의 문자..
-
[FTZ Level18 풀이]System/FTZ 2018. 2. 17. 00:44
[Level18 Code]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include #include #include #include void shellout(void);int main(){ char string[100]; int check; int x = 0; int count = 0; fd_set fds; printf("Enter your command: "); fflush(stdout); while(1) { if(count >= 100) printf("what are you trying to do?\n"); if(check == 0xdeadbeef) shel..
-
[FTZ Level17 풀이]System/FTZ 2018. 2. 16. 20:20
[Level17 Code]123456789101112131415#include void printit() { printf("Hello there!\n");} main(){ int crap; void (*call)()=printit; char buf[20]; fgets(buf,48,stdin); setreuid(3098,3098); call();} csLevel16과 흡사한 문제지만, 이번에는 쉘을 실행시켜주는 함수가 없다.그래서 나는 EGGShell로 환경변수를 등록한 후, 환경변수의 주소를 Call( )에 넘겨주는 식으로 쉘을 땄다. [Eggshell Code]12345678910111213141516171819202122232425262728293031323334353637383940414243444..
-
[FTZ Level16 풀이]System/FTZ 2018. 2. 16. 20:06
[Level16 Code]12345678910111213141516171819#include void shell() { setreuid(3097,3097); system("/bin/sh");} void printit() { printf("Hello there!\n");} main(){ int crap; void (*call)()=printit; char buf[20]; fgets(buf,48,stdin); call();} cs코드를 보면 call( ) printit( )를 저장해서 call( )가 실행되면 printit( )함수가 실행되도록 되어있다.그리고 위에 shell( )는 쉘을 실행시켜준다. 따라서, 우리는 printif( )의 주소가 저장되는 스택에 shell( )의 주소를 저장해서call( )..
-
[FTZ Level15 풀이]System/FTZ 2018. 2. 16. 19:50
[Level15 Code]1234567891011121314#include main(){ int crap; int *check; char buf[20]; fgets(buf,45,stdin); if (*check==0xdeadbeef) { setreuid(3096,3096); system("/bin/sh"); }} cs 문제는 Level14와 매우 흡사하다.다른 점이 있다면, check변수가 포인터변수로 변했다는 점이 있다.어셈블리에서는 어떻게 달라졌는지 한번 보도록 하자 [Level15 Assemble] 보면, [EBP-16]공간에 있는 4Byte를 EAX에 저장하고 [EAX]에 있는 4Byte를 deadbeef와 비교한다. 여기서 우리가 주목해야 할 점은 [ ]의 의미이다.CMP부분에서 EAX의 대괄호..
-
[FTZ Level14 풀이]System/FTZ 2018. 2. 16. 02:07
[Level14 Code]123456789101112131415#include #include main(){ int crap; int check; char buf[20]; fgets(buf,45,stdin); if (check==0xdeadbeef) { setreuid(3095,3095); system("/bin/sh"); }} cs Level14번 문제는 fgets( )에서 취약점이 발생한다.buf의 크기는 20인데, 표준입력으로 45Byte만큼의 데이터를 버퍼에 저장하고 있다. 그리고 밑에 if문으로 check의 값이 [0xdeadbeef]로 변조될 시, system("/bin/sh")가 실행되는 것을 볼수 있다.따라서, 우리는 BOF로 check메모리를 deadbeef로 변조해주면 Level15권한..
-
[FTZ Level13 풀이]System/FTZ 2018. 2. 16. 01:21
[Level13 Code]1234567891011121314151617#include main(int argc, char *argv[]){ long i=0x1234567; char buf[1024]; setreuid( 3094, 3094 ); if(argc > 1) strcpy(buf,argv[1]); if(i != 0x1234567) { printf(" Warnning: Buffer Overflow !!! \n"); kill(0,11); }} Colored by Color Scriptercs Level13은 BOF공격을 좀 힘들게 만들어놨다.변수 i가 buf보다 먼저 선언되어 있으므로, 일반적인 BOF공격을 시도한다면 i의 저장되어 있는 값이 변조될 것이다. [Level13 Stack] buf[1024..
-
[FTZ Level12 풀이]System/FTZ 2018. 2. 15. 23:49
[Level12 Code]1234567891011121314#include #include #include int main( void ){ char str[256]; setreuid( 3093, 3093 ); printf( "문자열을 입력하시오.\n" ); gets( str ); printf( "%s\n", str );} cs 해당 문제는 Level11과 비슷하지만, printf( )의 FSB 취약점이 사라졌고 gets( )함수로 입력을 받는다. 나는 이번 문제를 RTL을 이용해서 풀어봤다.RTL정리 : [이곳] #공격 시나리오1. EIP까지의 offset을 구한다. 2. System( )의 주소를 구한다. 3. /bin/sh문자열의 주소를 구한다. 4. RET공간에 System( )주소를 저장해서 Sy..