WebShell detection method based on machine learning

Through the WebShell detection method based on machine learning, combining dynamic features, static features and traffic detection, and using the GXL-Stacking model, the problem of difficulty in detecting new WebShells with existing technology is solved, achieving higher detection accuracy and lower errors. Report rate.

CN118551384APending Publication Date: 2024-08-27SHANXI JINXINAN TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410640600.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-22
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

Existing WebShell detection methods rely on dangerous function identification and rule matching, making it difficult to effectively detect new WebShells, especially because they use obfuscated characters, comments, dirty data, and code encryption to evade detection, resulting in poor detection results.

Method used

A WebShell detection method based on machine learning is used to obtain the PHP Opcode dynamic features and static features of the target file, combined with traffic detection, and use the GXL-Stacking model for integrated learning to improve the accuracy and stability of detection.

Benefits of technology

Dynamic features reveal file runtime operations, and static features provide file structure and content information. Combined with traffic detection to capture network activities, it significantly improves the accuracy of WebShell detection, reduces the false positive rate, and can discover performance only under specific network requests. malicious behavior.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118551384A
    Figure CN118551384A
Patent Text Reader

Abstract

The invention relates to a WebShell detection method based on machine learning, and relates to the technical field of network security, and the method comprises the steps: obtaining a target file; the target file is analyzed, PHP Opcode dynamic characteristics are obtained, and the PHP Opcode dynamic characteristics comprise an Opcode sequence, a function calling mode and system command execution; performing text content extraction according to the target file to obtain static features; combining the dynamic features with the static features to obtain a first detection result; performing flow detection based on the target file to obtain a second detection result; and based on the first detection result and the second detection result, determining that the target file is WebShell. The WebShel detection method and device have the effect of improving the accuracy of WebShel detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network security technology, and in particular to a WebShell detection method based on machine learning. Background Art

[0002] WebShell is a command execution environment in the form of web page files such as asp, php, jsp or cgi. WebShell can also be called a web backdoor. It is a script attack tool for hackers to invade website servers. At present, after hacking into a website, hackers usually mix these asp or php backdoor files with normal web page files in the web directory of the website server, and then access these asp or php backdoor files through a browser to obtain a command execution environment to achieve the purpose of controlling the website server. Therefore, detecting WebShell is very important to ensure website security.

[0003] A related one, WebShell detection method mainly relies on dangerous function identification and rule matching, and determines whether it is a WebShell by looking for specific keywords, function calls, and code structures.

[0004] By then, with the continuous development of technology, WebShell uses obfuscated characters, comments, dirty data, code feature changes, and code encryption to evade detection, making the detection method based on dangerous functions and malicious feature identification ineffective for new WebShell detection. Summary of the invention

[0005] In order to improve the accuracy of WebShell detection, this application provides a WebShell detection method based on machine learning.

[0006] In the first aspect, the present application provides a WebShell detection method based on machine learning, which adopts the following technical solution: a WebShell detection method based on machine learning, Get the target file; Parsing the target file to obtain PHP Opcode dynamic features, wherein the PHP Opcode dynamic features include Opcode sequence, function call mode, and system command execution; Extracting text content from the target file to obtain static features, including whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether an encoding function is used to confuse the text, information entropy of the text, compression ratio of the text, and coincidence index of the text; Combining the dynamic feature with the static feature to obtain a first detection result; Performing flow detection based on the target file to obtain a second detection result; Based on the first detection result and the second detection result, it is determined that the target file is a WebShell.

[0007] By adopting the above technical solutions, dynamic features can reveal the operations that the file may perform when it is running, while static features provide direct information about the file structure and content. The combination of the two can complement each other and improve the accuracy of detection. At the same time, by considering multiple aspects of features, including file name, file content, encoding method, information entropy, etc., false positives caused by the similarity of a single feature can be reduced. In addition to file and content analysis, traffic detection can capture network activities related to the target file. It helps to discover WebShells that only exhibit malicious behavior under specific network requests. By combining dynamic features, static features and traffic detection to detect whether the target file is a WebShell, the accuracy of detection can be improved and the false positive rate can be reduced.

[0008] In another possible implementation, the target file is parsed to obtain the PHP Opcode dynamic feature, including: Performing lexical analysis on the content of the target file to obtain lexical units; Constructing a syntax tree based on the lexical unit; Convert the syntax tree into Opcode and run it to get the running result; The PHP Opcode dynamic feature is extracted based on the running result.

[0009] By adopting the above technical solution, lexical units can be obtained by performing lexical analysis on the content of the target file. Further construction of the syntax tree can more clearly show the structure and logical relationship of the code, which is crucial for subsequent analysis and feature extraction. Converting the syntax tree into Opcode and running it actually simulates the execution process of the code in the PHP interpreter, which can capture the dynamic behavior generated by the code during execution, rather than just based on the static structure of the code. This kind of dynamic feature extraction helps to discover WebShells that only show malicious behavior at runtime. The extraction of dynamic features increases the depth and complexity of the analysis, but also improves the accuracy of detection.

[0010] In another possible implementation manner, combining the dynamic feature with the static feature to obtain a first detection result includes: Inputting the static feature into a first model for calculation to obtain a first score; Inputting the dynamic feature into a second model for calculation to obtain a second score; The first score, the second score and their corresponding weights are calculated to obtain a first detection result.

[0011] By adopting the above technical solution, combining dynamic features with static features, and calculating scores and weights through models, the accuracy of WebShell detection can be improved.

[0012] In another possible implementation, the performing flow detection based on the target file to obtain a second detection result includes: Get traffic data; Based on the flow data, the flow data is processed to obtain a feature vector; A GXL-Stacking model is constructed, and the feature vector is input into the GXL-Stacking model for detection to obtain a second detection result.

