A method for detecting process hook at application layer

By parsing the PE format characteristics and import table of the process at the application layer, distinguishing IAT HOOK and INLINE HOOK, it solves the problem that the existing technology cannot detect INLINE HOOK at the application layer, and achieves system stability and comprehensive HOOK detection.

CN118260755BActive Publication Date: 2024-10-01CHINESE PEOPLES LIBERATION ARMY UNIT 61660
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410340674.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-25
Publication Date
2024-10-01
Estimated Expiration
2044-03-25

AI Technical Summary

Technical Problem

Existing technology cannot detect IAT HOOK and INLINE HOOK at the application layer at the same time, and driver layer detection poses system stability risks.

Method used

By obtaining the local source file of the process to be detected, simulating its loading situation in the system, parsing the PE format characteristics, obtaining the import table and function address, comparing the function address and data, to distinguish IAT HOOK and INLINE HOOK, and trace the source of HOOK document.

Benefits of technology

It achieves comprehensive detection of process HOOKs at the application layer to ensure system stability, can detect IAT HOOKs and INLINE HOOKs, and trace the source files of INLINE HOOKs, avoiding the risk of driver layer detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118260755B_ABST
    Figure CN118260755B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for detecting process Hook at the application layer, and belongs to the field of network security. In order to solve the problem of detecting both IAT HOOK and INLINE HOOK at the application layer, the present invention obtains the local source file of the process to be detected; stretches the source file of the process to be detected to the memory in the current process; obtains the import table and parses the content in the table according to the PE format characteristics of the source file of the process to be detected, and uses the parsed relative virtual address RVA to obtain all modules and function addresses; reads the memory of the process to be detected according to the PE format, obtains all module names, module address ranges and addresses of all module functions in the import table, creates snapshots for all processes at the same time, obtains all module names, module base addresses and sizes loaded by the process to be detected through system functions, and then obtains all modules and function addresses; and detects IAT HOOK and INLINE HOOK by cyclic comparison. The present invention runs at the application layer, not only performs a comprehensive detection of the process Hook, but also ensures the stability of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of network security, and in particular relates to a method for detecting a process Hook at an application layer. Background Art

[0002] Hook is a technology that intercepts, modifies or enhances operations in computer programs. It can enable another function or program to receive notifications and take corresponding measures when a specific event or operation occurs. Hook technology has been widely used in operating systems, security software, games and other fields.

[0003] There may be some malicious Hooks in the actual environment. Malicious Hooks refer to the use of Hook technology by attackers to illegally modify or control the system or application. It can not only steal user information, but also tamper with the system behavior (such as modifying system settings, hiding viruses, etc.), remotely control the computer and turn it into a zombie computer, etc.

[0004] At present, there are two main technologies for detecting Hooks: one is to detect Hooks at the application layer; the other is to detect Hooks at the driver layer. The way to detect Hooks at the application layer can detect IAT HOOKs (Import Address Table Hooks), but there is no feasible solution for detecting INLINE HOOKs (Inline Hooks). Detecting Hooks at the driver layer can be a very comprehensive detection, which can not only detect IAT HOOKs, but also INLINE HOOKs, but drivers are more dangerous for the operating system, and if you are not careful, it may cause the system to crash with a blue screen and other unexpected situations. Therefore, based on this background, it is very necessary to be able to detect both IAT HOOKs and INLINE HOOKs at the application layer. Summary of the invention

[0005] 1. Technical issues to be resolved

[0006] The technical problem to be solved by the present invention is how to provide a method for detecting process Hook at the application layer, so as to solve the problem of detecting both IAT HOOK and INLINE HOOK at the application layer.

[0007] (II) Technical solution

[0008] In order to solve the above technical problems, the present invention proposes a method for detecting process Hook at the application layer, which comprises the following steps:

[0009] Step S1, obtaining the local source file of the process to be detected;

[0010] Step S2: In the current process, the source file of the process to be detected is stretched into the memory to simulate the loading status of the process to be detected in the system;

