A method to efficiently intercept Windows PE file loading

Through the Windows file microfilter driver and the hook and callback mechanism of MiCreateImageFileMap and FsRtlGetFileSize functions, efficient interception and detection of Windows PE files is achieved, solving the problem of low PE file loading efficiency in the existing technology, and providing safe and effective files. Filtering and loading rejection mechanisms.

CN118260749BActive Publication Date: 2024-09-27CHINESE PEOPLES LIBERATION ARMY UNIT 61660
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410341728.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-25
Publication Date
2024-09-27
Estimated Expiration
2044-03-25

AI Technical Summary

Technical Problem

Existing technology is difficult to efficiently intercept the loading of Windows PE files, especially because the same PE file object triggers multiple LoadImageNotifyRoutine calls, resulting in low efficiency, and there is a lack of method to terminate the PE file mapping virtual memory.

Method used

Use the Windows file microfilter driver, hook the MiCreateImageFileMap function and FsRtlGetFileSize function, and use the pre-operation callback function to detect and filter PE files. It will only detect the PE file when it is first created and memory mapped, and set the exception return value to prevent loading. .

Benefits of technology

It improves the efficiency of PE file detection, provides a safe and effective method to refuse file loading, and avoids the performance loss caused by multiple interception calls.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118260749B
    Figure CN118260749B
Patent Text Reader

Abstract

The present invention relates to a method for efficiently intercepting Windows PE file loading, and belongs to the field of network space security technology. In order to solve the problem of low efficiency of the existing method for intercepting Windows PE file loading, the present invention comprehensively considers Windows 32-bit and 64-bit systems, and designs a method for efficiently intercepting Windows PE file loading with the help of Windows file microfilter driver on the basis of in-depth research on Windows file microfilters and reverse analysis of multiple system functions such as MiCreateImageFileMap and FsRtlGetFileSize. The method only detects PE files when the Windows system creates PE files and memory mappings for the first time, thereby improving detection efficiency and providing a safe and effective method for rejecting file loading.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of network space security, and in particular relates to a method for efficiently intercepting Windows PE file loading. Background Art

[0002] PE files (Portable Executable) are the basic elements for executing code on Windows operating systems, and mainly include: executable files (EXE), dynamic link libraries (DLL), drivers (SYS), and other components such as screen savers (SCR), ActiveX (OCX), etc. Windows security software development often involves detecting PE files that are about to be loaded and preventing malicious files from being loaded into the system. How to effectively prevent PE files from loading is an important issue.

[0003] The intuitive way to intercept PE file loading can be achieved by setting the LoadImageNotifyRoutine callback function, but since the same PE file object often triggers multiple LoadImageNotifyRoutine calls, this method is inefficient. Although Microsoft provides the PsSetLoadImageNotifyRoutine / LoadImageNotifyRoutine mechanism to monitor the virtual memory mapping of PE files, it does not provide a method to terminate the mapping process. Summary of the invention

[0004] 1. Technical issues to be resolved

[0005] The technical problem to be solved by the present invention is: in order to solve the problems existing in the existing method for intercepting Windows PE file loading, a method for intercepting Windows PE file loading is designed.

[0006] (II) Technical solution

[0007] In order to solve the above technical problems, the present invention provides a method for efficiently intercepting Windows PE file loading, comprising the following steps:

[0008] Step S1: If the operating system is 32-bit, execute step S2; if the operating system is 64-bit, execute step S3;

[0009] Step S2, directly hook the system internal function MiCreateImageFileMap, access the file content through the first parameter of the MiCreateImageFileMap function, realize the detection and filtering of PE files, and go to step S5;

[0010] Step S3, registering the file micro-filter driver in the Windows system and setting the IRP major function code to be filtered and the pre-operation callback function;

[0011] The function of the pre-operation callback function is: by judging the type of IRP parameters and query parameters, intercept the call of FsRtlGetFileSize function, and then judge whether the previous layer calling function is MiCreateImageFileMap, if so, access the file content through the first parameter of MiCreateImageFileMap function, and realize the identification and detection filtering of PE files; otherwise, skip this interception;