[0013] By adopting the above technical solutions, the network behavior of the target file can be monitored and analyzed in real time by acquiring traffic data. Processing the traffic data and extracting feature vectors can help capture abnormal patterns and behaviors in network traffic, thereby improving the accuracy of detection. As an integrated learning method, the GXL-Stacking model combines the prediction results of multiple base learners and improves the overall prediction performance through stacking and fusion. In WebShell traffic detection, the GXL-Stacking model can make full use of the complex patterns and information in the traffic data to improve the accuracy and stability of detection.

[0014] In another possible implementation, the processing of the traffic data based on the traffic data to obtain a feature vector includes: Capture PCAP packets; Based on the PACP data packet, obtaining HTTP traffic through a preset filtering condition; Parsing the HTTP traffic to extract each HTTP request message; Field extraction is performed on each HTTP request message to obtain a feature vector.

[0015] By adopting the above technical solutions, feature extraction and representation based on traffic data have the advantages of directly observing network behavior, filtering and focusing, request-level analysis, feature extraction and representation, and improving detection capabilities in WebShell detection.

[0016] In another possible implementation manner, the constructing of the GXL-Stacking model includes: Input the feature vector into a plurality of base learners for base learning training to obtain a first training result, wherein the base learners include a comparative random forest, a support vector machine, GBDT, XGBoost, and LightGBM, and the first training result includes accuracy, error, precision, recall, and F1 value; Calculate based on the first training results and the corresponding weights to obtain a third score; Sorting the third scores from high to low to obtain a first sorting result; Selecting the base learner with the first ranking result as the meta learner; Selecting the algorithms of the base learners in the top three of the first ranking results as base learning algorithms; Based on the meta-learner and the base learning algorithm, a GXL-Stacking model is constructed.

[0017] By adopting the above technical solution, by comparing the training results of different base learners and calculating them in combination with their respective weights, a more accurate third score can be obtained, and then the base learner with the best performance is selected as the meta-learner, and the base learning algorithm with good performance is used to build the GXL-Stacking model. This helps to improve the overall performance of the model, including indicators such as accuracy, precision, recall rate, and F1 value. This makes it possible to build an efficient GXL-Stacking model, comprehensively utilize the advantages of multiple base learners, more accurately identify potential WebShell threats, and reduce the possibility of missed reports and false positives.

[0018] In another possible implementation, determining that the target file is a WebShell based on the first detection result and the second detection result includes: If the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

[0019] By adopting the above technical solution, through cross-verification of the first result and the second result, that is, when both the first result and the second result determine that the target file is a WebShell, it is finally confirmed to be a WebShell, thereby reducing the possibility of false positives and false negatives, and greatly improving the accuracy of WebShell detection.

[0020] In the second aspect, the present application provides a WebShell detection device based on machine learning, which adopts the following technical solution: A WebShell detection device based on machine learning, comprising: File acquisition module, acquires the target file; A file parsing module parses the target file to obtain PHP Opcode dynamic features, wherein the PHP Opcode dynamic features include Opcode sequence, function call mode, and system command execution; A text extraction module extracts text content from the target file to obtain static features, including whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether an encoding function is used to confuse the text encoding, the information entropy of the text, the compression ratio of the text, and the coincidence index of the text; A first detection module combines the dynamic feature with the static feature to obtain a first detection result; A second detection module performs flow detection based on the target file to obtain a second detection result; The file determination module determines that the target file is a WebShell based on the first detection result and the second detection result.

[0021] In an embodiment of the present application, dynamic features can reveal the operations that a file may perform when it is running, and static features provide direct information about the file structure and content. The combination of the two can complement each other and improve the accuracy of detection. At the same time, by considering multiple aspects of features, including file name, file content, encoding method, information entropy, etc., false positives caused by similar single features can be reduced. In addition to file and content analysis, traffic detection can capture network activities related to the target file. It helps to discover WebShells that only exhibit malicious behavior under specific network requests. By combining dynamic features, static features and traffic detection to detect whether the target file is a WebShell, the accuracy of detection can be improved and the false alarm rate can be reduced.

[0022] In another possible implementation, when the file parsing module parses the target file to obtain the PHP Opcode dynamic feature, it is specifically used to: Performing lexical analysis on the content of the target file to obtain lexical units; Constructing a syntax tree based on the lexical unit; Convert the syntax tree into Opcode and run it to get the running result; The PHP Opcode dynamic feature is extracted based on the running result.

[0023] In another possible implementation, when the first detection module combines the dynamic feature with the static feature to obtain the first detection result, it is specifically configured to: Inputting the static feature into a first model for calculation to obtain a first score; Inputting the dynamic feature into a second model for calculation to obtain a second score; The first score, the second score and their corresponding weights are calculated to obtain a first detection result.

[0024] In another possible implementation, when the second detection module performs flow detection based on the target file to obtain the second detection result, it is specifically used to: Get traffic data; Based on the flow data, the flow data is processed to obtain a feature vector; A GXL-Stacking model is constructed, and the feature vector is input into the GXL-Stacking model for detection to obtain a second detection result.

[0025] In another possible implementation, when the second detection module processes the traffic data based on the traffic data to obtain the feature vector, it is specifically configured to: Capture PCAP packets; Based on the PACP data packet, obtaining HTTP traffic through a preset filtering condition; Parsing the HTTP traffic to extract each HTTP request message; Field extraction is performed on each HTTP request message to obtain a feature vector.

[0026] In another possible implementation, when constructing the GXL-Stacking model, the second detection module is specifically used to: Input the feature vector into a plurality of base learners for base learning training to obtain a first training result, wherein the base learners include a comparative random forest, a support vector machine, GBDT, XGBoost, and LightGBM, and the first training result includes accuracy, error, precision, recall, and F1 value; Calculate based on the first training results and the corresponding weights to obtain a third score; Sorting the third scores from high to low to obtain a first sorting result; Selecting the base learner with the first ranking result as the meta learner; Selecting the algorithms of the base learners in the top three of the first ranking results as base learning algorithms; Based on the meta-learner and the base learning algorithm, a GXL-Stacking model is constructed.