[0011] Step S3, according to the PE format characteristics of the source file of the process to be detected, obtain the import table and parse the content in the table, and use the parsed relative virtual address RVA to obtain all module and function addresses;

[0012] Step S4, read the memory of the process to be detected according to the PE format, obtain all module names, module address ranges and addresses of all module functions in the import table, and create snapshots for all processes at the same time, obtain all module names, module base addresses and sizes loaded by the process to be detected through system functions, and then obtain all module and function addresses;

[0013] Step S5, loop all functions in the memory of the process to be detected, find the corresponding module and function address from the source file, and compare them. If the function addresses are different, it is IAT HOOK. If the function addresses are the same, compare 5 bytes of data. If the data is different, it is INLINE HOOK, and the source file of HOOK can be found.

[0014] Furthermore, the step S1 specifically includes:

[0015] Step S11, use the OpenProcess system function to open the process to be detected and obtain the returned process handle;

[0016] Step S12, obtaining an undisclosed API in the system library ntdll.dll: ZwQueryInformationProcess, the API obtains the image file information ProcessImageFileName of the process to be detected and passes it to the second parameter, and points the buffer pointer of the received file path to the parameter, thereby obtaining the local source file of the process to be detected.

[0017] Furthermore, the step S2 specifically includes:

[0018] Step S21, read the source file content into the memory, apply for the first virtual memory in the current process, read the local source file content of the process to be detected, and load it into the first virtual memory;

[0019] Step S22, obtaining the DOS header of the PE file in the source file, reading the DOS structure size content, and obtaining the DOS header structure data;

[0020] Step S23, applying for the second virtual memory: obtaining an offset according to the e_lfanew field of the PE DOS header, using the offset to obtain the PE NT header from the source file data, applying for the second virtual memory in the current process according to the base address and size in the PE NT header, if the second virtual memory cannot be applied for, then applying for a space in the virtual memory space at random, and using the starting address of the applied space as the starting address of the second virtual memory;

[0021] Step S24, according to the PE structure, each section in its record is stored at a corresponding offset position according to the start address of the applied second virtual memory through RVA;

[0022] Step S25, stretch the import table into the second virtual memory, obtain the offset of the import table according to the import table and RVA in the PE structure, and write the module name and function address data in the import table into the applied second virtual memory according to the offset and the starting address of the second virtual memory.

[0023] Furthermore, applying for a second virtual memory in the current process through the base address and size in the PE NT header includes: obtaining the PE NT header from the source file content according to the PE format, determining the starting address of the second virtual memory according to the ImageBase field of the PE NT header, and determining the size of the applied second virtual memory according to the SizeOfImage field of the PE NT header.

[0024] Furthermore, the step S3 specifically includes:

[0025] Step S31, obtain the module name and function name: according to the import table structure obtained in step S24, loop read the module name Name field in the import table descriptor structure IMAGE_IMPORT_DESCRIPTOR, obtain the function name according to the OriginalFirstThunk field structure of the linked list, and determine whether u1.Ordinal of the OriginalFirstThunk structure contains the IMAGE_ORDINAL_FLAG flag. If it does, obtain the memory offset through the u1.AddressOfData field, and use this offset to obtain the function name belonging to this module in the import table;

[0026] Step S32, obtain function address: use system function LoadLibrary to receive the returned module address, use system function GetProcAddress through this module address to obtain the addresses of all other system functions, and read the first 5 bytes of the address.

[0027] Furthermore, the step S4 specifically includes:

[0028] Step S41, obtaining the handle of the process to be detected, and using the system function OpenProcess to receive the returned handle of the process to be detected;

[0029] Step S42, obtaining the base address of the process to be detected, and using the system function EunmProcessModules to obtain the address of the first module, which is the base address of the process to be detected;

[0030] Step S43, obtaining the PE DOS header of the process to be detected, applying for a third virtual memory of the size of the PE DOS header structure in the current process for storing the PE DOS header, using the system function ReadProcessMemory to read the memory data of the corresponding size of the process to be detected, obtaining and storing the PE DOS header structure;

