Analysis function imparting method, analysis function imparting device, and analysis function imparting program
By imparting an analysis function to the script engine that detects and bypasses stalling or infinite loops, the method ensures continuous and comprehensive analysis of malicious scripts, addressing the limitations of existing dynamic analysis methods.
Patent Information
- Application Number
- JP2023553919
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-10-18
- Publication Date
- 2024-10-16
- Estimated Expiration
- 2041-10-18
AI Technical Summary
Existing dynamic analysis methods for malicious scripts are hindered by stalling loops and infinite loops, which cause delays or stops in analysis, preventing the detection of all execution paths and behaviors, especially when paths are conditionally executed or under specific environmental conditions.
An analysis function is imparted to a script engine that detects and suppresses execution delays or stops by analyzing the virtual machine, identifying and rewriting conditional branches to bypass stalling or infinite loops, using techniques such as hook insertion and exception handling to ensure continuous analysis.
The solution enables continuous analysis of malicious scripts by bypassing stalling and infinite loops, ensuring comprehensive detection of all execution paths without interruption, thereby enhancing the effectiveness of dynamic analysis.
Smart Images

Figure 0007568130000004 
Figure 0007568130000005 
Figure 0007568130000006
Abstract
Description
[Technical field]
[0001] The present invention relates to an analytical function imparting method, an analytical function imparting device, and an analytical function imparting program. [Background technology]
[0002] As various forms of attacks such as spam using malware (malspam) and fileless malware emerge, the threat of attacks using scripts that exhibit malicious behavior (malicious scripts) is becoming more apparent.
[0003] A malicious script is a script that has malicious behavior and is a program that realizes attacks by exploiting the functions provided by a script engine. In general, attacks are carried out using the script engine that is installed by default in the Operating System (OS) or the script engine of a specific application such as a web browser or document file viewer.
[0004] Many of these script engines can also perform system actions such as file operations, network communications, and process launches, although they may require user permission. Therefore, attacks using malicious scripts pose a threat to users in the same way as attacks using malware in executable files.
[0005] In order to take measures against these malicious script attacks, it is necessary to accurately understand the behavior of the scripts. Therefore, there is a demand for technology that can clarify the behavior of scripts by analyzing them.
[0006] One problem that arises when analyzing malicious scripts is code obfuscation. Many malicious scripts are subject to a process called obfuscation, which hinders analysis. Obfuscation intentionally increases the complexity of the code, making it difficult to analyze based on superficial information about the code. In other words, it hampers an analysis method called static analysis, which analyzes the script without executing it, but using information obtained from the code.
[0007] In particular, when a part of the code to be executed is dynamically obtained from outside, that code cannot be statically analyzed because it can only be obtained by executing the code. Therefore, static analysis is impossible in principle.
[0008] On the other hand, a method called dynamic analysis, which executes a script and monitors its behavior to learn its behavior, is not affected by the obfuscation described above. For this reason, methods based on dynamic analysis are mainly used to analyze malicious scripts.
[0009] In general dynamic analysis, a malicious script is executed in an analysis environment and its behavior is monitored, and only the behavior of a single execution path executed in the malicious script is obtained. Therefore, there is a problem that the behavior of paths that were not executed in the analysis environment cannot be obtained.
[0010] In other words, for a malicious script that has a path that is executed only under specific conditions, there is a problem that not all behaviors can be analyzed even by dynamic analysis.
[0011] There may be cases where a path is only executed under certain conditions, for example, when the further execution path is determined by commands from a command server, or when analysis interference prevents malicious behavior from occurring in the analysis environment.
[0012] In the former case, if there is no command from the command server, the execution path is not determined and the path with malicious behavior is not executed. When a malicious script is detected and analyzed, it is often the case that the attacker has already retreated and the command server no longer exists, so in such cases, the malicious behavior cannot be observed.
[0013] The latter is an anti-analysis technique in which a malicious script obtains information about the environment in which it is being executed, and does not exhibit malicious behavior unless certain conditions are met. For example, if a frequently seen characteristic is found in the analysis environment, the script will determine that it is being analyzed and will halt execution.
[0014] Figure 37 shows a code fragment that is an example of anti-analysis. This code fragment has an anti-analysis function that obtains the number of cores of the CPU (Central Processing Unit) of the environment in which it is being executed, and if it is not between 2 and 8, it determines that the environment is likely to be an analysis environment and terminates execution. Otherwise, it determines that the environment is not an analysis environment and displays malicious behavior.
[0015] In order to capture the behavior of a path that is executed only under such specific conditions, multi-pass execution, which executes multiple execution paths, is required.
[0016] In multipath execution, when execution reaches a conditional branch, the execution state branches and each branched execution state follows its own execution path, thereby executing both of the two execution paths that occur at the conditional branch.
[0017] Regarding the realization of multi-pass execution, for example, Non-Patent Document 1 describes a method for realizing symbolic execution, which is a type of multi-pass execution, for JavaScript (registered trademark). With this method, executable paths can be exhaustively traced in conditional branches of JavaScript scripts, and behavior can be observed.
[0018] In addition, Non-Patent Document 2 describes a method for implementing forced path execution, which is a type of multi-path execution, for JavaScript. This method makes it possible to comprehensively trace all paths in conditional branches of JavaScript scripts and observe their behavior.
[0019] Non-Patent Document 3 describes a method for implementing symbolic execution of scripts executed on a script engine through the script engine by manually modifying the script engine in advance and then executing the script engine on a binary symbolic execution platform. According to this method, if there is a script engine that can be manually modified, it is possible to implement symbolic execution generically for any script language, and to comprehensively trace executable paths and observe behavior.
[0020] Non-Patent Document 4 describes a method for analyzing a virtual machine (VM) that malware often uses to obfuscate its own programs. This method makes it possible to obtain information about the architecture by analyzing the VM. Since it is the VM that controls the execution of scripts in a script engine, the concept of this method can be partially diverted.
[0021] In Non-Patent Document 5, a script engine is analyzed, and based on the obtained architecture information, a code that realizes a multi-pass execution function is added, thereby enabling multi-pass execution of scripts. This method makes it possible to realize multi-pass execution for a variety of script languages and engines. [Prior art documents] [Non-patent literature]
[0022] [Non-Patent Document 1] Prateek Saxena, et al, “A Symbolic Execution Framework for JavaScript”, 2010 IEEE Symposium on Security and Privacy. [Non-Patent Document 2] Kyungtae Kim, et al, “J-Force: Forced Execution on JavaScript”. [Non-Patent Document 3] Stefan Bucur, et al, “Prototyping Symbolic Execution Engines for Interpreted Languages”. [Non-Patent Document 4] Monirul Sharif, et al, “Automatic Reverse Engineering of Malware Emulators”, 2009 30th IEEE Symposium on Security and Privacy. [Non-Patent Document 5] Toshinori Usui, Kazuki Furukawa, Hayato Otsuki, Tomonori Ikuyo, Yuhei Kawakoya, Makoto Iwamura, Jun Miyoshi, Kanta Matsuura, “Automatic Addition of Multi-path Execution Function to Script Execution Environments”, Computer Security Symposium 2019 (CSS2019), pp.961-968, 2019. [Non-Patent Document 6] Clemens Kolbitsch et al., “The Power of Procrastination: Detection and Mitigation of Execution-Stalling Malicious Code”, 2011 18th ACM conference on Computer and Communications Security Summary of the Invention [Problem to be solved by the invention]
[0023] Here, an attacker may intentionally use code that contains a long loop that takes a long time to execute, thereby delaying the execution of the analysis and hindering the analysis. This type of code is called stalling code, and causes delays in execution by repeating unnecessary instructions. A typical dynamic malware analysis sandbox analyzes only the behavior observed within a specified time, and such execution delays cause the analysis to end before reaching the behavior that should have been analyzed. Therefore, there is a demand for a technology that can continue the execution of the analysis even when a stalling code loop (stalling loop) exists.
[0024] In addition, in multi-pass execution using forced path execution, the execution path is forced, which can cause an infinite loop that would not occur in normal execution, causing the execution to stop. Since the analysis execution stops when an infinite loop occurs, there is a demand for a technology that can continue the analysis execution even when an infinite loop occurs.
[0025] Here, if a long loop is considered to be a loop that continues for a certain number of times or more, an infinite loop can be said to be an example of a long loop. Therefore, a long loop is considered to be a concept that includes both a stalling loop and an infinite loop. For example, in the following explanation, an "infinite loop" may be replaced with a "long loop" or a "stalling loop" as appropriate.
[0026] The present invention has been made in consideration of the above, and aims to provide an analysis function-imparting method, an analysis function-imparting device, and an analysis function-imparting program that can provide a script engine with an execution function that suppresses delays or stops in execution due to long loops. [Means for solving the problem]
[0027] In order to solve the above-mentioned problems and achieve the object, the analysis function providing method of the present invention is an analysis function providing method executed by an analysis function providing device, and is characterized in that it includes a first analysis step of analyzing the virtual machine of a script engine and acquiring a virtual program counter, which is a variable indicating the next virtual machine instruction to be executed, a second analysis step of analyzing the instruction set architecture, which is the system of virtual machine instructions, and acquiring a branch virtual machine instruction, which is a virtual machine instruction that generates a branch, and an providing step of detecting an instruction sequence that has been repeatedly executed a number of times equal to or greater than a threshold in the script engine based on the virtual program counter and the branch virtual machine instruction, which are architecture information obtained by the analysis in the first analysis step and the second analysis step, and providing the analysis function by applying a hook including a process of stopping execution of the instruction sequence by rewriting the condition related to the conditional branch at the end of the instruction sequence. Effect of the Invention
[0028] According to the present invention, it is possible to provide a script engine with an execution function that suppresses delays or stops in execution due to long loops. [Brief description of the drawings]
[0029] [Figure 1] FIG. 1 is a diagram illustrating an example of an exception handler. [Diagram 2] FIG. 2 is a diagram illustrating an example of a hypervisor call using a hook of a script API. [Diagram 3] FIG. 3 is a diagram illustrating an example of a configuration of an analysis function imparting device according to an embodiment. [Figure 4] FIG. 4 is a diagram showing an example of a test script used for detecting a virtual program counter (VPC). [Diagram 5] FIG. 5 is a diagram showing an example of a test script used for detecting a branch VM instruction. [Figure 6] FIG. 6 is a diagram illustrating an example of an execution trace. [Figure 7] FIG. 7 is a diagram illustrating an example of a VM execution trace. [Figure 8] FIG. 8 is a diagram illustrating the process of the VM instruction boundary detection unit. [Figure 9] FIG. 9 is a diagram illustrating the process of the virtual program counter detection unit. [Figure 10] FIG. 10 is a diagram for explaining the process of the dispatcher detection unit. [Figure 11] FIG. 11 is a diagram for explaining the process of the branch VM instruction detection unit. [Figure 12] FIG. 12 is a diagram illustrating the infinite loop detection process. [Figure 13] FIG. 13 is a diagram illustrating the infinite loop detection process. [Figure 14] FIG. 14 is a diagram illustrating the infinite loop detection process. [Figure 15] FIG. 15 is a diagram illustrating the infinite loop skip process. [Figure 16] FIG. 16 is a diagram illustrating the infinite loop skip process. [Figure 17] FIG. 17 is a diagram illustrating the VM branch trace construction process. [Figure 18] FIG. 18 is a diagram for explaining the control flow graph construction process. [Figure 19] FIG. 19 is a flowchart illustrating a processing procedure of the analysis function providing process according to the embodiment. [Figure 20] FIG. 20 is a flowchart illustrating a processing procedure of the analysis function providing process according to the embodiment. [Figure 21] FIG. 21 is a flowchart illustrating the processing procedure of the execution trace acquisition processing shown in FIGS. [Figure 22] FIG. 22 is a flowchart showing the procedure of the hook / tap point detection process shown in FIGS. [Diagram 23] FIG. 23 is a flowchart illustrating the procedure of the VM instruction boundary detection process shown in FIG. [Figure 24] FIG. 24 is a flowchart showing the processing procedure of the virtual program counter detection processing shown in FIGS. [Diagram 25] FIG. 25 is a flowchart of the conditional branch flag detection process shown in FIG. [Figure 26] FIG. 26 is a flowchart of the dispatcher detection process shown in FIG. [Figure 27] FIG. 27 is a flowchart of the VM execution trace acquisition process shown in FIG. [Figure 28] FIG. 28 is a flowchart of the branch VM instruction detection process shown in FIG. [Figure 29] FIG. 29 is a flowchart showing the procedure of the hook insertion process shown in FIG. [Diagram 30] FIG. 30 is a flowchart showing the procedure of the infinite loop detection process. [Diagram 31] FIG. 31 is a flowchart showing the procedure of the infinite loop skip process. [Diagram 32] FIG. 32 is a flowchart showing the procedure of the hook insertion process shown in FIG. [Diagram 33] FIG. 33 is a flowchart showing the procedure of the VM branch trace construction process. [Diagram 34] FIG. 34 is a flowchart showing the procedure of the control flow graph construction process. [Diagram 35] FIG. 35 is a flowchart showing the procedure of the exception handler insertion process. [Diagram 36] FIG. 36 is a diagram illustrating an example of a computer that realizes the analysis function providing device by executing a program. [Figure 37] FIG. 37 is a diagram showing a code fragment that is an example of anti-analysis. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0030] Hereinafter, an embodiment of an analysis function providing method, an analysis function providing device, and an analysis function providing program according to the present application will be described in detail with reference to the drawings. The present invention is not limited to the embodiment described below.
[0031] [Embodiment Mode] The analysis function adding device according to the embodiment is an analysis function adding device that can be applied to a script engine.
[0032] The analysis function providing device according to this embodiment executes a test script while monitoring the binary of a script engine, and obtains a branch trace and a memory access trace as an execution trace.
[0033] The analysis function providing device then analyzes the virtual machine based on this execution trace, and obtains architecture information such as hook points, tap points, a virtual program counter (VPC) which is a variable indicating the next VM instruction to be executed, VM instruction boundaries, a dispatcher, and conditional branch flags. Note that all of these are components of the script engine, and are information related to the architecture, and are stored in the architecture information DB 132 (described later).
[0034] Furthermore, the analysis function-adding device executes the test script to obtain a VM execution trace, and detects a change amount (offset) of the VPC using the VM execution trace. In this way, the analysis function-adding device obtains the change amount of the VPC as architecture information.
[0035] The analysis function adding device then inserts a hook using a hook handler based on the hook point of the script engine based on the acquired architecture information. Furthermore, the analysis function adding device inserts an exception handler into the script to be analyzed, thereby adding an exception handling function.
[0036] Fig. 1 is a diagram for explaining an example of an exception handler. Fig. 2 is a diagram showing an example of a hypervisor call using a script API hook. As shown in Fig. 1, the analysis function providing device statically adds the contents of the boxes E1 to E3 to the entry point of the script to be analyzed before execution ((1) and (2) in Fig. 1).
[0037] Specifically, as shown in FIG. 1, the analysis function adding device adds "try" and "catch" code to the entry point of the script to be analyzed (boxes E1 and E2), and adds "hooked_script_API(e)" code that hooks the script API when an exception occurs, as in the third line of box E3. As a result, when an exception occurs, the script API is hooked and used as a hypervisor call to skip the exception ((3) in FIG. 1). That is, as shown in FIG. 2, the analysis function adding device skips the instruction, function, basic block, etc. where the exception occurred by hooking the script API ((1) in FIG. 2).
[0038] In this way, the analysis function-adding device captures the exception and inserts an exception handler into the script to be analyzed, forcing execution to proceed beyond the point where the exception occurred, thereby preventing unintended stops in execution and continuing the analysis.
[0039] Furthermore, the analysis function adding device inserts a hook using a hook handler based on the hook point of the script engine based on the acquired architecture information. The hook handler is added with a function of detecting an instruction sequence that has been repeatedly executed a threshold number of times and skipping an instruction sequence in which an infinite loop has occurred by rewriting a condition related to a conditional branch at the end of the instruction sequence to stop the execution of the instruction sequence. As a result, the analysis function adding device transfers processing to the VM area when an infinite loop occurs, and suppresses delay or stop of execution by skipping the instruction sequence in which an infinite loop has occurred as instructed by the hook handler.
[0040] [Configuration of the analysis function adding device] The configuration of the analysis function-imparting device 10 according to the embodiment will be specifically described with reference to Fig. 3. Fig. 3 is a diagram illustrating an example of the configuration of the analysis function-imparting device according to the embodiment.
[0041] 3, the analysis function-imparting device 10 includes an input unit 11, a control unit 12, a storage unit 13, and an output unit 14. The analysis function-imparting device 10 receives inputs of a test script, a script engine binary, and a script to be analyzed.
[0042] The input unit 11 is composed of input devices such as a keyboard and a mouse, and accepts input of information from the outside and inputs it to the control unit 12. The input unit 11 also has a communication interface for transmitting and receiving various information to and from other devices connected via a wired connection or a network, etc., and accepts input of information transmitted from other devices. The input unit 11 accepts input of a test script, a script engine binary, and a script to be analyzed, and outputs it to the control unit 12. The test script is a script that is input when dynamically analyzing a script engine to obtain an execution trace and a VM execution trace. The test script will be described in detail later. The script engine binary is an executable file that constitutes the script engine. The script engine binary may be composed of multiple executable files. The script to be analyzed is a script to be analyzed.
[0043] The control unit 12 has an internal memory for storing programs that define various processing procedures and required data, and executes various processes using these. For example, the control unit 12 is an electronic circuit such as a CPU (Central Processing Unit) or an MPU (Micro Processing Unit). The control unit 12 has a virtual machine analysis unit 121 (first analysis unit), an instruction set architecture analysis unit 122, and an analysis function provision unit 123 (provision unit).
[0044] The virtual machine analysis unit 121 analyzes the VM of the script engine. The virtual machine analysis unit 121 acquires a plurality of execution traces by changing the conditions at the time of execution, analyzes the plurality of execution traces using differential execution analysis, and acquires hook points, tap points, and VPCs. The virtual machine analysis unit 121 also statically analyzes the script engine binary to acquire VM instruction boundaries and dispatchers. The virtual machine analysis unit 121 includes an execution trace acquisition unit 1211, a hook point / tap point detection unit 1212, a VM instruction boundary detection unit 1213, a virtual program counter detection unit 1214, a dispatcher detection unit 1215, and a conditional branch flag detection unit 1216.
[0045] The execution trace acquisition unit 1211 receives a test script and a script engine binary as input. The execution trace acquisition unit 1211 acquires an execution trace by executing the test script while monitoring the execution of the script engine binary.
[0046] The execution trace is composed of a branch trace and a memory access trace. The branch trace records the type of branch instruction at the time of execution, the branch source address, and the branch destination address. The memory access trace records the type of memory operation and the memory address of the operation target. It is known that the branch trace and the memory access trace can be acquired by an instruction hook. The execution trace acquired by the execution trace acquisition unit 1211 is stored in the execution trace DB 131.
[0047] The hook point / tap point detection unit 1212 analyzes the virtual machine based on the execution trace acquired by the execution trace acquisition unit 1211, and detects hook points and tap points. Here, a hook point is a point where a hook is applied and analysis code is inserted. In the embodiment, the unit is a function (called an internal function) that the internal implementation of the script engine has, and a hook is applied to the beginning of this internal function. Also, a tap point is a memory monitoring point that is logged by analysis code, and is one of the arguments of the internal function.
[0048] The hook point / tap point detection unit 1212 extracts and analyzes the execution trace stored in the execution trace DB 131 to find hook point candidates. The hook point / tap point detection unit 1212 searches the execution trace for calls to system APIs related to the analysis target, and detects hook point candidates by backtracing from there. The hook point / tap point detection unit 1212 detects hook points by applying a backtrace from the system API corresponding to the language element of the analysis target.
[0049] The hook point / tap point detection unit 1212 detects hook point candidates by extracting the differences between multiple execution traces obtained under different conditions and finding parts that satisfy specific conditions. The hook point / tap point detection unit 1212 detects hook points based on the differences found between execution traces obtained under multiple different conditions. In this case, the hook point / tap point detection unit 1212 detects hook points using an algorithm (e.g., the Smith-Waterman algorithm) that detects the occurrence of a highly homologous sequence a specific number of times.
[0050] The hook point / tap point detection unit 1212 hooks the obtained hook point candidates and detects tap points by searching the memory of the arguments of the hooked function. The hook point / tap point detection unit 1212 detects tap points, which are memory monitoring points that are logged by the analysis code, based on monitoring at the hook points. In addition, the hook point / tap point detection unit 1212 determines the hook point candidates that have tap points as hook points. Please refer to International Publication No. 2020 / 075335 for details of the processing of the hook point / tap point detection unit 1212.
[0051] The VM instruction boundary detection unit 1213 clusters the execution trace to detect the boundaries of each VM instruction. The VM instruction boundary detection unit 1213 clusters the execution trace to detect clusters with a threshold or more of execution count as VM instructions. In the clustering, consecutive code regions executed multiple times are detected. For example, executed instructions that are close to each other in the code may be grouped together, or a common subsequence of executed code blocks may be found, or other methods may be used. The analysis function providing device 10 detects the start and end points of consecutive instruction sequences that constitute the detected VM instruction as boundaries. The VM instruction boundaries detected here are used in VPC detection and dispatcher detection.
[0052] The virtual program counter detection unit 1214 extracts and analyzes the execution trace for the first test script stored in the execution trace DB 131 to detect a VPC. The virtual program counter detection unit 1214 analyzes a plurality of execution traces using differential execution analysis focusing on the number of memory reads to detect a VPC. The virtual program counter detection unit 1214 utilizes the fact that a read into a memory that holds a VPC always occurs after the execution of each VM instruction, and detects the VPC by discovering the read destination.
[0053] For this reason, the virtual program counter detection unit 1214 uses differential execution analysis focusing on the number of memory reads to detect VPCs. The virtual program counter detection unit 1214 compares execution traces of multiple test scripts acquired using the test scripts, and finds memories whose memory read counts change in proportion to both the increase and decrease of the number of repetitions and the number of repeated statements. The virtual program counter detection unit 1214 then refers to the boundaries of each VM instruction and narrows down the memory values read to those whose values always point to the start points of the VM instructions. The virtual program counter detection unit 1214 detects these memories as VPCs.
[0054] The dispatcher detection unit 1215 extracts each VM instruction portion from the script engine binary based on the boundaries of the VM instructions detected by the VM instruction boundary detection unit 1213, and detects the portion with high similarity between each VM instruction as a dispatcher. As a premise, the dispatcher is realized by referring to a pointer cache and jumping to the pointer of the next VM instruction handler. The dispatchers are distributed and arranged at the rear of each VM instruction handler, and the identity of their codes is generally high. By searching for the code with high identity at the rear of such VM instruction handlers, the analysis function adding device detects the dispatcher by a predetermined method. The detection of the portion with high similarity may use, for example, a sequence alignment algorithm, or other methods.
[0055] The conditional branch flag detection unit 1216 extracts and analyzes the execution trace for the second test script stored in the execution trace DB 131 to find the conditional branch flag. The conditional branch flag detection unit 1216 analyzes multiple execution traces using differential execution analysis focusing on the number of memory reads to detect the conditional branch flag. The conditional branch flag detection unit 1216 executes conditional branches in various patterns, and detects the memory that stores the conditional branch flag by comparing the memory change pattern at that time with the conditional branch pattern in the test script.
[0056] The instruction set architecture analysis unit 122 analyzes an instruction set architecture, which is a system of instructions for a VM. The instruction set architecture analysis unit 122 includes a VM execution trace acquisition unit 1221 (first acquisition unit), a branch VM instruction detection unit 1222 (first detection unit), and a VPC offset detection unit 1223.
[0057] Like the execution trace acquisition unit 1211, the VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input. The VM execution trace acquisition unit 1221 acquires a VM execution trace by monitoring a VPC and a pointer of a VM instruction handler dispatched by a dispatcher. The VM execution trace acquisition unit 1221 acquires a VM execution trace, which is an execution trace executed on a VM, by executing a test script while monitoring the execution of the script engine binary. The VM execution trace acquisition unit 1221 acquires a VM execution trace by executing a large number of test scripts in detecting a branch VM instruction. The VM execution trace acquisition unit 1221 associates a pointer to a VM instruction with the VM instruction, and virtually assigns a VM opcode as an identifier to each of them.
[0058] The VM execution trace is a record of the pointer of the executed VM instruction handler and the VPC. Specifically, the VM execution trace is composed of the VPC and the VM opcode for each executed VM instruction. The VPC can be recorded by monitoring the memory of the VPC detected by the virtual program counter detection unit 1214. The VM opcode is an identifier virtually assigned to each of the pointer to the VM instruction and the VM instruction that are linked to each other. The VM execution trace acquired by the VM execution trace acquisition unit 1221 is stored in the VM execution trace DB 133.
[0059] The branch VM instruction detection unit 1222 extracts and analyzes the VM execution trace stored in the VM execution trace DB 133 to detect a branch VM instruction. The branch VM instruction detection unit 1222 collects the amount of change in VPC before and after execution of each VM opcode assigned as an identifier. If the VM opcode is other than a branch VM instruction, the amount of change in VPC is almost constant. On the other hand, if the VM opcode is a branch VM instruction, the VPC varies depending on the branch destination.
[0060] Therefore, the branch VM instruction detection unit 1222 detects a branch VM instruction based on the variation in the amount of change in the virtual program counter for each VM opcode in the VM execution trace. The branch VM instruction detection unit 1222 focuses on the fact that the magnitude of variation in the VPC value differs between a branch VM instruction and other VM instructions, determines a threshold, and detects an instruction with a larger variation in the VPC value as a branch VM instruction. Specifically, the branch VM instruction detection unit 1222 evaluates the variation in the amount of change in the VPC for each VM opcode by variance, and detects an instruction with a variance equal to or greater than a certain threshold as a branch VM instruction.
[0061] The VPC offset detection unit 1223 extracts the VM execution trace acquired by the VM execution trace acquisition unit and stored in the VM execution trace DB 133, and analyzes the log of the VM execution trace. The VPC offset detection unit 1223 acquires a pair of the opcode of the VM instruction and the amount of change in the VPC before and after the execution of the VM instruction from the VM execution trace. The offset o is calculated by multiplying the value of the VPC before the execution of the VM instruction by p prev , the value after execution is p next Then, o=p next -p prev It is calculated as follows.
[0062] The hook insertion unit 1231 inserts a hook into the script engine. The hook insertion unit 1231 hooks the script engine based on architecture information obtained by the analysis by the virtual machine analysis unit 121. The hook insertion unit 1231 receives hook points and tap points, and inserts hooks into the script engine using a hook handler based on the hook points and tap points to provide an analysis function. The hook handler includes a process of detecting an instruction sequence that has been repeatedly executed a threshold or more, and canceling the execution of the instruction sequence by rewriting a condition related to a conditional branch at the end of the instruction sequence.
[0063] Specifically, the hook insertion unit 1231 adds an infinite loop detection process and an infinite loop skip process to the hook handler, which adds a function to the hook to transfer the process to the VM area when an infinite loop occurs and to skip the instruction sequence instructed by the hook handler in which the infinite loop occurs.
[0064] The exception handler insertion unit 1232 inserts an exception handler into the script to be analyzed, and provides an exception handling function. The exception handler has a function of forcibly transferring processing to a VM area when an exception occurs and is caught. The exception handler insertion unit 1232 analyzes the script to be analyzed, and inserts the exception handler by adding exception handler code (for example, see FIG. 1) to each entry point so that exceptions in the code after the entry point can be caught.
[0065] The storage unit 13 is realized by a semiconductor memory element such as a RAM (Random Access Memory) or a flash memory, or a storage device such as a hard disk or an optical disk, and stores a processing program that operates the analysis function providing device 10, data used during execution of the processing program, etc. The storage unit 13 has an execution trace database (DB) 131, a VM execution trace DB 133, and an architecture information DB 132 that stores architecture information acquired by the virtual machine analysis unit 121.
[0066] The execution trace DB131 and the VM execution trace DB133 store the execution traces acquired by the execution trace acquisition unit 1211 and the VM execution trace acquisition unit 1221. The execution trace DB131 and the VM execution trace DB133 are managed by the analysis function providing device 10. Of course, the execution trace DB131 and the VM execution trace DB133 may be managed by other devices (such as a server). In this case, the execution trace acquisition unit 1211 outputs the acquired execution traces and VM execution traces to a management server or the like of the execution trace DB131 and the VM execution trace DB133 via the communication interface of the output unit 14, and stores them in the execution trace DB131 and the VM execution trace DB133.
[0067] The output unit 14 is, for example, a liquid crystal display or a printer, and outputs various information including information related to the analysis function imparting device 10. The output unit 14 may also be an interface that controls input and output of various data between an external device, and may output various information to an external device.
[0068] [Test script configuration] Let us explain about test scripts. A test script is a script that is input when dynamically analyzing a script engine. This test script focuses on the number of branch instruction executions and memory reads and writes, and is used to capture the difference in the behavior of the script engine that occurs when the test script is executed a different number of times. This test script is prepared before the analysis and is created manually. Creating it requires knowledge of the specifications of the target script language.
[0069] 4 is a diagram showing an example of a test script (first test script) used to detect a virtual program counter (VPC). The first test script uses a repetitive process (line 2). The first test script changes the execution conditions and generates differences by increasing or decreasing the number of repetitions (line 2) and the number of repeated statements (lines 3 to 5) in the test script.
[0070] 5 is a diagram showing an example of a test script (second test script) used for detecting a branch VM instruction. In the second test script, multiple conditional branches are used (lines 4 to 8). In the second test script, the branch conditions are controlled so that the multiple conditional branches are either taken or not taken in a specific order pattern (lines 1 and 5). In the second test script, the number of conditional branches and the order pattern of branch success or failure are changed to generate differences.
[0071] Configure Execution Tracing Next, the execution trace will be explained. Fig. 6 is a diagram showing an example of an execution trace. As mentioned above, an execution trace is composed of a branch trace and a memory access trace. Fig. 6 shows an excerpt of a part of an execution trace. The structure of an execution trace will be explained below with reference to Fig. 6.
[0072] An execution trace has an element called "trace." In "trace," it is indicated whether the log line is a branch trace or a memory access trace.
[0073] A branch trace log line has the format shown in lines 1 to 10 of Figure 6, and consists of three elements: type, src, and dst. type indicates whether the executed branch instruction was a call instruction, a jmp instruction, or a ret instruction. src indicates the address of the branch source, and dst indicates the address of the branch destination.
[0074] A log line of a memory access trace has the format shown in lines 11 to 13 of Figure 6, for example, and consists of three elements: type, target, and value. Type indicates whether the memory access is a read or write. Target indicates the memory address that is the target of the memory access. Value stores the result of the memory access.
[0075] [Configuring VM execution tracing] Next, a VM execution trace will be described. Fig. 7 is a diagram showing an example of a VM execution trace. As described above, a VM execution trace is a record of a VM opcode and a VPC. Fig. 7 shows a part of a VM execution trace. The structure of a VM execution trace will be described below with reference to Fig. 7.
[0076] A log line of a VM execution trace is, for example, in the format shown in Figure 7 and consists of two elements, vpc and vmop (vm opcode). vpc indicates the value of VPC. Also, vmop indicates the value of the VM opcode virtually assigned to each pointer that points to the beginning of the VM instruction handler to be executed, obtained from the pointer cache.
[0077] [VM instruction boundary detection processing] Next, a description will be given of the processing of the VM instruction boundary detection unit 1213. FIG.
[0078] The VM instruction boundary detection unit 1213 detects the boundaries of each VM instruction. At this time, the VM instruction boundary detection unit 1213 detects VM instructions and their boundaries for a threaded code type VM in which it is difficult to grasp the boundaries of VM instructions because it does not have an interpreter loop. Specifically, the VM instruction boundary detection unit 1213 extracts an execution trace from the execution trace DB 131. Then, as shown in FIG. 8, the VM instruction boundary detection unit 1213 clusters the execution trace by a predetermined method, and detects a cluster whose execution count is equal to or greater than a threshold as a VM instruction (for example, VM instruction handlers 1 to 3). The VM instruction boundary detection unit 1213 detects the start point and end point of a continuous instruction sequence constituting a VM instruction as a boundary.
[0079] [Virtual program counter detection processing] Next, the processing of the virtual program counter detection unit 1214 will be described. The virtual program counter detection unit 1214 detects VPC and pointer cache. The detection of the virtual program counter is realized by analyzing the log of the memory access trace of the acquired execution trace. The virtual program counter detection unit 1214 uses differential execution analysis focusing on the number of times memory is read. FIG. 9 is a diagram for explaining the processing of the virtual program counter detection unit 1214.
[0080] The virtual program counter detection unit 1214 extracts one execution trace by the first test script from the execution trace DB 131. The number of times a VPC is read is proportional to the number of repetitions in the test script and the number of statements in the repetitive process. When the number of repetitions is N and the number of repeated statements is M, approximately MN VPCs are read. Therefore, the virtual program counter detection unit 1214 extracts memory that has increased by 4MN and 9MN in the execution trace for the first test script in which N and M have been increased to 2N and 2M, 3N and 3M, respectively. Specifically, as shown in FIG. 9, the virtual program counter detection unit 1214 extracts a memory area that has a monotonically increasing Read / Write for each VM instruction execution ((1) in FIG. 9).
[0081] Then, the virtual program counter detection unit 1214 detects, as a VPC, a memory value that always points to the start point of a VM instruction. Specifically, the virtual program counter detection unit 1214 compares the VPC's pointing destination with the address of the VM instruction handler, and narrows down the memory area to the matching memory area ((2) in FIG. 9).
[0082] [Dispatcher detection processing] Next, a description will be given of the processing of the dispatcher detection unit 1215. The dispatcher detection unit 1215 detects a dispatcher by analyzing the binary of the script engine using a predetermined method. FIG. 10 is a diagram for explaining the processing of the dispatcher detection unit 1215.
[0083] The dispatcher detection unit 1215 detects dispatchers. Based on the boundaries of VM instructions detected by the VM instruction boundary detection unit 1213, the dispatcher detection unit 1215 extracts each VM instruction portion from the script engine binary. Then, based on the assumption that the similarity of dispatcher codes is high ((1) in FIG. 10), the dispatcher detection unit 1215 calculates the similarity between codes of each VM instruction, and detects a portion with high similarity between all VM instructions as a dispatcher. The dispatcher detection unit 1215 can detect a code commonly executed in the latter half of a VM instruction as a dispatcher ((1) in FIG. 10).
[0084] [Conditional branch flag detection processing] Next, a description will be given of the processing of the conditional branch flag detection unit 1216. The conditional branch flag detection unit 1216 detects a conditional branch flag by analyzing memory access.
[0085] The conditional branch flag detection unit 1216 uses the execution trace obtained by using the second test script. The conditional branch flag detection unit 1216 detects the conditional branch flag by analyzing the test script and narrowing down the options in two stages. The conditional branch flag has two states: branching or not branching. It is considered that the conditional branch flag is read a number of times proportional to the number of conditional branches.
[0086] For this reason, the conditional branch flag detection unit 1216 extracts memories that have been read a number of times proportional to the number of conditional branches as a first stage of narrowing down.Then, the conditional branch flag detection unit 1216 extracts memories that alternate between two values at each memory read so that the value corresponds to the conditional branch of the test script as a second stage of narrowing down.
[0087] For example, if the conditional branch flag holds X when a branch is taken and Y when a branch is not taken, the order pattern of conditional branching in the second test script in Fig. 5 is taken, not taken, taken, taken, not taken. Therefore, the conditional branch flag detection unit 1216 extracts memory addresses that alternate between two values, X, Y, X, X, Y. The conditional branch flag detection unit 1216 detects conditional branch flags by repeating this process while changing the number of branchings.
[0088] [Branch VM instruction detection processing] Next, the process of the branch VM instruction detection unit 1222 will be described. The branch VM instruction detection unit 1222 detects a branch VM instruction by analyzing the acquired VM execution trace log. The test script here may be any script that includes a branch VM instruction and includes a branch control syntax. For example, the test script is prepared by collecting it from the Internet or obtaining it from an official document.
[0089] First, the branch VM instruction detection unit 1222 associates a pointer to a VM instruction with a VM instruction for each VM execution trace in the VM execution trace DB 133, and virtually assigns a VM opcode as an identifier to each VM instruction. FIG. 11 is a diagram for explaining the process of the branch VM instruction detection unit 1222.
[0090] Here, when a VM instruction is a branch instruction, the amount of change in VPC varies depending on the branch destination. On the other hand, when it is not a branch instruction, the amount of change in VPC varies depending on the size of the VM instruction. Therefore, when collecting pairs of VM instruction opcodes and pointers to VM instructions and looking at the amount of change in VPC for each opcode, if it is a branch instruction, the amount of change in VPC varies depending on the branch destination.
[0091] Therefore, the branch VM instruction detection unit 1222 uses variance to evaluate the variance of the pointer to this VM instruction. The branch VM instruction detection unit 1222 calculates the variance of the VPC change amount for each VM opcode, and narrows down to only VM opcodes whose calculated variance is greater than a threshold. In this way, the branch VM instruction detection unit 1222 detects a VM instruction (in the example of FIG. 11, VM instruction handler 3) with variance in the VPC change amount as a branch VM instruction while associating the pointer with the VM instruction ((1) of FIG. 11).
[0092] Let O be the set of VPC changes for a certain opcode, O={o0,o1,...,o N} (see equation (1) for the average of VPCo), and t for the threshold, whether or not it is a branch instruction is determined based on the variance s (see equation (2)) as shown in equation (3). In this way, the branch VM instruction detection unit 1222 detects a branch VM instruction.
[0093]
number
[0094]
number
[0095]
number
[0096] In addition, for VM instructions other than branches, there is little variation, and the boundary between branch VM instructions and other VM instructions is often clear. For this reason, the threshold is set to a value that can divide the two groups obtained by plotting the obtained variance value on a number line, for example.
[0097] [Hook insertion part processing] Next, a description will be given of the processing of the hook insertion unit 1231. The hook insertion unit 1231 receives as input the script engine binary and the hook points and tap points detected in the processing up to this point. The hook insertion unit 1231 inserts a hook using a hook handler into the hook point in the script engine.
[0098] Here, the hook insertion unit 1231 inserts an analysis code so that, at the time of hooking, a language element corresponding to the hook is executed and the memory of the tap point as an argument is logged. This analysis code can be easily generated if the hook point and the tap point are known. As a result, when the script is executed, its behavior is logged, and the analysis function is provided. Note that the hook insertion unit 1231 can apply a hook even if a hook point is not detected.
[0099] At this time, the hook insertion unit 1231 adds an infinite loop detection process and an infinite loop skip process to the hook handler.
[0100] 12, 13, and 14 are diagrams for explaining the infinite loop detection process. As shown in Fig. 12, the infinite loop detection process constantly traces the VPC ((1) in Fig. 12). It is also assumed that a threshold is specified in advance for the infinite loop detection process.
[0101] Then, as shown in Fig. 13, the infinite loop detection process detects a sequence of VPCs that are repeatedly executed as a loop ((2) in Fig. 13). For example, the infinite loop detection process detects a loop when the same sequence of VPCs is repeatedly executed two or more times.
[0102] As shown in FIG. 14, the infinite loop detection process counts the number of times a loop is repeated, and if the number of times is equal to or greater than a threshold, detects the loop as an infinite loop ((3) in FIG. 14).
[0103] 15 and 16 are diagrams for explaining the infinite loop skip processing. As shown in Fig. 15, the infinite loop skip processing detects the end of the infinite loop from the trace of the VPC, and executes instructions up to the end ((1) in Fig. 15).
[0104] Then, as shown in Fig. 16, the infinite loop skip process skips the infinite loop by rewriting and executing the conditional branch flag ((2) in Fig. 16). For example, the infinite loop skip process forcibly rewrites the conditional branch flag to a value that means that the loop will not be performed.
[0105] (Control flow graph method) In addition to the infinite loop resolution function including the infinite loop detection process and the infinite loop skip process described above, the hook insertion unit 1231 can provide an infinite loop resolution function using a control flow graph.
[0106] The infinite loop resolution function using a control flow graph constructs a control flow graph, detects an instruction sequence (infinite loop) whose repetition pattern satisfies certain conditions (for example, using a method described in non-patent document 6), and performs infinite loop skip processing on the detected infinite loop.
[0107] Non-Patent Document 6 describes detecting and skipping infinite loops in binary programs for which a control flow graph can be constructed.
[0108] On the other hand, for scripts, it is difficult to construct a control flow graph because it requires analysis of unknown bytecodes. Therefore, it is difficult to apply the method described in Non-Patent Document 6 to scripts.
[0109] In contrast, the method using a control flow graph according to the embodiment differs from the method described in Non-Patent Document 6 in that it is effective for scripts.
[0110] Here, a method for constructing a control flow graph will be described with reference to FIGS.
[0111] At this time, the hook insertion unit 1231 adds a VM branch trace construction process that constructs a VM branch trace, a control flow graph construction process that constructs a control flow graph, an infinite loop detection process that detects infinite loops, and an infinite loop skip process that skips infinite loops to the hook handler.
[0112] Fig. 17 is a diagram for explaining the VM branch trace construction process. In the VM branch trace construction process, as shown in Fig. 17, a branch VM instruction is detected from a VM execution trace 41 that records an opcode of an executed VM instruction and a VPC ((1) in Fig. 17). The branch VM instruction can be recognized by referring to a branch VM instruction list 42 detected by a branch VM instruction detection unit 1222.
[0113] Then, in the VM branch trace construction process, a VM branch trace 43 is constructed that associates the VPCs before and after the execution of the detected branch VM instruction ((2) in FIG. 17). In the VM branch trace construction process, for example, a branch VM instruction "0x1f" is detected from line R41 of the VM execution trace, and a VM branch trace shown in line R61 is constructed based on line R41 and line R42 that follows line R42. That is, in the VM branch trace construction process, the VPC "0x555c7e48" in line R41 is associated with the VPC "0x555c82a0" in line R42.
[0114] Similarly, in the VM branch trace construction process, when a branch VM instruction "0x21" is detected from line R51 of the VM execution trace, based on this line R51 and the next line R52, the VPC "0x555c832c" at the branch source of line R51 is associated with the VPC "0x555c7514" at the branch source of line R52 (line R71).
[0115] 18 is a diagram for explaining the control flow graph construction process. In the control flow graph construction process, a control flow graph is constructed using the VM branch trace 43 constructed in the VM branch trace construction process, with basic blocks as nodes and each branch of the VM branch trace 43 as an edge ((1) in FIG. 18).
[0116] Specifically, in the control flow graph construction process, the branch shown in row R61 of the VM branch trace 43 is defined as edge E61, the basic block from which edge E61 branches is defined as node N61, and the basic block to which edge E61 branches is defined as node N62.
[0117] The branch shown in row R71 of the VM branch trace 43 is designated as edge E71, the subblock from which edge E71 branches is designated as node N71, and the basic block to which edge E71 branches is designated as node N72. In the example of the control flow graph in Figure 18, node N71 has a branch shown by edge E72 in addition to edge E71, and the basic block to which this branch is directed is designated as node N73. In this way, in the control flow graph construction process, a control flow graph is constructed in which the branches of basic blocks are expressed in a graph structure based on the VM branch trace.
[0118] [Processing procedure of the analysis function adding device] Next, there will be described the procedure of the analysis function imparting process performed by the analysis function imparting device 10. Fig. 19 is a flowchart showing the procedure of the analysis function imparting process according to the embodiment.
[0119] First, the input unit 11 receives a test script and a script engine binary as input (step S1).
[0120] Then, the execution trace acquisition unit 1211 executes the test script while monitoring the binary of the script engine, thereby performing an execution trace acquisition process to acquire a branch trace and a memory access trace (step S2).
[0121] The hook point / tap point detection unit 1212 analyzes the virtual machine based on the execution trace acquired by the execution trace acquisition unit 1211, and performs hook / tap point detection processing to detect hook points and tap points (step S3).
[0122] The virtual program counter detection unit 1214 extracts and analyzes the execution trace for the first test script stored in the execution trace DB 131, and performs a virtual program counter detection process to discover a VPC (step S4).
[0123] The conditional branch flag detection unit 1216 extracts and analyzes the execution trace for the test script stored in the execution trace DB 131, and performs a conditional branch detection process to discover a conditional branch flag (step S5).
[0124] The hook insertion unit 1231 performs a hook insertion process for inserting a hook into the script engine based on the architecture information acquired in the processes of steps S1 to S5 (step S6).
[0125] Then, the output unit 124 outputs the script engine binary to which the infinite loop removal function has been added (step S7).
[0126] In addition, a processing procedure of the analysis function imparting process by the analysis function imparting device 10 in the case of imparting an infinite loop resolution function using a control flow graph will be described with reference to Fig. 20. Fig. 20 is a flowchart showing the processing procedure of the analysis function imparting process according to the embodiment.
[0127] First, the input unit 11 receives a test script and a script engine binary as input (step S11).
[0128] Then, the execution trace acquisition unit 1211 executes the test script while monitoring the binary of the script engine, thereby performing an execution trace acquisition process to acquire a branch trace and a memory access trace (step S12).
[0129] The hook point / tap point detection unit 1212 analyzes the virtual machine based on the execution trace acquired by the execution trace acquisition unit 1211, and performs hook / tap point detection processing to detect hook points and tap points (step S13).
[0130] The VM instruction boundary detection unit 1213 detects VM instructions and performs VM instruction boundary detection processing to detect VM instruction boundaries (step S14). The virtual program counter detection unit 1214 performs virtual program counter detection processing to extract and analyze the execution trace for the first test script stored in the execution trace DB 131 and discover the VPC (step S15).
[0131] The dispatcher detection unit 1215 performs a dispatcher detection process in which each VM instruction portion is extracted from the script engine binary, and a portion having a high degree of similarity between the VM instructions is detected as a dispatcher (step S16).
[0132] The VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input, and executes the test script while monitoring the execution of the script engine binary, thereby performing a VM execution trace acquisition process to acquire a VM execution trace (step S17).
[0133] The branch VM instruction detection unit 1222 extracts and analyzes the VM execution trace stored in the VM execution trace DB 133, and performs a branch VM instruction detection process to detect a branch VM instruction (step S18).
[0134] The hook insertion unit 1231 performs a hook insertion process for inserting a hook into the script engine based on the architecture information acquired in the processes of steps S11 to S18 (step S19).
[0135] Then, the output unit 14 outputs the script engine binary to which the infinite loop removal function has been added (step S20).
[0136] [Processing procedure for acquiring execution trace] Next, a description will be given of the flow of the execution trace acquisition process shown in Fig. 19 and Fig. 20. Fig. 21 is a flowchart showing the processing procedure of the execution trace acquisition process shown in Fig. 19 and Fig. 20.
[0137] First, the execution trace acquisition unit 1211 receives a test script and a script engine binary as input (step S21). Then, the execution trace acquisition unit 1211 hooks the received script engine to acquire a branch trace (step S22). The execution trace acquisition unit 1211 also hooks the received script engine to acquire a memory access trace (step S23).
[0138] Then, the execution trace acquisition unit 1211 inputs the test script received in this state to the script engine for execution (step S24), and stores the execution trace acquired thereby in the execution trace DB 131 (step S25).
[0139] The execution trace acquisition unit 1211 judges whether or not all the input test scripts have been executed (step S26). If all the input test scripts have been executed (step S26: Yes), the execution trace acquisition unit 1211 ends the process. On the other hand, if all the input test scripts have not been executed (step S26: No), the execution trace acquisition unit 1211 returns to the execution of the test scripts in step S24 and continues the process.
[0140] [Hook / tap point detection process procedure] FIG. 22 is a flowchart showing the procedure of the hook / tap point detection process shown in FIGS.
[0141] 22, in the hook / tap point detection process, the hook point / tap point detection unit 1212 detects hook point candidates (step S31). If the hook point / tap point detection unit 1212 detects a hook point candidate (step S32: Yes), the hook point / tap point detection unit 1212 proceeds to step S35. On the other hand, if the hook point candidate is not detected (step S32: No), the hook point / tap point detection unit 1212 performs a differential execution analysis process to detect hook points based on differences observed between execution traces under multiple different conditions (step S33).
[0142] If no hook point candidate is detected (step S34: No), the hook point / tap point detection unit 1210 ends the process since there is no hook point candidate. On the other hand, if a hook point candidate is detected (step S34: Yes), the hook point / tap point detection unit 1212 proceeds to step S35. The hook point / tap point detection unit 1212 detects a tap point (step S35).
[0143] [VM instruction boundary detection process procedure] Next, a description will be given of the flow of the VM instruction boundary detection process shown in Fig. 20. Fig. 23 is a flowchart showing the processing procedure of the VM instruction boundary detection process shown in Fig. 20.
[0144] First, the VM instruction boundary detection unit 1213 extracts the execution trace from the execution trace DB 131 (step S41). The VM instruction boundary detection unit 1213 clusters the execution trace using a predetermined method (step S42). Any method may be used for the clustering.
[0145] The VM instruction boundary detection unit 1213 detects a cluster whose execution count is equal to or greater than a threshold as a VM instruction (step S43).Then, the VM instruction boundary detection unit 1213 sets the start point and end point of a continuous instruction sequence that constitutes a VM instruction as a boundary (step S44).The VM instruction boundary detection unit 1213 outputs the VM instruction boundary as a return value (step S45), and ends the VM instruction boundary detection process.
[0146] [Procedure for detecting virtual program counter] Next, a description will be given of the flow of the virtual program counter detection process shown in Fig. 19 and Fig. 20. Fig. 24 is a flowchart showing the processing procedure of the virtual program counter detection process shown in Fig. 19 and Fig. 20.
[0147] First, the virtual program counter detection unit 1214 extracts one execution trace by the first test script from the execution trace DB 131 (step S51). Next, the virtual program counter detection unit 1214 focuses on memory access traces among the execution traces, and counts up the number of reads for each memory read destination (step S52).
[0148] The virtual program counter detection unit 1214 receives as input the first test script used to obtain the execution trace (step S53), and analyzes the first test script to obtain the number of repetitions and the number of repeated statements (step S54).
[0149] Next, the virtual program counter detection unit 1214 extracts another execution trace by the first test script having a different number of repetitions and number of repeated statements from the execution trace DB 131 (step S55).The virtual program counter detection unit 1214 then focuses on the memory access trace and counts up the number of reads for each memory read destination (step S56).The virtual program counter detection unit 1214 also receives as input the first test script used to obtain the execution trace (step S57), analyzes the test script, and obtains the number of repetitions and the number of repeated statements (step S58).
[0150] Here, the virtual program counter detection unit 1214 narrows down the memory read destinations to only those whose read counts change in proportion to the increase or decrease in the number of repetitions or repeated statements (step S59). Furthermore, the virtual program counter detection unit 1214 narrows down the memory read destinations narrowed down in step S59 to those whose read memory values always point to the start point of the VM instruction (step S60).
[0151] Then, the virtual program counter detection unit 1214 judges whether the memory read destinations have been narrowed down to only one (step S61). If the virtual program counter detection unit 1214 has not narrowed down the memory read destinations to only one (step S61: No), the process returns to step S55, and the virtual program counter detection unit 1214 extracts the next execution trace and continues the process. On the other hand, if the virtual program counter detection unit 1214 has narrowed down the memory read destinations to only one (step S61: Yes), the virtual program counter detection unit 1214 stores the narrowed down memory read destination in the architecture information DB 132 as a virtual program counter (step S62), and ends the process.
[0152] [Conditional branch flag detection process procedure] Next, a description will be given of the flow of the conditional branch flag detection process shown in Fig. 19. Fig. 25 is a flowchart showing the processing procedure of the conditional branch flag detection process shown in Fig. 19.
[0153] First, the conditional branch flag detection unit 1216 extracts one execution trace by the second test script using multiple conditional branches from the execution trace DB 131 (step S71). Then, the conditional branch flag detection unit 1216 focuses on the memory access trace and counts up the number of reads for each memory read destination (step S72).
[0154] The conditional branch flag detection unit 1216 also receives as input the second test script used to acquire the execution trace (step S73), analyzes the second test script, and acquires the number of conditional branches and the True / False order pattern (step S74).The conditional branch flag detection unit 1216 then narrows down the memory read destinations to only those whose read counts change in proportion to the number of conditional branches (step S75).The conditional branch flag detection unit 1216 further narrows down the memory read destinations to only those whose read memory values alternate between two values in accordance with the True / False order pattern (step S76).
[0155] The conditional branch flag detection unit 1216 determines whether the memory read destinations have been narrowed down to only one (step S77). If the conditional branch flag detection unit 1216 has not narrowed down the memory read destinations to only one (step S77: No), the unit returns to step S71, extracts the next execution trace, and continues the process. On the other hand, if the conditional branch flag detection unit 1216 has narrowed down the memory read destinations to only one (step S77: Yes), the unit stores the narrowed down read destination in the architecture information DB 132 as a virtual program counter (step S78), and ends the process.
[0156] [Dispatcher detection process procedure] Next, a description will be given of the flow of the dispatcher detection process shown in Fig. 20. Fig. 26 is a flowchart showing the processing procedure of the dispatcher detection process shown in Fig. 20.
[0157] First, the dispatcher detection unit 1215 receives a script engine binary as an input (step S81). The dispatcher detection unit 1215 receives a boundary of a VM instruction from the VM instruction boundary detection unit 1213 (step S82).
[0158] The dispatcher detection unit 1215 extracts each VM instruction portion from the script engine binary based on the boundaries of the VM instructions received from the VM instruction boundary detection unit 1213 (step S83). The dispatcher detection unit 1215 calculates the similarity between the codes of each VM instruction by a predetermined method (step S84). The method of calculating the similarity may be any method that can calculate the similarity between codes.
[0159] The dispatcher detection unit 1215 extracts a part having a high similarity among all VM instructions based on the similarity calculated in step S84 (step S85). Then, the dispatcher detection unit 1215 determines whether it is the end part of the VM instruction (step S86).
[0160] If it is not the end of the VM instruction (step S86: No), the dispatcher detection unit 1215 returns to step S85 and continues the process. If it is the end of the VM instruction (step S86: Yes), the dispatcher detection unit 1215 outputs the extracted part as a dispatcher (step S87) and ends the process.
[0161] [VM execution trace acquisition process procedure] Next, a description will be given of the flow of the VM execution trace acquisition process shown in Fig. 20. Fig. 27 is a flowchart showing the processing procedure of the VM execution trace acquisition process shown in Fig. 20.
[0162] First, the VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input (step S91). Then, the VM execution trace acquisition unit 1221 hooks the received script engine to record a VPC and a VM opcode (step S92).
[0163] The VM execution trace acquisition unit 1221 inputs the received test script in this state to the script engine for execution (step S93), and stores the VM execution trace acquired thereby in the VM execution trace DB 133 (step S94).
[0164] The VM execution trace acquisition unit 1221 judges whether or not all the input test scripts have been executed (step S95). If all the input test scripts have been executed (step S95: Yes), the VM execution trace acquisition unit 1221 ends the process. If all the input test scripts have not been executed (step S95: No), the VM execution trace acquisition unit 1221 returns to the execution of the test script in step S93 and continues the process.
[0165] [Branch VM instruction detection process procedure] Next, a description will be given of the flow of the branch VM instruction detection process shown in Fig. 20. Fig. 28 is a flowchart showing the processing procedure of the branch VM instruction detection process shown in Fig. 20.
[0166] First, the branch VM instruction detection unit 1222 extracts one VM execution trace from the VM execution trace DB 133 (step S101). The branch VM instruction detection unit 1222 associates a pointer to the VM instruction with the VM instruction and assigns a VM opcode to each as an identifier (step S102). Then, the branch VM instruction detection unit 1222 counts the amount of change in VPC before and after execution for each VM opcode (step S103).
[0167] The branch VM instruction detection unit 1222 judges whether or not all the VM execution traces in the VM execution trace DB 133 have been processed (step S104). If all the VM execution traces in the VM execution trace DB 133 have not been processed (step S104: No), the branch VM instruction detection unit 1222 returns to step S101 and extracts and processes the next VM execution trace.
[0168] If all VM execution traces in the VM execution trace DB 133 have been processed (step S104: Yes), the branch VM instruction detection unit 1222 calculates the variance of the VPC change amount for each VM opcode (step S105). Then, the branch VM instruction detection unit 1222 receives a threshold as an input (step S106). The branch VM instruction detection unit 1222 narrows down to only VM opcodes whose variance is greater than the threshold (step S107), stores them as branch VM instructions in the architecture information DB 132 (step S108), and ends the process.
[0169] [Hook insertion process] Next, a description will be given of the flow of the hook insertion process shown in Fig. 19. Fig. 29 is a flowchart showing the processing procedure of the hook insertion process shown in Fig. 19.
[0170] First, the hook insertion unit 1231 receives as input the hook point and tap point detected by the hook point / tap point detection unit 1212 (step S111), and prepares a hook handler (step S112).
[0171] The hook insertion unit 1231 adds a VPC trace process to the hook handler (step S113). The hook insertion unit 1231 adds an infinite loop detection process to the hook handler (step S114). The hook insertion unit 1231 adds an infinite loop skip process to the hook handler (step S115). The hook insertion unit 1231 inserts a hook using the hook handler at the hook point (step S116).
[0172] 30 is a flowchart showing the procedure of the infinite loop detection process. First, the infinite loop detection process receives as input a threshold value of the number of loops for determining an infinite loop (step S121). The threshold value may be specified by the user.
[0173] Next, the infinite loop detection process monitors consecutive VPC values and detects a repeatedly executed instruction sequence as a loop (step S122), and then counts the number of times the loop is repeated (step S123).
[0174] If the number of loops does not exceed the threshold for determining an infinite loop (step S124: No), the infinite loop detection process returns to step S122 and the process is repeated.
[0175] On the other hand, if the number of loops exceeds the threshold for determining an infinite loop (step S124: Yes), the infinite loop detection process transitions to an infinite loop skip process (step S125).
[0176] 31 is a flowchart showing the procedure of the infinite loop skip process. First, the infinite loop skip process receives a VPC and a conditional branch flag as input (step S131).
[0177] Next, the infinite loop skip process detects the value of the VPC that is the end of the loop from the repeatedly executed instruction sequence (step S132).
[0178] The infinite loop skip process then executes up to the conditional branch instruction at the end of the loop (step S133). Furthermore, the infinite loop skip process rewrites the conditional branch flag (step S134) and executes the conditional branch instruction at the end of the loop (step S135).
[0179] For example, consider a case where, in a sequence of instructions that is repeated unless a branch is taken, the value of the conditional branch flag is Y, indicating that the branch is not taken.
[0180] In this case, the infinite loop skip process forcibly rewrites the value of the conditional branch flag to X, which indicates that a branch is taken, in step S134. As a result, it is determined that a branch is taken in the conditional branch instruction at the end, and the repetition of the instruction sequence, i.e., the infinite loop, is skipped.
[0181] Fig. 32 is a flowchart showing the procedure of the hook insertion process shown in Fig. 20. First, the hook insertion unit 1231 receives as input the hook point and tap point detected by the hook point / tap point detection unit 1212 (step S141), and prepares a hook handler (step S142).
[0182] The hook insertion unit 1231 adds a VM branch trace construction process to the hook handler (step S143). The hook insertion unit 1231 adds a control flow graph construction process to the hook handler (step S144). The hook insertion unit 1231 adds an infinite loop resolution function to the hook handler (step S145). The hook insertion unit 1231 inserts a hook using the hook handler at the hook point (step S146).
[0183] [VM branch trace construction process] 33 is a flowchart showing the procedure of the VM branch trace construction process. In the VM branch trace construction process, a VM execution trace and a VM branch instruction list are received as inputs (step S151).
[0184] In the VM branch trace construction process, an entry of the VM execution trace is extracted (step S152). In the VM branch trace construction process, it is determined whether the VM opcode exists in the VM branch instruction list (step S153).
[0185] In the VM branch trace construction process, if the VM opcode exists in the VM branch instruction list (step S153: Yes), the VPC is set as the branch source, and the VPC of the next entry is saved as the branch destination in the VM branch trace (step S154).
[0186] In the VM branch trace construction process, if the VM opcode does not exist in the VM branch instruction list (step S153: No), or after step S154 is completed, it is determined whether all the entries of the VM execution trace have been processed (step S155).
[0187] In the VM branch trace construction process, if all the entries of the VM execution trace have not been processed (step S155: No), the next entry of the VM execution trace is extracted (step S156). Then, in the VM branch trace construction process, the process returns to step S153 and determines whether the VM opcode of the next entry exists in the VM branch instruction list.
[0188] On the other hand, in the VM branch trace construction process, if all the entries of the VM execution trace have been processed (step S155: Yes), the VM branch trace is output (step S157).
[0189] [Control flow graph construction process] 34 is a flowchart showing the procedure of the control flow graph construction process. In the control flow graph construction process, when a VM branch trace is received as an input (step S161), an entry of the VM branch trace is extracted (step S162).
[0190] In the control flow graph construction process, a basic block starting from a branch destination address is added as a node to the control flow graph (step S163). In the control flow graph construction process, an edge from the branch source address to the branch destination address is added to the control flow graph (step S164). In the control flow graph construction process, it is determined whether all entries of the VM branch trace have been processed (step S165).
[0191] In the control flow graph construction process, if all the entries of the VM branch trace have not been processed (step S165: No), the next entry of the VM execution trace is extracted (step S166). Then, in the control flow graph construction process, the process returns to step S163, and for the next entry, a basic block starting from the branch destination address is added to the control flow graph as a node.
[0192] In the control flow graph construction process, when all entries of the VM branch trace have been processed (step S165: Yes), the constructed control flow graph is output (step S167).
[0193] [Exception handler insertion process] The flow of the exception handler insertion process will be described. Fig. 35 is a flowchart showing the procedure of the exception handler insertion process. Note that the exception handler insertion process is not included in either Fig. 19 or Fig. 20.
[0194] The exception handler insertion unit 1232 receives a script to be analyzed as an input (step S171). The exception handler insertion unit 1232 analyzes the script to be analyzed using a predetermined method, and extracts an entry point (step S172).
[0195] The exception handler insertion unit 1232 extracts one entry point (step S173). The exception handler insertion unit 1232 adds an exception handler code (for example, see FIG. 1) so that an exception in the code after the entry point can be caught (step S174).
[0196] The exception handler insertion unit 1232 determines whether or not the exception handler has been added to all the entry points (step S175). If the exception handler has not been added to all the entry points (step S175: No), the exception handler insertion unit 1232 extracts the next entry point (step S176) and proceeds to step S174 to add the code of the exception handler.
[0197] If the exception handlers have been added to all the entry points (step S175: Yes), the exception handler insertion unit 1232 ends the process.
[0198] In the embodiment, the infinite loop resolution function can be provided by using a part of the functional unit shown in Fig. 3. In particular, the analysis function providing device 10 in the embodiment may not include the VPC offset detection unit 1223 and the exception handler insertion unit 1232.
[0199] [Effects of the embodiment] In this way, the analysis function adding device 10 according to the embodiment executes the test script while monitoring the binary of the script engine, and acquires the branch trace and the memory access trace as the execution trace. The analysis function adding device 10 analyzes the virtual machine based on the execution trace, and acquires architecture information of the tap point, the VPC, the VM instruction boundary, and the dispatcher. Furthermore, the analysis function adding device 10 executes the test script to acquire the VM execution trace, and analyzes the instruction set architecture using the VM execution trace to acquire the branch VM instruction as the architecture information.
[0200] Then, based on the obtained architecture information, the analysis function-imparting device 10 detects an instruction sequence that has been repeatedly executed a threshold number of times or more in the script engine, and applies a hook to the script engine that includes a process of stopping execution of the instruction sequence by rewriting the condition related to the conditional branch at the end of the instruction sequence, thereby imparting an analysis function including an infinite loop resolution function.
[0201] In addition, the analysis function adding device 10 can automatically add an infinite loop resolution function to a variety of script engines as long as a test script is prepared, so that the infinite loop resolution function can be added without the need for individual design or execution.
[0202] As described above, the analysis function-imparting device 10 is useful for analyzing the behavior of malicious scripts written in a wide variety of scripting languages, and is suitable for analyzing the behavior of malicious scripts that use infinite loops to cause delays or stops in execution without being affected by them. Therefore, by using the analysis function-imparting device 10 to impart an infinite loop resolution function to various script engines, it is possible to analyze the behavior of malicious scripts while suppressing delays or stops in execution caused by infinite loops, and this can be used for measures such as detection.
[0203] The analysis function providing device 10 can similarly capture infinite loops in multi-pass execution due to forced execution paths, and continue analysis while preventing unintended delays or stops in execution.
[0204] [System configuration of the embodiment] Each component of the analysis function-imparting device 10 shown in Fig. 3 is a functional concept, and does not necessarily have to be physically configured as shown in the figure. In other words, the specific form of distribution and integration of the functions of the analysis function-imparting device 10 is not limited to that shown in the figure, and all or part of it can be functionally or physically distributed or integrated in any unit depending on various loads, usage conditions, etc.
[0205] Further, all or any part of each process performed in the analysis function-imparting device 10 may be realized by a CPU and a program analyzed and executed by the CPU. Further, each process performed in the analysis function-imparting device 10 may be realized as hardware using wired logic.
[0206] Furthermore, among the processes described in the embodiments, all or part of the processes described as being performed automatically can be performed manually. Alternatively, all or part of the processes described as being performed manually can be performed automatically by a known method. In addition, the process procedures, control procedures, specific names, and information including various data and parameters described above and shown in the drawings can be changed as appropriate unless otherwise specified.
[0207] [program] 36 is a diagram showing an example of a computer in which a program is executed to realize the analytical function-imparting device 10. The computer 1000 has, for example, a memory 1010 and a CPU 1020. The computer 1000 also has a hard disk drive interface 1030, a disk drive interface 1040, a serial port interface 1050, a video adapter 1060, and a network interface 1070. These components are connected by a bus 1080.
[0208] The memory 1010 includes a ROM 1011 and a RAM 1012. The ROM 1011 stores a boot program such as a BIOS (Basic Input Output System). The hard disk drive interface 1030 is connected to a hard disk drive 1090. The disk drive interface 1040 is connected to a disk drive 1100. A removable storage medium such as a magnetic disk or an optical disk is inserted into the disk drive 1100. The serial port interface 1050 is connected to a mouse 1110 and a keyboard 1120, for example. The video adapter 1060 is connected to a display 1130, for example.
[0209] The hard disk drive 1090 stores, for example, an OS 1091, an application program 1092, a program module 1093, and program data 1094. That is, a program that defines each process of the analysis function-imparting device 10 is implemented as a program module 1093 in which code executable by the computer 1000 is written. The program module 1093 is stored, for example, in the hard disk drive 1090. For example, a program module 1093 for executing the same process as the functional configuration in the analysis function-imparting device 10 is stored in the hard disk drive 1090. The hard disk drive 1090 may be replaced by an SSD (Solid State Drive).
[0210] Furthermore, setting data used in the processing of the above-described embodiment is stored as program data 1094, for example, in memory 1010 or hard disk drive 1090. Then, CPU 1020 reads out program module 1093 or program data 1094 stored in memory 1010 or hard disk drive 1090 into RAM 1012 as necessary, and executes the program.
[0211] Note that the program module 1093 and the program data 1094 are not limited to being stored in the hard disk drive 1090, but may be stored in, for example, a removable storage medium and read by the CPU 1020 via the disk drive 1100 or the like. Alternatively, the program module 1093 and the program data 1094 may be stored in another computer connected via a network (such as a local area network (LAN) or wide area network (WAN)). The program module 1093 and the program data 1094 may then be read by the CPU 1020 from the other computer via the network interface 1070.
[0212] Although the embodiment of the invention made by the present inventor has been described above, the present invention is not limited by the description and drawings which form a part of the disclosure of the present invention according to the present embodiment. In other words, other embodiments, examples, operation techniques, etc. made by those skilled in the art based on the present embodiment are all included in the scope of the present invention. [Explanation of symbols]
[0213] 10. Analysis function providing device 11 Input section 12 Control section 13 Storage section 14 Output section 121 Virtual Machine Analysis Department 122 Instruction Set Architecture Analysis Department 123 Analysis Function Addition Department 131 Execution Trace DB 132 Architecture Information DB 133 VM Execution Trace DB 1211 Execution trace acquisition unit 1212 Hook point / tap point detector 1213 VM instruction boundary detection unit 1214 Virtual Program Counter Detector 1215 Dispatcher Detector 1216 Conditional Branch Flag Detection Unit 1221 VM Execution Trace Acquisition Unit 1222 Branch VM instruction detection unit 1223 VPC offset detector 1231 Hook insertion part 1232 Exception Handler Insertion
Claims
1. An analysis function imparting method executed by an analysis function imparting device, a first analysis step of analyzing a virtual machine of a script engine and acquiring a virtual program counter, which is a variable indicating a next command of the virtual machine to be executed, and a conditional branch flag, which is an area for holding a flag indicating whether or not a branch is to be taken at the time of a conditional branch in an execution state; an adding step of adding an analysis function to the script engine by applying a hook including a process of detecting an instruction sequence that has been repeatedly executed a number of times equal to or greater than a threshold based on the virtual program counter and the conditional branch flag, which are architecture information obtained by the analysis in the first analysis step, and stopping execution of the instruction sequence by rewriting a condition related to a conditional branch at the end of the instruction sequence; A method for imparting an analytical function, comprising:
2. 2. The method for providing an analysis function according to claim 1, wherein the providing step provides the analysis function by applying a hook including a process for detecting a sequence of identical VPCs that have been repeatedly executed two or more times as the instruction sequence.
3. An analysis function imparting method executed by an analysis function imparting device, a first analysis step of analyzing a virtual machine of a script engine and obtaining a virtual program counter, which is a variable indicating a next instruction of the virtual machine to be executed; a second analysis step of analyzing an instruction set architecture, which is an instruction system of the virtual machine, to obtain a branch virtual machine instruction, which is a virtual machine instruction that causes a branch; an adding step of constructing a virtual machine branch trace in the script engine based on the virtual program counter, which is architecture information obtained by the analysis in the first analysis step, associating the virtual program counter before and after execution of a branch virtual machine instruction, detecting an instruction sequence whose repetition pattern satisfies a predetermined condition, and adding an analysis function by applying a hook including a process of stopping execution of the instruction sequence by rewriting a condition related to a conditional branch at the end of the instruction sequence; A method for imparting an analytical function, comprising:
4. 4. The method according to claim 1, wherein the first analysis step performs an analysis using a test script.
5. a first analysis unit that analyzes a virtual machine of a script engine and acquires a virtual program counter, which is a variable indicating a next command of the virtual machine to be executed, and a conditional branch flag, which is an area for retaining a flag indicating whether or not a branch is to be taken at the time of a conditional branch in an execution state; an attachment unit that provides an analysis function by applying a hook to the script engine based on the virtual program counter and the conditional branch flag, which are architecture information obtained by the analysis by the first analysis unit, to detect an instruction sequence that has been repeatedly executed a number of times equal to or greater than a threshold, and to abort execution of the instruction sequence by rewriting a condition related to a conditional branch at the end of the instruction sequence; An analysis function-imparting device comprising:
6. a first analysis unit that analyzes a virtual machine of a script engine and obtains a virtual program counter that is a variable indicating a next instruction of the virtual machine to be executed; a second analysis unit that analyzes an instruction set architecture, which is an instruction system of the virtual machine, to obtain a branch virtual machine instruction, which is a virtual machine instruction that causes a branch; an attachment unit that constructs a virtual machine branch trace in the script engine, in which the virtual program counter before and after execution of a branch virtual machine instruction are associated with each other, based on the virtual program counter that is architecture information obtained by the analysis by the first analysis unit, detects an instruction sequence whose repetition pattern satisfies a predetermined condition, and attaches an analysis function by applying a hook including a process of halting execution of the instruction sequence by rewriting a condition related to a conditional branch at the end of the instruction sequence; An analysis function-imparting device comprising:
7. An analysis function-imparting program for causing a computer to function as the analysis function-imparting device according to claim 5 or 6.
Citation Information
Patent Citations
Detecting malware concealed by delay loops of software programs
EP3543883A1
Analysis function imparting device, analysis function imparting method, and analysis function imparting program
WO2020075335A1
Analysis function addition device, analysis function addition method, and analysis function addition program
WO2021070393A1
