Process tree creation tracking and dynamic monitoring method

Through the use of dynamic library files hook_fook.dll and hook_spawn.dll, the accuracy and compatibility problems of process tree monitoring in the existing technology are solved, and non-invasive, accurate and real-time process tree monitoring is achieved, and the system is enhanced. Monitoring capability and security defense.

CN119003334APending Publication Date: 2024-11-22深圳市云语科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410952139.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The prior art is difficult to accurately monitor the relationship between complex processes, especially when subprocesses are quickly created and destroyed, and the solutions implemented through the driver layer have compatibility problems and system stability risks, and cannot be applied to all environments.

Method used

By creating dynamic library files hook_fook.dll and hook_spawn.dll, providing hook interfaces and dynamic replacement APIs, real-time monitoring and recording of process trees are realized, using shared memory and synchronous resources, injecting and replacing CreateProcess system functions step by step, ensuring the process tree's Completeness and accuracy.

Benefits of technology

It realizes non-invasive, accurate and real-time monitoring of process trees, ensures the integrity and security of system monitoring, is suitable for a wide range of software and hardware environments, and improves system performance and security defense capabilities.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention discloses a process tree creation tracking and dynamic monitoring method. According to the method, the cookform.dll is used for initializing a monitoring environment, including creating a shared memory and synchronous resources, and is used for storing and managing records created by the process. The method comprises the following steps of: establishing a hook DLL (hook spread 32. Dll and hook spread 64. Dll) aiming at processes of different platform architectures, realizing dynamic replacement of a CreateProcess series API (Application Program Interface), and ensuring that a monitoring logic is automatically injected when a new process is established. According to the method, fine process creation monitoring logic is realized, and the process creation link is comprehensively captured and recorded in the shared memory on the premise that normal execution of the target process is not affected through the injection-recording-recovery process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer operating system management, and in particular to a method for creating, tracking and dynamically monitoring a process tree. Background Art

[0002] Current methods for monitoring process creation mainly rely on the APIs provided by the operating system, such as the Process32First series of functions. These methods have limitations and are difficult to accurately capture the relationship between complex processes, especially when child processes are quickly created and destroyed. In addition, although the driver layer can fully record process creation information, this solution is not suitable for all environments because it requires deep system permissions, has compatibility issues, and has system stability risks.

[0003] Therefore, the prior art has defects and needs to be improved. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a method for process tree creation tracking and dynamic monitoring, which can monitor and record the creation process of the entire process tree starting from the root process in real time and accurately, including temporary short-lived processes, and provide complete and reliable process information for system analysis and security monitoring.

[0005] The technical solution of the present invention is as follows: a method for creating, tracking and dynamically monitoring a process tree is provided, comprising the following steps.

[0006] S1: Create two dynamic library files: hook_fook.dll and hook_spawn.dll; the hook_fook.dll is used to initialize the monitoring environment, including creating shared memory and synchronization resources for storing and managing process creation records; the hook_fork.dll is the injected SDK, which provides a hook interface for injecting the root process to be monitored. The parameter is the process id of the root process to be monitored. Starting from the injection, the subsequent process tree will be monitorable; hook_spawn.dll is used for dynamic replacement of the CreateProcess series API to ensure that the monitoring logic is automatically injected when a new process is created.

[0007] S2: When calling the hook interface of hook_fork.dll to start monitoring a process tree, the process id of the root process of the process tree is pid_x, and the following process is performed: S21: Create an inter-process communication event named event_pid_x; S22: Create an A-byte shared memory named fork_pid_x, where the first B bytes are used to store the name of the above event; the middle C byte records the number of process tree records, and the subsequent D bytes are used to store the process id of the subsequent process tree; S23: Create an E-byte shared memory named spwan_pid_x, where the first F bytes are used to store the process id of the root process, that is, pid_x, and the subsequent G bytes are used to mark whether the injection is completed; S24: Inject hook_spawn.dll into the root process pid_x; S25: Wait for the injection of hook_spawn.dll to be completed. The x in pid_x is a number, such as 1, 2, 3..., a, b, c, etc., which is used to distinguish different processes.