[0031] Step S44, applying for a fourth virtual memory in the current process, reading the data of the size of the PE NT header structure of the process to be detected according to the e_lfanew field in the PE DOS header obtained in step S43, obtaining the base address and size of the PE NT header and applying for a corresponding fourth virtual memory, if the application fails, applying for a virtual memory space of this size as the fourth virtual memory without fixing the base address, recording the base address of the fourth virtual memory, and finally reading the data of this size from the base address position in the process to be detected into the applied fourth virtual memory;

[0032] Step S45, obtaining the base address and size of all modules of the process to be detected from the fourth virtual memory, using the system function CreateToolhelp32Snapshot, and using the constant TH32CS_SNAPALL as the first parameter to create snapshots of all processes, using the system functions Module32First and Module32Next to obtain the name, module base address and size of the module in the process to be detected, and then obtaining the module address range of all modules;

[0033] Step S46, obtain the module name and function name in the import table of the process to be detected, parse the PE file from the fourth virtual memory, directly parse the OriginalFirstThunk.u1.Function field in the import table of the PE file to obtain the function address, and read the first 5 bytes of the address.

[0034] Furthermore, in step S46, the virtual address used in the process to be detected does not need to be converted into an RVA and can be used directly.

[0035] Furthermore, the step S5 specifically includes:

[0036] Step S51, compare the function address of the PE file obtained from step S3 and step S4 with the function address of the process to be detected according to the module name and function name. If the function addresses under the same module and the same function name are different, it is determined that the function is IAT HOOKed; if the function addresses are the same, compare the first 5 bytes of data in the two function addresses to see if they are the same, if they are different, it is determined to be INLINE HOOKed;

[0037] In step S52, INLINE HOOK, if the first byte of the above 5 bytes is a jmp instruction, the next 4 bytes are parsed, and the 4-byte data is compared with the module address range of all modules of the process to be detected obtained in step S45. If the address represented by the 4-byte data is within the address range of a certain module, it is determined that the source file of the HOOK is this file.

[0038] Furthermore, the step S52 specifically includes: if the first byte is E9, that is, the jmp instruction, then continue to read the subsequent 4 bytes, calculate the jump address according to the 4-byte data and the current address, compare whether this jump address is the same as the function address after the source file is stretched, if different, it means that this function is INLINE HOOK, and find the module where it is located by detecting which module address range this address is in in the process to be detected according to the address after jmp, and obtain the corresponding module name information.

[0039] Furthermore, the jump address = 4 bytes of data + current address + 5

[0040] (III) Beneficial effects

[0041] The present invention proposes a method for detecting process hooks at the application layer. Compared with the prior art, the present invention has the following significant advantages: (1) Since it runs at the application layer, the stability of the system is guaranteed, unlike the driver that affects the stability of the system. (2) It can perform a comprehensive detection of process hooks like a driver, not only detecting IAT HOOKs, but also detecting INLINE HOOKs, and tracing the source files of INLINE HOOKs. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0043] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0044] The invention discloses a method for detecting whether a process is hooked at an application layer, which includes two detection modes: IAT HOOK and INLINE HOOK.

[0045] A method for detecting a process hook at the application layer of the present invention comprises the following steps:

[0046] Step S1, obtaining the local source file of the process to be detected;

[0047] Step S2: In the current process, the source file of the process to be detected is stretched into the memory to simulate the loading status of the process to be detected in the system;

[0048] Step S3, according to the PE format characteristics of the source file of the process to be detected, obtain the import table and parse the content in the table, and use the parsed relative virtual address RVA to obtain all module and function addresses;

[0049] Step S4, read the memory of the process to be detected according to the PE format, obtain all module names, module address ranges and addresses of all module functions in the import table, and create snapshots for all processes at the same time, obtain all module names, module base addresses and sizes loaded by the process to be detected through system functions, and then obtain all module and function addresses;

[0050] Step S5, loop all functions in the memory of the process to be detected, find the corresponding module and function address from the source file, and compare them. If the function addresses are different, it is IAT HOOK. If the function addresses are the same, compare 5 bytes of data. If the data is different, it is INLINE HOOK, and the source file of HOOK can be found.

