summaryrefslogtreecommitdiff
path: root/dirobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'dirobj.c')
-rw-r--r--dirobj.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/dirobj.c b/dirobj.c
new file mode 100644
index 0000000..b925e42
--- /dev/null
+++ b/dirobj.c
@@ -0,0 +1,153 @@
1/*
2 * Copyright (c) 2004 Security Architects Corporation. All rights reserved.
3 *
4 * Module Name:
5 *
6 * dirobj.c
7 *
8 * Abstract:
9 *
10 * This module implements various object directory hooking routines.
11 * These are not file system directories (see file.c) but rather containers
12 * for other objects.
13 *
14 * Author:
15 *
16 * Eugene Tsyrklevich 03-Sep-2004
17 *
18 * Revision History:
19 *
20 * None.
21 */
22
23
24#include "dirobj.h"
25
26
27#ifdef ALLOC_PRAGMA
28#pragma alloc_text (INIT, InitDirobjHooks)
29#endif
30
31
32fpZwOpenDirectoryObject OriginalNtOpenDirectoryObject = NULL;
33fpZwCreateDirectoryObject OriginalNtCreateDirectoryObject = NULL;
34
35
36
37/*
38 * HookedNtCreateDirectoryObject()
39 *
40 * Description:
41 * This function mediates the NtCreateDirectoryObject() system service and checks the
42 * provided directory object name against the global and current process security policies.
43 *
44 * NOTE: ZwCreateDirectoryObject creates or opens an object directory. [NAR]
45 *
46 * Parameters:
47 * Those of NtCreateDirectoryObject().
48 *
49 * Returns:
50 * STATUS_ACCESS_DENIED if the call does not pass the security policy check.
51 * Otherwise, NTSTATUS returned by NtCreateDirectoryObject().
52 */
53
54NTSTATUS
55NTAPI
56HookedNtCreateDirectoryObject
57(
58 OUT PHANDLE DirectoryHandle,
59 IN ACCESS_MASK DesiredAccess,
60 IN POBJECT_ATTRIBUTES ObjectAttributes
61)
62{
63 PCHAR FunctionName = "HookedNtCreateDirectoryObject";
64
65
66 HOOK_ROUTINE_START(DIROBJ);
67
68
69 ASSERT(OriginalNtCreateDirectoryObject);
70
71 rc = OriginalNtCreateDirectoryObject(DirectoryHandle, DesiredAccess, ObjectAttributes);
72
73
74 HOOK_ROUTINE_FINISH(DIROBJ);
75}
76
77
78
79/*
80 * HookedNtOpenDirectoryObject()
81 *
82 * Description:
83 * This function mediates the NtOpenDirectoryObject() system service and checks the
84 * provided directory object name against the global and current process security policies.
85 *
86 * NOTE: ZwOpenDirectoryObject opens an object directory. [NAR]
87 *
88 * Parameters:
89 * Those of NtOpenDirectoryObject().
90 *
91 * Returns:
92 * STATUS_ACCESS_DENIED if the call does not pass the security policy check.
93 * Otherwise, NTSTATUS returned by NtOpenDirectoryObject().
94 */
95
96NTSTATUS
97NTAPI
98HookedNtOpenDirectoryObject
99(
100 OUT PHANDLE DirectoryHandle,
101 IN ACCESS_MASK DesiredAccess,
102 IN POBJECT_ATTRIBUTES ObjectAttributes
103)
104{
105 PCHAR FunctionName = "HookedNtOpenDirectoryObject";
106
107
108 HOOK_ROUTINE_START(DIROBJ);
109
110
111 ASSERT(OriginalNtOpenDirectoryObject);
112
113 rc = OriginalNtOpenDirectoryObject(DirectoryHandle, DesiredAccess, ObjectAttributes);
114
115
116 HOOK_ROUTINE_FINISH(DIROBJ);
117}
118
119
120
121/*
122 * InitDirobjHooks()
123 *
124 * Description:
125 * Initializes all the mediated driver object operation pointers. The "OriginalFunction" pointers
126 * are initialized by InstallSyscallsHooks() that must be called prior to this function.
127 *
128 * NOTE: Called once during driver initialization (DriverEntry()).
129 *
130 * Parameters:
131 * None.
132 *
133 * Returns:
134 * TRUE to indicate success, FALSE if failed.
135 */
136
137BOOLEAN
138InitDirobjHooks()
139{
140 if ( (OriginalNtOpenDirectoryObject = (fpZwOpenDirectoryObject) ZwCalls[ZW_OPEN_DIRECTORYOBJECT_INDEX].OriginalFunction) == NULL)
141 {
142 LOG(LOG_SS_FILE, LOG_PRIORITY_DEBUG, ("InitDirobjHooks: OriginalNtOpenDirectoryObject is NULL\n"));
143 return FALSE;
144 }
145
146 if ( (OriginalNtCreateDirectoryObject = (fpZwCreateDirectoryObject) ZwCalls[ZW_CREATE_DIRECTORYOBJECT_INDEX].OriginalFunction) == NULL)
147 {
148 LOG(LOG_SS_FILE, LOG_PRIORITY_DEBUG, ("InitDirobjHooks: OriginalNtCreateDirectoryObject is NULL\n"));
149 return FALSE;
150 }
151
152 return TRUE;
153}