[0008] S3: Whenever the process pid_x is injected into hook_spawn.dll, the following process is performed; S31: Open the E-byte shared memory named spawn_pid_x, obtain the process id of the root process from the first F bytes, i.e. pid_x, and mark the subsequent G bytes as completed; S32: Open the shared memory named fork_pid_x, read the event name of the first B bytes, open the event, and read the number of records in the middle C bytes while ensuring synchronization of the event, write pid_x to the subsequent shared memory, and update the number of records in the middle C bytes; S33: Replace the CreateProcess system function with the function after modifying the parameters, the parameters are the parameters changed in processes S31 and S32; and record the original function, i.e. CreateProcess system function, as TrueCreateProcessW, and record the replaced function as MineCreateProcessW;; S34: Mark the subsequent G bytes of spawn_pid_x as completed, so that the injected process will stop waiting when it detects the completion mark.

[0009] S4: When any program needs to monitor the pid_x process tree, it only needs to open the shared memory named fork_pid_x, read the middle C byte to get the size of the process tree, and read the subsequent bytes to read the process id in the process tree.

[0010] AG is set according to actual needs; preferably, the value range is 1-100000. Preferably, in a better solution, A is 4096, B is 128, C is 4, D is 3964, E is 8, F is 4, and G is 4.

[0011] Furthermore, the hook_spawn.dll includes: hook_spawn_32.dll and hook_spawn_64.dll, hook_spawn_32.dll is injected into a 32-bit process, and the hook_spawn_64.dll is used to inject into a 64-bit process.

[0012] Furthermore, in process S25, polling is performed to detect whether the marking in S23 is completed. During the polling process, a timeout mechanism is added to prevent polling anomalies.

[0013] Furthermore, in process S23, the initial value of the mark injection is false.

[0014] Furthermore, whenever the process pid_m injected with hook_spawn.dll uses CreateProcessW to create a child process pid_n, the replaced MineCreateProcessW function will be called; the MineCreateProcessW of the parent process pid_m performs the following process.

[0015] A1: Change the parameter dwCreationFlags of CreateProcessW to the parameter CREATE_SUSPENDED for suspending the process, and call the TrueCreateProcessW function to create the child process pid_n.

[0016] A2: Create a shared memory of E bytes named spawn_pid_n, where the first F bytes are used to store the process ID of the root process, which is pid_x in step S2, and the subsequent G bytes are used to mark whether the injection is completed.

[0017] A3: Inject hook_spawn.dll into the child process pid_n; execute flow S31-S34.

[0018] A4: Wait for pid_n to complete the injection.

[0019] A5: If the original parameter dwCreationFlags does not have the CREATE_SUSPENDED flag, schedule ResumeProcess to start the child process pid_n;

[0020] Furthermore, in process A2, the initial value of the mark injection is false.

[0021] Furthermore, in process A4, the completion mark in spawn_pid_n is detected by polling to determine whether the injection is completed. During the polling process, a timeout mechanism is added to prevent polling anomalies.

[0022] By adopting the above scheme, the present invention provides a method for creating, tracking and dynamically monitoring a process tree, which is of great significance for enhancing system monitoring capabilities, improving security defense and optimizing system performance. The present invention has the following technical effects:

[0023] (1) Non-invasiveness: The present invention does not modify the underlying system, does not pose a threat to system stability, and is applicable to a wide range of software and hardware environments.

[0024] (2) Accuracy: Through the step-by-step injection and synchronous recording mechanism, the integrity and accuracy of the process tree structure can be ensured even in the face of processes that are created and destroyed quickly.

[0025] (3) Real-time: Dynamic monitoring design ensures real-time updating of process creation information, facilitating immediate analysis and response.

[0026] (4) Ease of use: Accessing shared memory data through a simple interface makes it easier for developers or system administrators to visualize and analyze process relationships, thereby improving work efficiency. DETAILED DESCRIPTION

[0027] The present invention is described in detail below in conjunction with specific embodiments.

[0028] This embodiment provides a method for creating, tracking and dynamically monitoring a process tree, including the following steps.

[0029] S1: Create two dynamic library files: hook_fook.dll and hook_spawn.dll; the hook_fook.dll is used to initialize the monitoring environment, including creating shared memory and synchronization resources for storing and managing process creation records; the hook_fork.dll is the injected SDK, which provides a hook interface for injecting the root process to be monitored. The parameter is the process id of the root process to be monitored. Starting from the injection, the subsequent process tree will be monitorable; hook_spawn.dll is used for dynamic replacement of the CreateProcess series API to ensure that the monitoring logic is automatically injected when a new process is created.

