Website attack defense method and device, storage medium, and electronic device

By monitoring and intercepting the code parsing events of the website server and determining whether the script file is stored in the specified directory, it solves the problem of attackers uploading malicious scripts to bypass defense and ensures the security of the website.

CN112395536BActive Publication Date: 2024-10-15QI AN XIN SECURITY TECH ZHUHAI CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910755848.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-08-15
Publication Date
2024-10-15
Estimated Expiration
2039-08-15

AI Technical Summary

Technical Problem

Existing technology is difficult to effectively prevent attackers from controlling websites by uploading malicious scripts, especially the problem of new malicious scripts that are not included in the signature database and bypass the protection directory.

Method used

By monitoring the code parsing events of the website server, it determines whether the script file is stored in the specified directory, and intercepts the code parsing events when it is stored in the directory to prevent the execution of malicious scripts.

Benefits of technology

It effectively prevents attacks on website directory files due to the execution of malicious scripts, ensuring the security of the website.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112395536B_ABST
    Figure CN112395536B_ABST
Patent Text Reader

Abstract

The present invention provides a website attack defense method and device, storage medium, and electronic device, the method comprising: monitoring the code parsing event of the website server; judging whether the script file parsed by the code parsing event is stored in a specified directory; and intercepting the code parsing event when the script file is stored in the specified directory. The present invention solves the technical problem of bypassing website defense and attacking the website by uploading malicious scripts in the related art, thereby ensuring the security of the website.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network security, and in particular to a website attack defense method and device, a storage medium, and an electronic device. Background Art

[0002] In related technologies, when attackers find a website vulnerability, they often attempt to upload malicious scripts (also called WebShells) to facilitate their control and exploitation. One common method used by attackers is to upload an image containing malicious code or other files with malformed file names to the website directory, bypassing the protected directory. They then exploit a parsing vulnerability to parse the file into the corresponding code and execute it. This will lead to the website being controlled and the files in the website directory being able to be manipulated. If the permissions are sufficient, it can also cause the server to collapse, causing huge damage.

[0003] Currently, most defenses against uploaded scripts rely on signature detection of script files, matching them against malicious string signature libraries or HTTP request / response signature libraries, for static or dynamic signature matching. This method is easily bypassed. If a new malicious script appears that is not included in the signature library, it can easily bypass the protection directory, making defense more difficult.

[0004] Currently, no effective solution has been found for the above-mentioned problems existing in the related technologies. Summary of the Invention

[0005] Embodiments of the present invention provide a website attack defense method and device, a storage medium, and an electronic device.

[0006] According to one embodiment of the present invention, a method for defending against attacks on a website is provided, comprising: monitoring a code parsing event on a website server; determining whether a script file parsed by the code parsing event is stored in a designated directory; and intercepting the code parsing event when the script file is stored in the designated directory.

[0007] Optionally, monitoring the code parsing event of the website server includes: monitoring the file creation Create File function in the website server; determining whether the call stack of the Create File function carries a dynamic link library file DLL file; when the call stack of the Create File function carries the DLL file, determining that a code parsing event is occurring on the website server.

[0008] Optionally, monitoring the Create File function in the website server includes: monitoring whether the first parsing process is parsing the hypertext preprocessor PHP; obtaining a system interface called by the PHP when accessing a file, wherein the system interface includes: Nt Create File.

[0009] Optionally, monitoring a code parsing event of a website server includes: monitoring a second parsing process running on the website server; and determining that a code parsing event is occurring on the website server when the second parsing process is a preset process.

[0010] Optionally, after determining whether the script file parsed by the code parsing event is stored in a designated directory, the method further includes: releasing the code parsing event when the script file is not stored in the designated directory.

[0011] Optionally, before determining whether the script file parsed by the code parsing event is stored in a designated directory, the method further includes: configuring the designated directory in a directory list of the website server, wherein files stored in the designated directory are prohibited from being parsed into code.

[0012] According to another embodiment of the present invention, there is provided an attack defense device for a website, comprising: a monitoring module for monitoring code parsing events of a website server; a judgment module for judging whether a script file parsed by the code parsing event is stored in a designated directory; and an interception module for intercepting the code parsing event when the script file is stored in the designated directory.

[0013] Optionally, the monitoring module includes: a first monitoring unit, used to monitor the file creation Create File function in the website server; a judgment unit, used to judge whether the call stack of the Create File function carries a dynamic link library file DLL file; and a first determination unit, used to determine that a code parsing event is occurring on the website server when the call stack of the Create File function carries a DLL file.

