use after free 라는 취약점은 프로그램 메모리는 크게 Code/Data/Heap/Stack으로 나눌 수 있는데 Code+Data=Binary영역 Heap=프로그래머가 동적 할당/회수/제어 할 수 있는 영역 Stack=함수 개별공간(스택프레임),인자전달등으로 사용하는 영역 이렇게 구분할 수 있다 이 중에서 UAF는 프로그래머가 힙 영역을 잘못 다뤘을 때 발생하는 취약점이다.


아래의 소스를 보자


#include <stdio.h>

#include <stdlib.h>


typedef struct UAF

{

int number;

}uaf;


int main(void)

{

uaf *one;

uaf *two;


one = malloc(100);

printf("one->number:%d\n",one->number);


one->number=12345;

printf("one->numver:%d\n",one->number);


free(one);

two=malloc(100);


printf("two->number:%d\n",two->number);

}


소스를 실행하면



이러한 결과를 볼수 있다. 과연 이렇게 되는 이유는 무엇일까? 우리는 free를 이용해서 힙 메모리 할당을 제거해서 one 이후 two에는 값이 없을 거라고 생각하지만 free를 이용해서 힙 메모리를 제거한다고 해도 값은 지워지지 않고 있다.

그래서 two 또한 12345가 나오는 것을 확인 할 수 있다.



과연 주소값을 보면 어떨까?


위에서 볼수 있듯 같은 주소값을 참조하는 것을 참조하는 것을 볼 수 있다.

이러한 취약점을 use after free 취약점이다.


[참고]http://cd80.tistory.com/40

728x90

'Security Study > System' 카테고리의 다른 글

integer overflow  (0) 2015.10.22
system 24byte shellcode  (0) 2015.10.15
memory 영역  (0) 2015.10.07
C언어의 메모리 구조  (0) 2015.09.21
race condition(경쟁 조건)attack  (0) 2015.09.17