[0030] S2: When the hook interface of hook_fork.dll is called to start monitoring a process tree, the process id of the root process of the process tree is pid_x, such as pid_1; the following process is performed: S21: Create an inter-process communication event named event_pid_x; S22: Create a 4096-byte shared memory named fork_pid_x, of which the first 128 bytes are used to store the name of the above event; the middle 4 bytes record the number of process tree records, and the subsequent 3964 bytes are used to store the process id of the subsequent process tree; S23: Create an 8-byte shared memory named spwan_pid_x, of which the first 4 bytes are used to store the process id of the root process, that is, pid_x, and the subsequent 4 bytes are used to mark whether the injection is completed; S24: Inject hook_spawn.dll into the root process pid_x; S25: Wait for the injection of hook_spawn.dll to be completed.

[0031] S3: Whenever the process pid_x is injected into hook_spawn.dll, the following process is performed; S31: Open the 8-byte shared memory named spawn_pid_x, obtain the process id of the root process from the first 4 bytes, that is, pid_x, and mark the subsequent 4 bytes as completed; S32: Open the shared memory named fork_pid_x, read the first 128 bytes of the event name, open the event, and read the number of records in the middle 4 bytes while ensuring synchronization of the event, write pid_x to the subsequent shared memory, and update the number of records in the middle 4 bytes; S33: Replace the CreateProcess system function with the function after modifying the parameters, and the parameters are the parameters changed in processes S31 and S32; and record the original function, that is, the CreateProcess system function, as TrueCreateProcessW, and record the replaced function as MineCreateProcessW; S34: Mark the subsequent 4 bytes of spawn_pid_x as completed, so that the injected process will stop waiting when it detects the completion mark.

[0032] S4: When any program needs to monitor the pid_x process tree, it only needs to open the shared memory named fork_pid_x, read the middle 4 bytes to get the size of the process tree, and read the subsequent bytes to read the process id in the process tree.

[0033] In this embodiment, the hook_spawn.dll includes: hook_spawn_32.dll and hook_spawn_64.dll, hook_spawn_32.dll is injected into a 32-bit process, and the hook_spawn_64.dll is used to inject into a 64-bit process.

[0034] In this embodiment, in process S25, polling is performed to detect whether the marking in S23 is completed. During the polling process, a timeout mechanism is added to prevent polling anomalies.

[0035] In this embodiment, in process S23, the initial value of the mark injection is false.

[0036] In this embodiment, whenever the process pid_m injected with hook_spawn.dll uses CreateProcessW to create a child process pid_n, the replaced MineCreateProcessW function will be called; MineCreateProcessW of the parent process pid_m performs the following process.

[0037] A1: Change the parameter dwCreationFlags of CreateProcessW to the parameter CREATE_SUSPENDED for suspending the process, and call the TrueCreateProcessW function to create the child process pid_n.

[0038] A2: Create an 8-byte shared memory named spawn_pid_n, where the first 4 bytes are used to store the process ID of the root process, which is pid_x in step S2, and the subsequent 4 bytes are used to mark whether the injection is completed.

[0039] A3: Inject hook_spawn.dll into the child process pid_n; execute flow S31-S34.

[0040] A4: Wait for pid_n to complete the injection.

[0041] A5: If the original parameter dwCreationFlags does not have the CREATE_SUSPENDED flag, schedule ResumeProcess to start the child process pid_n;

[0042] In this embodiment, in process A2, the initial value of the mark injection is false.

[0043] In this embodiment, in process A4, whether the injection is completed is determined by polling to detect the completion mark in spawn_pid_n. During the polling process, a timeout mechanism is added to prevent polling abnormalities.

[0044] In summary, the present invention provides a method for creating, tracking and dynamically monitoring a process tree, which is of great significance for enhancing system monitoring capabilities, improving security defense and optimizing system performance. The present invention has the following technical effects:

[0045] (1) Non-invasiveness: The present invention does not modify the underlying system, does not pose a threat to system stability, and is applicable to a wide range of software and hardware environments.

[0046] (2) Accuracy: Through the step-by-step injection and synchronous recording mechanism, the integrity and accuracy of the process tree structure can be ensured even in the face of processes that are created and destroyed quickly.

[0047] (3) Real-time: Dynamic monitoring design ensures real-time updating of process creation information, facilitating immediate analysis and response.

[0048] (4) Ease of use: Accessing shared memory data through a simple interface makes it easier for developers or system administrators to visualize and analyze process relationships, thereby improving work efficiency.