[0051] Furthermore, step S1 specifically includes:

[0052] Step S11, use the OpenProcess system function to open the process to be detected and obtain the returned process handle;

[0053] Step S12, obtain the undisclosed API of Microsoft in the system library ntdll.dll: ZwQueryInformationProcess, the API obtains the image file information ProcessImageFileName of the process to be detected and passes it to the second parameter, and points the buffer pointer of the received file path to the parameter, thereby obtaining the local source file of the process to be detected.

[0054] Furthermore, step S2 specifically includes:

[0055] Step S21, read the source file content into the memory, apply for the first virtual memory in the current process (not the process of detecting the Hook), read the local source file content of the process to be detected, and load it into the first virtual memory;

[0056] Step S22, obtaining the DOS header of the PE file in the source file, reading the DOS structure size content, and obtaining the DOS header structure data;

[0057] Step S23, applying for the second virtual memory: obtaining an offset according to the e_lfanew field of the PE DOS header, using the offset to obtain the PE NT header from the source file data, applying for the second virtual memory in the current process through the base address and size in the PE NT header, specifically, obtaining the PE NT header from the source file content according to the PE format, determining the starting address of the second virtual memory according to the ImageBase field of the PE NT header, and determining the size of the second virtual memory to be applied for according to the SizeOfImage field of the PE NT header. If the second virtual memory cannot be applied for, applying for a space in the virtual memory space at random, and using the starting address of the applied space as the starting address of the second virtual memory;

[0058] Step S24, according to the PE structure, each section in its record is stored at a corresponding offset position according to the start address of the applied second virtual memory through RVA;

[0059] Step S25, stretch the import table into the second virtual memory, obtain the offset of the import table according to the import table and RVA in the PE structure, and write the data such as the module name and function address in the import table into the applied second virtual memory according to the offset and the starting address of the second virtual memory.

[0060] Furthermore, step S3 specifically includes:

[0061] Step S31, obtain the module name and function name: according to the import table structure obtained in step S24, loop read the module name Name field in the import table descriptor structure IMAGE_IMPORT_DESCRIPTOR, obtain the function name according to the OriginalFirstThunk field structure of the linked list, and determine whether u1.Ordinal of the OriginalFirstThunk structure contains the IMAGE_ORDINAL_FLAG flag. If it does, obtain the memory offset through the u1.AddressOfData field, and use this offset to obtain the function name belonging to this module in the import table;

[0062] Step S32, get function address: use system function LoadLibrary to receive the returned module address, use system function GetProcAddress through this module address to get the addresses of all other system functions (the principle is that the virtual address of the system library is fixed when the system is loaded, so its virtual address is the same no matter in which process), and read the first 5 bytes of the address;

[0063] Furthermore, step S4 specifically includes:

[0064] Step S41, obtaining the handle of the process to be detected, and using the system function OpenProcess to receive the returned handle of the process to be detected;

[0065] Step S42, obtain the base address of the process to be detected, and use the system function EunmProcessModules to obtain the address of the first module (that is, the base address of the process to be detected);

[0066] Step S43, obtaining the PE DOS header of the process to be detected, applying for a third virtual memory of the size of the PE DOS header structure in the current process for storing the PE DOS header, using the system function ReadProcessMemory to read the memory data of the corresponding size of the process to be detected, obtaining and storing the PE DOS header structure;

[0067] Step S44, applying for a fourth virtual memory in the current process, reading the data of the size of the PE NT header structure of the process to be detected according to the e_lfanew field in the PE DOS header obtained in step S43, obtaining the base address and size of the PE NT header and applying for a corresponding fourth virtual memory, if the application fails, applying for a virtual memory space of this size as the fourth virtual memory without fixing the base address, recording the base address of the fourth virtual memory, and finally reading the data of this size from the base address position in the process to be detected into the applied fourth virtual memory;

