Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Test_NtSetInformationProcess.cpp
Go to the documentation of this file.
1// Tests the Hooked_NtSetInformationProcess check. Setting ProcessProtectionInformation (61) is
2// reported whether or not the call succeeds: only the kernel can change a process's protection,
3// so from user mode the call always fails and the attempt itself is the signal. The event carries
4// the status the call returned. Other information classes are not reported.
6#include <winternl.h>
7
8#define TEST_PROCESS_PROTECTION_INFORMATION ((PROCESSINFOCLASS)61)
9
12#define TEST_WIN32_PROTECTION_LEVEL_INFO ((PROCESSINFOCLASS)7)
13
14typedef NTSTATUS(NTAPI* NtSetInformationProcess_t)(HANDLE ProcessHandle,
15 PROCESSINFOCLASS ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength);
16
17static void SetInformation(HANDLE process, PROCESSINFOCLASS informationClass, PVOID information, ULONG length) {
18 NtdllFunction<NtSetInformationProcess_t>("NtSetInformationProcess")(process, informationClass, information, length);
19}
20
22static void SetProtection(HANDLE process) {
23 UCHAR protection = 0x62;
24 SetInformation(process, TEST_PROCESS_PROTECTION_INFORMATION, &protection, sizeof(protection));
25}
26
27static const std::vector<HookTestCase> g_Cases = {
28 {
29 "Protection set on current process (pseudo-handle)",
30 [](HookTestContext&) {
31 SetProtection(GetCurrentProcess());
32 },
33 { "NtSetInformationProcess: attempt to set the protection of the current process, status 0xc*" },
34 },
35 {
36 "Protection set on current process (real handle to self)",
37 [](HookTestContext&) {
38 HANDLE self = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
39 SetProtection(self);
40 CloseHandle(self);
41 },
42 { "NtSetInformationProcess: attempt to set the protection of the current process, status 0xc*" },
43 },
44 {
45 "Protection set on remote process",
46 [](HookTestContext& context) {
47 SetProtection(context.RemoteProcess());
48 },
49 { "NtSetInformationProcess: attempt to set the protection of the remote process, status 0xc*" },
50 },
51 {
52 "Protection set through a handle without PROCESS_SET_INFORMATION",
53 [](HookTestContext& context) {
54 HANDLE remote = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, GetProcessId(context.RemoteProcess()));
55 SetProtection(remote);
56 CloseHandle(remote);
57 },
58 { "NtSetInformationProcess: attempt to set the protection of the remote process, status 0xc*" },
59 },
60 {
61 "Other information class that succeeds is not reported",
62 [](HookTestContext&) {
63 // Goes through NtSetInformationProcess(ProcessPriorityBoost)
64 SetProcessPriorityBoost(GetCurrentProcess(), FALSE);
65 },
66 {},
67 },
68 {
69 "Win32 ProcessProtectionLevelInfo value (native ProcessDebugPort) is not reported",
70 [](HookTestContext&) {
71 HANDLE port = NULL;
72 SetInformation(GetCurrentProcess(), TEST_WIN32_PROTECTION_LEVEL_INFO, &port, sizeof(port));
73 },
74 {},
75 },
76};
77
78int main(int argc, char** argv) {
79 return RunHookTests(argc, argv, "NtSetInformationProcess", g_Cases);
80}
NTSTATUS(NTAPI * NtSetInformationProcess_t)(HANDLE ProcessHandle, PROCESSINFOCLASS ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength)
#define TEST_WIN32_PROTECTION_LEVEL_INFO
#define TEST_PROCESS_PROTECTION_INFORMATION
int main()
Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this...
Resources shared by the cases of one test run, created in the child process. The remote processes are...
T NtdllFunction(const char *name)
Looks up an ntdll export. Calls through the result go through the hooks, because the hooks patch the ...
int RunHookTests(int argc, char **argv, const char *apiName, const std::vector< HookTestCase > &cases)
Runs the cases and prints a PASS/FAIL line for each. Call from main.