[0012] Step S4, calling the pre-operation callback function to detect and filter PE files;

[0013] Step S5: Mark the file according to the detection and filtering results. If it is a malicious file, it will be marked as BAD. The mark is set in the SECTION object that uniquely corresponds to the PE file.

[0014] Step S6: Allow or deny the loading of the PE file according to the mark in step S5.

[0015] Preferably, in step S4, the pre-operation callback function uses the IRP parameter to perform stack backtracing to locate the MiCreateImageFileMap function, thereby realizing the detection of the PE file.

[0016] Preferably, in step S4, the pre-operation callback function uses the IRP parameter to perform stack backtracing to locate the MiCreateImageFileMap function, thereby realizing the detection of the PE file, which specifically includes: the pre-operation callback function determines whether the current call occurs in FsRtlGetFileSize by judging whether it is a FileStandardInformation query. If it is a FileStandardInformation query, it means that the current call occurs in FsRtlGetFileSize. At this time, according to the IRP parameter passed by FsRtlGetFileSize for querying, the next instruction address returned by the FsRtlGetFileSize function is obtained in reverse, and the characteristics of the address are matched with the corresponding part of the assembly instructions of the MiCreateImageFileMap function. If the match is successful, it is finally determined that the current call is in the MiCreateImageFileMap function call, and then a filtering operation is performed. Otherwise, it is determined that the current call is not in the MiCreateImageFileMap function call; if it is not a FileStandardInformation query, the current call does not occur in FsRtlGetFileSize, and it is also determined that the current call is not in the MiCreateImageFileMap function call.

[0017] Preferably, when the filtering operation is performed in step S4, the call of the FsRtlGetFileSize function is intercepted by the pre-operation callback function, and the return value of the FsRtlGetFileSize function is set, thereby affecting the loading of the PE file.

[0018] Preferably, when step S4 performs the filtering operation, the call of the FsRtlGetFileSize function is intercepted by the pre-operation callback function, and the return value of the FsRtlGetFileSize function is set, thereby affecting the loading of the PE file. Specifically, by setting the status Status and information Information returned by the call to the FsRtlGetFileSize function to normal file information, it is ensured that the MiCreateImageFileMap function continues to run normally. By setting them to abnormal values, the MiCreateImageFileMap function can be prevented from continuing to run, thereby achieving the purpose of PE file filtering.

[0019] Preferably, in step S4, when the operating system calls MiCreateImageFileMap, it further calls the FsRtlGetFileSize function, thereby falling into the pre-operation callback function.

[0020] Preferably, the IRP main function code is IRP_MJ_QUERY_INFORMATION, which is a file information query function code. The main function code is set to intercept the file information query operation of the operating system.

[0021] The present invention also provides a system for implementing the method.

[0022] The invention also provides a Windows security software design method implemented based on the method.

[0023] The invention also provides a Windows security system designed based on the system.

[0024] (III) Beneficial effects

[0025] In order to solve the defects of the existing methods for intercepting Windows PE file loading, the present invention comprehensively considers Windows 32-bit and 64-bit systems, and designs a method for efficiently intercepting Windows PE file loading with the help of Windows file microfilter driver based on in-depth research on Windows file microfilters and reverse analysis of multiple system functions such as MiCreateImageFileMap and FsRtlGetFileSize. This method only detects PE files when the Windows system creates PE files and memory mappings for the first time, which improves detection efficiency and provides a safe and effective method for rejecting file loading. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 This is a schematic diagram of the Windows file system minifilter manager;

[0027] Figure 2 It is a flow chart of intercepting PE file loading of the present invention. DETAILED DESCRIPTION

[0028] 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.

[0029] like Figure 1 The following is a diagram of the Windows file system minifilter manager. The Windows file minifilter driver can filter IRP-based I / O operations, fast I / O operations, and file system filter (FSFilter) callback operations. The minifilter driver selects the I / O operation to filter and can register the preoperation callback routine (Preoperation Callback Routine) or the postoperation callback routine (Postoperation Callback Routine), or both.