[0068] Step S45, obtaining the base address and size of all modules of the process to be detected from the fourth virtual memory, using the system function CreateToolhelp32Snapshot, and using the constant TH32CS_SNAPALL (0x80000000) as the first parameter to create snapshots of all processes, using the system functions Module32First and Module32Next to obtain the name, module base address and size of the module in the process to be detected, and then obtaining the module address range of all modules;

[0069] Step S46, obtain the module name and function name in the import table of the process to be detected, and parse the PE file from the fourth virtual memory, which is the same as step S31, except that the virtual address used in the process to be detected does not need to be converted to RVA, and can be used directly. The function address does not need to be obtained through the system. The OriginalFirstThunk.u1.Function field in the import table of the PE file is directly parsed as the function address, and the first 5 bytes of the address are read.

[0070] Furthermore, step S5 specifically includes:

[0071] Step S51, compare the function address of the PE file obtained from step S3 and step S4 with the function address of the process to be detected according to the module name and function name. If the function addresses are different under the same module and the same function name, it is IATHOOK; if the function addresses are the same, compare the first 5 bytes of data in the two function addresses to see if they are the same, if they are different, it is judged to be INLINE HOOK;

[0072] In step S52, INLINE HOOK, if the first byte of the above 5 bytes is a jmp instruction, the next 4 bytes are parsed, and the 4-byte data is compared with the module address range of all modules of the process to be detected obtained in step S45. If the address represented by the 4-byte data is within the address range of a certain module, it is determined that the source file (dynamic library) of HOOK is this file. Example

[0073] The object of the present invention is to provide a method for comprehensively detecting process HOOK at the application layer.

[0074] The technical solution to achieve the purpose of the present invention is: a method for detecting process HOOK at the application layer, the steps are as follows:

[0075] The first step is to obtain the local source file of the process to be detected: obtain the local source file of the process to be detected according to the system interface, in preparation for the second step of simulating the loading of the process to be detected in the system;

[0076] The second step is to stretch the source file of the process to be detected into the memory of the current process: according to the PE structure, parse the content data PE structure of the local source file, read the DOS header and NT header from the PE structure, and obtain the import table of the PE file in turn, and obtain the RVA according to the import table structure, so as to load the data such as the module name and function address in the import table into the requested virtual memory;

[0077] The third step is to obtain the import table of the PE file stretched into the virtual memory, obtain all module names and function names of the PE file from the RVA of the module name and function name recorded in the import table, and use the system function to obtain the address of other functions and read 5 bytes of the address;

[0078] Step 4: Open the process to be detected, create snapshots of all processes, and use system functions to obtain the names, base addresses, and sizes of all modules loaded by the process to be detected.

[0079] Step 5: Open the process to be detected, obtain the PE DOS header of the process according to the PE file structure, and then find the PE NT header to obtain the process base address. Find the import table structure of the process to be detected from the NT header, obtain all the module names and function names in the import table according to the module name and function name virtual address recorded in the import table, and obtain the function address according to the offset field in the import table structure, and read the 5 bytes pointed to by the function address;

[0080] The sixth step is to find the corresponding function of the process to be detected obtained in the fifth step according to the module name obtained in the third step and the function name contained in the module, and compare their function addresses. If the function addresses are different, it is IAT HOOK; if the function addresses are the same, compare 5 bytes of data. If the data is different, it is INLINE HOOK, and compare the last four bytes with the module range obtained in the fourth step. If the address of the last four bytes is within a certain module, the source file of HOOK is this module. Example

[0081] Combination Figure 1 The method for detecting process Hook at the application layer of the present invention comprises the following steps:

[0082] The first step is to obtain the source file according to the process to be detected;

[0083] The second step is to stretch the source file of the process to be detected into the memory in the current process to simulate the loading status of the process to be detected in the system;

[0084] The third step is to obtain the import table of the PE file (IMAGE_IMPORT_DESCRIPTOR structure) according to the format of the source PE file, and use RVA to obtain all modules and function addresses;

[0085] The fourth step is to read the memory of the process to be detected according to the PE format, and obtain all module names, module address ranges and addresses of all module functions in the import table;