[0027] In another possible implementation, when the file determination module determines that the target file is a WebShell based on the first detection result and the second detection result, the file determination module is specifically used to: If the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

[0028] In a third aspect, the present application provides an electronic device, which adopts the following technical solution: An electronic device, comprising: at least one processor; Memory; At least one application, wherein at least one application is stored in a memory and configured to be executed by at least one processor, and at least one is configured to: execute the machine learning-based WebShell detection method shown in any possible implementation of the first aspect.

[0029] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium, when the computer program is executed in a computer, causes the computer to execute the WebShell detection method based on machine learning as described in any one of the first aspects.

[0030] In summary, the present application includes at least one of the following beneficial technical effects: 1. Dynamic features can reveal the operations that a file may perform when it is running, while static features provide direct information about the file structure and content. The combination of the two can complement each other and improve the accuracy of detection. At the same time, by considering multiple aspects of features, including file name, file content, encoding method, information entropy, etc., false positives caused by the similarity of a single feature can be reduced. In addition to file and content analysis, traffic detection can capture network activities related to the target file. It helps to discover WebShells that only exhibit malicious behavior under specific network requests. By combining dynamic features, static features and traffic detection to detect whether the target file is a WebShell, the accuracy of detection can be improved and the false positive rate can be reduced; 2. By performing lexical analysis on the contents of the target file, lexical units can be obtained. Further construction of a syntax tree can more clearly show the structure and logical relationship of the code, which is crucial for subsequent analysis and feature extraction. Converting the syntax tree into Opcode and running it actually simulates the execution process of the code in the PHP interpreter, which can capture the dynamic behavior generated by the code during execution, rather than just based on the static structure of the code. This kind of dynamic feature extraction helps to discover WebShells that only exhibit malicious behavior at runtime. The extraction of dynamic features increases the depth and complexity of the analysis, but also improves the accuracy of detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a flow chart of the WebShell detection method based on machine learning in the embodiment of the present application.

[0032] Figure 2 It is a flow chart of a WebShell detection device based on machine learning in an embodiment of the present application.

[0033] Figure 3 It is a schematic diagram of the process of constructing the GXL-Stacking model in the embodiment of the present application.

[0034] Figure 4 It is a structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The following is combined with Figure 1-4 This application is described in further detail.

[0036] After reading this specification, those skilled in the art may make modifications to this embodiment without any creative contribution as needed, but such modifications are protected by patent law as long as they are within the scope of the claims of this application.

[0037] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution 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 part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0038] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.

[0039] The embodiments of the present application are further described in detail below in conjunction with the drawings in the specification.

[0040] The embodiment of the present application provides a WebShell detection method based on machine learning, which is executed by an electronic device, which can be a server or a terminal device, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present application. Figure 1 As shown, the method includes: steps S10 to S15, wherein: Step S10, obtaining the target file.

[0041] In the embodiment of the present application, the electronic device can directly access the file path, or through file search and network transmission. Specifically, if you are not sure about the exact location of the target file, but know some key information (such as part of the file name, file type or specific keywords in the file content), you can use file search tools or commands to find the file; if the target file is located on a remote server, you may need to download or access the file through a network protocol (such as FTP, SFTP, HTTP, SCP, etc.).

[0042] Step S11, parsing the target file to obtain PHP Opcode dynamic features, which include Opcode sequence, function call mode, and system command execution.

[0043] In the embodiment of the present application, Opcode may also be referred to as an operation code, which represents an operation instruction in an instruction set architecture. Each operation code corresponds to a specific operation and is used to specify the execution of a specific operation or operation sequence.

[0044] PHP is a server scripting language. Parsing a PHP file into Opcode goes through the following four steps: In the first step, the PHP interpreter performs lexical analysis on the file content and decomposes the source code into lexical units. In the second step, the interpreter combines lexical units into a grammatical structure and constructs an abstract syntax tree. In the third step, the interpreter converts the abstract syntax tree into Opcode instructions during the compilation phase. The fourth step is the final execution phase, where the PHP interpreter performs the corresponding operations according to the type and parameters of the Opcode instruction to complete the update of the program status.

[0045] Step S12, extracting text content from the target file to obtain static features.

[0046] Static features include whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether the encoding function is used to confuse the text, the information entropy of the text, the compression ratio of the text, and the coincidence index of the text.

[0047] In the embodiment of the present application, due to the different categories of static features, the extraction method is also different. The specific extraction method is as follows: whether the file name or file content contains the WebShell keyword is detected by string matching to see whether the file name or file content contains the WebShell feature field. The rule base for string matching is based on previous WebShell features, and the rule base is formed by analyzing and summarizing new WebShell texts. For example, the detection of the file name is to detect whether the file is named WebShell or Shell, and whether it is a known WebShell name. Detect whether the file content contains the keyword "hacker". Taking the original Ice Scorpion WebShell as an example, the WebShell content contains "the default connection password is rebeyond".

[0048] The ratio of the longest statement to the text content refers to the ratio of the length of the longest statement in the text to the length of the entire text content. Since the number of code statements in WebShell code is small except for the big horse, for example, a one-sentence Trojan is a WebShell constructed by a PHP statement containing the eval() function. A single command execution statement can realize the command execution function, thereby obtaining sensitive information of the compromised server. Most new WebShells will use coding obfuscation to bypass detection. This obfuscation method lengthens the length of a single statement, which increases the ratio of the longest statement to the text content after code obfuscation.

