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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
        The Lord of the BOF : The Fellowship of the BOF
        - succubus
        - calling functions continuously
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <dumpcode.h>
 
// the inspector
int check = 0;
 
void MO(char *cmd)
{
        if(check != 4)
                exit(0);
 
        printf("welcome to the MO!\n");
 
        // olleh!
        system(cmd);
}
 
void YUT(void)
{
        if(check != 3)
                exit(0);
 
        printf("welcome to the YUT!\n");
        check = 4;
}
 
void GUL(void)
{
        if(check != 2)
                exit(0);
 
        printf("welcome to the GUL!\n");
        check = 3;
}
 
void GYE(void)
{
        if(check != 1)
                exit(0);
 
        printf("welcome to the GYE!\n");
        check = 2;
}
 
void DO(void)
{
        printf("welcome to the DO!\n");
        check = 1;
}
 
main(int argc, char *argv[])
{
        char buffer[40];
        char *addr;
 
        if(argc < 2){
                printf("argv error\n");
                exit(0);
        }
 
        // you cannot use library
        if(strchr(argv[1], '\x40')){
                printf("You cannot use library\n");
                exit(0);
        }
 
        // check address
        addr = (char *)&DO;
        if(memcmp(argv[1]+44&addr, 4!= 0){
                printf("You must fall in love with DO\n");
                exit(0);
        }
 
        // overflow!
        strcpy(buffer, argv[1]);
        printf("%s\n", buffer);
 
        // stack destroyer
        // 100 : extra space for copied argv[1]
        memset(buffer, 044);
        memset(buffer+48+10000xbfffffff - (int)(buffer+48+100));
 
        // LD_* eraser
        // 40 : extra space for memset function
        memset(buffer-300003000-40);
}
cs


소스가 너무 길어서 캡처하기 힘들어 긁어왔다.

딱봐도 함수 Chaining을 이용해 

DO - GYE - GUL - YUT - MO 순서로 함수를 실행시킨 뒤

MO 함수의 인자로 "/bin/sh"를 집어넣으라는 의미인 것 같다.



우선 GDB로 함수의 주소를 각각 구했고


(클릭하면 커집니다)

인자로 아무 값이나 주고 뒤에 /bin/sh 문자열을 넣어 주었다.



덤프된 코어 파일을 확인해 보니 /bin/sh 문자열의 주소는 0xbffffaac이다.



그대로 바꿔 주면 정상적으로 들어가고, 쉘을 딸 수 있다.

'Wargame > Lord of Buffer overflow' 카테고리의 다른 글

LOB Redhat : assassin > zombie_assassin  (0) 2015.11.16
LOB Redhat : giant > assassin  (0) 2015.11.03
LOB Redhat : bugbear > giant  (0) 2015.11.03
LOB Redhat : darkknight > bugbear  (0) 2015.11.02
LOB Redhat : golem > darkknight  (0) 2015.10.17
블로그 이미지

__미니__

E-mail : skyclad0x7b7@gmail.com 나와 계약해서 슈퍼 하-카가 되어 주지 않을래?

,