[LOB] goblin -> orc

Posted by dw0rdptr
2015. 3. 21. 18:26 System/LOB
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
/*
        The Lord of the BOF : The Fellowship of the BOF
        - orc
        - egghunter
*/
 
#include <stdio.h>
#include <stdlib.h>
 
extern char **environ;
 
main(int argc, char *argv[])
{
    char buffer[40];
    int i;
 
    if(argc < 2){
        printf("argv error\n");
        exit(0);
    }
 
    // egghunter 
    for(i=0; environ[i]; i++)
        memset(environ[i], 0, strlen(environ[i]));
 
    if(argv[1][47!= '\xbf')
    {
        printf("stack is still your friend.\n");
        exit(0);
    }
 
    strcpy(buffer, argv[1]); 
    printf("%s\n", buffer);
}
cs

여러 제약조건이 추가되었다

1) egghunter 환경변수를 못씀

2) argv[1][47] 에 \xbf가 없으면 종료(ret 주소) -> 스택 내에 쉘코드삽입을 뜻함


gdb로 분석해보면


스택에 2c(44)바이트만큼의 공간이 할당되어있다.

메모리구조는

(row) | i[4] | buffer[40] | sfp[4] | ret[4] | (high)


strcpy 함수가 호출된 직후 브포를 걸어 buffer의 시작주소를 찾는다


NOP(19)+쉘코드(25)+버퍼의 시작주소(4)로 페이로드를 짜서 공격해봤다

Segmentation fault가 뜬다. 어떻게 된건지 찾아봤더니 gdb로 디버깅해서 나오는 주소값과 실제 프로그램상의 주소가 차이가 난다고 한다.

정확한 버퍼 주소를 알아보기 위해 orc.c 소스에서 printf("%s",buffer);를 %p로 바꿔 주소를 출력하게 했다.



페이로드와 Password


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

[LOB] wolfman -> darkelf  (0) 2015.03.25
[LOB] orc -> wolfman  (0) 2015.03.24
[LOB] cobolt -> goblin  (0) 2015.03.20
[LOB] gremlin -> cobolt  (0) 2015.03.18
[LOB] gate->gremlin  (0) 2015.03.17