hOwDayS 선린 10720
realloc vulnerability 본문
#include <stdio.h>#include <iostream>/*Realloc 의 취약점을 이용한 메모리 참조*/int main(){unsigned long *temp;unsigned long *p = (unsigned long *)malloc(400);unsigned long * p_1 = (unsigned long*)malloc(80);temp = p;scanf("%c",&p[0]);printf("the address of p %p \n",p);printf("the content of p %c \n",p[0]);printf("\n");printf("the address of temp %p \n",temp);printf("the content of temp(p) %c \n",temp[0]);printf("\n");printf("the address of p_1 %p \n",p_1);printf("the distace between p and p_1 : %d \n",p - p_1);printf("\n");printf("=====Vulnerability=====");printf("\n\n");p = (unsigned long *)realloc(p,1500);//realloc을 이용해 p_1에 영향을 줄 수 있을 만큼 재할당/*기존의 p를 free하고 p의 내용을 복사하여 다른 곳에 할당 받게 됨.*/printf("the address of p %p \n",p);printf("the content of p %c \n",p[0]); //기존의 p를 free하고 p의 내용을 복사하여 다른 곳에 할당 받게 됨. 기존p의 내용은 보존된다는 취약점printf("\n");printf("the address of temp %p \n",temp); //하지만 temp의 주소는 변경이 안되므로 원래의 p 의 주소를 갖고있음.printf("the content of temp %c \n",temp[0]); //원래 p의 내용 출력printf("\n");return 0;}
리눅스 같은 경우 smallbin을 free할 경우 fd , bk 에 main_arena + 88 의 값이 들어가므로 이걸 이용해서 libc 릭 할 수 있다.
'잡다한거..' 카테고리의 다른 글
Haskell Decomplier (0) | 2018.03.17 |
---|---|
HITCON 2014 stkof (0) | 2018.03.11 |
Memory Leak (0) | 2018.03.04 |
unsortedbin_attack (0) | 2018.02.22 |
pwnable.tw orw (0) | 2018.02.15 |
Comments