[0049] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for creating, tracking and dynamically monitoring a process tree, characterized in that: The following steps are involved: S1: Create two dynamic library files: hook_fook.dll, hook_spawn.dll; The hook_fook.dll is used to initialize the monitoring environment, including creating shared memory and synchronization resources for storing and managing process creation records; the hook_fork.dll is an injected SDK, providing a hook interface for injecting the root process to be monitored, and the parameter is the process ID of the root process to be monitored; hook_spawn.dll is used to dynamically replace the CreateProcess series API to ensure that the monitoring logic is automatically injected when a new process is created; S2: When the hook interface of hook_fork.dll is called to start monitoring a process tree, the process id of the root process of the process tree is pid_x, and the following process is performed: S21: Create an inter-process communication event named event_pid_x; S22: Create an A-byte shared memory named fork_pid_x, where the first B bytes are used to store the name of the above event; the middle C byte records the number of process tree records, and the subsequent D bytes are used to store the process ID of the subsequent process tree; S23: Create a shared memory of E bytes named spwan_pid_x, where the first F bytes are used to store the process ID of the root process, i.e. pid_x, and the subsequent G bytes are used to mark whether the injection is completed; S24: Inject hook_spawn.dll into the root process pid_x; S25: Wait for the injection of hook_spawn.dll to be completed; S3: Whenever process pid_x is injected into hook_spawn.dll, the following process is performed; S31: Open the shared memory of E bytes named spawn_pid_x, obtain the process ID of the root process, i.e. pid_x, from the first F bytes, and mark the subsequent G bytes as completed; S32: Open the shared memory named fork_pid_x, read the event name of the first B bytes, open the event, and read the number of records in the middle C bytes when the event is synchronized, write pid_x to the subsequent shared memory, and update the number of records in the middle C bytes; S33: Replace the CreateProcess system function with a function after modifying parameters, where the parameters are the parameters changed in processes S31 and S32; and record the original function, i.e., the CreateProcess system function, as TrueCreateProcessW, and record the replaced function as MineCreateProcessW; S34: mark the subsequent G bytes of spawn_pid_x as completed; S4: When any program needs to monitor the pid_x process tree, it only needs to open the shared memory named fork_pid_x, read the middle C byte to get the size of the process tree, and read the subsequent bytes to read the process id in the process tree.

2. A method for creating, tracking and dynamically monitoring a process tree according to claim 1, characterized in that: The hook_spawn.dll includes: hook_spawn_32.dll and hook_spawn_64.dll, hook_spawn_32.dll is injected into a 32-bit process, and the hook_spawn_64.dll is used to inject into a 64-bit process.

3. A method for creating, tracking and dynamically monitoring a process tree according to claim 1, characterized in that: In process S25, whether the marking in S23 is completed is detected by polling.

4. A method for creating, tracking and dynamically monitoring a process tree according to claim 3, characterized in that: During the polling process, add a timeout mechanism to prevent polling exceptions.

5. A method for creating, tracking and dynamically monitoring a process tree according to claim 1, characterized in that: In process S23, the initial value of the mark injection is false.

6. A method for creating, tracking and dynamically monitoring a process tree according to claim 1, characterized in that: Whenever the process pid_m injected with hook_spawn.dll uses CreateProcessW to create a child process pid_n, the replaced MineCreateProcessW function will be called; the MineCreateProcessW of the parent process pid_m performs the following process. A1: Change the parameter dwCreationFlags of CreateProcessW to the parameter CREATE_SUSPENDED for suspending the process, and call the TrueCreateProcessW function to create the child process pid_n; A2: Create a shared memory of E bytes named spawn_pid_n, where the first F bytes are used to store the process ID of the root process, which is pid_x in step S2, and the subsequent G bytes are used to mark whether the injection is completed; A3: Inject hook_spawn.dll into the child process pid_n; execute flow S31-S34; A4: Wait for pid_n to complete injection; A5: If the original parameter dwCreationFlags does not have the CREATE_SUSPENDED flag, schedule ResumeProcess to start the child process pid_n; 7. A method for creating, tracking and dynamically monitoring a process tree according to claim 6, characterized in that: In process A2, the initial value of the mark injection is false.

8. A method for creating, tracking and dynamically monitoring a process tree according to claim 6, characterized in that: In process A4, whether the injection is completed is determined by polling and detecting the completion flag in spawn_pid_n.

9. A method for creating, tracking and dynamically monitoring a process tree according to claim 8, characterized in that: During the polling process, add a timeout mechanism to prevent polling exceptions.

10. A method for creating, tracking and dynamically monitoring a process tree according to claim 1, characterized in that: A is 4096, B is 128, C is 4, D is 3964, E is 8, F is 4, and G is 4.