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"
|
|
|
|
|
2014-06-07 19:24:10 +00:00
|
|
|
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;
|
|
|
|
|
2014-06-07 19:24:10 +00:00
|
|
|
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-06-07 19:24:10 +00:00
|
|
|
{
|
2014-04-06 18:31:53 +00:00
|
|
|
lStatus = ERROR_SUCCESS;
|
2014-06-07 19:24:10 +00:00
|
|
|
}
|
2014-04-06 18:31:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
lStatus = GetLastError();
|
|
|
|
LocalFree(*pBufferOut);
|
|
|
|
}
|
|
|
|
}
|
2014-06-07 19:24:10 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2014-06-07 19:24:10 +00:00
|
|
|
else
|
|
|
|
PRINT_ERROR_AUTO(L"CreateFile");
|
2014-04-06 18:31:53 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-06-07 19:24:10 +00:00
|
|
|
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
|
|
|
{
|
2014-06-07 19:24:10 +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;
|
2014-06-07 19:24:10 +00:00
|
|
|
PVOID buffer = NULL;
|
2014-04-06 18:31:53 +00:00
|
|
|
DWORD i, szBuffer;
|
|
|
|
|
2014-06-07 19:24:10 +00:00
|
|
|
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;
|
|
|
|
}
|