[0030] In order to solve the defects of the existing methods for intercepting Windows PE file loading, the present invention comprehensively considers Windows 32-bit and 64-bit systems, and designs a method for efficiently intercepting Windows PE file loading with the help of Windows file microfilter driver based on in-depth research on Windows file microfilters and reverse analysis of multiple system functions such as MiCreateImageFileMap and FsRtlGetFileSize. This method only detects PE files when the Windows system creates PE files and memory mappings for the first time, which improves detection efficiency and provides a safe and effective method for rejecting file loading.

[0031] refer to Figure 2 The present invention provides a method for efficiently intercepting Windows PE file loading, comprising the following steps:

[0032] Step S1: If the operating system is 32-bit, execute step S2; if the operating system is 64-bit, execute step S3;

[0033] Step S2, directly hook the system internal function MiCreateImageFileMap, access the file content through the first parameter of the MiCreateImageFileMap function, realize the detection and filtering of PE files, and go to step S5;

[0034] Step S3: Since the 64-bit system does not support hooking, the file micro-filter driver is registered in the Windows system and the IRP major function code (IRP_MJ_QUERY_INFORMATION) to be filtered and the pre-operation callback function are set; the IRP major function code is a file information query function code, and setting this major function code is mainly used to intercept file information query operations of the operating system;

[0035] The function of the pre-operation callback function is: by judging the type of IRP parameters and query parameters, intercept the call of FsRtlGetFileSize function, and then judge whether the previous layer calling function is MiCreateImageFileMap, if so, access the file content through the first parameter of MiCreateImageFileMap function, and realize the identification and detection filtering of PE files; otherwise, skip this interception;

[0036] Step S4, calling the pre-operation callback function to detect and filter PE files; in this step, since the pre-operation callback function has been registered, the operating system will further call the FsRtlGetFileSize function when calling MiCreateImageFileMap, thereby falling into the pre-operation callback function set in step S3;

[0037] Step S5: Mark the file according to the detection and filtering results. If it is a malicious file, it will be marked as BAD. The mark is set in the SECTION object that uniquely corresponds to the PE file;

[0038] Step S6: Allow or deny the loading of the PE file according to the mark in step S5.

[0039] In the method, in step S4, the pre-operation callback function uses the IRP parameter to perform stack backtracing to locate the MiCreateImageFileMap function, thereby realizing the detection of the PE file. Specifically, the pre-operation callback function determines whether the current call occurs in FsRtlGetFileSize by judging whether the current call is a FileStandardInformation query. If it is a FileStandardInformation query, it means that the current call occurs in FsRtlGetFileSize. At this time, according to the IRP parameter passed by FsRtlGetFileSize for querying, the next instruction address returned by the FsRtlGetFileSize function can be obtained in reverse, and the characteristics of the address are matched with the corresponding assembly instructions of the MiCreateImageFileMap function. If the match is successful, it is finally determined that the current call is in the MiCreateImageFileMap function call, and then the filtering operation is performed. Otherwise, it is determined that the current call is not in the MiCreateImageFileMap function call; if it is not a FileStandardInformation query, the current call does not occur in FsRtlGetFileSize, and it is also determined that the current call is not in the MiCreateImageFileMap function call.

[0040] In the method, when step S4 performs the filtering operation, the call of the FsRtlGetFileSize function is intercepted by the pre-operation callback function, and the return value of the FsRtlGetFileSize function is set, thereby affecting the loading of the PE file. Specifically, by setting the status Status and information Information returned by calling the FsRtlGetFileSize function to normal file information, the MiCreateImageFileMap function is guaranteed to continue to run normally, and by setting them to abnormal values, the MiCreateImageFileMap function can be prevented from continuing to run, thereby achieving the purpose of PE file filtering, and then achieving the purpose of refusing PE file loading.

