본문 바로가기

system

[ftz]level9 풀이

level9, apple

 

[level9@ftz level9]$ ls
hint  public_html  tmp
[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의 권한을 얻어라.

 

buf가 40을 넘으면,

buf2 값을 go로 바꾸고 system명령어를 통해

쉘을 실행시키는 명령어를 진행함을 알 수 있다.

 

 

해당 경로로 가서 보니,

level9는 실행만 가능함을 알 수 있다.

우리는 gdb로 분석해볼 것이니, 코드를 복사해서 만들어보자.

 

[level9@ftz bin]$ cd /tmp
[level9@ftz tmp]$ cat > bof.c
#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");
   }

}

[level9@ftz tmp]$

 

bof.c를 만들어준다.

 

[level9@ftz tmp]$ gcc -o bof bof.c
[level9@ftz tmp]$ gdb bof
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) disas main
Dump of assembler code for function main:
0x08048420 <main+0>:    push   %ebp
0x08048421 <main+1>:    mov    %esp,%ebp
0x08048423 <main+3>:    sub    $0x28,%esp
0x08048426 <main+6>:    and    $0xfffffff0,%esp
0x08048429 <main+9>:    mov    $0x0,%eax
0x0804842e <main+14>:   sub    %eax,%esp
0x08048430 <main+16>:   sub    $0xc,%esp
0x08048433 <main+19>:   push   $0x8048554
0x08048438 <main+24>:   call   0x8048350 <printf>
0x0804843d <main+29>:   add    $0x10,%esp
0x08048440 <main+32>:   sub    $0x4,%esp
0x08048443 <main+35>:   pushl  0x8049698
0x08048449 <main+41>:   push   $0x28
0x0804844b <main+43>:   lea    0xffffffd8(%ebp),%eax
0x0804844e <main+46>:   push   %eax
0x0804844f <main+47>:   call   0x8048320 <fgets>
0x08048454 <main+52>:   add    $0x10,%esp
0x08048457 <main+55>:   sub    $0x4,%esp
0x0804845a <main+58>:   push   $0x2
0x0804845c <main+60>:   push   $0x804856a
0x08048461 <main+65>:   lea    0xffffffe8(%ebp),%eax
0x08048464 <main+68>:   push   %eax

 

gcc를 통해 bof.c를 컴파일해주고

gdb를 실행해준다.

 

  fgets(buf,40,stdin);

  if ( strncmp(buf2, "go", 2) == 0 )
   {
        printf("Good Skill!\n");
        setreuid( 3010, 3010 );
        system("/bin/bash");
   }

 

코드를 한번 더 보면,

strncmp나 fgets나 모두 비교함으로써 넘어갈 듯 하다.

 

 

비교함으로써 단계가 진행됨을 알 수 있다.

 

 

비교하는 부분을 비교하면 16바이트만큼 차이남을 알 수 있다.

 

 

버퍼 오버플로우를 하고,

쉘이 실행됨을 알 수 있다.

 

my-pass로 비밀번호를 조회할 수 있다.

반응형

'system' 카테고리의 다른 글

[ftz]level7 풀이  (0) 2021.02.06
[ftz]level8 풀이, john the ripper 사용법  (0) 2021.02.04
[ftz]level6 풀이  (0) 2021.02.02
ftz level5  (0) 2021.01.28
ftz level4  (0) 2021.01.19