mimikatz/modules/kull_m_kernel.c

76 lines
2.4 KiB
C
Raw Normal View History

2014-04-06 18:31:53 +00:00
/* Benjamin DELPY `gentilkiwi`
http://blog.gentilkiwi.com
benjamin@gentilkiwi.com
Licence : http://creativecommons.org/licenses/by/3.0/fr/
*/
#include "kull_m_kernel.h"
BOOL kull_m_kernel_ioctl_handle(HANDLE hDriver, DWORD ioctlCode, PVOID bufferIn, DWORD szBufferIn, PVOID * pBufferOut, PDWORD pSzBufferOut, BOOL autobuffer)
2014-04-06 18:31:53 +00:00
{
BOOL status = FALSE;
DWORD lStatus = ERROR_MORE_DATA, returned;
if(!autobuffer)
{
status = DeviceIoControl(hDriver, ioctlCode, bufferIn, szBufferIn, pBufferOut ? *pBufferOut : NULL, pSzBufferOut ? *pSzBufferOut : 0, &returned, NULL);
}
else
2014-04-06 18:31:53 +00:00
{
for(*pSzBufferOut = 0x10000; (lStatus == ERROR_MORE_DATA) && (*pBufferOut = LocalAlloc(LPTR, *pSzBufferOut)) ; *pSzBufferOut <<= 1)
{
if(status = DeviceIoControl(hDriver, ioctlCode, bufferIn, szBufferIn, *pBufferOut, *pSzBufferOut, &returned, NULL))
{
2014-04-06 18:31:53 +00:00
lStatus = ERROR_SUCCESS;
}
2014-04-06 18:31:53 +00:00
else
{
lStatus = GetLastError();
LocalFree(*pBufferOut);
}
}
}
if(!status)
{
PRINT_ERROR(L"DeviceIoControl (0x%08x) : 0x%08x\n", ioctlCode, GetLastError());
if(autobuffer)
LocalFree(*pBufferOut);
}
else if(pSzBufferOut)
*pSzBufferOut = returned;
return status;
}
BOOL kull_m_kernel_ioctl(PCWSTR driver, DWORD ioctlCode, PVOID bufferIn, DWORD szBufferIn, PVOID * pBufferOut, PDWORD pSzBufferOut, BOOL autobuffer)
{
BOOL status = FALSE;
HANDLE hDriver;
hDriver = CreateFile(driver, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(hDriver && hDriver != INVALID_HANDLE_VALUE)
{
status = kull_m_kernel_ioctl_handle(hDriver, ioctlCode, bufferIn, szBufferIn, pBufferOut, pSzBufferOut, autobuffer);
2014-04-06 18:31:53 +00:00
CloseHandle(hDriver);
}
else
PRINT_ERROR_AUTO(L"CreateFile");
2014-04-06 18:31:53 +00:00
return status;
}
BOOL kull_m_kernel_mimidrv_ioctl(DWORD ioctlCode, PVOID bufferIn, DWORD szBufferIn, PVOID * pBufferOut, PDWORD pSzBufferOut, BOOL autobuffer)
2014-04-06 18:31:53 +00:00
{
return kull_m_kernel_ioctl(L"\\\\.\\" MIMIKATZ_DRIVER, ioctlCode, bufferIn, szBufferIn, pBufferOut, pSzBufferOut, autobuffer);
2014-04-06 18:31:53 +00:00
}
BOOL kull_m_kernel_mimidrv_simple_output(DWORD ioctlCode, PVOID bufferIn, DWORD szBufferIn)
{
BOOL status = FALSE;
PVOID buffer = NULL;
2014-04-06 18:31:53 +00:00
DWORD i, szBuffer;
if(status = kull_m_kernel_ioctl(L"\\\\.\\" MIMIKATZ_DRIVER, ioctlCode, bufferIn, szBufferIn, &buffer, &szBuffer, TRUE))
2014-04-06 18:31:53 +00:00
{
for(i = 0; i < szBuffer / sizeof(wchar_t); i++)
kprintf(L"%c", ((wchar_t *) buffer)[i]);
LocalFree(buffer);
}
return status;
}