[0086] Step 5: Loop through all functions in the process memory, find the corresponding module and function address from the source file, and compare them;

[0087] a. If the function address is different, it is judged that this function is IAT HOOKed, and the corresponding function in the process can be located according to this address;

[0088] b. If the function address is the same, read the data at the address. If the first byte is E9 (i.e., the jmp instruction), continue to read the following 4 bytes, calculate the jump address based on the 4-byte data and the current address (jump address = 4-byte data + current address + 5), and compare whether this jump address is the same as the function address after the source file is stretched. If they are different, it means that this function is INLINE HOOKed, and the module where it is located can be found based on the address after the jmp (see which module address range this address is in in the process to be detected), and the corresponding module name and other information can be obtained.

[0089] Compared with the prior art, the present invention has the following significant advantages: (1) Since it runs at the application layer, the stability of the system is guaranteed, unlike the driver that affects the stability of the system. (2) Like the driver, it can perform a comprehensive detection of the process hook, not only detecting IAT HOOK, but also INLINE HOOK. And the source file of INLINE HOOK can be traced back.

[0090] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for detecting process hook at application layer, characterized in that: The method comprises the following steps: Step S1, obtaining the local source file of the process to be detected; Step S2: In the current process, the source file of the process to be detected is stretched into the memory to simulate the loading status of the process to be detected in the system; Step S3, according to the PE format characteristics of the source file of the process to be detected, obtain the import table and parse the content in the table, and use the parsed relative virtual address RVA to obtain all module and function addresses; Step S4, read the memory of the process to be detected according to the PE format, obtain all module names, module address ranges and addresses of all module functions in the import table, and create snapshots for all processes at the same time, obtain all module names, module base addresses and sizes loaded by the process to be detected through system functions, and then obtain all module and function addresses; Step S5, loop all functions in the memory of the process to be detected, find the corresponding module and function address from the source file, and compare them. If the function addresses are different, it is IAT HOOK. If the function addresses are the same, compare 5 bytes of data. If the data is different, it is INLINE HOOK, and the source file of HOOK can be found; in, The step S4 specifically includes: Step S41, obtaining the handle of the process to be detected, and using the system function OpenProcess to receive the returned handle of the process to be detected; Step S42, obtaining the base address of the process to be detected, and using the system function EunmProcessModules to obtain the address of the first module, which is the base address of the process to be detected; Step S43, obtaining the PE DOS header of the process to be detected, applying for a third virtual memory of the size of the PE DOS header structure in the current process for storing the PE DOS header, using the system function ReadProcessMemory to read the memory data of the corresponding size of the process to be detected, obtaining and storing the PE DOS header structure; Step S44, applying for a fourth virtual memory in the current process, reading the data of the size of the PENT header structure of the process to be detected according to the e_lfanew field in the PE DOS header obtained in step S43, obtaining the base address and size of the PE NT header and applying for a corresponding fourth virtual memory, if the application fails, applying for a virtual memory space of this size as the fourth virtual memory without fixing the base address, recording the base address of the fourth virtual memory, and finally reading the data of this size from the base address position in the process to be detected into the applied fourth virtual memory; Step S45, obtaining the base address and size of all modules of the process to be detected from the fourth virtual memory, using the system function CreateToolhelp32Snapshot, and using the constant TH32CS_SNAPALL as the first parameter to create snapshots of all processes, using the system functions Module32First and Module32Next to obtain the name, module base address and size of the module in the process to be detected, and then obtaining the module address range of all modules; Step S46, obtain the module name and function name in the import table of the process to be detected, parse the PE file from the fourth virtual memory, directly parse the OriginalFirstThunk.u1.Function field in the import table of the PE file to obtain the function address, and read the first 5 bytes of the address.

2. The method for detecting process hook at the application layer according to claim 1, characterized in that: The step S1 specifically includes: Step S11, use the OpenProcess system function to open the process to be detected and obtain the returned process handle; Step S12, obtaining an undisclosed API in the system library ntdll.dll: ZwQueryInformationProcess, the API obtains the image file information ProcessImageFileName of the process to be detected and passes it to the second parameter, and points the buffer pointer of the received file path to the parameter, thereby obtaining the local source file of the process to be detected.

