-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathfilterCommPorts.js
170 lines (131 loc) · 6.75 KB
/
filterCommPorts.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict";
function initializeScript()
{
return [new host.functionAlias(GetHandlesToDevice, "DeviceFileHandles"),
new host.functionAlias(GetQueuedIrpsForPort, "IrpsForPort"),
new host.functionAlias(RegisteredFilterDrivers, "RegisteredFilters"),
new host.functionAlias(EnumCommPortListForFilter, "EnumCommPortListForFilter"),
new host.functionAlias(EnumServerPortsForFilter, "EnumServerPortsForFilter"),
new host.functionAlias(AllServerPorts, "AllServerPorts"),
new host.apiVersionSupport(1, 6)];
}
function GetHandlesToDevice(Device)
{
// Get easy access to the debug output method
let dbgOutput = host.diagnostics.debugLog;
// Loop over each process
let processes = host.currentSession.Processes;
let objHeaderType = host.getModuleType("nt", "_OBJECT_HEADER");
let objHeaderOffset = objHeaderType.fields.Body.offset;
for (let process of processes)
{
let handles = process.Io.Handles;
try {
for (let handle of handles) {
try {
let fileObj = handle.Object.ObjectType;
if (fileObj === "File") {
if (host.parseInt64(handle.Object.UnderlyingObject.DeviceObject.address, 16).compareTo(Device) == 0)
{
let fscontext2 = handle.Object.UnderlyingObject.FsContext2.address;
let fltCcbType = host.getModuleType("FltMgr", "_FLT_CCB");
let port = host.createTypedObject(fscontext2, fltCcbType).Data.Port.Port;
let portObjHeader = host.createTypedObject(port.ServerPort.address.subtract(objHeaderOffset), objHeaderType);
dbgOutput("\tProcess ", process.Name, " has handle ", handle.Handle, " to port ", portObjHeader.ObjectName, "\n");
}
}
} catch (e) {
dbgOutput("\tException parsing handle ", handle.Handle, "in process ", process.Name, "!\n");
}
}
} catch (e) {
// dbgOutput("\tException parsing handle table for process ", process.Name, " PID ", process.Id, "!\n");
}
}
}
function GetQueuedIrpsForPort(Port)
{
let dbgOutput = host.diagnostics.debugLog;
let v_port = host.createTypedObject(Port.address, host.getModuleType("FltMgr", "_FLT_PORT_OBJECT"));
dbgOutput("Port: ", v_port.address, "\n");
let waiterlist = host.namespace.Debugger.Utility.Collections.FromListEntry(v_port.MsgQ.WaiterQ.mList, "nt!_IRP", "Tail.Overlay.ListEntry");
for (let entry of waiterlist) {
dbgOutput("\tIRP address: ", entry.address, " by thread ", entry.CurrentThread.Cid.UniqueThread.address,"\n");
}
}
function RegisteredFilterDrivers()
{
let dbgOutput = host.diagnostics.debugLog;
let fltglobals = host.getModuleSymbolAddress("fltmgr", "FltGlobals");
let typedFltGlobals = host.createTypedObject(fltglobals, "fltmgr", "_GLOBALS");
dbgOutput("Flt Globals: ", typedFltGlobals.address, "\n");
let flt_frames = host.namespace.Debugger.Utility.Collections.FromListEntry(typedFltGlobals.FrameList.rList, "fltmgr!_FLTP_FRAME", "Links");
for (let flt_frame of flt_frames) {
dbgOutput("Frame ", flt_frame.FrameID, "\n");
let filters = host.namespace.Debugger.Utility.Collections.FromListEntry(flt_frame.RegisteredFilters.rList, "fltmgr!_FLT_FILTER", "Base.PrimaryLink");
for (let filter of filters) {
dbgOutput("\tFilter ", filter.Name, " : ", filter.address, "\n");
let instances = host.namespace.Debugger.Utility.Collections.FromListEntry(filter.InstanceList.rList, "fltmgr!_FLT_INSTANCE", "FilterLink");
for (let instance of instances) {
dbgOutput("\t\tInstance: ", instance.address, ", Name: ", instance.Name, ", Altitude: ", instance.Altitude, "\n");
}
}
}
}
function EnumCommPortListForFilter(Filter)
{
let dbgOutput = host.diagnostics.debugLog;
let v_filter = host.createTypedObject(Filter, host.getModuleType("FltMgr", "_FLT_FILTER"));
dbgOutput("Filter: ", v_filter.address, "\n");
if (v_filter.PortList.mCount != 0) {
let ports = host.namespace.Debugger.Utility.Collections.FromListEntry(v_filter.PortList.mList, "fltmgr!_FLT_PORT_OBJECT", "FilterLink");
for (let port of ports) {
if (port != 0) {
dbgOutput("Port: ", port.address, "\n");
dbgOutput("\tServerPort: ", port.ServerPort.address, "\n");
dbgOutput("\t\tConnectNotify: ", port.ServerPort.ConnectNotify.address, "\n");
dbgOutput("\t\tDisconnectNotify: ", port.ServerPort.DisconnectNotify.address, "\n");
dbgOutput("\t\tMessageNotify: ", port.ServerPort.MessageNotify.address, "\n");
dbgOutput("\t\tNumberOfConnections: ", port.ServerPort.NumberOfConnections, "\n");
dbgOutput("\t\tMaxConnections: ", port.ServerPort.MaxConnections, "\n");
dbgOutput("\tMsgQ: ", port.MsgQ.address, "\n");
dbgOutput("\tDisconnected: ", port.Disconnected, "\n");
}
}
}
}
function EnumServerPortsForFilter(Filter)
{
let dbgOutput = host.diagnostics.debugLog;
let v_filter = host.createTypedObject(Filter, host.getModuleType("FltMgr", "_FLT_FILTER"));
if (v_filter.ConnectionList.mCount != 0)
{
let ports = host.namespace.Debugger.Utility.Collections.FromListEntry(v_filter.ConnectionList.mList, "fltmgr!_FLT_SERVER_PORT_OBJECT", "FilterLink");
for (let port of ports) {
let objectHeaderAddress = host.parseInt64(port.address, 16).subtract(0x30);
let objectHeader = host.createTypedObject(objectHeaderAddress, host.getModuleType("nt", "_OBJECT_HEADER"));
dbgOutput("\tServerPort ", objectHeader.ObjectName, ": ", port.address, "\n");
dbgOutput("\t\tConnectNotify: ", port.ConnectNotify.address, "\n");
dbgOutput("\t\tDisconnectNotify: ", port.DisconnectNotify.address, "\n");
dbgOutput("\t\tMessageNotify: ", port.MessageNotify.address, "\n");
dbgOutput("\t\tNumberOfConnections: ", port.NumberOfConnections, "\n");
dbgOutput("\t\tMaxConnections: ", port.MaxConnections, "\n");
}
}
}
function AllServerPorts()
{
let dbgOutput = host.diagnostics.debugLog;
let fltglobals = host.getModuleSymbolAddress("fltmgr", "FltGlobals");
let typedFltGlobals = host.createTypedObject(fltglobals, "fltmgr", "_GLOBALS");
let flt_frames = host.namespace.Debugger.Utility.Collections.FromListEntry(typedFltGlobals.FrameList.rList, "fltmgr!_FLTP_FRAME", "Links");
for (let flt_frame of flt_frames) {
dbgOutput("Frame ", flt_frame.FrameID, "\n");
let filters = host.namespace.Debugger.Utility.Collections.FromListEntry(flt_frame.RegisteredFilters.rList, "fltmgr!_FLT_FILTER", "Base.PrimaryLink");
for (let filter of filters) {
dbgOutput("Filter ", filter.Name, " : ", filter.address, "\n");
EnumServerPortsForFilter(filter.address);
dbgOutput("\n");
}
}
}