61
Memory Protection Mechanism of Linux TEAM PWN&PLAY YIS of KSIA 김김김 [email protected] fb.com/xodnr631

Memory Protection Mechanism of Linux

  • Upload
    kaiser

  • View
    61

  • Download
    7

Embed Size (px)

DESCRIPTION

Memory Protection Mechanism of Linux. TEAM PWN&PLAY YIS of KSIA 김태욱 [email protected] fb.com/xodnr631. YIS. TEAM PWN&PLAY. SYSTEM HACKING. Memory Protection Mechanism of Linux. Buffer Overflow (1). 사용자가 입력한 데이터의 크기가 너무 과하여 제한된 버퍼의 용량을 넘쳐버렸을때 생기는 버그를 이용해 해킹하는 기술 - PowerPoint PPT Presentation

Citation preview

Page 1: Memory Protection Mechanism  of Linux

Memory Protection Mechanism of Linux

TEAM PWN&PLAYYIS of KSIA

김태욱[email protected]

comfb.com/xodnr631

Page 2: Memory Protection Mechanism  of Linux

YIS

Page 3: Memory Protection Mechanism  of Linux

TEAM PWN&PLAY

Page 4: Memory Protection Mechanism  of Linux

SYSTEM HACKINGMemory Protection Mechanismof Linux

Page 5: Memory Protection Mechanism  of Linux

Buffer Overflow (1)

• 사용자가 입력한 데이터의 크기가 너무 과하여 제한된 버퍼의 용량을 넘쳐버렸을때 생기는 버그를 이용해 해킹하는 기술

• 버퍼 : 컴퓨터의 주기억 장치와 주변장치 사이에서 데이터를 주고받을때 정보를 임시로 기억해두는 임시저장공간

Page 6: Memory Protection Mechanism  of Linux

Buffer Overflow (1)

• 사용자가 입력한 데이터의 크기가 너무 과하여 제한된 버퍼의 용량을 넘쳐버렸을때 생기는 버그를 이용해 해킹하는 기술

• 버퍼 : 컴퓨터의 주기억 장치와 주변장치 사이에서 데이터를 주고받을때 정보를 임시로 기억해두는 임시저장공간

Page 7: Memory Protection Mechanism  of Linux

Buffer Overflow (2)

낮은 주소

CODE 컴파일 된 기계어 코드

DATA 전역 / 정적 및 각종 변수

HEAP 프로그래머가 직접 할당한 공간

STACK 지역 변수 , 함수 인자 , 환경 변수

높은 주소

Page 8: Memory Protection Mechanism  of Linux

Buffer Overflow (2)

낮은 주소

CODE 컴파일 된 기계어 코드

DATA 전역 / 정적 및 각종 변수

HEAP 프로그래머가 직접 할당한 공간

STACK 지역 변수 , 함수 인자 , 환경 변수

높은 주소

Page 9: Memory Protection Mechanism  of Linux

Buffer Overflow (3)

BUFFER SFP RET

BUFFER – SFP – RET – Argc/Argv – 환경변수 - 파일명

Page 10: Memory Protection Mechanism  of Linux

Buffer Overflow (3)

BUFFER SFP RET

BUFFER – SFP – RET – Argc/Argv – 환경변수 - 파일명

A A A A A A A A A A A A A A A A A A A

Page 11: Memory Protection Mechanism  of Linux

Stack

낮은 주소

CODE 컴파일 된 기계어 코드

DATA 전역 / 정적 및 각종 변수

HEAP 프로그래머가 직접 할당한 공간

STACK 지역 변수 , 함수 인자 , 환경 변수

높은 주소

Page 12: Memory Protection Mechanism  of Linux

Stack

낮은 주소

CODE 컴파일 된 기계어 코드

DATA 전역 / 정적 및 각종 변수

HEAP 프로그래머가 직접 할당한 공간

STACK 지역 변수 , 함수 인자 , 환경 변수

높은 주소

유저영역

Page 13: Memory Protection Mechanism  of Linux

Memory

커널 유저HIGH LOW

Page 14: Memory Protection Mechanism  of Linux

Memory

커널 유저HIGH LOW

STACK | HEAP | DATA | CODE

Page 15: Memory Protection Mechanism  of Linux

Buffer Overflow (5)