3. The method for detecting process hook at the application layer according to claim 1, characterized in that: The step S2 specifically includes: Step S21, read the source file content into the memory, apply for the first virtual memory in the current process, read the local source file content of the process to be detected, and load it into the first virtual memory; Step S22, obtaining the DOS header of the PE file in the source file, reading the DOS structure size content, and obtaining the DOS header structure data; Step S23, applying for a second virtual memory: obtaining an offset according to the e_lfanew field of the PE DOS header, using the offset to obtain a PENT header from the source file data, applying for a second virtual memory in the current process according to the base address and size in the PENT header, if the second virtual memory cannot be applied for, applying for a space in the virtual memory space at random, and using the starting address of the applied space as the starting address of the second virtual memory; Step S24, according to the PE structure, each section in its record is stored at a corresponding offset position according to the start address of the applied second virtual memory through RVA; Step S25, stretch the import table into the second virtual memory, obtain the offset of the import table according to the import table and RVA in the PE structure, and write the module name and function address data in the import table into the applied second virtual memory according to the offset and the starting address of the second virtual memory.

4. The method for detecting process hook at the application layer as claimed in claim 3, characterized in that: Applying for the second virtual memory in the current process through the base address and size in the PE NT header includes: obtaining the PE NT header from the source file content according to the PE format, determining the starting address of the second virtual memory according to the ImageBase field of the PE NT header, and determining the size of the applied second virtual memory according to the SizeOfImage field of the PE NT header.

5. The method for detecting process hook at the application layer as claimed in claim 3 or 4, characterized in that: The step S3 specifically includes: Step S31, obtain the module name and function name: according to the import table structure obtained in step S24, loop read the module name Name field in the import table descriptor structure IMAGE_IMPORT_DESCRIPTOR, obtain the function name according to the OriginalFirstThunk field structure of the linked list, and determine whether u1.Ordinal of the OriginalFirstThunk structure contains the IMAGE_ORDINAL_FLAG flag. If it does, obtain the memory offset through the u1.AddressOfData field, and use this offset to obtain the function name belonging to this module in the import table; Step S32, obtain function address: use system function LoadLibrary to receive the returned module address, use system function GetProcAddress through this module address to obtain the addresses of all other system functions, and read the first 5 bytes of the address.

6. The method for detecting process hook at the application layer according to claim 1, characterized in that: In step S46, the virtual address used in the process to be detected does not need to be converted into RVA and can be used directly.

7. The method for detecting process hook at the application layer according to claim 1, characterized in that: The step S5 specifically includes: Step S51, compare the function address of the PE file obtained from step S3 and step S4 with the function address of the process to be detected according to the module name and function name. If the function addresses under the same module and the same function name are different, it is determined that the function is IAT HOOKed; if the function addresses are the same, compare the first 5 bytes of data in the two function addresses to see if they are the same, if they are different, it is determined to be INLINE HOOKed; In step S52, INLINE HOOK, if the first byte of the above 5 bytes is a jmp instruction, the next 4 bytes are parsed, and the 4-byte data is compared with the module address range of all modules of the process to be detected obtained in step S45. If the address represented by the 4-byte data is within the address range of a certain module, it is determined that the source file of the HOOK is this file.

8. The method for detecting process hook at the application layer as claimed in claim 7, characterized in that: The step S52 specifically includes: if the first byte is E9, that is, a jmp instruction, then continue to read the subsequent 4 bytes, calculate the jump address according to the 4-byte data and the current address, compare whether the jump address is the same as the function address after the source file is stretched, if different, it means that the function is INLINE HOOK, and find the module where the address is located by detecting which module address range the address is in in the process to be detected according to the address after the jmp, and obtain the corresponding module name information.

9. The method for detecting process hook at the application layer as claimed in claim 8, characterized in that: Jump address = 4 bytes of data + current address + 5.