[0014] Optionally, the monitoring unit includes: a monitoring subunit, used to monitor whether the first parsing process is parsing the hypertext preprocessor PHP; an acquisition subunit, used to acquire the system interface called by the PHP when accessing the file, wherein the system interface includes: Nt Create File.

[0015] Optionally, the monitoring module includes: a second monitoring unit, configured to monitor a second parsing process running on the website server; and a second determining unit, configured to determine that a code parsing event is occurring on the website server when the second parsing process is a preset process.

[0016] Optionally, the device further includes: allowing the code parsing event to proceed when the script file is not stored in the designated directory.

[0017] Optionally, the device further includes: configuring the designated directory in a directory list of the website server, wherein files stored in the designated directory are prohibited from being parsed into codes.

[0018] According to yet another embodiment of the present invention, a storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.

[0019] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.

[0020] Through the present invention, since the designated directory is set as a protection directory for prohibiting script parsing, and then the code parsing events of the website server are monitored to determine whether the script file parsed by the code parsing event is stored in the designated directory, if it exists, the code parsing event is intercepted, thereby preventing the execution of malicious scripts from attacking files in the website directory, solving the technical problem of uploading malicious scripts to bypass the website defense to attack the website in the related art, thereby ensuring the security of the website. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0022] Figure 1 This is a hardware structure diagram of a website attack defense method applied to a server according to an embodiment of the present invention;

[0023] Figure 2 is a flow chart of a website attack defense method according to an embodiment of the present invention;

[0024] Figure 3 This is a specific flow chart of a website attack defense method provided according to an embodiment of the present invention;

[0025] Figure 4 The figure is a structural block diagram of a device for defending against website attacks according to an embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of this application. It should be noted that, in the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] Example 1

[0029] The method embodiment provided in the first embodiment of the present application can be executed in a server, computer, terminal or similar computing device. Taking running on a computer as an example, Figure 1 This is a hardware structure diagram of a website attack defense method applied to a server according to an embodiment of the present invention. Figure 1 As shown, the computer may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data. Optionally, the above server may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0030] Memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to a website attack defense method in an embodiment of the present invention. Processor 102 executes the computer program stored in memory 104 to execute various functional applications and data processing, thereby implementing the above-mentioned method. Memory 104 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, memory 104 may further include memory remotely located relative to processor 102, and such remote memory may be connected to computer 10 via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0031] Transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the communications provider of computer 10. In one embodiment, transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0032] In this embodiment, a method for defending against attacks on a website is provided. Figure 2 FIG. 1 is a flow chart of a website attack defense method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0033] Step S202, monitoring code parsing events of the website server;

[0034] In this embodiment, the server monitors the code parsing events of the website server after the defense system is deployed.

[0035] Step S204, determining whether the script file parsed by the code parsing event is stored in the designated directory;

[0036] The files under the designated directory in this embodiment are protected directories that are configured by the administrator to be prohibited from being parsed into codes.

[0037] Step S206: When the script file is stored in the designated directory, a code parsing event is intercepted.

[0038] Through the above steps, since the designated directory is set as a protection directory for prohibiting script parsing, and then by monitoring the code parsing events of the website server, it is determined whether the script file parsed by the code parsing event is stored in the designated directory. If it exists, the code parsing event is intercepted, thereby preventing the execution of malicious scripts from attacking files in the website directory, solving the technical problem of using uploading malicious scripts to bypass website defense to attack the website in the related technology, thereby ensuring the security of the website.

[0039] Optionally, monitoring the code parsing event of the website server includes: monitoring the file creation Create File function in the website server; determining whether a dynamic link library (DLL) file is carried in the call stack of the Create File function; when the DLL file is carried in the call stack of the Create File function, determining that a code parsing event is occurring on the website server.

[0040] In an alternative embodiment, in an Apache + PHP combination, PHP runs as an Apache module, primarily the Apache process httpd.exe. httpd.exe cannot directly execute script files and must rely on a script parsing DLL to parse the script before returning the corresponding content to the browser. When parsing PHP, httpd.exe generates a dynamic link library (DLL) file. Therefore, confirming that a specified directory contains the DLL file can confirm that the website server is parsing code.

