Malicious application detection method, device, server and readable storage medium
By performing reverse engineering and grayscale image processing on binary files combined with machine learning algorithm detection, the problem of low efficiency in malicious application detection is solved and fast and accurate malicious application identification is achieved.
Patent Information
- Application Number
- CN202110738329.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-30
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-06-30
AI Technical Summary
Existing malicious application detection methods are inefficient. Malware uses code obfuscation technology to make it more difficult to reverse engineer SO files into code, resulting in reduced detection efficiency.
By reverse engineering the binary file, if the target code is obtained by reverse engineering, it will be directly judged as malicious or non-malicious; if it cannot be reverse engineered into code, the binary file will be converted into a grayscale image and operation code sequence, combined with the preset machine learning algorithm. detection.
It effectively shortens the detection time, improves the efficiency of malicious application detection, and can accurately identify whether the target application is a malicious application.
Smart Images

Figure CN113360910B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of application software detection, and in particular to a method, device, server and readable storage medium for detecting malicious applications. Background Art
[0002] With the rapid development of mobile Internet technology, Android smart terminals are becoming more and more popular. Android system has gradually become a popular operating system for mobile terminals. Compared with other terminal operating systems, the open Android system provides more functional interfaces for application developers. These functional interfaces improve the scalability of the system, but also provide convenience for malware. At present, malicious applications mainly put malicious behaviors such as privilege escalation and attack vector codes in the corresponding shared object (SO) files. These malicious applications will obtain illegal benefits by stealing user privacy data such as text messages, bank card account passwords, etc., which poses a serious threat to user property and privacy. Therefore, it is necessary to analyze and detect SO files to detect these malicious applications.
[0003] In the prior art, SO files are mainly detected by heuristic scanning methods, and SO files with unknown security are audited in combination with formulated rules. The rules are usually formulated based on existing malicious binary code segments or common malicious behaviors.
[0004] However, the premise of using formulated rules for auditing in the prior art is that the SO file must be able to be reversed into code, and the developers of malicious applications often use code obfuscation technology to encrypt, pack, and self-modify the code, making it more difficult to reverse the SO file into code, thereby reducing the detection efficiency of malicious applications. Summary of the invention
[0005] The present application provides a malicious application detection method, device, server and readable storage medium, which are used to solve the problem of low efficiency of existing malicious application detection methods.
[0006] In a first aspect, an embodiment of the present application provides a method for detecting malicious applications, which is applied to a server and includes:
[0007] In response to a binary file uploaded by a client, reverse engineering the binary file to determine whether the binary file is reversed to obtain a target code, wherein the binary file is a file compiled according to a preset programming language and runs in a native layer of a target application;
[0008] If the binary file is reversed to obtain a target code, a first detection result is obtained according to the target code, where the first detection result is used to indicate whether the target application is a malicious application or a non-malicious application;
[0009] If the target code cannot be obtained by reversing the binary file, obtaining an operation code sequence corresponding to the binary file;
[0010] The binary file is converted into a grayscale image, and a second detection result is calculated based on a preset machine learning algorithm, the grayscale image, and the operation code sequence, where the second detection result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0011] In a possible design of the first aspect, converting the binary file into a grayscale image includes:
[0012] Using a preset first function to convert the binary file into a hexadecimal string;
[0013] Perform byte segmentation on the hexadecimal character string to obtain segmented bytes, and generate a target matrix according to a preset second function and the segmented bytes;
[0014] According to a preset third function, the target matrix is converted into a grayscale image.
[0015] In another possible design of the first aspect, obtaining the operation code sequence corresponding to the binary file includes:
[0016] Reversing the binary file to obtain a target instruction set;
[0017] The target instruction set is converted into the operation code sequence by a preset computer programming language.
[0018] In another possible design of the first aspect, the calculating the second detection result according to the preset machine learning algorithm, the grayscale image and the operation code sequence includes:
[0019] Splitting the operation code sequence into multiple subsequences of length N, where N is a positive integer greater than 1;
[0020] Calculate the frequency of each subsequence appearing in the opcode sequence;
[0021] Determine the weight of each subsequence according to the frequency of occurrence of each subsequence in the operation code sequence;
[0022] According to the weight of each subsequence, each subsequence is weighted to calculate the feature vector corresponding to the binary file;
[0023] A second detection result is calculated based on the preset machine learning algorithm, the feature vector corresponding to the binary file, and the grayscale image.
[0024] In another possible design of the first aspect, the preset machine learning algorithm is a random forest algorithm, and the calculating the second detection result according to the preset machine learning algorithm, the feature vector corresponding to the binary file, and the grayscale image includes:
[0025] Calculate the cosine similarity between the feature vector corresponding to the binary file and m different types of preset malicious sample vectors, where m is a positive integer greater than 1;
[0026] Performing vector description on the grayscale image to obtain an image vector corresponding to the grayscale image;
[0027] The second detection result is calculated based on the random forest algorithm, the cosine similarity and the image vector corresponding to the grayscale image.
[0028] In another possible design of the first aspect, obtaining a first detection result according to the target code includes:
[0029] Scanning the target code according to a preset automated scanning tool to obtain a combined feature of the target code;
[0030] The combined feature is compared with a preset malicious code to obtain the first detection result.
[0031] In another possible design of the first aspect, after responding to the binary file uploaded by the client, the method further includes:
[0032] Using a preset disassembly application, disassemble the binary file to generate a target file containing assembly code;
[0033] The system calls of the target application are recorded in the target file, and the target application is classified according to the target file recording the system calls and the preset machine learning algorithm to obtain a classification result, wherein the classification result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0034] In yet another possible design of the first aspect, before reversing the binary file, the method further includes:
[0035] Calculate and obtain a hash value corresponding to the binary file;
[0036] Comparing the hash value corresponding to the binary file with a preset hash value, where the preset hash value is the hash value corresponding to the initial binary file of the target application;
[0037] If the hash value corresponding to the binary file does not match the preset hash value, the binary file is reversed.
[0038] In a second aspect, an embodiment of the present application provides a malicious application detection device, including:
[0039] A file determination module, configured to, in response to a binary file uploaded by a client, reverse the binary file to determine whether the binary file is reversed to obtain a target code, wherein the binary file is a file compiled according to a preset programming language and runs in a native layer of a target application;
[0040] A first detection module, configured to obtain a first detection result according to the target code and a preset malicious code if the target code is obtained by reverse engineering the binary file, wherein the first detection result is used to indicate whether the target application is a malicious application or a non-malicious application;
[0041] A sequence acquisition module, used for acquiring an operation code sequence corresponding to the binary file if the target code cannot be obtained by reverse engineering the binary file;
[0042] The second detection module is used to convert the binary file into a grayscale image, and calculate a second detection result based on a preset machine learning algorithm, the grayscale image and an operation code sequence, wherein the second detection result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0043] In a third aspect, an embodiment of the present application provides a service, including a memory and at least one processor;
[0044] The memory stores computer-executable instructions;
[0045] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the above method.
[0046] In a fourth aspect, an embodiment of the present application provides a readable storage medium, in which computer instructions are stored. When the computer instructions are executed by a processor, they are used to implement the method as described above.
[0047] In a fifth aspect, an embodiment of the present application provides a program product, including computer instructions, which implement the above method when executed by a processor.
[0048] The malicious application detection method, device, server and readable storage medium provided in the embodiments of the present application reverse the SO file in the malicious application. If it can be reversed into code, the SO file is directly used to determine whether there is malicious code and whether the target application is a malicious application. If it cannot be reversed into code, a grayscale image and an operation code sequence can be obtained through the SO file, and a machine learning algorithm can be combined to detect whether the target application is a malicious application, which can effectively shorten the detection time spent on the target application and improve the detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings herein are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the description, are used to explain the principles of the present application;
[0050] Figure 1 A schematic diagram of a scenario of a method for detecting malicious applications provided in an embodiment of the present application;
[0051] Figure 2 A schematic diagram of a malicious application detection method provided in an embodiment of the present application;
[0052] Figure 3 A schematic diagram of the structure of a malicious application detection device provided in an embodiment of the present application;
[0053] Figure 4 A schematic diagram of the hardware structure of the server provided in an embodiment of the present application.
[0054] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0055] 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.
[0056] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0057] First, the terms involved in this application are explained:
[0058] Native layer:
[0059] The native layer (NATIVE layer) consists of two parts: one part is the NATIVE library written in C and C++ languages. The system provides some functions of the NATIVE library to mobile application developers through the Java framework application programming interface (Application Programming Interface, API); the other part is the process of application running. For devices running Android 5.0 and above, each mobile application is allowed to run in a separate system process.
[0060] SO Files:
[0061] There are two types of SO files: system-provided and developer-developed. Both are compiled from C or C++ language codes. SO files are codes and data that can be used by other programs.
[0062] Figure 1 The following is a schematic diagram of a method for detecting malicious applications provided in an embodiment of the present application. The method can be applied to a server in the cloud. Figure 1 As shown, the mobile terminal 11 can be a smart phone. For example, the mobile terminal 11 can be a smart phone equipped with an Android operating system. Users can install various applications in the mobile terminal 11, some of which may contain malicious codes that steal user privacy data. These applications are collectively referred to as malicious applications. Malicious codes are usually placed in SO files, so when detecting these applications, the mobile terminal 11 can upload its SO file to the server 12, and the server 12 will detect the SO file to determine whether malicious codes are implanted therein, thereby determining whether the application is a malicious application.
[0063] In actual application development, since the execution code efficiency of SO files running in the native layer is higher than that of the execution code written in Java, the modules with strict performance requirements in the applications installed in smartphones are gradually implemented by generating SO files (such as high-precision search, bitmap decoding, image clarity processing, etc.). The development language of Android applications is Java, but the code at the Java layer is easily decompiled, while it is difficult to decompile C / C++ programs. With this feature, non-malicious applications will implement their core workflow codes that need to be kept confidential in mixed languages, while malicious applications tend to put malicious behaviors such as privilege escalation and attack vector codes in the corresponding SO files.
[0064] The mobile terminal 11 often stores a large amount of user privacy data, especially the user's address book, short messages, call records, etc., and many functions and services of the mobile terminal 11 involve user charges and are directly related to the user's economic interests. If there is malicious code in the SO file, when these SO files are loaded, the malicious code will obtain illegal benefits by stealing user privacy data such as text messages, bank card account passwords, etc., posing a serious threat to user property and privacy.
[0065] In this context, in order to combat the growing number of malicious applications in mobile terminals, developers of anti-malware applications need to rely heavily on automated tools to analyze new malicious application variants and then develop corresponding protection measures. However, automated analysis is relatively difficult because malicious program developers often use code obfuscation techniques, such as binary encryption, shells, or code self-modification, to increase the difficulty of automated analysis. These methods are particularly effective against traditional anti-static security analysis. Unlike static security analysis, dynamic binary stream security analysis can effectively monitor the malicious behavior of programs, which are usually not easily obfuscated by shells and directly reflect their corresponding attack behaviors. Therefore, existing research work focuses on developing specific detection tools to dynamically detect and monitor the behavior of malicious mobile applications.
[0066] In the prior art, automated analysis methods based on machine learning have been applied to the detection of malicious computer applications. There are two main types of methods. One is to classify malicious application behaviors. The goal is to correspond malicious operations to known malicious behavior categories. From the perspective of artificial intelligence, this is to apply the classification algorithm of machine learning to the security field. The other is to cluster malicious application behaviors. The goal is to discover new types of malicious behaviors with similar behaviors. From the perspective of artificial intelligence, this is to apply the clustering algorithm of machine learning to the security field. The main implementation of this process is to use isolation processing technology to perform relevant processing on preset instructions, such as updating a bitmap to record whether the corresponding memory is contaminated or to judge the safety of the jump.
[0067] Specifically, the prior art mainly uses two tools to detect malicious applications, one of which is an existing security tool such as DroidLegacy and Deshotels, which uses the method of scanning the code to obtain API calls and uses this function to classify malware. DroidLegacy emphasizes the importance of system API calls. The DroidLegacy system generates signatures by dividing the application into modules to create a class dependency graph, in which each node represents a class and each edge shows the relationship between classes. The graph combines the same classes together to form a single module, and the similarity of these modules will be checked using Jaccard similarity with known malware, and the selected shared features (such as API call frequency) are used to generate malware series signatures. Malware is detected and classified according to each malware series signature, but the tool does not use multiple malware classification features, and the detection effect is not ideal. Another tool is the DroidNative tool, which detects and classifies malware by applying static control flow graph analysis. The system can process Java bytecode and native libraries contained in the application, which provide important help for malware detection. If a high percentage of modules in the call flow graph of the application match some modules of known malware samples, the application is determined to be malware. The system uses two techniques: Annotated Control Flow Graph technology and Sliding Window of Difference technology, which are used to generate signatures from the call flow graph to determine the similarity of the test graph with the graph generated by the malware training dataset. However, obfuscation technology will reduce the detection performance and make the detection efficiency low.
[0068] In response to the above problems, the malicious application detection method, device, server and readable storage medium provided in the embodiments of the present application reverse the SO file in the malicious application. If it can be reversed into code, it is directly judged whether there is malicious code in the SO file through the code to determine whether the target application is a malicious application. If it cannot be reversed into code, a grayscale image and an operation code sequence can be obtained through the SO file, and combined with a machine learning algorithm to detect whether the target application is a malicious application, which can effectively shorten the detection time spent on the target application and improve the detection efficiency.
[0069] The technical solution of the present application is described in detail below through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0070] Figure 2The following is a flow chart of a method for detecting malicious applications provided in an embodiment of the present application. The method can be applied to a server in the cloud, such as Figure 2 As shown, the method may specifically include the following steps:
[0071] S201. In response to a binary file uploaded by a client, reverse the binary file to determine whether the binary file is reversed to obtain a target code.
[0072] Among them, the binary file is a file that is compiled according to a preset programming language and runs in the native layer of the target application.
[0073] In this embodiment, the binary file is an SO file. Exemplarily, the preset programming language may be a computer programming language such as C / C++, and the SO file generated by compiling the C / C++ program of the NATIVE layer of the application software in the Android phone is a pure binary file.
[0074] For example, reverse engineering refers to reversing an SO file into assembly code. In real life, some malicious application developers will shell and harden SO files, making it more difficult to reversely restore them into assembly code, or even making it difficult to reverse an SO file into assembly code. Some SO files may not be shelled or hardened, in which case you can reverse the SO file to get the assembly code, i.e., the target code.
[0075] S202: If the binary file is reversed to obtain a target code, a first detection result is obtained according to the target code and a preset malicious code.
[0076] The first detection result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0077] In this embodiment, for binary files that can be reversed to obtain the target code, the target code can be directly compared with some existing malicious codes. If they match, it means that the target code is also a malicious code, and the target application is determined to be a malicious program. If they do not match, the target application is determined to be a non-malicious program.
[0078] Exemplarily, in a possible implementation, the target code may be scanned by a preset automated scanning tool to obtain a combined feature of the target code, and then the combined feature is compared with a preset malicious code to obtain a first detection result.
[0079] The preset automated scanning tool may be an existing common code scanning tool, and the target codes obtained by reverse engineering may include N, and each target code may be combined with each other to form a combined feature. For example, two target codes may be combined to form a combined feature, or more than three target codes may be combined to form a combined feature. In the combination process, each target code may be configured in a different order, for example, one target code may be at the head, middle, or tail of the combined feature.
[0080] S203: If the target code cannot be obtained by reversing the binary file, an operation code sequence corresponding to the binary file is obtained.
[0081] In this embodiment, the operation code (OPcode) is a machine code that describes a machine language instruction and specifies an operation to be performed. For example, taking NOP as an instruction, a mobile terminal or a computer or other machine only recognizes the numbers 0 and 1, and the machine does not know the meaning of "NOP". At this time, a hexadecimal number "0x90" is used to replace "NOP". Here, "0x90" is an OPcode, and "NOP" is called a mnemonic.
[0082] Exemplarily, the binary file can be reversed to obtain the ARM instruction set, and the OPcode sequence can be obtained from the ARM instruction set.
[0083] S204: Convert the binary file into a grayscale image, and calculate a second detection result according to a preset machine learning algorithm, the grayscale image, and the operation code sequence.
[0084] The second detection result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0085] Exemplarily, the preset machine learning algorithm can be a random forest algorithm. By using grayscale images and operation code sequences as feature vectors, the random forest algorithm can be used to analyze and detect whether the SO file is a malicious file under threshold setting. If the SO file is a malicious file, the target application is a malicious application; if the SO file is a non-malicious file, the target application is a non-malicious application.
[0086] Exemplarily, the training subset (60% training set and 40% test set) and feature extraction of Python's numpy, pandas, PIL, and scikit-learn libraries can be used to construct a random forest containing 500 decision trees, and an algorithm prompt tool and an algorithm prompt script library can be used to speed up the training of the random forest algorithm. Exemplarily, the algorithm prompt tool can be Xgboost, which is an optimized distributed gradient boosting library designed to be efficient, flexible, and portable. The algorithm prompt script library can be PyPy, which is a dynamic compiler for Python for dynamic compilation.
[0087] Among them, Python is a computer programming language. NumPy, the full name of which is Numerical Python, is an extension library of Python that supports a large number of dimensional arrays and matrix operations, and also provides a large number of mathematical function libraries for array operations. Pandas is a tool based on NumPy that was created to solve data analysis tasks. Pandas incorporates a large number of libraries and some standard data models, and provides the tools needed to efficiently operate large data sets. PIL, the full name of which is Python Image Library, is an image processing toolkit that provides basic image processing functions, such as: resizing, rotating, converting, color field space conversion, image enhancement, histogram processing, interpolation and filtering, etc. Scikit-learn is a free software machine learning library for Python that has various classification, regression and clustering algorithms, including support vector machines, random forests, gradient boosting, etc., and is designed to be used in conjunction with NumPy.
[0088] The embodiment of the present application constructs a grayscale image of the binary file and combines the OpCode sequence, which is the characteristic of the random forest algorithm, to substantially shorten the detection time and more accurately detect whether the target application is a malicious application, thereby improving the detection efficiency of malicious applications.
[0089] In some embodiments, in the above step S204, “converting the binary file into a grayscale image” may be implemented by the following steps:
[0090] Use the preset first function to convert the binary file into a hexadecimal string;
[0091] Perform byte segmentation on the hexadecimal string to obtain the bytes after segmentation, and generate a target matrix according to the preset second function and the bytes after segmentation;
[0092] According to the preset third function, the target matrix is converted into a grayscale image.
[0093] In this embodiment, the preset first function may be a hexlify function, wherein the hexlify function is a data conversion function in Python, and a binary file is used as input, and a hexadecimal string may be converted through the hexlify function.
[0094] For example, taking 00 as the input of the hexlify function, the hexadecimal string obtained by the server after calculating hexlify(00) is 0.
[0095] Exemplarily, the preset second function may be a reshape function, which is used to change the shape of an array or matrix, and the reshape function is used to generate a rectangle according to a set width. Each element in the matrix represents a byte in binary, and the size of the matrix is determined by a specific binary file.
[0096] Exemplarily, the preset third function may be a fromarray function, which may implement conversion from a matrix to an image.
[0097] The embodiment of the present application converts a binary file into a grayscale image because malicious samples often have familial characteristics, which are represented by texture similarity in a grayscale image. Different types of malicious samples are quite different, so it is possible to determine whether a binary file is a malicious file by texture similarity.
[0098] Further, in one embodiment, the "obtaining the operation code sequence corresponding to the binary file" in the above step S203 can be specifically implemented by the following steps:
[0099] Reverse the binary file to get the target instruction set;
[0100] The target instruction set is converted into a sequence of operation codes by a preset computer programming language.
[0101] In this embodiment, the target instruction set may be composed of Arm assembly code. Exemplarily, the ARM assembly code includes various instructions, such as ADD, PUSH, SUB, POP, LDR and the like.
[0102] Exemplarily, the preset computer programming language may be python, and the Opcode sequence finally obtained by using python may be 00000FF8 (the corresponding assembly code is PUSH), 00000FFA (the corresponding assembly code is ADD), and 00001002 (the corresponding assembly code is LDR), etc. Exemplarily, the corresponding meaning of the assembly code LDR is Load register (Word).
[0103] Take the following code as an example:
[0104] Jclass class=(*env)->FindClass(env,“com / zhangning / jnidemo / TestClass”)
[0105] The ARM assembly code corresponding to the above code is as follows:
[0106]
[0107] The embodiment of the present application obtains the target instruction set by reversing the binary file, and then obtains the opcode sequence through Python, which can quickly and accurately obtain the opcode sequence corresponding to the binary file, thereby improving the efficiency of malicious detection of the target application.
[0108] Further, in some embodiments, in the above step S204, “calculating and obtaining the second detection result according to the preset machine learning algorithm, the grayscale image and the operation code sequence” can be specifically implemented by the following steps:
[0109] The operation code sequence is split into multiple subsequences of length N;
[0110] Calculate the frequency of each subsequence in the opcode sequence;
[0111] Determine the weight of each subsequence according to the frequency of each subsequence appearing in the opcode sequence;
[0112] According to the weight of each subsequence, each subsequence is weighted and the feature vector corresponding to the binary file is calculated;
[0113] A second detection result is calculated based on a preset machine learning algorithm, a feature vector corresponding to the binary file, and a grayscale image.
[0114] Wherein, N is a positive integer greater than 1.
[0115] Specifically, the code segment of the SO file is reversed to obtain the Arm instruction set, and the Python code is used to obtain its Opcode sequence. The Opcode sequence is processed according to the subsequence length N. For example, N can be 3, 4, or 5. Then, the term frequency (TF value) of each Opcode sequence of length n is calculated to obtain a vector S = (Δ1, Δ2, ... Δn) composed of the Opcode sequence frequencies. According to the principle that the sum of the frequencies is 1, the frequencies of occurrence of the Opcode sequences are weighted to obtain a feature vector V = (wtf1, wtf2, ... wtf n) composed of the weighted Opcode sequence frequencies.
[0116] In this embodiment, the preset machine learning algorithm can be a random forest algorithm, which can use python's numpy, pandas, PIL, and scikit-learn library training subsets (including 60% training sets and 40% test sets) and feature extraction to construct a random forest containing 500 decision trees, and then input the above-mentioned feature vector and grayscale image into the random forest to output a second detection result.
[0117] The embodiment of the present application splits the operation code sequence corresponding to the binary file, and finally obtains the feature vector corresponding to the binary file, which is input as a feature into the random forest algorithm. It can accurately and quickly detect whether the target application is a malicious application, thereby improving the detection efficiency of malicious applications.
[0118] Further, based on the above embodiment, in some embodiments, if the preset machine learning algorithm is a random forest algorithm, the above step of "calculating the second detection result according to the preset machine learning algorithm, the feature vector corresponding to the binary file and the grayscale image" can be specifically implemented by the following steps:
[0119] Calculate the cosine similarity between the feature vector corresponding to the binary file and m different types of preset malicious sample vectors;
[0120] Perform vector description on the grayscale image to obtain the image vector corresponding to the grayscale image;
[0121] A second detection result is calculated based on the random forest algorithm, the cosine similarity and the image vector corresponding to the grayscale image.
[0122] Wherein, m is a positive integer greater than 1.
[0123] In this embodiment, the grayscale image can be described by using the GIST feature technology of computer vision and a vector of a five-dimensional perception dimension as an image vector. That is, a grayscale image is taken as input, and the GIST feature technology is used to output the corresponding GIST descriptor as an image vector.
[0124] The embodiment of the present application uses the image vector corresponding to the grayscale image as the feature input of the random forest algorithm, so as to accurately and quickly detect whether the target application is a malicious application, thereby improving the detection efficiency of malicious applications.
[0125] In some embodiments, the above malicious application detection method may further include the following steps:
[0126] Use the preset disassembly application to disassemble the binary file and generate a target file containing the assembly code;
[0127] The system calls of the target application are recorded in a target file, and the target application is classified according to the target file in which the system calls are recorded and a preset machine learning algorithm to obtain a classification result.
[0128] The classification result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0129] Using system call sequences as features for machine learning often appears in existing works, because most malware uses a sequence of system calls to exploit vulnerabilities in the system. Some system calls are commonly used in malware.
[0130] In this embodiment, the preset disassembly application can be an interactive disassembler professional tool (Interactive Disassembler Professional, IDA Pro), which can disassemble each binary file into assembly language and generate a gdl file containing assembly code as a target file. System calls are recorded in the output format of the gdl file as input to feed into the machine learning algorithm, and the output file is used to simulate the behavior of binary or native code in malware and non-malicious applications.
[0131] Exemplarily, the preset machine learning algorithm may be a random forest algorithm.
[0132] The embodiment of the present application disassembles the binary file and records the system calls, and detects and classifies the target application according to a preset machine learning algorithm, so as to accurately obtain the classification result and determine whether the target application is a malicious application or a non-malicious application.
[0133] Based on the above embodiments, in some embodiments, the above malicious application detection method may further include the following steps:
[0134] Calculate the hash value corresponding to the binary file;
[0135] Compare the hash value corresponding to the binary file with the preset hash value;
[0136] If the hash value corresponding to the binary file does not match the preset hash value, the binary file is reversed.
[0137] The preset hash value is a hash value corresponding to an initial binary file of the target application. Exemplarily, the preset hash value may be a hash value corresponding to an SO file of the target application when it is first uploaded to the server.
[0138] In this embodiment, the SO file code segment uploaded to the server is detected. First, if the SO file is uploaded to the server for the first time, the server does not have the hash value corresponding to the SO file at this time. The server will first calculate the hash value of the SO file and store it as a preset hash value. If the original SO file of the target application is replaced by a malicious SO file during a subsequent update process, its hash value will change. At this time, the server needs to detect and analyze the SO file again. When the hash value has not changed, the server does not need to perform analysis, thereby improving the detection efficiency of malicious applications.
[0139] In actual applications, in order to evade detection, malicious applications will place SO files containing malicious codes outside the application. After the target application is executed, the non-local external SO file is called through dynamic loading, that is, the external SO file containing the malicious code is loaded and replaced with the original SO file. The embodiment of the present application uses hash values for comparison and establishes a dynamic monitoring method, which can monitor the security of third-party SO files loaded when the target application is running in real time, thereby improving the detection effect of malicious applications.
[0140] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0141] Figure 3 This is a schematic diagram of the structure of a malicious application detection device provided in an embodiment of the present application. The detection device can be integrated on a server, or can be independent of the server and work in collaboration with the server to implement the present solution. Figure 3 As shown, the detection device 30 includes a file determination module 31 , a first detection module 32 , a sequence acquisition module 33 and a second detection module 34 .
[0142] Among them, the file determination module 31 is used to respond to the binary file uploaded by the client, reverse the binary file, and determine whether the binary file is reversed to obtain the target code. The first detection module 32 is used to obtain the first detection result according to the target code and the preset malicious code if the binary file is reversed to obtain the target code. The sequence acquisition module 33 is used to obtain the operation code sequence corresponding to the binary file if the binary file cannot be reversed to obtain the target code. The second detection module 34 is used to convert the binary file into a grayscale image, and calculate the second detection result according to the preset machine learning algorithm, the grayscale image and the operation code sequence.
[0143] Among them, the binary file is a file compiled according to a preset programming language and runs in the native layer of the target application. The first detection result is used to indicate whether the target application is a malicious application or a non-malicious application, and the second detection result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0144] In some embodiments, the second detection module 34 may be specifically used for:
[0145] Use the preset first function to convert the binary file into a hexadecimal string;
[0146] Perform byte segmentation on the hexadecimal string to obtain the bytes after segmentation, and generate a target matrix according to the preset second function and the bytes after segmentation;
[0147] According to the preset third function, the target matrix is converted into a grayscale image.
[0148] In some embodiments, the sequence acquisition module 33 may be specifically used for:
[0149] Reverse the binary file to get the target instruction set;
[0150] The target instruction set is converted into a sequence of operation codes by a preset computer programming language.
[0151] In some embodiments, the second detection module 34 may be specifically used for:
[0152] The operation code sequence is split into multiple subsequences of length N, where N is a positive integer greater than 1;
[0153] Calculate the frequency of each subsequence in the opcode sequence;
[0154] Determine the weight of each subsequence according to the frequency of each subsequence appearing in the opcode sequence;
[0155] According to the weight of each subsequence, each subsequence is weighted and the feature vector corresponding to the binary file is calculated;
[0156] A second detection result is calculated based on a preset machine learning algorithm, a feature vector corresponding to the binary file, and a grayscale image.
[0157] In some embodiments, if the preset machine learning algorithm is a random forest algorithm, the second detection module 34 may be specifically used to:
[0158] Calculate the cosine similarity between the feature vector corresponding to the binary file and m different types of preset malicious sample vectors, where m is a positive integer greater than 1;
[0159] Perform vector description on the grayscale image to obtain the image vector corresponding to the grayscale image;
[0160] A second detection result is calculated based on the random forest algorithm, the cosine similarity and the image vector corresponding to the grayscale image.
[0161] In some embodiments, the first detection module 32 may be specifically used for:
[0162] Scan the target code according to the preset automated scanning tool to obtain the combined features of the target code;
[0163] The combined feature is compared with the preset malicious code to obtain a first detection result.
[0164] In some embodiments, the detection device 30 may further include a system call recording module for:
[0165] Use the preset disassembly application to disassemble the binary file and generate a target file containing the assembly code;
[0166] The system calls of the target application are recorded in a target file, and the target application is classified according to the target file in which the system calls are recorded and a preset machine learning algorithm to obtain a classification result.
[0167] The classification result is used to indicate whether the target application is a malicious application or a non-malicious application.
[0168] In some embodiments, the detection device 30 may further include a comparison module for:
[0169] Calculate the hash value corresponding to the binary file;
[0170] Comparing the hash value corresponding to the binary file with a preset hash value, where the preset hash value is the hash value corresponding to the initial binary file of the target application;
[0171] If the hash value corresponding to the binary file does not match the preset hash value, the binary file is reversed.
[0172] Figure 4 The hardware structure diagram of the server provided in the embodiment of the present application is shown in FIG. Figure 4 As shown, the server 40 includes: at least one processor 41, a memory 42, and a bus 43.
[0173] Wherein: the processor 41 and the memory 42 communicate with each other via a bus.
[0174] The memory 42 is used to store computer-executable instructions. The memory 42 may include a high-speed RAM memory, or may also include a non-volatile memory, such as at least one disk memory.
[0175] The processor 41 is used to execute the computer-executable instructions stored in the memory 42, so that at least one processor executes the above method. Exemplarily, the relevant steps in the method described in the above embodiment can be specifically executed.
[0176] The processor 41 may be a central processing unit, or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiment of the present invention. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0177] This embodiment also provides a readable storage medium, in which computer instructions are stored. When at least one processor of a server executes the computer instructions, the server executes the malicious application detection method provided by the various implementation modes described above.
[0178] This embodiment also provides a program product, which includes computer instructions, which are stored in a readable storage medium. At least one processor of the server can read the computer instructions from the readable storage medium, and at least one processor executes the computer instructions so that the server implements the malicious application detection method provided by the various embodiments described above.
[0179] In the present application, "at least one" means one or more, and "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship; in the formula, the character " / " indicates that the previous and next associated objects are in a "division" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0180] It is to be understood that the various numerical numbers involved in the embodiments of the present application are only for the convenience of description and are not intended to limit the scope of the embodiments of the present application. In the embodiments of the present application, the size of the sequence number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0181] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for detecting malicious applications, characterized in that: Applicable to servers, including: In response to a binary file uploaded by a client, reverse engineering the binary file to determine whether the binary file is reversed to obtain a target code, wherein the binary file is a file compiled according to a preset programming language and runs in a native layer of a target application; If the binary file is reversed to obtain a target code, a first detection result is obtained according to the target code and a preset malicious code, wherein the first detection result is used to indicate whether the target application is a malicious application or a non-malicious application; If the target code cannot be obtained by reversing the binary file, the target instruction set is obtained by reversing the binary file, and the target instruction set is converted into an operation code sequence by using a preset computer programming language, wherein the preset computer programming language is Python; The binary file is converted into a hexadecimal string using a preset first function, the preset first function being a hexlify function; the hexadecimal string is byte-segmented to obtain bytes after segmentation, and a target matrix is generated according to a preset second function and the bytes after segmentation, the preset second function being a reshape function; the target matrix is converted into a grayscale image according to a preset third function, the preset third function being a fromarray function; The operation code sequence is split to obtain a plurality of subsequences of length N, where N is a positive integer greater than 1; the frequency of occurrence of each subsequence in the operation code sequence is calculated; the weight of each subsequence is determined according to the frequency of occurrence of each subsequence in the operation code sequence; each subsequence is weighted according to the weight of each subsequence, and a feature vector corresponding to the binary file is calculated; the cosine similarity between the feature vector corresponding to the binary file and m different types of preset malicious sample vectors is calculated, where m is a positive integer greater than 1; the grayscale image is described by vector to obtain an image vector corresponding to the grayscale image; a second detection result is calculated according to a random forest algorithm, the cosine similarity and the image vector corresponding to the grayscale image, and the second detection result is used to indicate that the target application is a malicious application or a non-malicious application; The obtaining a first detection result according to the target code and the preset malicious code includes: Scanning the target code according to a preset automated scanning tool to obtain a combined feature of the target code; Comparing the combined feature with a preset malicious code to obtain the first detection result; Before reversing the binary file, the method further includes: Calculate and obtain a hash value corresponding to the binary file; Comparing the hash value corresponding to the binary file with a preset hash value, where the preset hash value is the hash value corresponding to the initial binary file of the target application; If the hash value corresponding to the binary file does not match the preset hash value, the binary file is reversed.
2. The method according to claim 1, characterized in that After responding to the binary file uploaded by the client, the method further includes: Using a preset disassembly application, disassemble the binary file to generate a target file containing assembly code; The system calls of the target application are recorded in the target file, and the target application is classified according to the target file recording the system calls and a preset machine learning algorithm to obtain a classification result, wherein the classification result is used to indicate whether the target application is a malicious application or a non-malicious application.
3. A malicious application detection device, characterized in that: include: A file determination module, configured to, in response to a binary file uploaded by a client, reverse the binary file to determine whether the binary file is reversed to obtain a target code, wherein the binary file is a file compiled according to a preset programming language and runs in a native layer of a target application; A first detection module, configured to obtain a first detection result according to the target code and a preset malicious code if the target code is obtained by reverse engineering the binary file, wherein the first detection result is used to indicate whether the target application is a malicious application or a non-malicious application; A sequence acquisition module, for reversing the binary file to obtain a target instruction set if the target code cannot be obtained by reversing the binary file, and converting the target instruction set into an operation code sequence by using a preset computer programming language, wherein the preset computer programming language is Python; The second detection module is used to convert the binary file into a hexadecimal string using a preset first function, the preset first function is a hexlify function; perform byte segmentation on the hexadecimal string to obtain bytes after segmentation, and generate a target matrix according to a preset second function and the bytes after segmentation, the preset second function is a reshape function; according to a preset third function, convert the target matrix into a grayscale image, the preset third function is a fromarray function; The second detection module is further used to split the operation code sequence into multiple subsequences of length N, where N is a positive integer greater than 1; and calculate the frequency of each subsequence appearing in the operation code sequence; Determine the weight of each subsequence according to the frequency of occurrence of each subsequence in the operation code sequence; According to the weight of each subsequence, each subsequence is weighted to calculate the feature vector corresponding to the binary file; the cosine similarity between the feature vector corresponding to the binary file and m different types of preset malicious sample vectors is calculated, where m is a positive integer greater than 1; the grayscale image is described by vector to obtain the image vector corresponding to the grayscale image; according to the random forest algorithm, the cosine similarity and the image vector corresponding to the grayscale image, a second detection result is calculated, where the second detection result is used to indicate that the target application is a malicious application or a non-malicious application; The first detection module is specifically used to scan the target code according to a preset automatic scanning tool to obtain a combination feature of the target code; compare the combination feature with a preset malicious code to obtain the first detection result; A comparison module, used to calculate a hash value corresponding to the binary file; Comparing the hash value corresponding to the binary file with a preset hash value, where the preset hash value is the hash value corresponding to the initial binary file of the target application; If the hash value corresponding to the binary file does not match the preset hash value, the binary file is reversed.
4. A server, characterized in that: comprising a memory and at least one processor; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1-2.
5. A readable storage medium, characterized in that: The readable storage medium stores computer instructions, which are used to implement the method according to any one of claims 1 to 2 when executed by a processor.