[0049] Whether to use encoding functions to encode text is to detect whether the file content contains encoding functions. Since WebShell uses commands to perform encoding and decoding to bypass detection, detecting whether the text content contains functions such as base64_encode() and base64_decode() that encode and decode codes is used as a feature to determine whether the file is a WebShell file.

[0050] The information entropy of a text is a measure of the amount of information or uncertainty in a text. The higher the information entropy, the more evenly the characters in the text are distributed. WebShell uses character numbers and encoding to evade detection, so WebShell has a higher information entropy than normal text. The mathematical calculation formula for information entropy is as follows, where H(x) represents the information entropy of the text, and p(x i ) represents the probability of a character appearing.

[0051] H(x)=-∑ n n=1 p(x i )logp(x i ) The text compression ratio is the ratio of the file size after the text content is compressed to the original text size before compression. When there are a lot of repeated characters in the text content or the text is regular, the compression ratio of the text will be high. On the contrary, if the text is unevenly distributed, the compression ratio of the text will be low. Since WebShell text uses encoding obfuscation to evade detection, this type of text contains a lot of redundant characters and numbers, so the compression ratio of the obfuscated WebShell text is higher than that of normal files.

[0052] The text overlap index is used to measure the balance of character distribution in the text. The characters of the obfuscated WebShell are usually arranged in disorder, so the calculated text overlap index is smaller than that of the normal file content.

[0053] Step S13, combining the dynamic features with the static features to obtain a first detection result.

[0054] In the embodiment of the present application, since dynamic features reflect the behavior pattern of the file when it is executed, and static features provide information about the file structure and content, in order to capture more features related to WebShell and improve the accuracy of detection, static features and dynamic features are combined. Specifically, since the features need to be input into the machine learning model before the first detection result is obtained, and then machine learning usually requires numerical input, and static features and dynamic features often exist in original formats, such as text, images, time series, etc. Feature vectorization can convert these non-numeric features into numerical vectors. Furthermore, feature vectorization processing not only converts features into numerical form, but also involves the integration and compression of features. By integrating multiple features into one feature vector, the computational complexity of the machine learning model can be reduced and the computational efficiency can be improved.

[0055] Specifically, in order to capture the correlation and pattern between Opcodes, it is necessary to split the continuous Opcode sequence into smaller units (unigrams, bigrams, trigrams, etc.) and analyze the frequency and order of these units. Use the N-gram algorithm to segment Opcodes. N-gram is one of the commonly used text processing technologies in the field of natural language processing. It is a statistical text model used to analyze the frequency and probability of n consecutive words or characters in the original text. The steps of the N-gram algorithm are to first determine the size of N, which represents the number of items. Different N values ​​have different names. For example, when N is 1, it is also called unigram, when N is 2, it is called bigram, and when N is 3, it is called trigram. After selecting the N value, the next step is to preprocess the text and segment the original text. The preprocessing process also includes operations such as removing stop words and standardizing text. The constructed N-gram combination is used as a feature to represent the text.

[0056] In order to analyze the importance of each word in the Opcode, the TF-IDF algorithm is used to calculate the weights and vectorize the features. TF-IDF is a commonly used weighted technology for text feature extraction and weight calculation, which is used to measure the importance of a word in the entire text. TF in TF-IDF is called word frequency, which is used to count the frequency of words in the file content. IDF is called inverse document frequency, which is used to measure the general importance of words in a document collection. By calculating the inverse of the frequency of words in the entire file content, frequently occurring words are given lower weights and rare words are given higher weights. The calculation process of TF-IDF is as follows.

[0057] Calculate word frequency. For the target file, count the frequency of words appearing in the file content.

[0058] Calculates the inverse document frequency. For a given term, calculates how often the term appears in the entire target document, then takes the inverse and smoothes the result.

[0059] Calculate TF-IDF. Multiply the term frequency by the inverse document frequency to get the TF-IDF weight for each term.

[0060] TF=TF×IDF It should be noted that the advantage of the TF-IDF algorithm is that calculating the word frequency can capture the importance of the word, and calculating the inverse document frequency focuses on the general importance of the word in the entire file content, which reduces the weight of common repeated words, highlights the importance of low-frequency words, and makes rare words obtain higher weights in feature representation. However, the TF-IDF algorithm has the problem of being unable to effectively capture the semantic relationship between words and the relevance of contextual information. Therefore, in the embodiment of the present application, the extracted WebShell dynamic feature vector is vectorized by combining the N-gram and TF-IDF algorithms. Thereby, the frequency of words in the text and the relationship between contextual information can be comprehensively considered, the N-gram algorithm can obtain the contextual information of rare words, and the TF-IDF algorithm can obtain appropriate weights for rare words, and more accurately represent the importance of words.

[0061] Step S14: Perform flow detection based on the target file to obtain a second detection result.

[0062] In an embodiment of the present application, traffic data is acquired; based on the traffic data, the traffic data is processed to obtain a feature vector; a GXL-Stacking model is constructed, and the feature vector is input into the GXL-Stacking model for detection to obtain a second detection result.

[0063] Step S15: determining that the target file is a WebShell based on the first detection result and the second detection result.

[0064] In an embodiment of the present application, if the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

[0065] A possible implementation of the embodiment of the present application is to parse the target file to obtain the PHP Opcode dynamic feature, including: Step S110 to Step S112 (not shown in the figure), wherein: Step S110, performing lexical analysis on the content of the target file to obtain lexical units.

[0066] In an embodiment of the present application, when performing lexical analysis, the content of the target file is first read by the lexical analyzer, converted into a character stream, and then the character stream is traversed, that is, the lexical analyzer begins to read the characters in the character stream one by one. According to the category and word formation rules of the characters, the lexical analyzer determines whether the current character can constitute a meaningful lexical unit, such as a keyword, identifier, number, operator, separator, etc. If the current character can constitute a lexical unit, then this lexical unit will be pushed into the stack and the current lexical unit category will be updated. If it cannot constitute a lexical unit, the current lexical unit (or part of the lexical unit) may be popped out of the stack and the judgment of the next word will be restarted. When the file end character is encountered, the lexical analysis process ends, and all lexical units and their categories have been determined.

[0067] Step S111, constructing a syntax tree based on lexical units.

[0068] In the embodiment of the present application, first, it is necessary to define the grammatical rules of the language. The grammatical rules are usually defined in the form of context-free grammar (CFG), including terminal symbols (usually lexical units) and non-terminal symbols (symbols representing grammatical structures), which are specifically set according to the use requirements, and the embodiment of the present application will not be described in detail. The grammatical analyzer parses the lexical units according to the defined grammatical rules. This process can be from top to bottom (such as recursive descent parsing) or from bottom to top (such as shift-reduce parsing), which is specifically set according to the parsing algorithm. In the parsing process, whenever the grammatical rules are successfully matched, a node of a grammar tree is created. These nodes usually contain information about matching, such as the type of rule and the associated lexical units. Then, these nodes are connected according to their parent-child relationship in the grammatical rules to form a tree structure. When all lexical units are successfully parsed and added to the grammar tree, a complete grammar tree is constructed.

[0069] Step S112, converting the syntax tree into Opcode, and running it to obtain the running result.

[0070] Extract PHP Opcode dynamic features based on running results.

[0071] In the embodiment of the present application, the virtual machine executes the Opcode in sequence to realize the function of the PHP script. Each Opcode will be interpreted and executed by the virtual machine until all Opcodes are executed and the final operation result is obtained. During the Opcode execution process, key operations and state changes are monitored and recorded, and dynamic features related to the operation result are extracted based on the monitoring information. The dynamic features include the type of Opcode executed, the number of calls, memory usage, execution time, etc.

[0072] A possible implementation of the embodiment of the present application combines the dynamic features with the static features to obtain the first detection result, including: Step S130 to Step S132 (not shown in the figure), wherein: Step S130: Input the static features into the first model for calculation to obtain a first score.

[0073] In an embodiment of the present application, a pre-trained first model is loaded, or an untrained model is initialized. Wherein, if an untrained model is used, the parameters of the model, such as learning rate, optimizer, etc., need to be set. The prepared static features are passed to the model as input data. The data is loaded into the input layer of the model. After the model receives the input features, a forward propagation calculation is performed, that is, the output of the model is calculated according to the parameters and structure of the model. The results are obtained from the output layer of the model, and then the model output is scored according to the accuracy, recall rate, F1 value, etc. and the corresponding weights to obtain a first score.

[0074] Step S131, input the dynamic features into the second model for calculation to obtain a second score.

[0075] In an embodiment of the present application, if the dynamic feature includes time series data or features that change over time, it is necessary to ensure that these features have been arranged in chronological order and load the trained second model. The dynamic feature is passed to the second model as input data. This can be implemented by the corresponding function or method of the programming language, such as a function in a deep learning framework (such as TensorFlow or PyTorch) using Python. After the model receives the input, it will be calculated according to its internal structure and parameters. After the model calculation is completed, an output will be generated, and then the model output will be scored according to the accuracy, recall, F1 value, etc. and the corresponding weights to obtain a second score.

[0076] Step S132, calculating the first score, the second score and their corresponding weights to obtain a first detection result.

[0077] In the embodiment of the present application, the first score is the calculation result of the dynamic feature, and the second score is the calculation result of the static feature. Since the dynamic feature and the static feature have different effects on WebShell detection, the weight is set according to the importance of the dynamic feature and the static feature, and then the first score, the second score and the corresponding weight are calculated to obtain the final first detection result, thereby reducing the error and deviation that may exist in a single result.

[0078] A possible implementation of the embodiment of the present application is to perform flow detection based on the target file to obtain a second detection result, including: steps S140 to S142 (not shown in the figure), wherein: Step S140, obtaining traffic data.

[0079] Step S141, based on the flow data, the flow data is processed to obtain a feature vector.

[0080] In an embodiment of the present application, it is necessary to first identify the target server or application to be detected and determine the range of network traffic that needs to be captured. Use a network traffic capture tool such as Wireshark to configure capture rules on the target server or key network nodes to collect relevant network traffic, start the traffic capture tool, and begin capturing network traffic data in real time.

[0081] Specifically, when processing traffic data, the captured raw traffic data is exported as a file (such as PCAP format) for subsequent analysis and processing, and the traffic data is cleaned to remove irrelevant or duplicate traffic packets, and the traffic data related to the target WebShell is retained. Use traffic analysis tools or write scripts to parse the cleaned traffic data and extract features related to WebShell activities. Features may include specific fields in the HTTP request header, request methods, URL patterns, data size transmitted, encryption methods, etc. Encode the extracted features, convert text or string features into numerical features, construct feature vectors, and use each feature value as an element in the vector for subsequent machine learning algorithms or statistical analysis.

[0082] Step S142, constructing a GXL-Stacking model, inputting the feature vector into the GXL-Stacking model for detection, and obtaining a second detection result.

[0083] In an embodiment of the present application, a feature vector is input into a plurality of base learners for base learning training to obtain a first training result, and a third score is obtained based on the first training result and the corresponding weights. The third score is sorted from high to low to obtain a first sorting result. The base learner with the first first sorting result is selected as a meta-learner. The algorithms of the top three base learners in the first sorting result are selected as base learning algorithms. A GXL-Stacking model is constructed based on the meta-learner and the base learning algorithm. The feature vector is then input into the trained GXL-Stacking model, and the model will make predictions based on the input feature vector to generate a second detection result.

[0084] A possible implementation of the embodiment of the present application is to process the flow data based on the flow data to obtain a feature vector, including: steps Sa1 to Sa4 (not shown in the figure), wherein: Step Sa1, capture PCAP data packets.

[0085] In the embodiment of the present application, a network traffic capture tool is used to select a suitable network port to ensure that the port can capture the target network traffic, wherein the network traffic capture tool may be Wireshark, Tcpdump, etc. As required, the capture filter conditions are set, such as only capturing traffic from a specific IP address or port, setting parameters such as capture time and buffer size, and starting the capture process. The tool will begin to collect network traffic passing through the network interface in real time, and save the captured data in PCAP (Packet Capture) file format.

[0086] Step Sa2, based on the PACP data packet, obtain HTTP traffic through preset filtering conditions.

[0087] In the embodiment of the present application, a capture tool or a dedicated PCAP file analysis tool is used to open the saved PCAP file, and in the analysis tool, a filter is set to filter out HTTP traffic. Assume that this is achieved by entering HTTP-related keywords or expressions in the filter bar, such as "http".

[0088] Step Sa3, parse the HTTP traffic and extract each HTTP request message.

[0089] In the embodiment of the present application, an analysis tool is used to perform protocol analysis on the filtered HTTP traffic to extract the components of the HTTP request and response, such as the request line, request header, request body, etc., thereby extracting each HTTP request message. The analysis tool may be, but does not include, Wireshark, TCPDump, HTTP Sniffer, Fiddler, etc.

[0090] Step Sa4, extract fields from each HTTP request message to obtain a feature vector.

[0091] In an embodiment of the present application, according to the needs of WebShell detection, the features to be extracted from the HTTP traffic are determined. These features may include specific fields in the request header, request methods, URL patterns, data size of the transmission, etc. A feature extraction script is written using a scripting language (such as Python), and the corresponding data is extracted from the parsed HTTP traffic according to the determined features. The extracted feature data is organized into the form of a feature vector. Each feature corresponds to an element in the vector, which can be a numerical or text data. Specifically, the features extracted from different fields are also different, for example: 3D features are extracted from the URL field, which are whether WebShell sensitive keywords are contained, whether the file name accessed contains numbers or characters, and the ratio of the URL length to the length of the normal access URL. Whether the WebShell sensitive keywords are contained is to detect whether the file name accessed is the name of a known WebShell, or whether the file name contains sensitive keywords such as "shell". Since attackers use "%00" truncation, point bypass, space bypass and other attack methods to bypass detection, detection is performed by checking whether the URL file name contains numbers or characters. In order to connect to WebShell stably and conveniently, the attacker uploads the Trojan to the root directory, or uses the directory traversal vulnerability to upload the Trojan to the root directory. At this time, the length of the URL is shorter than the normal access business URL. Therefore, the ratio of the URL length to the normal access URL length is used as a feature.

[0092] Extract a 1-dimensional feature from the Host field, that is, whether the Host field content is an IP. Users usually access websites by domain name, but in order to ensure that the WebShell is uploaded to the destination server and obtain a stable connection, the attacker will resolve the domain name to an IP and upload it to the server using the vulnerability, and connect to the WebShell in the form of an IP.

[0093] The User-Agent field extracts one-dimensional features, that is, whether the field contains WebShell-specific keywords or whether the User-Agent field is a fixed string in the User-Agent library.

[0094] The Accept field extracts two-dimensional features, namely, whether there is an Accept field in the HTTP message and whether the Accpet field is a string possessed by WebShell.

[0095] The Referer field extracts a one-dimensional feature, that is, whether there is a Referer field. The Referer field records the address of the source page. The attacker directly accesses the WebShell to connect, so this field is not included.

[0096] The Accept-Language field extracts a one-dimensional feature, that is, whether the message contains the Accept-Language field.

[0097] The Connection field extracts a one-dimensional feature, that is, whether the Connection field is in a connected state. The feature of this field in the Ice Scorpion WebShell communication traffic is the connection state.

[0098] The Content-Length field extracts a 1-dimensional feature, namely the length ratio. Since the WebShell contains the commands to be executed in the BODY, and the length of the obfuscated and encrypted WebShell traffic BODY is longer, the ratio of the WebShell Content-Length to the normal access Content-Length is calculated as a feature.

[0099] Cookie field extraction extracts 3-dimensional features, namely whether there is a cookie, the number of cookies, and whether the cookie ends with a semicolon. WebShell usually does not have a cookie or the number of cookies is 1. The cookie in Godzilla traffic ends with a semicolon. Checking whether the cookie ends with a semicolon is used as a feature to detect Godzilla WebShell.

[0100] The BODY field extracts 6-dimensional features, namely whether it contains BODY, whether the BODY contains WebShell keywords or specific functions, information entropy, coincidence index, the ratio of the longest word length to the entire BODY text, and text compression ratio. The WebShell management tool encrypts and obfuscates the traffic, so calculating the statistical features of the BODY field can help better identify WebShell traffic.

[0101] A possible implementation method of an embodiment of the present application is to construct a GXL-Stacking model, including: steps Sb1 to Sb6 (not shown in the figure), wherein, in step Sb1, the feature vector is input into multiple base learners for base learner training to obtain a first training result.

[0102] The base learners include random forest, support vector machine, GBDT, XGBoost, and LightGBM. The first training results include accuracy, error, precision, recall, and F1 value.

[0103] In the embodiments of the present application, Figure 3As shown, the feature vector is organized into a format suitable for machine learning model training, usually a two-dimensional array or data frame (DataFrame), where each row represents a sample and each column represents a feature. The feature vector is then used as input and trained using the selected base learner. The feature vector is divided into a training set and a test set, and then the model is trained with the training set. During the training process, the base learner learns how to predict the target variable from the feature vector. During the learning process, the model weights, learning decision boundaries, etc. are adjusted according to actual requirements. After the training is completed, the test set (if any) is used to evaluate the performance of the base learner to obtain the first training result, that is, the accuracy, error, precision, recall rate, and F1 value of each base learner.

