Fileless attack detection method, device, equipment and storage medium
By hooking the write function and permission check function in the kernel space, eBPF technology is used to detect fileless attacks, which solves the problems of high intrusiveness and poor detection effect of fileless attack detection in the existing technology, and achieves low intrusiveness and high efficiency. Fileless attack detection.
Patent Information
- Application Number
- CN202311083527.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-24
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2043-08-24
AI Technical Summary
Existing fileless attack detection methods are highly intrusive in Linux systems, affecting the stability and security of the target process, and malware can bypass ptrace detection through anti-debugging technology, resulting in the inability to effectively detect fileless attacks.
By hooking the write function and permission check function in the kernel space, eBPF technology is used to detect whether the target process calls to write a memory file, and fileless attack detection is performed based on the file's unique identification information to avoid additional code in the target process and reduce intrusion. .
It achieves low-intrusive and efficient fileless attack detection, which can detect fileless attacks from the kernel level, improve detection accuracy and business stability, and reduce the impact on normal business and underlying systems.
Smart Images

Figure CN117272298B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a fileless attack detection method, apparatus, device, and storage medium. Background Art
[0002] Fileless attack is an attack method that does not write malicious programs to the disk. When the attacker uses this technology to carry out the attack, the malicious file will not be written to the disk, but the malicious file will be hidden in the memory and executed, hence the name fileless attack. The implementation of fileless attack takes advantage of the defects of traditional anti-malware tools in detection and defense: disk file-based detection is required.
[0003] Currently, the mainstream fileless attack detection under Linux is mainly implemented using ptrace. However, using ptrace for fileless attack detection requires attaching ptrace to the target process, which is highly invasive and will affect the stability and security of the target process, thereby affecting normal business and even the stability and security of the underlying system. In addition, malware can easily bypass ptrace by using anti-debugging technology, resulting in the inability to detect fileless attacks. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present disclosure provide a fileless attack detection method, apparatus, device and storage medium.
[0005] A first aspect of an embodiment of the present disclosure provides a fileless attack detection method, the method comprising:
[0006] When the write function of the kernel space is called by the target process, it is triggered to detect whether the target process is calling the write function to write the memory file;
[0007] If it is detected that the target process is calling a write function to write a memory file, the file unique identification information of the memory file written by the target process is saved in a first preset storage unit;
[0008] When the permission check function of the kernel space is called by the target process, it triggers the acquisition of the file unique identification information of the executable file checked by the target process calling the permission check function, and detects whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit;
[0009] If the first preset storage unit stores the file unique identification information of the executable file checked by the target process, a memory file corresponding to the target process is obtained, and based on the memory file corresponding to the target process, it is detected whether the target process belongs to a fileless attack.
[0010] A second aspect of an embodiment of the present disclosure provides a fileless attack detection device, the device comprising:
[0011] The first detection module is used to trigger detection of whether the target process is calling the write function to write a memory file when the write function of the kernel space is called by the target process;
[0012] A first storage module is used to save the file unique identification information of the memory file written by the target process to a first preset storage unit if it is detected that the target process is calling a write function to write a memory file;
[0013] The second detection module is used to trigger, when the permission check function of the kernel space is called by the target process, to obtain the file unique identification information of the executable file checked by the target process calling the permission check function, and to detect whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit;
[0014] The third detection module is used to obtain the memory file corresponding to the target process if the first preset storage unit stores the file unique identification information of the executable file checked by the target process, and detect whether the target process belongs to a fileless attack based on the memory file corresponding to the target process.
[0015] A third aspect of an embodiment of the present disclosure provides an electronic device, the server comprising: a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the method of the first aspect above.
[0016] A fourth aspect of an embodiment of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method of the first aspect described above can be implemented.
[0017] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0018] The disclosed embodiment can, when the write function of the kernel space is called by the target process, trigger the detection of whether the target process is calling the write function to write the memory file; if it is detected that the target process is calling the write function to write the memory file, the file unique identification information of the memory file written by the target process is saved to the first preset storage unit; when the permission check function of the kernel space is called by the target process, trigger the acquisition of the file unique identification information of the executable file checked by the target process calling the permission check function, and detect whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit; if the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit, the memory file corresponding to the target process is acquired, and based on the memory file corresponding to the target process, it is detected whether the target process belongs to a fileless attack. It can be seen that the above scheme can detect fileless attacks on the target process without adding code to the target process as in the prior art, with low intrusion, imperceptible to the business process, and little impact on the stability and security of normal business and underlying systems, and can detect fileless attacks from the kernel level, so that the detection rate of fileless attacks is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] Figure 1 is a flow chart of a fileless attack detection method provided by an embodiment of the present disclosure;
[0022] Figure 2 It is a logic diagram of fileless attack detection provided by an embodiment of the present disclosure;
[0023] Figure 3 It is a structural diagram of a fileless attack detection device provided by an embodiment of the present disclosure;
[0024] Figure 4 It is a structural schematic diagram of an electronic device in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0026] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0027] Figure 1 1 is a flowchart of a fileless attack detection method provided by an embodiment of the present disclosure, and the method can be performed by an electronic device. The electronic device can be exemplarily understood as a device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, a smart TV, etc. Figure 1 As shown, the method provided in this embodiment includes the following steps:
[0028] S110. When the write function of the kernel space is called by the target process, a trigger is provided to detect whether the target process is calling the write function to write a memory file.
[0029] In the disclosed embodiment, a fileless attack detection module can be deployed in an electronic device, and the fileless attack detection module can include a probe (i.e., an Agent), and the probe can include a user-state Agent and a kernel-state Agent. The user-state Agent is used to control the kernel-state Agent, and its form is binary, and it is a daemon running on the electronic device. The kernel-state Agent is implemented using the extended Berkeley Packet Filter (eBPF) technology, and its form is an eBPF bytecode file. The eBPF bytecode file is loaded into the kernel space of the electronic device by the user-state Agent, and the corresponding kernel function that needs to be hooked includes a write function (i.e., vfs_write, also known as a virtual file system file write function). In this way, when the write function of the kernel space is called by the target process, the kernel-state Agent can be triggered to detect whether the target process is calling the write function to write a memory file.
[0030] Specifically, the target process may be any process in the electronic device.
[0031] Specifically, the write function is a function used for file write operations in the Linux kernel. It is used to process file write requests at the virtual file system (VFS) layer, that is, whether the target process wants to write a memory file (i.e., write a memory file) or write a disk file, the write function will be called.
[0032] In some embodiments, detecting whether the target process is calling a write function to write a memory file includes: obtaining the file path of the file written by the target process; if the file path includes a preset file path prefix, it is determined that the target process is calling a write function to write a memory file (that is, the file written is a memory file).
[0033] Specifically, the file path is the storage location of the file.
[0034] When the target process calls the write function, the file path of the written file is passed into the write function as a parameter, so the file path can be extracted from the write function.
[0035] Specifically, the preset file path prefix is a file path prefix corresponding to the memory file, and may include, for example, / memfd:, / run / shm / , / dev / shm / , etc., but is not limited thereto.
[0036] Optionally, if the file path does not include a preset file path prefix, it is determined that the target process is not calling a write function to write a memory file (ie, the target process is not writing a memory file), and the written file is not a memory file.
[0037] It can be understood that based on whether the file path of the file written by the target process includes a preset file path prefix, detecting whether the target process is writing a memory file is simple, efficient, and easy to implement, which is conducive to reducing the difficulty of implementing the eBPF bytecode file corresponding to the kernel state Agent.
[0038] Of course, other specific implementations known to those skilled in the art may also be used to detect whether the target process is calling a write function to write a memory file, and this application does not limit this.
[0039] S120: If it is detected that the target process is calling a write function to write a memory file, the file unique identification information of the memory file written by the target process is saved in a first preset storage unit.
[0040] Optionally, if it is detected that the target process is not calling a write function to write a memory file (ie, the target process is not writing a memory file), it is determined that the target process is not a fileless attack.
[0041] In the disclosed embodiment, the file-free detection storage module also includes a storage layer, the storage layer includes a first preset storage unit, and the kernel-state Agent and the user-state Agent can interact with each other through the first preset storage unit, wherein the first preset storage unit may include an eBPF map, and the eBPF map is a general data structure that stores different types of data and provides functions such as user-state (i.e., user space) and kernel-state (i.e., kernel space) data interaction, data storage, and multi-program data sharing.
[0042] Specifically, the file unique identification information may include Device ID and Inode, but is not limited thereto.
[0043] Device ID is the identifier of the file system where the file is located under Linux. It is an integer used to identify the storage device where the file is located. The Linux file system supports multiple file systems, each of which has a unique Device ID. Inode is the identifier of the file in the file system under Linux. It is an integer used to identify the uniqueness of the file. Each file has a unique inode number that can be used to access the file's metadata information, such as file permissions, timestamps, owners, and other information.
[0044] Exemplarily, if it is detected that the target process is calling a write function to write a memory file, the file information of the memory file written by the target process is obtained, the Device ID and Inode of the memory file are extracted from the file information, and the two are concatenated as a key and stored in the eBPF map.
[0045] S130. When the permission check function of the kernel space is called by the target process, it triggers the acquisition of the file unique identification information of the executable file checked by the target process calling the permission check function, and detects whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit.
[0046] In the disclosed embodiment, the kernel function corresponding to the eBPF bytecode file that needs to be hooked also includes a permission check function (i.e., security_bprm_check, also known as the Linux security subsystem executable file permission check function). In this way, when the permission check function in the kernel space is called by the target process, the kernel state Agent can be triggered to obtain the file unique identification information of the executable file checked by the target process calling the permission check function, and detect whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit.
[0047] Specifically, the role of the permission check function is to perform a security check on the executable file before executing it. It is part of the security subsystem in the Linux kernel and is used to implement access control and security policies. That is, the target process will call the permission check function regardless of whether it executes the executable file from memory or from disk.
[0048] When the target process calls the permission check function, the permission check function can receive a pointer to a structlinux_binprm structure as a parameter, which contains file information related to the executable file, such as file path, file permissions, etc. In this way, the file information of the executable file checked by the target process can be extracted from the struct linux_binprm structure, and then the file unique identification information of the executable file checked by the target process can be extracted from the file information.
[0049] Specifically, if the file unique identification information of the executable file can be found in the first preset storage unit, it means that the executable file is a memory file, which is first written into the memory and then executed, and subsequent detection can be performed. Optionally, if the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit, it can be identified that the executable file is a memory file.
[0050] In some embodiments, obtaining the file unique identification information of the executable file checked by the target process calling the permission check function includes: if the file name of the executable file checked by the target process is not in a preset whitelist and the file size is less than a first preset threshold, then obtaining the file unique identification information of the executable file checked by the target process calling the permission check function.
[0051] In an embodiment of the present disclosure, the user-state Agent can send a preset whitelist and a first preset threshold (i.e., a file size limit) to the kernel-state Agent through the first storage space, so that the kernel-state Agent matches the executable file checked by the target process based on the preset whitelist and detects whether the file size of the executable file checked by the target process is less than the first preset threshold.
[0052] Specifically, the file names included in the preset whitelist and the specific value of the first preset threshold can be set by those skilled in the art according to actual conditions and are not limited here.
[0053] Optionally, if the file name of the executable file checked by the target process is in a preset whitelist, it indicates that the executable file checked by the target process is not a suspicious file (i.e., a file that is first written to the memory and then executed), and there is no need to further determine whether the executable file checked by the target process is a suspicious file. In this way, electronic device resources can be saved.
[0054] Optionally, if the file size of the executable file checked by the target process is greater than or equal to a first preset threshold, it indicates that the executable file checked by the target process is relatively large, and therefore the probability that it is a suspicious file is low. There is no need to further determine whether the executable file checked by the target process is a suspicious file. In this way, electronic device resources can be saved.
[0055] It can be understood that by setting the file name of the executable file checked by the target process to be not in the preset whitelist and the file size is less than the first preset threshold, the file unique identification information of the executable file checked by the target process calling the permission check function is obtained, so as to further determine whether the executable file checked by the target process is a suspicious file based on the file unique identification information, so that when the probability that the executable file checked by the target process is a suspicious file is high, it is further detected, thereby saving electronic device resources.
[0056] Exemplarily, if the file name of the executable file checked by the target process is not in the preset whitelist and the file size is smaller than the first preset threshold, the Device ID and Inode of the executable file checked by the target process are obtained, the two are concatenated into a key, and the key is searched in the eBPF map. If the key exists in the eBPF map, it indicates that the executable file checked by the target process is first written into the memory and then executed, and is a suspicious file.
[0057] Of course, it is also possible not to use the preset whitelist and the first preset threshold to filter the executable files checked by the target process. When the permission check function of the kernel space is called by the target process, the file unique identification information of the executable file checked by the target process calling the permission check function is obtained unconditionally. This application does not limit this.
[0058] S140: If the first preset storage unit stores the file unique identification information of the executable file checked by the target process, obtain the memory file corresponding to the target process, and detect whether the target process belongs to a fileless attack based on the memory file corresponding to the target process.
[0059] Optionally, if the first preset storage unit does not store the file unique identification information of the executable file checked by the target process, it indicates that the executable file checked by the target process is not first written into the memory and then executed, and therefore, is not a suspicious file. It can be determined that the target process is not a fileless attack.
[0060] In the disclosed embodiment, the fileless attack detection module also includes a detection layer. After the kernel-state Agent obtains the memory file corresponding to the target process, it can store the memory file corresponding to the target process in the first storage space, and then the user-state Agent can read the memory file corresponding to the target process from the first storage space, so that the subsequent detection layer can detect whether the target process belongs to a fileless attack.
[0061] Specifically, the memory file corresponding to the target process is the memory file on which the target process depends on for running.
[0062] In some embodiments, obtaining the memory file corresponding to the target process may include: obtaining memory file distribution information corresponding to the target process; and reading the memory file corresponding to the target process based on the memory file distribution information.
[0063] Specifically, a process is the execution process of a program. A program consists of multiple program segments (for example, code segments, data segments, BSS segments (i.e., memory area segments), and stack segment groups). The storage address of each program segment in the memory is the memory file distribution information corresponding to the process.
[0064] For example, in Linux, each process has an associated task_struct (i.e., process control module) structure, which contains various information about the process, such as the process ID, the parent process ID, the process status, scheduling information, file descriptors, memory mapping, memory distribution information, etc. Therefore, the memory distribution information of the target process can be obtained according to the task_struct of the target process.
[0065] It can be understood that the memory file corresponding to the target process is read based on the memory file distribution information, and the acquisition method is simple, efficient, and easy to implement, which is conducive to reducing the implementation difficulty of the eBPF bytecode file corresponding to the kernel state Agent.
[0066] Of course, the memory file corresponding to the target process may also be obtained according to other specific implementation methods known to technicians in this field, and this application does not limit this.
[0067] In some embodiments, detecting whether the target process is a fileless attack based on the memory file corresponding to the target process may include: converting the memory file corresponding to the target process into a disk file; using a detection engine corresponding to a preset detection strategy to perform malicious file detection on the disk file corresponding to the target process to obtain a corresponding detection result; and determining whether the target process is a fileless attack based on the detection result.
[0068] In the disclosed embodiment, the user-state Agent can convert the memory file corresponding to the target process into a disk file, thus completing the transformation from no file to file, and then the detection engine of the detection layer can be used to perform malicious file detection on the disk file corresponding to the target process.
[0069] In the disclosed embodiment, the user-state Agent can send a preset detection strategy and the disk file corresponding to the target process to the detection layer, so that the detection layer uses the detection engine corresponding to the preset detection strategy to perform malicious file detection on the disk file corresponding to the target process, obtain the corresponding detection result, and determine whether the target process belongs to a fileless attack based on the detection result.
[0070] Specifically, the preset detection strategy includes a detection engine used to perform malicious file detection on disk files corresponding to the target process. The specific detection engine included in the preset detection strategy can be set by a technician in this field according to actual conditions and is not limited here.
[0071] For example, the detection engine may include ClamAV, Antivirus scanner, IOC, Avira, etc., but is not limited thereto. ClamAV is an open source antivirus software engine that is mainly used to detect and remove viruses and malware on mail servers, file servers, and gateways. ClamAV uses a variety of technologies to detect malware, such as signature scanning, code simulation, behavioral analysis, etc. Antivirus scanner is a security software used to detect and remove viruses, malware, and other malicious codes in computer systems. It scans files, folders, network traffic, and processes in computer systems to detect whether there are viruses or other malware. Antivirus scanners usually need to update the virus database in a timely manner to ensure that the latest viruses and malware can be detected. IOC is an indicator used to identify whether a computer system has been attacked or infected. It can include IP addresses, domain names, file names, process names, registry entries, etc. Virus detection engines usually use IOCs to determine whether a computer system is infected and take corresponding treatment measures. Avira is an antivirus software engine that uses a variety of technologies to detect and remove viruses and malware from computer systems, including signature scanning, behavioral analysis, code simulation, etc. Avira also has firewall, anti-spyware, ad blocking and other functions to fully protect computer system security.
[0072] Specifically, for each detection engine, the detection result corresponding to the detection engine is used to characterize the probability that the disk file corresponding to the target process is a malicious file when the detection engine is used for detection.
[0073] In one example, determining whether a target process is a fileless attack based on the detection results may include: weighted summing of the detection results corresponding to each detection engine to obtain a summed result; if the summed result is greater than a second preset threshold, determining that the disk file corresponding to the target process is a malicious file; if the summed result is less than or equal to the second preset threshold, determining that the disk file corresponding to the target process is not a malicious file.
[0074] In another example, determining whether the target process is a fileless attack based on the detection results may include: if the detection result corresponding to any detection engine is greater than a third preset threshold, determining that the disk file corresponding to the target process is a malicious file; if the detection result corresponding to each detection engine is less than or equal to the third preset threshold, determining that the disk file corresponding to the target process is not a malicious file.
[0075] Specifically, if it is determined that the disk file corresponding to the target process is a malicious file, then the target process is determined to be a fileless attack; if it is determined that the disk file corresponding to the target process is not a malicious file, then the target process is determined not to be a fileless attack.
[0076] It can be understood that converting the memory file corresponding to the target process into a disk file can realize the conversion from fileless to file, so that it can be detected by the relevant mature file-based detection engine. By reusing the relevant mature detection engine for detection, it is helpful to reduce the difficulty of implementing fileless attack detection.
[0077] The disclosed embodiments can perform fileless attack detection on the target process without adding code to the target process as in the prior art. It has low invasiveness, is imperceptible to the business process, has little impact on the stability and security of normal business and underlying systems, and can perform fileless attack detection from the kernel level, resulting in a high fileless attack detection rate.
[0078] In another embodiment of the present disclosure, the method further includes: obtaining process information corresponding to the target process;
[0079] If it is determined based on the detection result that the target process belongs to a fileless attack, a fileless attack alarm is generated, the fileless attack alarm is saved and displayed, and the disk file and process information corresponding to the target process are saved.
[0080] In the disclosed embodiment, the fileless attack detection module may further include a display layer, and the storage layer may further include a second preset storage unit and a third preset storage unit. If the detection layer determines that the target process is a fileless attack based on the detection result, a fileless attack alarm may be generated, and the fileless attack alarm may be saved to the second preset storage unit, so that the display layer reads and displays the fileless attack alarm from the second preset storage unit. Of course, the display layer may also provide query and export functions, etc., which are not limited. In addition, the detection layer may also save the disk file and progress information corresponding to the target process to the third preset storage unit.
[0081] Specifically, the process information may include process ID, process name, process path, process command line, parent process ID, parent process name, parent process path, parent process command line, etc., but is not limited thereto. Exemplarily, the process information of the target process may be obtained according to the task_struct of the target process.
[0082] Specifically, the process information corresponding to the target process, the disk file, and the detection result detected by the detection engine may be combined to generate a fileless attack alarm.
[0083] Specifically, the second preset storage unit may include Kafka, etc. Kafka is a distributed messaging system, but is not limited thereto.
[0084] Optionally, the method may further include: obtaining and saving the running status of the user state agent and the kernel state agent, wherein the running status includes, but is not limited to, the running time, CPU, memory and other resource usage, etc. In this way, it is convenient for users to view the running status of the fileless attack detection module.
[0085] Specifically, the running states of the user-state Agent and the kernel-state Agent may be stored in the second preset storage unit.
[0086] Specifically, the third preset storage unit may include MiniIO, which is a lightweight, distributed, highly reliable, secure, and easy-to-deploy object storage service suitable for building distributed storage systems, cloud storage services, and other application scenarios, but is not limited thereto.
[0087] It is understandable that by setting the target process to generate and display a fileless attack warning when it is determined that the target process is a fileless attack, the user can be informed in time that the electronic device is being attacked by a fileless attack, and then take protective measures in time. In addition, by setting the disk file and process information corresponding to the target process to be saved, it is convenient for the user to view and analyze the target process later.
[0088] In another embodiment of the present disclosure, when the write function of the kernel space is called by the target process, triggering detection of whether the target process writes the memory file before calling the write function also includes:
[0089] In response to a first configuration operation for a whitelist, determining a preset whitelist configured by the first configuration operation, and saving the preset whitelist;
[0090] In response to a second configuration operation for the file size, determining a first preset threshold configured by the second configuration operation, and saving the first preset threshold;
[0091] In response to a third configuration operation for the detection strategy, determining a preset detection strategy configured by the third configuration operation, and saving the preset detection strategy;
[0092] In response to the loading operation, loading a bytecode file for fileless attack detection into kernel space; and / or;
[0093] In response to a detection enable operation, fileless attack detection is enabled.
[0094] Optionally, the method further comprises:
[0095] In response to the uninstall operation, uninstalling the bytecode file for fileless attack detection from the kernel space; and / or;
[0096] In response to a detection shutdown operation, fileless attack detection is stopped.
[0097] In the embodiment of the present disclosure, the fileless attack detection module may further include a control layer, and the storage layer may further include a fourth preset storage unit and a fifth preset storage unit. The control layer may include at least one of the following functions:
[0098] In response to the first configuration operation for the whitelist, the control layer can determine the preset whitelist configured by the first configuration operation, send the preset whitelist to the user state agent, and save the preset whitelist persistently to the fourth preset unit. The user state agent can save the preset whitelist persistently to the fifth preset unit and send the preset whitelist to the kernel state agent through the first preset storage unit.
[0099] Specifically, the fourth preset unit may include MySQL (ie, Michael database), etc. MySQL is a commonly used relational database, but is not limited thereto.
[0100] Specifically, the fifth preset unit may include sqlite (i.e., a lightweight database), etc. SQLite is a lightweight, embedded relational database management system that does not require an independent server process or configuration and can be directly embedded in other applications for use, but is not limited thereto.
[0101] In response to the second configuration operation for the file size, the control layer may determine the first preset threshold configured by the second configuration operation, send the first preset threshold to the user state agent, and save the first preset threshold persistently to the fourth preset unit. The user state agent may save the first preset threshold persistently to the fifth preset unit and send the first preset threshold to the kernel state agent through the first preset storage unit.
[0102] In response to the third configuration operation for the detection strategy, the control layer may determine the preset detection strategy configured by the third configuration operation, and send the preset detection strategy to the detection layer, and save it to the fourth preset unit.
[0103] In response to the loading operation, the control layer may control the user-state Agent to load the bytecode file for fileless attack detection into the kernel space.
[0104] In response to the detection start operation, the kernel-state Agent starts the fileless attack detection, so that when the write function of the kernel space is called by the target process, it can trigger the detection of whether the target process is calling the write function to write the memory file.
[0105] In response to the uninstall operation, the control layer may control the user-mode Agent to uninstall the bytecode file for fileless attack detection from the kernel space.
[0106] In response to the detection closing operation, the kernel-state Agent stops the fileless attack detection. Thus, when the write function of the kernel space is called by the target process, it will not trigger the detection of whether the target process is calling the write function to write the memory file.
[0107] It can be understood that by setting the first configuration operation, the second configuration operation, the third configuration operation, the loading operation, the unloading operation, the opening operation, and / or the closing operation, the user can deploy flexibly, the probe can be hot-swappable, dynamically configured, and take effect immediately without changing the original business architecture.
[0108] The following describes in detail the fileless attack detection method and the fileless attack detection module provided by the embodiments of the present disclosure based on a specific example.
[0109] Figure 2 is a logical diagram of the fileless attack detection provided by the embodiment of the present disclosure. Figure 2 The fileless attack detection module may include: a control layer, a probe (Agent), a storage layer and a detection layer, wherein the probe (Agent) needs to be deployed on an electronic device that needs to perform fileless attack detection, and includes a kernel-state Agent and a user-state Agent.
[0110] The control layer is used to configure the preset whitelist, the first preset threshold, the preset detection strategy, etc., send the preset whitelist, the first preset threshold, etc. to the user-state Agent, send the preset detection strategy to the detection layer, and persist the preset whitelist, the first preset threshold, the preset detection strategy, etc. to the MySQL database.
[0111] The storage layer is used for data transmission and storage between different services, including sqlite, mysql databases, kafka, eBPF map, and MiniIO.
[0112] The user-state agent can control the kernel-state agent to load / unload, turn on / off detection, etc. It is in binary form and is a daemon running on the server. The user-state agent and the kernel-state agent exchange data through the eBPF map. The user-state agent can store the preset whitelist and the first preset threshold issued by the control layer in the local sqlite database and send the preset whitelist and the first preset threshold to the kernel-state agent through the eBPF map. The kernel-state agent is implemented using eBPF technology and is in the form of an eBPF bytecode file. It is loaded into the electronic device kernel by the user-state agent to monitor kernel events related to fileless attacks. The corresponding kernel functions that need to be hooked are vfs_write and security_bprm_check. When writing files in Linux, whether writing memory files or disk files, the kernel function vfs_write will be called. When executing files in Linux, whether executing files from memory or from disk, the kernel function security_bprm_check will be called. Moreover, through the hook vfs_write and security_bprm_check, the Device ID and Inode of the corresponding file can be obtained. The Device ID plus the Inode can uniquely mark a file in the file system.
[0113] The user-state Agent is used to receive the preset whitelist, the first preset threshold, etc. sent by the layer, store the preset whitelist, the first preset threshold, etc. in sqlite, and send them to the kernel-state Agent.
[0114] The user-state Agent is used to detect whether vfs_write is writing a memory file (the file path prefix of the memory file is any one of / memfd:, / run / shm / , and / dev / shm / ). If it is writing a memory file, the DeviceID and Inode of the file are spliced into a key and stored in the eBPF map; detect whether security_bprm_check is executing a memory file (that is, whether the executable file is a memory file). First, the executable file is restricted and filtered through a preset whitelist and a first preset threshold. If the file name of the executable file is not in the preset whitelist and the executable file is less than the first preset threshold, the Device ID and Inode of the security_bprm_check executable file are obtained, and the two are spliced into a key and searched in the eBPFmap. If the key exists, it indicates that the file is first written to the memory and then executed, and is a suspicious file. Then, the memory distribution information of the target process is obtained according to the task_struct of the target process, and the memory file corresponding to the process is read according to the memory distribution information. The read memory file data, process information, etc. are stored in the eBPF map for reading by the user-state Agent. The user-state agent reads the memory file data and process information sent by the kernel-state agent through the eBPF map, converts the memory file data into disk files, and sends the disk files and process information to the detection layer for detection. Of course, the user-state agent will also send the user-state agent running status and the kernel-state agent running status to Kafka, where the running status includes but is not limited to the running time, CPU, memory and other resource usage, etc.
[0115] The detection layer is used to receive the disk files (i.e., suspicious files) and process information corresponding to the target process sent by the user-state Agent, and use multiple detection engines (including but not limited to ClamAV, Antivirus scanner, IOC, Avira, self-developed virus detection engine, etc.) to detect the disk files, and perform weighted summation according to the detection results corresponding to each detection engine. Based on the summed value, it is determined whether the disk file is a malicious file. If it is a malicious file, the malicious file is stored in MiniIO, and the process information, disk file, and detection results corresponding to the detection engine are combined to generate a fileless attack alarm, which is then sent to Kafka.
[0116] The presentation layer is used to receive and display the probe (Agent) running status and fileless attack alarms from Kafka, and can also provide query and export functions.
[0117] The disclosed embodiment has low invasiveness, is imperceptible to the business process, and has little impact on the stability and security of normal business and underlying systems; the detection rate of fileless attacks is high, and detection is performed at the kernel level, supporting the detection scenarios of most fileless attacks (it can also detect fileless attacks with shelling and anti-debugging); flexible deployment, the probe can be hot-swappable, dynamically configured, and effective immediately, without changing the original business architecture; using ebpf technology to hook vfs_write and security_bprm_check, through Device ID+Inode association memory file writing and memory file execution behavior, determine suspected fileless attack behavior, convert the fileless file into a disk file, and detect it through the existing mature malicious file detection engine based on file detection, reuse the existing mature malicious file detection engine, and support the detection of fileless attacks. Compared with the traditional detection of fileless attack behavior based on ptrace, the disclosed embodiment has high timeliness, low invasiveness, high detection rate, and low resource consumption.
[0118] Figure 3 is a schematic diagram of the structure of a fileless attack detection device provided by an embodiment of the present disclosure. The fileless attack detection device can be understood as the above electronic device or a part of the functional modules in the above electronic device. Figure 3 As shown, the fileless attack detection device 300 includes:
[0119] The first detection module is used for, when the write function of the kernel space is called by the target process, triggering detection of whether the target process is calling the write function to write a memory file;
[0120] A first storage module is used for saving the file unique identification information of the memory file written by the target process to a first preset storage unit if it is detected that the target process is calling the write function to write a memory file;
[0121] a second detection module, configured to trigger, when the permission check function of the kernel space is called by the target process, obtaining the file unique identification information of the executable file checked by the target process calling the permission check function, and detecting whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit;
[0122] The third detection module is used to obtain the memory file corresponding to the target process if the first preset storage unit stores the file unique identification information of the executable file checked by the target process, and detect whether the target process belongs to a fileless attack based on the memory file corresponding to the target process.
[0123] In another embodiment of the present disclosure, the first storage module may include:
[0124] A first acquisition submodule is used to obtain the file path of the file written by the target process;
[0125] The first determination submodule is used to determine that the target process is calling the write function to write a memory file if the file path includes a preset file path prefix.
[0126] In another embodiment of the present disclosure, the second detection module may include a second acquisition sub-module, which is used to obtain the file unique identification information of the executable file checked by the target process calling the permission check function, wherein the second acquisition sub-module is specifically used to obtain the file unique identification information of the executable file checked by the target process calling the permission check function if the file name of the executable file checked by the target process is not in a preset whitelist and the file size is less than a first preset threshold.
[0127] In yet another embodiment of the present disclosure, the third detection module may include:
[0128] A third acquisition submodule is used to obtain memory file distribution information corresponding to the target process;
[0129] A first reading submodule, configured to read a memory file corresponding to the target process based on the memory file distribution information;
[0130] A first conversion submodule, used to convert the memory file corresponding to the target process into a disk file;
[0131] The first detection submodule is used to use a detection engine corresponding to a preset detection strategy to perform malicious file detection on the disk file corresponding to the target process to obtain a corresponding detection result;
[0132] The second determination submodule is used to determine whether the target process belongs to a fileless attack based on the detection result.
[0133] In another embodiment of the present disclosure, the device further comprises:
[0134] A second acquisition module is used to acquire process information corresponding to the target process;
[0135] The display and storage module is used to generate a fileless attack alarm if it is determined based on the detection result that the target process belongs to a fileless attack, save and display the fileless attack alarm, and save the disk file and process information corresponding to the target process.
[0136] In another embodiment of the present disclosure, the device further comprises:
[0137] A module is provided, which is used to trigger, when the write function of the kernel space is called by the target process, to detect whether the target process has called the write function to write the memory file before writing the memory file.
[0138] In response to a first configuration operation for a whitelist, determining a preset whitelist configured by the first configuration operation, and saving the preset whitelist; and / or;
[0139] In response to a second configuration operation for the file size, determining a first preset threshold configured by the second configuration operation, and saving the first preset threshold; and / or;
[0140] In response to a third configuration operation for the detection strategy, determining a preset detection strategy configured by the third configuration operation, and saving the preset detection strategy; and / or;
[0141] In response to the loading operation, loading a bytecode file for fileless attack detection into the kernel space; and / or;
[0142] In response to a detection enable operation, fileless attack detection is enabled.
[0143] In yet another embodiment of the present disclosure, the setting module may also be used to, in response to an uninstall operation, uninstall the bytecode file for fileless attack detection from the kernel space; and / or;
[0144] In response to a detection shutdown operation, fileless attack detection is stopped.
[0145] The device provided in this embodiment can execute the method of any of the above embodiments, and its execution method and beneficial effects are similar, which will not be repeated here.
[0146] An embodiment of the present disclosure further provides an electronic device, which includes: a memory, in which a computer program is stored; and a processor, for executing the computer program. When the computer program is executed by the processor, the method of any of the above embodiments can be implemented.
[0147] For example, Figure 4 Schematic diagram of the structure of an electronic device in the embodiment of the present disclosure. Figure 4 , which shows a schematic diagram of the structure of an electronic device 400 suitable for implementing the embodiment of the present disclosure. The electronic device 400 in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0148] like Figure 4 As shown, the electronic device 400 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 are also stored. The processing device 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0149] Typically, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 408 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device 400 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 400 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0150] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 409, or installed from the storage device 408, or installed from the ROM 402. When the computer program is executed by the processing device 401, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0151] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0152] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0153] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0154] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:
[0155] When the write function of the kernel space is called by the target process, it is triggered to detect whether the target process is calling the write function to write the memory file;
[0156] If it is detected that the target process is calling a write function to write a memory file, the file unique identification information of the memory file written by the target process is saved in a first preset storage unit;
[0157] When the permission check function of the kernel space is called by the target process, it triggers the acquisition of the file unique identification information of the executable file checked by the target process calling the permission check function, and detects whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit;
[0158] If the first preset storage unit stores the file unique identification information of the executable file checked by the target process, a memory file corresponding to the target process is obtained, and based on the memory file corresponding to the target process, it is detected whether the target process belongs to a fileless attack.
[0159] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0160] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0161] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.
[0162] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0163] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0164] The embodiments of the present disclosure further provide a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method of any of the above embodiments can be implemented. The execution method and beneficial effects are similar and will not be repeated here.
[0165] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0166] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A fileless attack detection method, characterized in that: include: When the write function of the kernel space is called by the target process, trigger detection to determine whether the target process is calling the write function to write a memory file; If it is detected that the target process is calling the write function to write a memory file, the file unique identification information of the memory file written by the target process is saved in a first preset storage unit; When the permission check function of the kernel space is called by the target process, triggering the acquisition of the file unique identification information of the executable file checked by the target process calling the permission check function, and detecting whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit; If the first preset storage unit stores the file unique identification information of the executable file checked by the target process, then obtaining the memory file corresponding to the target process, and detecting whether the target process belongs to a fileless attack based on the memory file corresponding to the target process; The obtaining of the memory file corresponding to the target process, and detecting whether the target process belongs to a fileless attack based on the memory file corresponding to the target process, includes: Obtaining memory file distribution information corresponding to the target process; Reading the memory file corresponding to the target process based on the memory file distribution information; Convert the memory file corresponding to the target process into a disk file; Using a detection engine corresponding to a preset detection strategy to perform malicious file detection on the disk file corresponding to the target process to obtain a corresponding detection result; Determine whether the target process belongs to a fileless attack based on the detection result.
2. The method according to claim 1, characterized in that The detecting whether the target process is calling the write function to write a memory file includes: Get the file path of the file written by the target process; If the file path includes a preset file path prefix, it is determined that the target process is calling the write function to write a memory file.
3. The method according to claim 1, characterized in that The obtaining of the file unique identification information of the executable file checked by the target process calling the permission checking function includes: If the file name of the executable file checked by the target process is not in the preset whitelist and the file size is smaller than the first preset threshold, the file unique identification information of the executable file checked by the target process calling the permission check function is obtained.
4. The method according to claim 1, characterized in that: Also includes: Obtaining process information corresponding to the target process; If it is determined based on the detection result that the target process belongs to a fileless attack, a fileless attack alarm is generated, the fileless attack alarm is saved and displayed, and the disk file and process information corresponding to the target process are saved.
5. The method according to claim 1, characterized in that When the write function of the kernel space is called by the target process, triggering detection of whether the target process is before calling the write function to write the memory file also includes: In response to a first configuration operation for a whitelist, determining a preset whitelist configured by the first configuration operation, and saving the preset whitelist; In response to a second configuration operation for the file size, determining a first preset threshold configured by the second configuration operation, and saving the first preset threshold; In response to a third configuration operation for the detection strategy, determining a preset detection strategy configured by the third configuration operation, and saving the preset detection strategy; In response to the loading operation, loading a bytecode file for fileless attack detection into the kernel space; and / or; In response to a detection enable operation, fileless attack detection is enabled.
6. The method according to claim 5, characterized in that The method further comprises: In response to the uninstall operation, uninstalling the bytecode file for fileless attack detection from the kernel space; and / or; In response to a detection shutdown operation, fileless attack detection is stopped.
7. A fileless attack detection device, characterized in that: include: The first detection module is used for, when the write function of the kernel space is called by the target process, triggering detection of whether the target process is calling the write function to write a memory file; A first storage module is used for saving the file unique identification information of the memory file written by the target process to a first preset storage unit if it is detected that the target process is calling the write function to write a memory file; a second detection module, configured to trigger, when the permission check function of the kernel space is called by the target process, obtaining the file unique identification information of the executable file checked by the target process calling the permission check function, and detecting whether the file unique identification information of the executable file checked by the target process is stored in the first preset storage unit; A third detection module is used to obtain a memory file corresponding to the target process if the first preset storage unit stores the file unique identification information of the executable file checked by the target process, and detect whether the target process belongs to a fileless attack based on the memory file corresponding to the target process; The third detection module includes: a third acquisition submodule, configured to acquire memory file distribution information corresponding to the target process if the first preset storage unit stores file unique identification information of the executable file checked by the target process; A first reading submodule, configured to read a memory file corresponding to the target process based on the memory file distribution information; A first conversion submodule, used to convert the memory file corresponding to the target process into a disk file; The first detection submodule is used to use a detection engine corresponding to a preset detection strategy to perform malicious file detection on the disk file corresponding to the target process to obtain a corresponding detection result; The second determination submodule is used to determine whether the target process belongs to a fileless attack based on the detection result.
8. An electronic device, characterized in that: include: A processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