[0041] Optionally, monitoring the Create File function in the website server includes: monitoring whether the first parsing process is parsing a hypertext preprocessor PHP; obtaining a system interface called by PHP when accessing a file, wherein the system interface includes: NtCreate File.

[0042] According to the above embodiment, when httpd.exe parses PHP, it accesses the script file by calling the Windows API function CreateFileW or function CreateFileA. There will be php5ts.dll (php5) or php7ts.dll (php7) in its function call stack. Therefore, the CreateFileW and CreateFileA events of httpd.exe are monitored. When the file in the specified directory is currently operated, it is determined whether there is php5ts.dll / php7ts.dll in the function call stack; if there is a dll file, it means that httpd.exe is parsing the script file and it is blocked in time.

[0043] Optionally, monitoring the code parsing event on the website server includes: monitoring a second parsing process running on the website server; and determining that a code parsing event is occurring on the website server when the second parsing process is a preset process. In this embodiment, the preset process is a process capable of parsing script files. If the currently running parsing process parses a static file, such as an image, the code will not be executed and will not further affect the website server.

[0044] In an optional embodiment, for another mode of the Apache+PHP combination, PHP runs as a standalone program, and the PHP code parsing body becomes php-cgi.exe. In this mode, PHP-CGI will not access resources such as images and static files. It will only access the corresponding PHP script files when parsing PHP scripts. Therefore, by restricting PHP-CGI.exe from operating files in a specified directory (such as an upload directory), PHP parsing can be blocked. Therefore, in this embodiment, if it is detected that the process PHP-CGI.exe is operating files in a specified directory, it indicates that a code parsing event is occurring on the website server.

[0045] In another optional embodiment, for the IIS+asp combination mode, the IIS process w3wp.exe is monitored. When calling the CreateFileW function and the CreateFileA function, asp.dll will be called when parsing asp. If the process w3wp.exe is monitored, it means that the process w3wp.exe is executing script parsing.

[0046] Optionally, after determining whether the script file parsed by the code parsing event is stored in the designated directory, the method further includes: when the script file is not stored in the designated directory, releasing the code parsing event.

[0047] According to the above embodiment, when it is determined that there is no dll file in the function call stack of Create File, it means that it is accessing other resource files and does not threaten the security of the website, and then it is released.

[0048] Optionally, before determining whether the script file parsed by the code parsing event is stored in the designated directory, the method further includes: configuring the designated directory in a directory list of the website server, wherein files stored in the designated directory are prohibited from being parsed into codes.

[0049] In this embodiment, after the defense system is deployed, files in the directory specified by the administrator are blocked from being parsed into code to prevent the execution of malicious scripts. Therefore, before determining whether the script file parsed by the code parsing event is stored in the specified directory, the administrator first pre-configures the directory list in the server and configures the specified directory as a protection directory that is prohibited from being parsed into code.

[0050] Based on the above embodiment, the specific process of a website attack defense method is briefly described below:

[0051] Figure 3 This is a specific flow chart of a website attack defense method provided according to an embodiment of the present invention. Figure 3 As shown, it includes the following processes:

[0052] S301, after deploying the defense system, the administrator configures a protection directory, that is, configures the above-mentioned designated directory as a protection directory in which files stored therein are prohibited from being parsed into code;

[0053] S303, monitoring Createfile event;

[0054] S305: Determine whether the event is a file in the protection directory. If not, release it. If so, proceed to step S309.

[0055] S307, determine whether there is a script parsed DLL in the function call stack, if not, release it; if so, continue to step S309;

[0056] S309: Intercept and end the process.

[0057] When the server process accesses files in the specified directory, it monitors whether there is a script parsing DLL in its call stack. If so, it blocks the access, thereby blocking the execution of the script. However, access to other non-script resources will not be affected.

[0058] No matter how the attacker bypasses the website's upload protection and successfully uploads a malicious script to the server, this method prevents the script from being executed, rendering it useless and making the website more secure.

[0059] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0060] Example 2

[0061] This embodiment also provides a device for website attack defense, which is used to implement the above-mentioned embodiments and preferred implementations. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0062] Figure 4 is a structural block diagram of a device for defending against attacks on a website according to an embodiment of the present invention. Figure 4 As shown, the device includes: a monitoring module 402, which is used to monitor the code parsing events of the website server; a judgment module 404, which is connected to the above-mentioned monitoring module 402, and is used to judge whether the script file parsed by the code parsing event is stored in a specified directory; an interception module 406, which is connected to the above-mentioned judgment module 404, and is used to intercept the code parsing event when the script file is stored in the specified directory.