[0104] Step Sb2, performing calculation based on the first training result and the corresponding weights to obtain a third score.

[0105] In the embodiment of the present application, since the first training result includes the accuracy, error, precision, recall rate and F1 value of each base learner, weights are set for different indicators of each base learner according to the focus of each base learner, and then the third score of each base learner is obtained, thereby calculating the performance of each base learner under the weighted condition.

[0106] Step Sb3, sorting the third scores from high to low to obtain a first sorting result. In the embodiment of the present application, in step Sb2, the third score of each base learner is calculated according to the first training result of the base learner and the corresponding weights, and the third scores are sorted from high to low using a sorting algorithm. Among them, the sorting method includes but is not limited to bubble sort, insertion sort, quick sort, etc. The sorted third scores and their corresponding base learners are recorded to form a first sorting result.

[0107] Step Sb4, selecting the base learner with the first ranking result as the meta learner.

[0108] Step Sb5, selecting the algorithms of the top three base learners in the first sorting result as the base learning algorithms.

[0109] Step Sb6, constructing a GXL-Stacking model based on the meta-learner and the base learning algorithm.

[0110] In the embodiment of the present application, the basic principle of the meta-learner is to train a "meta-model", that is, a model that learns how to learn. This meta-model can be regarded as a high-level learning strategy, which extracts common learning rules and strategies by observing and learning the characteristics and patterns of a large number of different tasks, and applies them to new tasks. Therefore, the base learner with the first ranking result shows good performance in the evaluation process, including accuracy, precision, recall rate and F1 value, which means that it has strong generalization ability, can better adapt to new data, and make accurate predictions. Therefore, using it as a meta-learner can further improve the prediction performance of the entire GXL-Stacking model.

[0111] Assume that the base learners are random forest, support vector machine, GBDT, XGBoost, and LightGBM, then generate samples according to the feature extraction method and feature vectorization processing method in the embodiments of the present application, and then input the samples into the above five base learners respectively, so as to obtain the first ranking result, that is, GBDT>XGBoost>LightGBM>random forest>support vector machine.

[0112] A possible implementation of the embodiment of the present application is to determine that the target file is a WebShell based on the first detection result and the second detection result, including: If the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

[0113] In an embodiment of the present application, the first detection result is a WebShell text detection result, and the second detection result is a WebShell flow detection result. When both the first detection result and the second detection result are detected as WebShell, it can be determined that the target file is a WebShell. When the first detection result is a normal file and the second detection result is a WebShell, or the first detection result is a WebShell and the second detection result is a normal file, it means that an error has occurred in the two detections, which may be caused by multiple factors. It is necessary to re-correct the two detection methods to accurately determine whether the target file is a WebShell.

[0114] The above embodiment introduces a WebShell detection method based on machine learning from the perspective of the method flow. The following embodiment introduces a WebShell detection device 20 based on machine learning from the perspective of a virtual module or a virtual unit. For details, please refer to the following embodiment.

[0115] The embodiment of the present application provides a device 20 for WebShell detection based on machine learning, such as Figure 2As shown, the device 20 for WebShell detection based on machine learning may specifically include: File acquisition module 201, acquires the target file; The file parsing module 202 parses the target file to obtain PHP Opcode dynamic features, which include Opcode sequence, function call mode, and system command execution; The text extraction module 203 extracts text content according to the target file to obtain static features, including whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether the encoding function is used to confuse the text encoding, the information entropy of the text, the compression ratio of the text, and the coincidence index of the text; A first detection module 204 combines the dynamic features with the static features to obtain a first detection result; The second detection module 205 performs flow detection based on the target file to obtain a second detection result; The file determination module 206 determines that the target file is a WebShell based on the first detection result and the second detection result.

[0116] In a possible implementation of the embodiment of the present application, when the file parsing module 202 parses the target file to obtain the PHP Opcode dynamic feature, it is specifically used to: Perform lexical analysis on the content of the target file to obtain lexical units; Build a syntax tree based on lexical units; Convert the syntax tree into Opcode, run it, and get the running result; Extract PHP Opcode dynamic features based on running results.

[0117] In a possible implementation of the embodiment of the present application, when the first detection module 204 combines the dynamic feature with the static feature to obtain the first detection result, it is specifically used to: Inputting the static features into the first model for calculation to obtain a first score; The dynamic feature is input into the second model for calculation to obtain a second score; The first score, the second score, and their corresponding weights are calculated to obtain a first detection result.

[0118] In a possible implementation of the embodiment of the present application, when the second detection module 205 performs flow detection based on the target file and obtains the second detection result, it is specifically used to: Get traffic data; Based on the flow data, the flow data is processed to obtain a feature vector; A GXL-Stacking model is constructed, and the feature vector is input into the GXL-Stacking model for detection to obtain a second detection result.

[0119] In a possible implementation of the embodiment of the present application, when the second detection module 205 processes the traffic data based on the traffic data to obtain the feature vector, it is specifically used to: Capture PCAP packets; Based on PACP packets, HTTP traffic is obtained through preset filtering conditions; Parse HTTP traffic and extract each HTTP request message; Perform field extraction on each HTTP request message to obtain a feature vector.

[0120] In a possible implementation of the embodiment of the present application, when constructing the GXL-Stacking model, the second detection module 205 is specifically used to: Input the feature vector into multiple base learners for base learning training to obtain a first training result, the base learners include random forest, support vector machine, GBDT, XGBoost, LightGBM, and the first training result includes accuracy, error, precision, recall rate and F1 value; Calculate based on the first training result and the corresponding weights to obtain a third score; Sort the third scores from high to low to obtain a first sorting result; Select the base learner with the first ranking result as the meta-learner; Select the algorithms of the top three base learners in the first ranking result as the base learning algorithms; Based on the meta-learner and base learning algorithm, the GXL-Stacking model is constructed.

