-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could dump drivers? #5
Comments
I legitimately don't even know where to start, not very strong with kernel drivers. Sure, to modify this driver to dump the memory of another driver given some kind of identifier of that driver, you could follow these general steps: Define a new IOCTL control code that your driver will use to receive the identifier of the driver whose memory needs to be dumped. Implement a function that takes the identifier received through the IOCTL and finds the corresponding driver object. Use the driver object obtained in step 2 to read its memory and write it to a file. Here's an example implementation of these steps: #define IOCTL_DUMP_DRIVER_MEMORY CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef struct _DUMP_DRIVER_MEMORY_REQUEST {
WCHAR DriverName[MAX_PATH];
WCHAR FilePath[MAX_PATH];
} DUMP_DRIVER_MEMORY_REQUEST, *PDUMP_DRIVER_MEMORY_REQUEST; Implement a function that searches for the driver object corresponding to the given name: PDRIVER_OBJECT GetDriverObjectByName(WCHAR* driverName)
{
PDRIVER_OBJECT driverObject = NULL;
UNICODE_STRING uDriverName;
RtlInitUnicodeString(&uDriverName, driverName);
// Enumerate loaded drivers
ULONG bytesNeeded;
ZwQuerySystemInformation(SystemModuleInformation, NULL, 0, &bytesNeeded);
PVOID systemInfoBuffer = ExAllocatePoolWithTag(NonPagedPool, bytesNeeded, 'sm01');
if (systemInfoBuffer == NULL)
{
return NULL;
}
if (!NT_SUCCESS(ZwQuerySystemInformation(SystemModuleInformation, systemInfoBuffer, bytesNeeded, NULL)))
{
ExFreePool(systemInfoBuffer);
return NULL;
}
PSYSTEM_MODULE_INFORMATION pModuleInfo = (PSYSTEM_MODULE_INFORMATION)systemInfoBuffer;
for (ULONG i = 0; i < pModuleInfo->NumberOfModules; i++)
{
if (wcsstr(pModuleInfo->Modules[i].ImageName, uDriverName.Buffer) != NULL)
{
UNICODE_STRING uFullPath;
RtlInitUnicodeString(&uFullPath, pModuleInfo->Modules[i].FullPathName);
// Get driver object from the driver file path
PDRIVER_OBJECT tmpDriverObject = NULL;
if (NT_SUCCESS(OsGetDriverObject(&uFullPath, &tmpDriverObject)))
{
if (tmpDriverObject->DriverSection == pModuleInfo->Modules[i].Section)
{
driverObject = tmpDriverObject;
}
else
{
// This is not the correct driver object, dereference it
ObDereferenceObject(tmpDriverObject);
}
}
RtlFreeUnicodeString(&uFullPath);
break;
}
}
ExFreePool(systemInfoBuffer);
return driverObject;
} Modify the IoControl function to handle the new IOCTL control code, find the driver object using GetDriverObjectByName, and dump its memory to a file: case IOCTL_DUMP_DRIVER_MEMORY:
{
PDUMP_DRIVER_MEMORY_REQUEST request = (PDUMP_DRIVER_MEMORY_REQUEST)Irp->AssociatedIrp.SystemBuffer;
PDRIVER_OBJECT driverObject = GetDriverObjectByName(request->DriverName);
if (driverObject == NULL)
{
status = STATUS_NOT_FOUND;
bytesIO = 0;
break;
}
// Dump driver memory to file
HANDLE fileHandle;
OBJECT_ATTRIBUTES fileAttributes;
UNICODE_STRING uFilePath;
RtlInitUnicodeString(&uFilePath, request->FilePath);
InitializeObjectAttributes(&fileAttributes, &uFilePath, OBJ_KERNEL_HANDLE | |
No description provided.
The text was updated successfully, but these errors were encountered: