This source file includes following definitions.
- HKEYToString
- TryOpenKey
- TestRegistry
#include "sandbox/win/sandbox_poc/pocdll/exports.h"
#include "sandbox/win/sandbox_poc/pocdll/utils.h"
const wchar_t *HKEYToString(const HKEY key) {
switch (reinterpret_cast<LONG_PTR>(key)) {
case HKEY_CLASSES_ROOT:
return L"HKEY_CLASSES_ROOT";
case HKEY_CURRENT_CONFIG:
return L"HKEY_CURRENT_CONFIG";
case HKEY_CURRENT_USER:
return L"HKEY_CURRENT_USER";
case HKEY_LOCAL_MACHINE:
return L"HKEY_LOCAL_MACHINE";
case HKEY_USERS:
return L"HKEY_USERS";
}
return L"unknown";
}
void TryOpenKey(const HKEY hive, const wchar_t *path, FILE *output) {
HKEY key;
LONG err_code = ::RegOpenKeyEx(hive,
path,
0,
MAXIMUM_ALLOWED,
&key);
if (ERROR_SUCCESS == err_code) {
fprintf(output, "[GRANTED] Opening key \"%S\\%S\". Handle 0x%p\r\n",
HKEYToString(hive),
path,
key);
::RegCloseKey(key);
} else {
fprintf(output, "[BLOCKED] Opening key \"%S\\%S\". Error %d\r\n",
HKEYToString(hive),
path,
err_code);
}
}
void POCDLL_API TestRegistry(HANDLE log) {
HandleToFile handle2file;
FILE *output = handle2file.Translate(log, "w");
TryOpenKey(HKEY_LOCAL_MACHINE, NULL, output);
TryOpenKey(HKEY_CURRENT_USER, NULL, output);
TryOpenKey(HKEY_USERS, NULL, output);
TryOpenKey(HKEY_LOCAL_MACHINE,
L"Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon",
output);
}