Method, device, processor and storage medium for parsing WMI client process
By loading context marshaling and demarshalling modules in the WMI framework service and provider processes, the problem of client process information loss in the WMI framework is solved, more precise access control and auditing are achieved, and malicious code is prevented from evading security detection.
Patent Information
- Application Number
- CN202311659800.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-05
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2043-12-05
AI Technical Summary
The existing WMI framework causes the client process information to be lost during the request delivery process. Malware can use this information to avoid security detection and attack backtracking difficulties.
Load the context marshaling module when the WMI framework service process starts, extract and add the client context to the context parameters of the WMI request, load the context unsealing module when the provider process starts, extract and set the client context to the current thread context, and ensure that the subject Process information transfer.
By ensuring the delivery of client process information, the accuracy of access control and auditing is improved, preventing malicious code from bypassing security detection and source tracing interruptions.
Smart Images

Figure CN117978428B
Abstract
Description
Technical Field
[0001] The present application relates to the field of network security technology, and in particular to a method, device, processor and storage medium for parsing a WMI client process. Background Art
[0002] WMI (Windows Management Instrumentation) is a management and monitoring framework in Microsoft Windows operating system. It implements the management functions of various hardware and software components of computer systems based on the provider / consumer model. WMI allows administrators to query and control various system resources and services on the computer through programming or command line tools.
[0003] WMI is an important tool for Windows system management. It provides administrators and developers with a powerful way to manage and monitor various resources and services on Windows computers. It is widely used in tasks such as automated system management, performance monitoring, and system information collection. For a management object class under a WMI namespace, WMI supports structured queries (WQL), class instance object enumeration, class method calls, and registered event notifications. However, since WMI uses DCOM as the basic communication mechanism, it will make it difficult to trace which consumer (client) initiated the call when the above-mentioned query, enumeration, method execution, etc. are executed by the provider. In other words, the existing WMI framework has the problem of information loss of the main process (i.e., consumer, i.e., client process) when the WMI request is transmitted between processes such as the consumer to the WMI framework and then to the WMI provider. This information loss caused by the "broken link" can be exploited by malware to evade behavior detection and attack backtracking of security software. For example, malicious code executes WMI queries to collect system information in various ways to evade security detection. For another example, malicious code executes WMI methods in various ways to bypass the security system and damage the computer operating system. Summary of the invention
[0004] In order to solve the above technical problems, the purpose of the embodiments of the present application is to provide a method, device, processor and storage medium for parsing a WMI client process.
[0005] In order to achieve the above-mentioned object, the first aspect of the embodiment of the present application provides a method for parsing a WMI client process, the method comprising:
[0006] When the WMI framework service process starts, the context marshaling module is loaded;
[0007] Before the WMI request is dispatched to the thread pool, the client context is extracted through the context marshaling module and added to the WMI context parameter of the WMI request;
[0008] When the WMI provider process starts, the context unpacking module is loaded;
[0009] The client context in the WMI context parameter is extracted through the context unpacking module, and the client context is set to the current thread context.
[0010] In an embodiment of the present application, the client context is extracted through a context marshaling module, and the client context is added to the WMI context parameters of the WMI request, including: when the WMI framework service process loads the WMI core dynamic library, locating the virtual function table of the IWbemServices interface of the WMI namespace class; hooking the interface method containing the WMI context parameters in the virtual function table; obtaining the client context by calling the interface method, and setting the client context to the WMI context parameters.
[0011] In an embodiment of the present application, the client context is obtained by calling an interface method and the client context is set in a WMI context parameter, including: extracting the client context through an RPC request corresponding to a WMI request; and setting the client context in a WMI context parameter of the WMI request.
[0012] In an embodiment of the present application, extracting the client context through the RPC request corresponding to the WMI request includes: when the RPC request passes through the RPC transport layer, parsing the protocol type of the transport layer according to the RPC message data of the RPC request; parsing the client context of the RPC request according to the protocol type.
[0013] In an embodiment of the present application, parsing the client context of the RPC request according to the protocol type includes: when the protocol type is a local call protocol, extracting the client's process identifier and thread identifier from the RPC message data to combine and form the client context; when the protocol type is a named pipe protocol, extracting the characteristic data of the RPC call, and querying the RPC tracing module based on the characteristic data to obtain the client context; when the protocol type is other network protocols, extracting the remote host information from the RPC message data to form the client context.
[0014] In an embodiment of the present application, setting the client context in the WMI context of the WMI request includes: determining whether the interface method provides a context interface pointer; if the interface method provides a context interface pointer, calling the set value method of the context interface to set the client context to the named value.
[0015] In an embodiment of the present application, the method also includes: when the interface method does not provide a context interface pointer, creating a context instance object and obtaining an interface pointer of the newly created context instance; calling a set value method of the context instance interface to set the client context to a named value.
[0016] In an embodiment of the present application, the client context in the WMI context parameters is extracted through the context unpacking module, and the client context is set to the current thread context, including: when the provider process is started, locating the virtual function table of the IWbemServices interface that intercepts the request; hooking the interface method containing the WMI context parameters in the virtual function table; extracting the client context in the WMI context by calling the interface method, and setting the client context to the current thread context.
[0017] A second aspect of the present application provides a processor configured to execute the above-mentioned method for parsing a WMI client process.
[0018] The third aspect of the present application provides a device for parsing a WMI client process, the device comprising: a context marshaling module loading unit, which is used to load a context marshaling module when a WMI framework service process is started; a context marshaling module running unit, which extracts a client context through the context marshaling module before a WMI request is dispatched to a thread pool, and adds the client context to the WMI context parameter of the WMI request; a context unsealing module loading unit, which loads a context unsealing module when a WMI provider process is started; a context unsealing module running unit, which extracts the client context in the WMI context parameter through the context unsealing module, and sets the client context to the current thread context.
[0019] A fourth aspect of the present application provides a machine-readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the above-mentioned method for parsing a WMI client process is implemented.
[0020] The above technical solution, by loading the context marshaling module when the WMI framework service process is started, extracting the client context through the context marshaling module before the WMI request is dispatched to the thread pool, and adding the client context to the WMI context parameter of the WMI request, loading the context unsealing module when the WMI provider process is started, extracting the client context in the WMI context parameter through the context unsealing module, and setting the client context to the current thread context. The present application can determine the subject of resource access triggered by the WMI request as the client that initiates the WMI request, making access control and auditing more precise, and is conducive to preventing malicious code from bypassing security detection and tracing interruption.
[0021] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:
[0023] Figure 1 A flowchart of a method for parsing a WMI client process provided in an embodiment of the present application;
[0024] Figure 2 A schematic diagram of the process of client context injection and unsealing provided in a specific embodiment of the present application;
[0025] Figure 3 A schematic diagram of a method for parsing a WMI client process provided in a specific embodiment of the present application;
[0026] Figure 4 A structural block diagram of a device for parsing a WMI client process provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0028] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back...), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0029] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0030] Figure 1 A flowchart of a method for parsing a WMI client process provided by an embodiment of the present application. Figure 1 As shown, an embodiment of the present application provides a method for parsing a WMI client process, which is described by taking the method applied to a processor as an example. The method may include the following steps.
[0031] Step S101, when the WMI framework service process is started, the context marshaling module is loaded;
[0032] Step S102: before the WMI request is dispatched to the thread pool, the client context is extracted through the context marshaling module, and the client context is added to the WMI context parameter of the WMI request;
[0033] Step S103: When the WMI provider process is started, the context unpacking module is loaded;
[0034] Step S104: extract the client context in the WMI context parameter through the context unpacking module, and set the client context to the current thread context.
[0035] In the existing WMI method call process, the WMI request from the client to the final provider spans multiple processes, that is, the WMI request is not directly from the client to the server through RPC, but there is a forwarding of the WMI service in the middle. The WMI service does not directly forward the WMI request to the provider, but encapsulates the WMI request into a structure, schedules it to the thread pool, and then the thread in the thread pool forwards the request to the provider. In this process, due to the change of the thread in the middle link, the provider cannot trace back to the corresponding consumer after receiving the WMI request. In other words, during the transmission process of the WMI request from the consumer to the WMI service and then to the provider, the main process information of the WMI request is lost. In this regard, the embodiment of the present application introduces a context marshaling module and a context unmarshaling module to transmit the main process information during the WMI method call process, thereby solving the problem of the loss of the main process information.
[0036] Specifically, when the WMI framework service process is started, the processor can load an additional context marshaling module for the WMI framework service process. In the WMI service framework, the context marshaling module can extract the client context corresponding to the WMI request before the WMI request is dispatched to the thread pool, and set the client context to the WMI context parameter of the WMI request. Among them, the client context may include the process ID and thread ID of the client that initiates the WMI request. In one example, when the host process svchost.exe loads wbemcore.dll, the process manager in the kernel layer can determine that this process is a WMI framework service process, and then load an additional context marshaling module for the WMI framework service process.
[0037] It can be understood that after the processing of the context marshaling module, when the WMI request is dispatched to the thread pool, the context parameters of the WMI request already include the client context, and at this time, the thread in the thread pool will forward the WMI request to the provider. In order to obtain the subject process information, when the WMI provider process is started, an additional context unsealing module can be injected into the WMI provider process. The context unsealing module can extract the client context from the WMI context parameters before the provider executes the WMI request, thereby ensuring that the subject process information is dispatched from the WMI request entry (i.e., the WMI framework service) to the request executor (i.e., the WMI provider). In one example, in order to make access control and auditing more accurate, after the client context is extracted from the WMI context parameters by the context unsealing module, the context unsealing module can also set the client context to the current thread context, so that the client process is used as the subject of access during access control, instead of using the current WMI provider process as the subject of access in the traditional method, thereby improving the accuracy of access control and auditing.
[0038] The above technical solution, by loading the context marshaling module when the WMI framework service process is started, extracting the client context through the context marshaling module before the WMI request is dispatched to the thread pool, and adding the client context to the WMI context parameter of the WMI request, loading the context unsealing module when the WMI provider process is started, extracting the client context in the WMI context parameter through the context unsealing module, and setting the client context to the current thread context. The present application can determine the subject of resource access triggered by the WMI request as the client that initiates the WMI request, making access control and auditing more precise, and is conducive to preventing malicious code from bypassing security detection and tracing interruption.
[0039] In an embodiment of the present application, the client context is extracted through the context marshaling module, and the client context is added to the WMI context parameters of the WMI request, which may include: when the WMI framework service process loads the WMI core dynamic library, locating the virtual function table of the IWbemServices interface of the WMI namespace class; hooking the interface method containing the WMI context parameters in the virtual function table; obtaining the client context by calling the interface method, and setting the client context to the WMI context parameters.
[0040] Specifically, WMI defines a set of standardized interfaces and namespaces for accessing system information. These interfaces allow developers to write scripts, applications, or management tools to query system status, perform configuration changes, and monitor performance. WMI namespace classes are namespaces and classes. WMI organizes system information into a set of namespaces and classes. Namespaces usually represent different functional areas, while classes represent the type of object or resource. For example, the Win32_Process class represents a running process, and the Win32_LogicalDisk class represents a logical disk.
[0041] It can be understood that the core dynamic library of WMI is wbemcore.dll. When the WMI framework service process loads the core dynamic library of WMI, the virtual function table of the IWbemServices interface of the WMI namespace class is first located. Since the embodiment of the present application mainly transmits the main process information through the WMI context parameter, it is necessary to hook the interface method containing the WMI context parameter in the virtual function table. In one example, there are dozens of methods in the IWbemServices interface, including multiple interface methods containing WMI context parameters. The common feature of the interface methods containing WMI context parameters is that they all have a specific parameter (i.e., the IWbemContext pointer). Further, by calling the interface method containing the WMI context parameter, the client context corresponding to the WMI request is obtained, and the client context is set to the parameters of the WMI context. In one example, since the WMI request is sent through a Distributed Component Object Model (DCOM) call, and the DCOM call is implemented based on the Remote Procedure Call (RPC) technology, the client context can be obtained through the RPC request.
[0042] In this way, by extracting the client context of the client that initiates the WMI request and setting the client context in the WMI context parameter, the main process information can be transmitted, the main process information can be prevented from being lost, and the security of the system can be improved.
[0043] It should be noted that the method for parsing the WMI client process provided in the embodiment of the present application is universal and has nothing to do with the specific WMI namespace or class.
[0044] In an embodiment of the present application, obtaining the client context by calling an interface method and setting the client context in a WMI context parameter may include: extracting the client context through an RPC request corresponding to a WMI request; and setting the client context in a WMI context parameter of the WMI request.
[0045] It can be understood that WMI uses DCOM (Distributed Component Object Model) as the basic communication mechanism. DCOM calls are implemented based on RPC (Remote Procedure Call) technology. In this process, WMI requests are encapsulated into DCOM calls, and DCOM calls are further encapsulated into RPC requests. Therefore, the client context can be extracted through the RPC request further encapsulated by the WMI request. In an example, the corresponding client context can be parsed according to the RPC message data of the RPC request. Furthermore, in order to pass the client process information to the WMI provider, the extracted client context can be set to the context of the WMI request to realize the transfer of the main process information from the WMI framework service process to the WMI provider process.
[0046] In an embodiment of the present application, extracting the client context through the RPC request corresponding to the WMI request includes: when the RPC request passes through the RPC transport layer, parsing the protocol type of the transport layer according to the RPC message data of the RPC request; parsing the client context of the RPC request according to the protocol type.
[0047] Specifically, when the RPC request passes through the RPC transport layer, the protocol type of the transport protocol of the transport layer can be parsed according to the RPC message data of the RPC request, and the client context of the RPC request can be further parsed according to the parsed protocol type. In an example, the parsed protocol type of the transport protocol of the transport layer can include the local procedure call protocol, the named pipe protocol, and other network protocols, such as "ncacn_ip_tcp" and "ncacn_ipx".
[0048] In an embodiment of the present application, parsing the client context of an RPC request according to the protocol type may include: when the protocol type is a local call protocol, extracting the client's process identifier and thread identifier from the RPC message data to combine and form the client context; when the protocol type is a named pipe protocol, extracting feature data of the RPC call, and querying the RPC tracing module based on the feature data to obtain the client context; when the protocol type is other network protocols, extracting the remote host information from the RPC message data to form the client context.
[0049] Specifically, according to the RPC message data, the protocol type of the transport layer protocol is parsed, and the client context is further parsed according to the protocol type, including:
[0050] If the transport layer protocol is a local procedure call protocol, such as "ncalrpc", the client's process ID and thread ID are directly extracted from a specific position in the RPC message data and combined to form the client context.
[0051] If the transport layer protocol is a named pipe protocol, such as "ncacn_np", the feature data of the RPC call is extracted, and the kernel layer RPC tracing module is queried according to the feature data to obtain the client context of the pipe client.
[0052] If the transmission protocol is other network protocols, such as "ncacn_ip_tcp" and "ncacn_ipx", the remote host information can be extracted from the message data as required to form the client context.
[0053] In this way, the client context of the RPC request is determined in different ways according to different transport layer protocols, so that the accuracy of the subject of the subsequent determination of the access action can be guaranteed.
[0054] In an embodiment of the present application, setting the client context in the WMI context of the WMI request may include: determining whether the interface method provides a context interface pointer; if the interface method provides a context interface pointer, calling the set value method of the context interface to set the client context to the named value.
[0055] Specifically, when setting the client context to the WMI context parameter, a specific parameter in the interface method, namely the IWbemContext pointer, is required. However, in the WMI request initiated by the client, this parameter may be set to NULL. Therefore, in order to smoothly set the client context to the WMI context parameter, when calling the interface method, it is necessary to first determine whether the interface method has raised the context interface pointer. In one example, if the specific parameter is not set to null, it means that the interface method provides a context interface pointer. In another example, if the specific parameter is set to null, it means that the interface method does not provide a context interface pointer.
[0056] It is understood that, when the interface method provides a context interface pointer, the interface method can be directly called to set the client context to the WMI context parameter. Specifically, the set value method of the context interface is called to set the client context to a named value, thereby completing the setting of the client context to the WMI context parameter.
[0057] In an embodiment of the present application, when the current process is about to end, that is, after the WMI framework service process calls the original IWbemServices interface method, it can then call the delete value method of the context interface to delete the named client context value, thereby effectively preventing memory waste.
[0058] In an embodiment of the present application, the method may further include: when the interface method does not provide a context interface pointer, creating a context instance object and obtaining an interface pointer of the newly created context instance; calling a set value method of the context instance interface to set the client context to a named value.
[0059] It can be understood that if the interface method does not provide a context interface pointer, it is necessary to temporarily create one to achieve setting the client context into the WMI context parameter. Specifically, first create a context instance object, and obtain the interface pointer of the newly created context instance. Then call the set value method of the newly created context instance interface to set the client context to the named value, thereby completing the setting of the client context into the WMI context parameter.
[0060] In an embodiment of the present application, when the current process is about to end, the interface pointer of the newly created context instance can be used as a parameter to call the original IWbemServices interface method and release the newly created context instance, thereby effectively preventing memory waste.
[0061] In an embodiment of the present application, extracting the client context in the WMI context parameters through the context unpacking module and setting the client context to the current thread context can include: locating the virtual function table of the IWbemServices interface that intercepts the request when the provider process is started; hooking the interface method containing the WMI context parameters in the virtual function table; extracting the client context in the WMI context by calling the interface method, and setting the client context to the current thread context.
[0062] It can be understood that when the provider process WmiPrvSE.exe process is started, the process manager module of the kernel layer can additionally load a context unpacking module for the provider process to extract the client context in the WMI context parameters and set the client context to the current thread context, providing a basis for subsequent access control.
[0063] Specifically, when the provider process is started, the virtual function table of the IWbemServices interface of the intercept request is first located, and the interface method containing the WMI context parameter in the virtual function table is hooked. In one example, there are dozens of methods in the IWbemServices interface, including multiple interface methods containing WMI context parameters. The common feature of the interface methods containing WMI context parameters is that they all have a specific parameter (i.e., the IWbemContext pointer). Further, the interface method is called, the client context is extracted from the WMI context parameter by a specific name, the original thread context is saved, and then the extracted client context is set to the current thread context. Among them, the specific name refers to the naming adopted by the client context when the client context is set to the WMI context parameter, and the thread context is a specific field in the Windows thread structure. In this way, it can be ensured that the client process information of the WMI request will not be lost, and the client context process access control or audit will be used to improve the accuracy of access control and audit.
[0064] In the embodiment of the present application, when the provider process calls the original IWbemServices interface method, the current context can be restored to the original state based on the previously saved thread context.
[0065] In this way, after the above processing, the process information and thread information of the client (consumer) that initiates the WMI request can be passed to the WMI provider via the WMI framework service, and then set to the client's thread context. When access occurs, the corresponding filtering module can extract the original client process and thread information from the thread context to accurately implement access control.
[0066] In a specific embodiment, access control usually occurs at the kernel layer. For example, when the client process c.exe attempts to delete a file through a WMI request, the action of deleting the file is finally completed by the WMI executor process wmiprvse.exe. In the traditional method, the file system access control uses wmiprvse.exe as the subject, which has low security. In a specific embodiment of the present application, in the process of forwarding the WMI request, a client context is formed by the process and thread information of the client process (c.exe), which is forwarded to the WMI executor together with the WMI request. At this time, the context of the current thread already contains the context of the client. Therefore, in the file system filter program, the client context can be extracted from the current thread context, and then the client process is used as the subject of the access, instead of using the traditional method of using the current WMI provider process as the subject, that is, the subject is c.exe instead of wmiprvse.exe. Obviously, it is more reasonable and accurate to use the client process information as the subject of the access action, which is conducive to improving the accuracy of access control.
[0067] Figure 2 A schematic diagram of the process of client context injection and unpacking provided in a specific embodiment of the present application. Figure 2 As shown, based on the method for parsing the WMI client process provided by the embodiment of the present application, in the WMI method calling process, client context injection and unsealing are implemented in the WMI framework service and the WMI provider process respectively.
[0068] like Figure 2 As shown, in the process of implementing client context injection and unsealing, the WMI framework service process may include the following steps:
[0069] S10, start the WMI framework service process;
[0070] S11, method of hooking IWbemServices interface;
[0071] S12, the interface method is called;
[0072] S13, extract the calling client context;
[0073] S14, constructing context parameters;
[0074] S15, calling the original interface method;
[0075] S16, releasing context parameters;
[0076] S17, end.
[0077] like Figure 2As shown, in the process of implementing client context injection and unsealing, the WMI provider process may include the following steps:
[0078] S10, start the WMI provider process;
[0079] S11, an asynchronous method for hooking the IWbemServices interface;
[0080] S12, the interface method is called;
[0081] S13, extracting context parameters;
[0082] S14, setting the client context to the current thread;
[0083] S15, calling the original interface method;
[0084] S16, restore thread context;
[0085] S17, end.
[0086] Through the above technical solution, when the WMI request is forwarded from the WMI framework service to the WMI provider, the original client (i.e., consumer) context is passed; when the WMI provider process executes the request, the client context is extracted and set to the thread context. This can solve the problem of RPC context loss caused by thread pool scheduling when the WMI request is passed from the consumer to the WMI framework and then to the WMI provider, thereby causing the loss of consumer subject process information.
[0087] Figure 3 The following is a schematic diagram of a method for parsing a WMI client process provided by a specific embodiment of the present application. Figure 3 As shown, in a specific embodiment of the present application, a method for parsing a WMI client process proposed in the present application is applied to a terminal detection and response product of a certain platform. The kernel layer of the platform is provided with a process manager, which is used to implement the startup detection and injection of the WMI framework service process and the WMI provider process. It can be understood that the client context is composed of a process ID and a thread ID. Since the process ID and the thread ID in the Windows system are both integer multiples of 4, the synthesis algorithm is to shift the process ID and the thread ID right by 2 bits each and place them in the upper 16 bits and the lower 16 bits of the 32-bit integer.
[0088] It can be understood that in actual application, the WMI framework service process is as follows:
[0089] When the host process svchost.exe loads wbemcore.dll, the process manager in the kernel layer of the platform can determine that this process is a WMI framework service process and load an additional context marshaling module for the process. After the context marshaling module is loaded, the location of the IWbemServices interface of the WMI namespace class and the hooking of the interface method are implemented through the following process:
[0090] 1. Hook the exported function DllGetClassObject of wbemcore.dll.
[0091] 2. In the hook function of DllGetClassObject, when the class factory object of CWbemLevel1Login is created for the first time (CLSID is {4FA18276-912A-11D1-AD9B-00C04FD8FDFF}), its CreateInstanceWbemLevel1Login method is hooked according to the returned IWbemLevel1Login interface pointer.
[0092] 3. In the aforementioned CreateInstanceWbemLevel1Login hook function, when the interface pointer of IWbemLevel1Login is obtained for the first time, the function pointer of its NTLMLogin method is hooked.
[0093] 4. In the hook function of NTLMLogin, the IWbemServices interface pointer successfully returned for the first time is the interface to be injected. According to the IWbemServices interface declaration, hook all methods with IWb emContext*pCtx.
[0094] Furthermore, the specific method executed in the hook function of the IWbemServices interface method of the above WMI request entry is as follows:
[0095] 1. Extract the client context from the RPC handle. The client context includes the client's process ID and thread ID.
[0096] 2. Determine whether the above interface method provides a context interface pointer.
[0097] If the interface method provides a context interface (IWbemContext) pointer, call the context interface's set value method to set the client context to the named value. Call the original IWbemServices interface method. Call the context interface's delete value method to delete the named client context value.
[0098] If the interface method does not provide a context interface pointer, create a context instance object and obtain the interface pointer of the newly created context instance; call the set value method of the newly created context instance interface to set the client context to the named value; use the interface pointer of the newly created context instance as a parameter and call the original IWbemServices interface method; release the newly created context instance.
[0099] It can be understood that in actual application, the WMI provider process is as follows:
[0100] When the provider host process WmiPrvSE.exe is started, the process manager module of the platform kernel layer additionally loads the context unpacking module for the provider host process. After the context unpacking module is loaded, the IWbemServices interface method responsible for receiving the request of the provider is located and hooked through the following process:
[0101] 1. Hook the CoRegisterClassObject of Windows API.
[0102] 2. In the hook function of CoRegisterClassObject, when the provider host class is registered for the first time, hook the CreateInstance method of its class factory according to the passed in interface pointer.
[0103] 3. In the aforementioned CreateInstance hook function, when the provider host class instance object is created for the first time, its GetObject method is hooked.
[0104] 4. In the aforementioned GetObject hook function, when the WMI provider host class factory object is successfully obtained for the first time, its GetProvider method is hooked.
[0105] 5. In the aforementioned GetProvider hook function, when the provider object instance is successfully obtained for the first time, the methods of its IWbemServices interface are hooked.
[0106] Further, the context unsealing sub-process is entered, and the context unsealing sub-process is as follows:
[0107] 1. Extract the client context using the specified name from the WMI context parameter of the method.
[0108] 2. Save the original thread context, which is a special field in the Windows thread structure.
[0109] 3. Set the client context into the thread context.
[0110] 4. Call the original IWbemServices interface method. It is understandable that this process may trigger access control of the product, so in the filtering engine of the product, the WMI client context can be extracted from the thread context as the subject for access control or auditing.
[0111] 5. Restore the thread context.
[0112] 6. Complete the process.
[0113] Through the above technical solution, when the WMI framework service process is started, the context marshaling module is loaded, the client context is extracted at the entrance of the WMI request, and the WMI context parameters in the request are added; then when the WMI provider process is started, the context unsealing module is loaded, and the client context is extracted from the WMI context parameters before executing the WMI request, thereby ensuring that the client information is dispatched from the request entrance (WMI framework service) to the request executor (WMI provider). In addition, when the provider executes the WMI request, the client context is set to the thread context for extraction as the subject during access control. In this way, the subject of the resource access triggered by the WMI request can be determined as the client that initiates the WMI request, instead of using the traditional method of determining the WMI provider process as the client that initiates the WMI request, which can make access control and auditing more accurate and prevent bypassing and tracing interruption.
[0114] The embodiment of the present application also provides a processor configured to execute the method for parsing a WMI client process in the above implementation.
[0115] Figure 4 A structural block diagram of a device for parsing a WMI client process provided by an embodiment of the present application. Figure 4 As shown, the embodiment of the present application provides a device 400 for parsing a WMI client process, which may include:
[0116] The context marshaling module loading unit 410 is used to load the context marshaling module when the WMI framework service process is started;
[0117] The context marshaling module execution unit 420 extracts the client context through the context marshaling module before the WMI request is dispatched to the thread pool, and adds the client context to the WMI context parameter of the WMI request;
[0118] The context unsealing module loading unit 430 loads the context unsealing module when the WMI provider process is started;
[0119] The context unsealing module execution unit 440 extracts the client context in the WMI context parameter through the context unsealing module, and sets the client context into the current thread context.
[0120] The above-mentioned device 400 for parsing the WMI client process, by loading the context marshaling module when the WMI framework service process is started, extracting the client context through the context marshaling module before the WMI request is dispatched to the thread pool, and adding the client context to the WMI context parameter of the WMI request, loading the context unsealing module when the WMI provider process is started, extracting the client context in the WMI context parameter through the context unsealing module, and setting the client context to the current thread context. The above-mentioned technical solution can determine the subject of the resource access triggered by the WMI request as the client that initiates the WMI request, making access control and auditing more precise, and is conducive to preventing malicious code from bypassing security detection and tracing interruption.
[0121] In one embodiment, the context marshaling module running unit 420 is also used to: locate the virtual function table of the IWbemServices interface of the WMI namespace class when the WMI framework service process loads the WMI core dynamic library; hook the interface method containing the WMI context parameters in the virtual function table; obtain the client context by calling the interface method, and set the client context to the WMI context parameters.
[0122] In one embodiment, the context marshaling module execution unit 420 is further used to: extract the client context through the RPC request corresponding to the WMI request; and set the client context in the WMI context parameter of the WMI request.
[0123] In one embodiment, the context marshaling module execution unit 420 is further used to: when the RPC request passes through the RPC transport layer, parse the protocol type of the transport layer according to the RPC message data of the RPC request; and parse out the client context of the RPC request according to the protocol type.
[0124] In one embodiment, the context marshaling module running unit 420 is also used for: when the protocol type is a local call protocol, extracting the client's process identifier and thread identifier from the RPC message data to combine and form a client context; when the protocol type is a named pipe protocol, extracting the characteristic data of the RPC call, and querying the RPC tracing module based on the characteristic data to obtain the client context; when the protocol type is other network protocols, extracting the remote host information from the RPC message data to form a client context.
[0125] In one embodiment, the context marshaling module execution unit 420 is further used to: determine whether the interface method provides a context interface pointer; if the interface method provides a context interface pointer, call the set value method of the context interface to set the client context to the named value.
[0126] In one embodiment, the context marshaling module execution unit 420 is further used to: create a context instance object and obtain the interface pointer of the newly created context instance when the interface method does not provide a context interface pointer; call the set value method of the context instance interface to set the client context to the named value.
[0127] In one embodiment, the context marshaling module running unit 440 is also used to: when the provider process is started, locate the virtual function table of the IWbemServices interface that intercepts the request; hook the interface method containing the WMI context parameter in the virtual function table; extract the client context in the WMI context by calling the interface method, and set the client context to the current thread context.
[0128] An embodiment of the present application also provides a machine-readable storage medium, on which a program or instruction is stored, and wherein the program or instruction, when executed by a processor, implements the method for parsing a WMI client process in the above-mentioned implementation manner.
[0129] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0130] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0131] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0133] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0134] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0135] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0136] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0137] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A method for parsing a WMI client process, characterized in that: The method comprises: When the Windows Management Instrumentation (WMI) framework service process starts, the context marshaling module is loaded; Before the WMI request is dispatched to the thread pool, the client context is extracted by the context marshaling module, and the client context is added to the WMI context parameter of the WMI request; When the WMI provider process starts, the context unpacking module is loaded; Extract the client context in the WMI context parameter through the context unpacking module, and set the client context to the current thread context; The extracting of the client context by the context marshaling module and adding the client context to the WMI context parameter of the WMI request comprises: When the WMI framework service process loads the WMI core dynamic library, the virtual function table of the IWbemServices interface of the WMI namespace class is located; Hooking the interface method containing WMI context parameters in the virtual function table, wherein the interface method is used to extract the client context from the RPC handle; The client context is acquired by calling the interface method, and the client context is set into the WMI context parameter.
2. The method according to claim 1, characterized in that The acquiring the client context by calling the interface method and setting the client context into the WMI context parameter comprises: Extracting the client context through an RPC request corresponding to the WMI request; The client context is set in a WMI context parameter of the WMI request.
3. The method according to claim 2, characterized in that The extracting the client context through the RPC request corresponding to the WMI request comprises: When the RPC request passes through the RPC transport layer, parsing the protocol type of the transport layer according to the RPC message data of the RPC request; The client context of the RPC request is parsed according to the protocol type.
4. The method according to claim 3, characterized in that The client context of the RPC request parsed according to the protocol type includes: In the case where the protocol type is a local call protocol, extracting the process identifier and thread identifier of the client from the RPC message data to combine and form the client context; In the case where the protocol type is a named pipe protocol, extracting characteristic data of the RPC call, querying an RPC tracing module according to the characteristic data to obtain the client context; When the protocol type is other network protocols, the remote host information is extracted from the RPC message data to form the client context.
5. The method according to claim 2, characterized in that: The setting of the client context in the WMI context of the WMI request comprises: Determine whether the interface method provides a context interface pointer; In case the interface method provides a context interface pointer, the set value method of the context interface is called to set the client context to the named value.
6. The method according to claim 5, characterized in that The method further comprises: In the case where the interface method does not provide the context interface pointer, creating a context instance object and obtaining the interface pointer of the newly created context instance; Call the set value method of the context instance interface to set the client context to the named value.
7. The method according to claim 1, characterized in that The extracting the client context in the WMI context parameter by the context unpacking module and setting the client context to the current thread context includes: When the provider process is started, locate the virtual function table of the IWbemServices interface that intercepts the request; Hooking the interface method of the WMI context parameter contained in the virtual function table, the interface method is used to extract the client context from the WMI context parameter by a specific name, the specific name is the name of the client context when the client context is set to the WMI context parameter; The client context in the WMI context is extracted by calling the interface method, and the client context is set in the current thread context.
8. A processor, characterized in that: The method is configured to execute the method for parsing a WMI client process according to any one of claims 1 to 7.
9. A device for parsing a WMI client process, characterized in that: The device comprises: The context marshaling module loading unit is used to load the context marshaling module when the WMI framework service process is started; A context marshaling module running unit, which extracts a client context through the context marshaling module before the WMI request is dispatched to the thread pool, and adds the client context to the WMI context parameter of the WMI request; A context unsealing module loading unit loads the context unsealing module when the WMI provider process is started; A context unsealing module running unit extracts the client context in the WMI context parameter through the context unsealing module, and sets the client context into the current thread context; The extracting of the client context by the context marshaling module and adding the client context to the WMI context parameter of the WMI request comprises: When the WMI framework service process loads the WMI core dynamic library, the virtual function table of the IWbemServices interface of the WMI namespace class is located; Hooking the interface method containing WMI context parameters in the virtual function table, wherein the interface method is used to extract the client context from the RPC handle; The client context is acquired by calling the interface method, and the client context is set into the WMI context parameter.
10. A machine-readable storage medium storing a program or an instruction, characterized in that: When the program or the instruction is executed by a processor, the method for parsing a WMI client process according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Service tracking method and device and computer readable storage medium
CN109992465A
Call management and control method and device for remote procedure call, equipment and storage medium
CN114466053A