[0041] 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 efficiently intercepting Windows PE file loading, characterized in that: The following steps are involved: Step S1: If the operating system is 32-bit, execute step S2; if the operating system is 64-bit, execute step S3; Step S2, directly hook the system internal function MiCreateImageFileMap, access the file content through the first parameter of the MiCreateImageFileMap function, realize the detection and filtering of PE files, and go to step S5; Step S3, registering the file micro-filter driver in the Windows system and setting the IRP major function code to be filtered and the pre-operation callback function; The function of the pre-operation callback function is: by judging the type of IRP parameters and query parameters, intercept the call of FsRtlGetFileSize function, and then judge whether the previous layer calling function is MiCreateImageFileMap, if so, access the file content through the first parameter of MiCreateImageFileMap function, and realize the identification and detection filtering of PE files; otherwise, skip this interception; Step S4, calling the pre-operation callback function to detect and filter PE files; Step S5: Mark the file according to the detection and filtering results. If it is a malicious file, it will be marked as BAD. The mark is set in the SECTION object that uniquely corresponds to the PE file. Step S6, allowing or denying the loading of the PE file according to the mark in step S5; In step S4, the pre-operation callback function uses the IRP parameter to perform stack backtracing to locate the MiCreateImageFileMap function, thereby realizing the detection of the PE file; In step S4, the pre-operation callback function uses the IRP parameter to perform stack backtracing to locate the MiCreateImageFileMap function, thereby realizing the detection of the PE file, which specifically includes: the pre-operation callback function determines whether the current call occurs in FsRtlGetFileSize by judging whether it is currently a FileStandardInformation query. If it is a FileStandardInformation query, it means that the current call occurs in FsRtlGetFileSize. At this time, according to the IRP parameter passed by FsRtlGetFileSize for querying, the next instruction address returned by the FsRtlGetFileSize function is obtained in reverse, and the characteristics of the address are matched with the corresponding assembly instructions of the MiCreateImageFileMap function. If the match is successful, it is finally determined that the current call is in the MiCreateImageFileMap function call, and then the filtering operation is performed, otherwise it is determined that the current call is not in the MiCreateImageFileMap function call; If it is not a FileStandardInformation query, the current call does not occur in FsRtlGetFileSize, and it is also determined that the current call is not in the MiCreateImageFileMap function call.

2. The method according to claim 1, characterized in that When the filtering operation is performed in step S4, the call of the FsRtlGetFileSize function is intercepted by the pre-operation callback function, and the return value of the FsRtlGetFileSize function is set, thereby affecting the loading of the PE file.

3. The method according to claim 2, characterized in that When step S4 performs the filtering operation, the call of the FsRtlGetFileSize function is intercepted by the pre-operation callback function, and the return value of the FsRtlGetFileSize function is set, thereby affecting the loading of the PE file. Specifically, the status Status and information Information returned by the call to the FsRtlGetFileSize function are set to normal file information to ensure that the MiCreateImageFileMap function continues to run normally, and by setting them to abnormal values, the MiCreateImageFileMap function is prevented from continuing to run, thereby achieving the purpose of PE file filtering.

4. The method according to claim 1, characterized in that In step S4, when the operating system calls MiCreateImageFileMap, it further calls the FsRtlGetFileSize function, thereby falling into the pre-operation callback function.

5. The method according to claim 1, characterized in that The IRP main function code is IRP_MJ_QUERY_INFORMATION, which is a file information query function code. The main function code is set to intercept the file information query operation of the operating system.

6. A system for implementing the method according to any one of claims 1 to 5.

7. A Windows security software design method implemented based on the method as claimed in any one of claims 1 to 5.

8. A Windows security system based on the system design according to claim 6.

Citation Information

Patent Citations

  • Managed file system filter model and architecture

    CA2450044A1

  • File mandatory access control method and system thereof based on minifilter drive

    CN104657676A

  • Windows system-oriented file protection system and method

    CN115329351A

  • File Security system based on filter driver and method thereof

    KR1020160024265A

  • Interacting with data in hidden storage

    US20100095082A1