[0121] In a possible implementation of the embodiment of the present application, when the file determination module 206 determines that the target file is a WebShell based on the first detection result and the second detection result, it is specifically used to: If the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0123] An electronic device is provided in an embodiment of the present application, such as Figure 4 As shown, Figure 4The electronic device 30 shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device 30 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 30 does not constitute a limitation on the embodiments of the present application.

[0124] Processor 301 may be a CPU (Central Processing Unit), a general purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0125] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the diagram, but it does not mean that there is only one bus or only one type of bus.

[0126] The memory 303 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.

[0127] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.

[0128] The electronic devices include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and fixed terminals such as digital TVs, desktop computers, etc. It can also be a server, etc. Figure 4 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0129] The embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when it is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the related art, in the embodiment of the present application, the dynamic features can reveal the operations that the file may perform when it is running, and the static features provide direct information about the file structure and content. The combination of the two can complement each other and improve the accuracy of detection. At the same time, by considering multiple aspects of features, including file name, file content, encoding method, information entropy, etc., false positives caused by similar single features can be reduced. In addition to the analysis of files and content, traffic detection can capture network activities related to the target file. It is helpful to discover WebShells that only show malicious behavior under specific network requests. By combining dynamic features, static features and traffic detection to detect whether the target file is a WebShell, the accuracy of detection can be improved and the false positive rate can be reduced.

[0130] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0131] The above are only some implementation methods 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. WebShell detection method based on machine learning, It is characterized in that include: Get the target file; Parsing the target file to obtain PHP Opcode dynamic features, wherein the PHP Opcode dynamic features include Opcode sequence, function call mode, and system command execution; Extracting text content from the target file to obtain static features, including whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether an encoding function is used to confuse the text, information entropy of the text, compression ratio of the text, and coincidence index of the text; Combining the dynamic feature with the static feature to obtain a first detection result; Performing flow detection based on the target file to obtain a second detection result; Based on the first detection result and the second detection result, it is determined that the target file is a WebShell.

2. According to the WebShell detection method based on machine learning in claim 1, It is characterized in that The target file is parsed to obtain PHP Opcode dynamic features, including: Performing lexical analysis on the content of the target file to obtain lexical units; Constructing a syntax tree based on the lexical unit; Convert the syntax tree into Opcode and run it to get the running result; The PHP Opcode dynamic feature is extracted based on the running result.

3. According to the WebShell detection method based on machine learning in claim 1, It is characterized in that The combining the dynamic feature with the static feature to obtain a first detection result includes: Inputting the static feature into a first model for calculation to obtain a first score; Inputting the dynamic feature into a second model for calculation to obtain a second score; The first score, the second score and their corresponding weights are calculated to obtain a first detection result.

4. The WebShell detection method based on machine learning according to claim 1, It is characterized in that The flow detection is performed based on the target file to obtain a second detection result, including: Get traffic data; Based on the flow data, the flow data is processed to obtain a feature vector; A GXL-Stacking model is constructed, and the feature vector is input into the GXL-Stacking model for detection to obtain a second detection result.

5. The WebShell detection method based on machine learning according to any one of claim 4, It is characterized in that The processing of the flow data based on the flow data to obtain a feature vector includes: Capture PCAP packets; Based on the PACP data packet, obtaining HTTP traffic through a preset filtering condition; Parsing the HTTP traffic to extract each HTTP request message; Field extraction is performed on each HTTP request message to obtain a feature vector.

6. The WebShell detection method based on machine learning according to any one of claim 4, It is characterized in that The construction of the GXL-Stacking model includes: Input the feature vector into a plurality of base learners for base learning training to obtain a first training result, wherein the base learners include a comparative random forest, a support vector machine, GBDT, XGBoost, and LightGBM, and the first training result includes accuracy, error, precision, recall, and F1 value; Calculate based on the first training results and the corresponding weights to obtain a third score; Sorting the third scores from high to low to obtain a first sorting result; Selecting the base learner with the first ranking result as the meta learner; Selecting the algorithms of the base learners in the top three of the first ranking results as base learning algorithms; Based on the meta-learner and the base learning algorithm, a GXL-Stacking model is constructed.

7. The WebShell detection method based on machine learning according to claim 1, It is characterized in that The determining, based on the first detection result and the second detection result, that the target file is a WebShell includes: If the first detection result is WebShell and the second detection result is WebShell, it is determined that the target file is WebShell.

8. WebShell detection device based on machine learning, It is characterized in that include: File acquisition module, to acquire the target file; A file parsing module parses the target file to obtain PHP Opcode dynamic features, wherein the PHP Opcode dynamic features include Opcode sequence, function call mode, and system command execution; A text extraction module extracts text content from the target file to obtain static features, including whether the file name or file content contains WebShell keywords, the ratio of the longest sentence to the text content, whether an encoding function is used to confuse the text encoding, the information entropy of the text, the compression ratio of the text, and the coincidence index of the text; A first detection module combines the dynamic feature with the static feature to obtain a first detection result; A second detection module performs flow detection based on the target file to obtain a second detection result; The file determination module determines that the target file is a WebShell based on the first detection result and the second detection result.

9. An electronic device, It is characterized in that It includes: at least one processor; Memory; At least one application, wherein the at least one application is stored in the memory and is configured to be executed by the at least one processor, and the at least one application is used to execute the WebShell detection method based on machine learning according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed in a computer, the computer is caused to execute the WebShell detection method based on machine learning according to any one of claims 1 to 7.

Citation Information

Cited By

  • Automatic malicious code capturing method

    CN119094205A