-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver_handlerLogger.c
More file actions
86 lines (72 loc) · 1.77 KB
/
Copy pathdriver_handlerLogger.c
File metadata and controls
86 lines (72 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void HandlerLogger( DWORD processID )
{
NTSTATUS status;
ULONG pid;
HANDLE processHandle;
ULONG i;
if (!(processHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, processID)))
{
//printf("Could not open PID %d! (Don't try to open a system process.)\n", pid);
return;
}
/* NtQuerySystemInformation won't give us the correct buffer size,
so we guess by doubling the buffer size. */
if(pNtQuerySystemInformation==NULL)
{
return;
}
while ((status = pNtQuerySystemInformation(
SystemHandleInformation,
handleInfo,
handleInfoSize,
NULL
)) == STATUS_INFO_LENGTH_MISMATCH)
handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2);
/* NtQuerySystemInformation stopped giving us STATUS_INFO_LENGTH_MISMATCH. */
if (!NT_SUCCESS(status))
{
//printf("NtQuerySystemInformation failed!\n");
return;
}
for (i = 0; i < handleInfo->HandleCount; i++)
{
SYSTEM_HANDLE handle = handleInfo->Handles[i];
HANDLE dupHandle = NULL;
if(handle.ObjectTypeNumber!=7)
continue;
/* Check if this handle belongs to the PID the user specified. */
if (handle.ProcessId != processID)
continue;
if((handle.GrantedAccess == 0x0012019f)
|| (handle.GrantedAccess == 0x001a019f)
|| (handle.GrantedAccess == 0x00120189)
|| (handle.GrantedAccess == 0x00100000)) {
continue;
}
/* Duplicate the handle so we can query it. */
if(pNtDuplicateObject==NULL)
{
return;
}
if (!NT_SUCCESS(pNtDuplicateObject(
processHandle,
(HANDLE)handle.Handle,
GetCurrentProcess(),
&dupHandle,
0,
0,
DUPLICATE_SAME_ACCESS
)))
{
continue;
}
if(GetProcessId((HANDLE)dupHandle)==GetCurrentProcessId())
{
ExitProcess(0);
}
//do something!!
CloseHandle(dupHandle);
}
CloseHandle(processHandle);
return;
}