/*************************************************************************************

* FindPMHeap.c

*

* Locates the mapped heap address of a target app through reading the target 

*   process's PEB pointer.

*

* 0x7fdf094h	- GDI Shared Handle Table

* +60000h		- Process Mapped Heap

*

* Brett Moore [ brett.moore@security-assessment.com ]

* www.security-assessment.com

*

* Blackhat USA 2004 package

*

**************************************************************************************/

#include <windows.h>



int main(int argc, char *argv[])

{

      

	long result;

	

	DWORD pid,offset;

	HANDLE hProcess;

	

	long bread;



	printf("%% FindPMHeap - Locate Process Mapped Heap\n");

	printf("%% brett.moore@security-assessment.com\n\n");



	if (argc < 2) 

	{

		printf("+ FindHeap <pid>\n");

		exit(0);

	}

	

	// Get PID

	pid=atoi(argv[1]);



	printf("+ Opening process: %d\n",pid);



	// Open Target Process And Read Address

	hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid);

	result = ReadProcessMemory(hProcess,0x7ffdf094,&offset,4,&bread);

	printf("+ Target GDI shared handle table: 0x%xh\n",offset);

	printf("+ Target process mapped heap:     0x%xh\n",offset+0x60000);

	CloseHandle (hProcess);



}