<BOF 문제풀이 유형 >

Page 16: Memory Protection Mechanism  of Linux

Buffer Overflow (5)int main(int argc, char *argv[]){    char buffer[256];    if(argc < 2){        printf("argv error\n”);        exit(0);    }    strcpy(buffer, argv[1]);    printf("%s\n", buffer);}

Page 17: Memory Protection Mechanism  of Linux

Buffer Overflow (5)

Page 18: Memory Protection Mechanism  of Linux

Buffer Overflow (5)int main(){    char buffer[16];    gets(buffer);    printf("%s\n", buffer);}

Page 19: Memory Protection Mechanism  of Linux

Buffer Overflow (5)      // here is changed! // egghunter for(i=0; environ[i]; i++) memset(environ[i], 0,

strlen(environ[i]));

Page 20: Memory Protection Mechanism  of Linux

Buffer Overflow (5)        // here is changed!        if(strlen(argv[0]) != 77){                printf("argv[0] error\n");                 exit(0);        }

Page 21: Memory Protection Mechanism  of Linux

BUT

Page 22: Memory Protection Mechanism  of Linux
Page 23: Memory Protection Mechanism  of Linux
Page 24: Memory Protection Mechanism  of Linux
Page 25: Memory Protection Mechanism  of Linux
Page 26: Memory Protection Mechanism  of Linux
Page 27: Memory Protection Mechanism  of Linux

Memory Protection (1)DEP(Data Execution Prevention)

Page 28: Memory Protection Mechanism  of Linux

Memory Protection (1)DEP(Data Execution Prevention)

STACKBUFFER SFP RET 인자 환경변수 파일명

Page 29: Memory Protection Mechanism  of Linux

Memory Protection (1)DEP(Data Execution Prevention)

STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 30: Memory Protection Mechanism  of Linux

Memory Protection (1)DEP(Data Execution Prevention)

STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 31: Memory Protection Mechanism  of Linux

Memory Protection (1)RTL(Return-to-libc)

STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 32: Memory Protection Mechanism  of Linux

Memory Protection (1)

RTL(Return-to-libc)

BUFFER SFP RET

A A A A A A A A A A A A A A A A A A A

Page 33: Memory Protection Mechanism  of Linux

Memory Protection (1)RTL(Return-to-libc)

BUFFER SFP RET

A A A A A A A A A A A A A A A A A A A

&system() &execl() &/bin/sh

Page 34: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)

Page 35: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACK

Page 36: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 37: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 38: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 39: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 40: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 41: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 42: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 43: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커

Page 44: Memory Protection Mechanism  of Linux

Memory Protection (2)ASLR(Address Space Layout Random-

ization)STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

난짱해커똑같은주소

Page 45: Memory Protection Mechanism  of Linux
Page 46: Memory Protection Mechanism  of Linux

↑ 계속해서 바뀌는 주소↑ 고정 된 주소

Page 47: Memory Protection Mechanism  of Linux

↑ 계속해서 바뀌는 주소↑ 고정 된 주소

Page 48: Memory Protection Mechanism  of Linux

Memory Protection (3)ASCII Armor

Page 49: Memory Protection Mechanism  of Linux

Memory Protection (3)ASCII Armor

STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 50: Memory Protection Mechanism  of Linux

Memory Protection (3)ASCII Armor

STACKBUFFER SFP RET 인자 환경변수 파일명

LOW HIGH

Page 51: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

BUFFER SFP RET

Page 52: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

BUFFER SFP CANARY RET

Page 53: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

BUFFER SFP CANARY RET

A A A A A A A A A A ? ! # $ A A A A A

Page 54: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

CANARY RANDOM

Page 55: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

CANARY RANDOM

TERMINATOR

Page 56: Memory Protection Mechanism  of Linux

Memory Protection (4)Canary

CANARY RANDOM

TERMINATOR

NULL

Page 57: Memory Protection Mechanism  of Linux

DEP

Page 58: Memory Protection Mechanism  of Linux

DEP + ASLR

Page 59: Memory Protection Mechanism  of Linux

DEP + ASLR+ ASCII Armor

Page 60: Memory Protection Mechanism  of Linux

DEP + ASLR+ ASCII Ar-mor+ Canary

Page 61: Memory Protection Mechanism  of Linux