[0063] Optionally, the monitoring module 402 includes: a first monitoring unit, used to monitor the file creation Create File function in the website server; a judgment unit, used to judge whether the call stack of the Create File function carries a dynamic link library file DLL file; a first determination unit, used to determine that a code parsing event is occurring on the website server when the call stack of the Create File function carries a DLL file.

[0064] Optionally, the monitoring unit includes: a monitoring subunit, used to monitor whether the first parsing process is parsing the hypertext preprocessor PHP; an acquisition subunit, used to acquire the system interface called by PHP when accessing the file, wherein the system interface includes: Nt Create File.

[0065] Optionally, the monitoring module 402 includes: a second monitoring unit, configured to monitor a second parsing process running on the website server; and a second determining unit, configured to determine that a code parsing event is occurring on the website server when the second parsing process is a preset process.

[0066] Optionally, the above device further includes: when the script file is not stored in the designated directory, allowing the code parsing event.

[0067] Optionally, the above-mentioned device further includes: configuring a designated directory in a directory list of the website server, wherein files stored in the designated directory are prohibited from being parsed into codes.

[0068] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0069] Example 3

[0070] An embodiment of the present invention further provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0071] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:

[0072] S1, monitors the code parsing events of the website server;

[0073] S2, determining whether the script file parsed by the code parsing event is stored in the specified directory;

[0074] S3 intercepts code parsing events when script files are stored in a specified directory.

[0075] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0076] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0077] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0078] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0079] S1, monitors the code parsing events of the website server;

[0080] S2, determining whether the script file parsed by the code parsing event is stored in the specified directory;

[0081] S3 intercepts code parsing events when script files are stored in a specified directory.

[0082] Optionally, specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0083] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0084] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0085] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0086] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0087] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0088] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

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

Claims

1. A website attack defense method, characterized in that: include: Monitor code parsing events of website servers; Determine whether the script file parsed by the code parsing event is stored in a designated directory, where the designated directory is used to store a directory of files that are prohibited from being parsed into codes; When the script file is stored in the designated directory, intercepting the code parsing event; The code parsing events of the monitoring website server include: Monitor the Create File function of the file creation in the website server; Determine whether the call stack of the Create File function carries a dynamic link library file DLL file; When the DLL file is carried in the call stack of the Create File function, it is determined that a code parsing event is occurring on the website server; When the call stack of the Create File function does not carry the DLL file, the function is released; The code parsing events of the monitoring website server also include: Monitoring a second parsing process running on the website server; When the second parsing process is a preset process, it is determined that a code parsing event is occurring on the website server.

2. The method according to claim 1, characterized in that Monitoring the Create File function in the website server includes: Monitor whether the first parsing process is parsing the hypertext preprocessor PHP; Obtain the system interface called by the PHP when accessing the file, wherein the system interface includes: NtCreateFile.

3. The method according to claim 1, characterized in that After determining whether the script file parsed by the code parsing event is stored in a designated directory, the method further includes: When the script file is not stored in the designated directory, the code parsing event is released.

4. The method according to claim 1, characterized in that: Before determining whether the script file parsed by the code parsing event is stored in a designated directory, the method further includes: The designated directory is configured in a directory list of the website server.

5. A website attack defense device, characterized in that: include: Monitoring module, used to monitor the code parsing events of the website server; A judgment module, used to judge whether the script file parsed by the code parsing event is stored in a designated directory, wherein the designated directory is used to store a directory of files that are prohibited from being parsed into codes; An interception module, used for intercepting the code parsing event when the script file is stored in the designated directory; The monitoring module comprises: A first monitoring unit is used to monitor a Create File function in the website server; A judging unit, used for judging whether a dynamic link library file DLL file is carried in the call stack of the Create File function; A first determining unit, configured to determine that a code parsing event is occurring on the website server when a DLL file is carried in the call stack of the Create File function; The first determining unit is further configured to release the Create File function when the call stack does not carry the DLL file; The monitoring module also includes: A second monitoring unit, used for monitoring a second parsing process running on the website server; The second determining unit is used to determine that a code parsing event is occurring on the website server when the second parsing process is a preset process.

6. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 4 when executed.

7. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 4.