Analysis function imparting method, analysis function imparting device, and analysis function imparting program

The analysis function provision method addresses incomplete behavior analysis of malicious scripts by analyzing script engines' virtual machines, inserting hooks, and using exception handlers to ensure continuous execution, thereby overcoming obfuscation and conditional path challenges.

JP7568131B2Active Publication Date: 2024-10-16NIPPON TELEGRAPH & TELEPHONE CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
JP2023553920
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

Technical Problem

Existing methods for analyzing malicious scripts, such as static and dynamic analysis, are hindered by code obfuscation and conditional execution paths, leading to incomplete behavior analysis and potential interruption due to exceptions during multi-pass execution.

Method used

An analysis function provision method that analyzes a script engine's virtual machine, inserts hooks at specific points, and employs exception handlers to continue execution by skipping the basic block where the exception occurred, using a hook handler to transfer processing to the virtual machine area.

Benefits of technology

Enables comprehensive analysis of malicious scripts by preventing execution stoppages due to exceptions, allowing for the detection and analysis of all execution paths, including those triggered by conditional conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007568131000004
    Figure 0007568131000004
  • Figure 0007568131000005
    Figure 0007568131000005
  • Figure 0007568131000006
    Figure 0007568131000006
Patent Text Reader

Abstract

An analysis function addition device (10) comprises: a virtual machine analysis unit (121) that analyzes a VM of a script engine, and obtains a hook point, which is a point where an analysis code is to be inserted by hooking, and a VPC, which is a variable pointing to the next VM instruction to be executed; an instruction set architecture analysis unit (122) that analyzes an instruction set architecture, which is the instruction system of the VM, and thereby obtains a branch VM instruction, which is a VM instruction that causes branching; and a function addition unit (123) that, on the basis of the VPC and the branch VM instruction, which are architecture information obtained by analysis by the virtual machine analysis unit (121) and the instruction set architecture analysis unit (122), adds an analysis function by hooking that includes processing of, if an exception occurs at the hook point of the script engine, changing the destination to which the VPC points to the beginning of the basic block immediately following the basic block where the exception occurs.
Need to check novelty before this filing date? Find Prior Art

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 even dynamic analysis cannot analyze all of the behavior.

[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 29 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. Summary of the Invention [Problem to be solved by the invention]

[0023] Here, an attacker may intentionally cause an exception to stop the analysis execution and disrupt the analysis. In addition, in multi-path execution using forced path execution, forcing the execution path may cause an exception that would not occur in normal execution to occur, causing the execution to stop. Since the analysis execution stops when an exception occurs, there is a demand for a technology that can continue the analysis execution even when an exception occurs.

[0024] To achieve this, when an exception occurs, it is necessary to forcibly skip the part that caused the exception and continue execution. In this case, the extent to which the part should be skipped (for example, should the currently executing instruction be skipped, should the basic block be skipped, or should the function be skipped) depends on the exception that occurred.

[0025] Therefore, as one of the techniques for preventing execution from being stopped due to an exception, a technique for skipping the basic block that caused the exception and continuing execution is required.

[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 execution stoppage due to an exception by skipping a basic block that causes an exception. [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 including: a first analysis step of analyzing a virtual machine of a script engine and obtaining a hook point, which is a point where analysis code is inserted by applying a hook, and a virtual program counter, which is a variable indicating the next virtual machine instruction to be executed; a second analysis step of analyzing an instruction set architecture, which is a system of virtual machine instructions, and obtaining a branch virtual machine instruction, which is a virtual machine instruction that generates a branch; and an providing step of providing an analysis function by applying a hook to the hook point of the script engine, based on the virtual program counter and the branch virtual machine instruction, which are architectural information obtained by the analysis in the first analysis step and the second analysis step, including a process of changing the destination of the virtual program counter to the beginning of the basic block immediately following the basic block in which the exception occurred, when an exception occurs. Effect of the Invention

[0028] According to the present invention, it is possible to provide a script engine with an execution function that prevents execution from being stopped due to an exception. [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 illustrating 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 VM branch trace construction process. [Figure 13] FIG. 13 is a diagram for explaining the control flow graph construction process. [Figure 14] FIG. 14 is a diagram for explaining the basic block skip processing. [Figure 15] FIG. 15 is a flowchart illustrating a processing procedure of the analysis function providing process according to the embodiment. [Figure 16]FIG. 16 is a flowchart of the execution trace acquisition process shown in FIG. [Figure 17] FIG. 17 is a flowchart showing the procedure of the hook / tap point detection process shown in FIG. [Figure 18] FIG. 18 is a flowchart illustrating the procedure of the VM instruction boundary detection process shown in FIG. [Figure 19] FIG. 19 is a flowchart illustrating the procedure of the virtual program counter detection process shown in FIG. [Figure 20] FIG. 20 is a diagram illustrating the process of the dispatcher detection unit. [Figure 21] FIG. 21 is a flowchart of the VM execution trace acquisition process shown in FIG. [Figure 22] FIG. 22 is a flowchart of the branch VM instruction detection process shown in FIG. [Diagram 23] FIG. 23 is a flowchart showing the procedure of the hook insertion process shown in FIG. [Figure 24] FIG. 24 is a flowchart showing the procedure of the VM branch trace construction process. [Diagram 25] FIG. 25 is a flowchart showing the procedure of the control flow graph construction process. [Figure 26] FIG. 26 is a flowchart showing the procedure of the basic block skip process. [Figure 27] FIG. 27 is a flowchart illustrating the procedure of the exception handler insertion process shown in FIG. [Figure 28] FIG. 28 is a diagram illustrating an example of a computer that realizes the analysis function providing device by executing a program. [Figure 29] FIG. 29 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, and a dispatcher. Note that all of these are components of the script engine, and are information related to the architecture, and are stored in an architecture information DB 132 (described later).

[0034] Furthermore, the analysis function adding device executes the test script to obtain a VM execution trace, and uses the VM execution trace to analyze the instruction set architecture, thereby obtaining a branch VM instruction, which is a VM instruction that causes a branch in the script, as architecture information.

[0035] Then, the analysis function adding device inserts a hook into the hook point of the script engine using a hook handler based on the acquired architecture information. Furthermore, the analysis function adding device inserts an exception handler into the script to be analyzed, and adds an exception handling function. The exception handler has a function of forcibly transferring processing to the VM area when an exception occurs and captures the occurrence of the exception. The hook handler is added with a function of skipping the basic block in which the exception occurred by changing the pointing destination of the VPC to the beginning of the basic block immediately following the basic block in which the exception occurred. As a result, the analysis function adding device transfers processing to the VM area when an exception occurs, and suppresses the stop of execution due to the exception by skipping the basic block in which the exception occurred as instructed by the hook handler.

[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" codes 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 realizes the equivalent of a hypervisor call by hooking the script API ((1) in FIG. 2), and when an exception occurs, it transfers processing to the VM area and skips the basic block instructed by the hook handler where the exception occurred.

[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] [Configuration of the analysis function adding device] Next, 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.

[0040] 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.

[0041] 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 and a script engine binary, 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 a script engine. The script engine binary may be composed of multiple executable files. The analysis target script is a script to be analyzed.

[0042] 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 (second analysis unit), and a function provision unit 123 (provision unit).

[0043] 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 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 / tap point detection unit 1212, a VM instruction boundary detection unit 1213, a virtual program counter detection unit 1214, and a dispatcher detection unit 1215.

[0044] 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.

[0045] 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.

[0046] The hook / 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.

[0047] The hook / tap point detection unit 1212 extracts and analyzes the execution trace stored in the execution trace DB 131 to find candidates for hook points. The hook / 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 / tap point detection unit 1212 detects hook points by applying a backtrace from a system API corresponding to the language element (e.g., a script API) of the analysis target.

[0048] The hook / 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 / 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 / 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.

[0049] The hook / tap point detection unit 1212 detects a tap point by hooking the obtained hook point candidate and searching the memory of the argument of the hooked function. The hook / tap point detection unit 1212 detects a tap point, which is a memory monitoring location that is logged by the analysis code, based on monitoring at the hook point. In addition, the hook / tap point detection unit 1212 determines the hook point candidate having the tap point as a hook point. Please refer to International Publication No. 2020 / 075335 for details of the processing of the hook / tap point detection unit 1212.

[0050] 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.

[0051] 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 detects a VPC by analyzing a plurality of execution traces using differential execution analysis focusing on the number of memory reads and the boundaries of each VM instruction detected by the VM instruction boundary detection unit 1213. 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 destination of this read.

[0052] 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 detected by the VM instruction boundary detection unit 1213, and narrows down the memory values ​​that are read to those that always point to the start points of the VM instructions. The virtual program counter detection unit 1214 detects this memory as a VPC.

[0053] 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.

[0054] 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) and a branch VM instruction detection unit 1222 (first detection unit).

[0055] 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.

[0056] 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.

[0057] 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.

[0058] 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.

[0059] Furthermore, the branch VM instruction detection unit 1222 determines which of the branch VM instructions are conditional branch VM instructions in order to construct an elaborate control flow graph. When a conditional branch occurs, an access to a conditional branch flag is always generated in order to determine the branch destination. Therefore, a conditional branch VM instruction can be determined by verifying whether or not a conditional branch flag is accessed when each branch VM instruction is executed. In other words, when a branch VM instruction is executed, if the conditional branch flag is accessed, it can be determined that the instruction is a conditional branch VM instruction, and if not, it can be determined that the instruction is not a conditional branch VM instruction. Therefore, the branch VM instruction detection unit 1222 determines, based on the VM execution trace and the memory access trace, that among the branch VM instructions, an instruction involving an access to a conditional branch flag is a conditional branch VM instruction.

[0060] Furthermore, the branch VM instruction detection unit 1222 also determines call and return VM instructions. A branch caused by a call VM instruction is characterized in that the address immediately following the caller's bytecode is saved, and after execution of the called subroutine, a return VM instruction is used to return to the saved address. Thus, when a certain branch VM instruction is designated as instruction 1, and another subsequent branch VM instruction is designated as instruction 2, and instruction 2 is used to return to the address immediately following instruction 1's bytecode, the branch VM instruction detection unit 1222 determines that the pair of instruction 1 and instruction 2 are call and return VM instructions.

[0061] The function adding unit 123 inserts a hook into the script engine based on the acquired architecture information, and inserts an exception handler into the script to be analyzed, thereby adding an exception handling function. The function adding unit 123 adds an analysis function by applying a hook including a process of changing the VPC's pointing destination to the beginning of the basic block immediately following the basic block where the exception occurred, to a hook point of the script engine based on the VPC and branch VM instruction, which are architecture information obtained by the analysis by the virtual machine analysis unit 121 and the instruction set architecture analysis unit 122. The function adding unit 123 includes a hook insertion unit 1231 and an exception handler insertion unit 1232.

[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 analysis by the virtual machine analysis unit 121 and the instruction set architecture analysis unit 122. 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 changing the destination pointed to by the VPC in the VM area to the beginning of the basic block immediately following the basic block in which the exception occurred.

[0063] Specifically, the hook insertion unit 1231 adds a VM branch trace construction process (first process), a control flow graph construction process (second process), and a basic block skip process (third process) for skipping a basic block in which an exception has occurred to the hook handler. This adds to the hook a function for changing the VPC's pointing destination to the beginning of the basic block immediately following the basic block in which an exception has occurred, and skipping the basic block in which an exception has occurred. In the VM branch trace construction process, a VM branch trace is constructed in which VPCs before and after the execution of a branch VM instruction are associated. In the control flow graph construction process, a control flow graph is constructed using the VM branch trace, with basic blocks as nodes and branches due to the execution of a branch VM instruction as edges.

[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 and the instruction set architecture analysis unit 122.

[0066] The execution trace DB131 and the VM execution trace DB133 store the execution trace and the VM execution trace acquired by the execution trace acquisition unit 1211 and the VM execution trace acquisition unit 1221, respectively. 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 and the VM execution trace acquisition unit 1221 output the acquired execution trace and the VM execution trace 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 store 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 VPCs. 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] [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.

[0085] 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.

[0086] Here, when a VM instruction is a branch instruction, the advance of the VPC changes depending on the branch destination. On the other hand, when it is not a branch instruction, the advance of the VPC changes 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 advance of the VPC for each opcode, if it is a branch instruction, the advance of the VPC will vary depending on the branch destination.

[0087] 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 change amount of the VPC 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 with variance in the advance of the VPC (VM instruction handler 3 in the example of FIG. 11) as a branch VM instruction while associating the pointer with the VM instruction ((1) in FIG. 11).

[0088] Let O be the set of VPC advances for a certain opcode, O={o 0 ,o 1 ,···,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.

[0089]

number

[0090]

number

[0091]

number

[0092] 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.

[0093] [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.

[0094] Here, the hook insertion unit 1231 inserts an analysis code so that execution transitions to processing of the hook handler in the VM area when the script API corresponding to the hook is executed at the time of hooking. This analysis code can be easily generated if the hook point and the tap point are known. As a result, by calling the hooked script API from the script, the function of the hook handler implemented in the VM area can be called as a hypervisor call, and the provision of the analysis function is realized.

[0095] At this time, the hook insertion unit 1231 adds to the hook handler a VM branch trace construction process that constructs a VM branch trace, a control flow graph construction process that constructs a control flow graph, and a basic block skip process that skips a basic block in which an exception has occurred.

[0096] Fig. 12 is a diagram for explaining the VM branch trace construction process. In the VM branch trace construction process, as shown in Fig. 12, 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. 12). 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.

[0097] 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. 12). 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 branch source VPC "0x555c7e48" of line R41 is associated with the branch source VPC "0x555c82a0" of line R42.

[0098] 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” in line R51 is associated with the VPC “0x555c7514” in line R52 (line R71).

[0099] 13 is a diagram for explaining the control flow graph construction process. In the control flow graph construction process, a control flow graph is constructed in which basic blocks are nodes and each branch of the VM branch trace 43 is an edge, using the VM branch trace 43 constructed in the VM branch trace construction process ((1) in FIG. 13).

[0100] 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.

[0101] 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 13, 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.

[0102] FIG. 14 is a diagram for explaining the basic block skip processing. In the basic block skip processing, the VPC is constantly tracked, and when an exception occurs, it is determined which part of the control flow graph constructed in the control flow graph construction processing corresponds to this exception. Then, in the basic block skip processing, the VPC is changed to the beginning of the basic block immediately following the basic block in which the exception occurred, thereby skipping the basic block in which the exception occurred ((1) in FIG. 14). Specifically, in the example of FIG. 14, the VPC is changed to the beginning node N71 immediately following the node in which the exception occurred. Then, depending on the execution content of node N71, the processing branches to edge E71 or edge E72 and proceeds.

[0103] Therefore, the function adding unit 123 can add an exception skip function to the script to be analyzed by inserting an exception handler into the script to be analyzed and adding a basic block skip process to the hook handler.

[0104] [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. 15 is a flowchart showing the procedure of the analysis function imparting process according to the embodiment.

[0105] First, the input unit 11 receives a test script and a script engine binary as input (step S1).

[0106] 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).

[0107] The hook / 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).

[0108] The VM instruction boundary detection unit 1213 detects VM instructions and performs VM instruction boundary detection processing to detect VM instruction boundaries (step S4). 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 S5).

[0109] 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 similarity between each VM instruction is detected as a dispatcher (step S6).

[0110] The VM execution trace acquisition unit 1221 receives the test script and the script engine binary as input, and executes the test script while monitoring the execution of the script engine binary to perform a VM execution trace acquisition process to acquire a VM execution trace (step S7). 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 S8).

[0111] The hook insertion unit 1231 performs a hook insertion process to insert a hook into the script engine based on the architecture information acquired in the processes of steps S1 to S6 (step S9).Then, the exception handler insertion unit 1232 performs an exception handler insertion process to insert an exception handler into the script to be analyzed and to impart an exception handling function (step S10).Then, the output unit 124 outputs the script engine binary to which the exception skip function has been imparted (step S11).

[0112] [Processing procedure for acquiring execution trace] Next, a description will be given of the flow of the execution trace acquisition process shown in Fig. 15. Fig. 16 is a flowchart showing the processing procedure of the execution trace acquisition process shown in Fig. 15.

[0113] 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).

[0114] 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).

[0115] 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.

[0116] [Hook / tap point detection process procedure] FIG. 17 is a flowchart showing the procedure of the hook / tap point detection process shown in FIG.

[0117] 17, in the hook tap point detection process, the hook tap point detection unit 1212 detects hook point candidates (step S31). If the hook tap point detection unit 1212 detects a hook point candidate (step S32: Yes), the hook 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 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).

[0118] If no hook point candidate is detected (step S34: No), the hook / 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 / tap point detection unit 1212 proceeds to step S35. The hook / tap point detection unit 1212 detects a tap point (step S35).

[0119] [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. 15. Fig. 18 is a flowchart showing the processing procedure of the VM instruction boundary detection process shown in Fig. 15.

[0120] 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.

[0121] 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.

[0122] [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. 15. Fig. 19 is a flowchart showing the processing procedure of the virtual program counter detection process shown in Fig. 15.

[0123] 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).

[0124] 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).

[0125] 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).

[0126] 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).

[0127] 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.

[0128] [Dispatcher detection process procedure] Next, a description will be given of the flow of the dispatcher detection process shown in Fig. 15. Fig. 20 is a flowchart showing the processing procedure of the dispatcher detection process shown in Fig. 15.

[0129] First, the dispatcher detection unit 1215 receives a script engine binary as an input (step S71). The dispatcher detection unit 1215 receives a boundary of a VM instruction from the VM instruction boundary detection unit 1213 (step S72).

[0130] 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 S73). The dispatcher detection unit 1215 calculates the similarity between the codes of each VM instruction by a predetermined method (step S74). The method of calculating the similarity may be any method that can calculate the similarity between codes.

[0131] The dispatcher detection unit 1215 extracts a part having a high similarity among all VM instructions based on the similarity calculated in step S74 (step S75). Then, the dispatcher detection unit 1215 determines whether it is the end part of the VM instruction (step S76).

[0132] If it is not the end of the VM instruction (step S76: No), the dispatcher detection unit 1215 returns to step S75 and continues the process. If it is the end of the VM instruction (step S76: Yes), the dispatcher detection unit 1215 outputs the extracted part as a dispatcher (step S77) and ends the process.

[0133] [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. 15. Fig. 21 is a flowchart showing the processing procedure of the VM execution trace acquisition process shown in Fig. 15.

[0134] First, the VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input (step S81). Then, the VM execution trace acquisition unit 1221 hooks the received script engine to record a VPC and a VM opcode (step S82).

[0135] The VM execution trace acquisition unit 1221 inputs the received test script in this state to the script engine for execution (step S83), and stores the VM execution trace acquired thereby in the VM execution trace DB 133 (step S84).

[0136] The VM execution trace acquisition unit 1221 judges whether or not all the input test scripts have been executed (step S85). If all the input test scripts have been executed (step S85: Yes), the VM execution trace acquisition unit 1221 ends the process. If all the input test scripts have not been executed (step S85: No), the VM execution trace acquisition unit 1221 returns to the execution of the test script in step S83 and continues the process.

[0137] [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. 15. Fig. 22 is a flowchart showing the processing procedure of the branch VM instruction detection process shown in Fig. 15.

[0138] First, the branch VM instruction detection unit 1222 extracts one VM execution trace from the VM execution trace DB 133 (step S91). 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 of them as an identifier (step S92). Then, the branch VM instruction detection unit 1222 counts the amount of change in VPC before and after execution for each VM opcode (step S93).

[0139] 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 S94). If all the VM execution traces in the VM execution trace DB 133 have not been processed (step S94: No), the branch VM instruction detection unit 1222 returns to step S91 and extracts and processes the next VM execution trace.

[0140] If all VM execution traces in the VM execution trace DB 133 have been processed (step S94: Yes), the branch VM instruction detection unit 1222 calculates the variance of the VPC change amount for each VM opcode (step S95). Then, the branch VM instruction detection unit 1222 receives a threshold as an input (step S96). The branch VM instruction detection unit 1222 narrows down to only VM opcodes whose variance is greater than the threshold (step S97), stores them as branch VM instructions in the architecture information DB 132 (step S98), and ends the process.

[0141] [Hook insertion process] Next, a description will be given of the flow of the hook insertion process shown in Fig. 15. Fig. 23 is a flowchart showing the processing procedure of the hook insertion process shown in Fig. 15.

[0142] First, the hook insertion unit 1231 receives as input the hook point and the tap point detected by the hook / tap point detection unit 1212 (step S101), and prepares a hook handler (step S102).

[0143] The hook insertion unit 1231 adds a VM branch trace construction process to the hook handler (step S103). The hook insertion unit 1231 adds a control flow graph construction process to the hook handler (step S104). The hook insertion unit 1231 adds a basic block skip process to the hook handler (step S105). The hook insertion unit 1231 inserts a hook using the hook handler at the hook point (step S106).

[0144] [VM branch trace construction process] 24 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 S111).

[0145] In the VM branch trace construction process, an entry of a VM execution trace is extracted (step S112). In the VM branch trace construction process, it is determined whether a VM opcode exists in a VM branch instruction list (step S113).

[0146] In the VM branch trace construction process, if the VM opcode exists in the VM branch instruction list (step S113: 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 S114).

[0147] In the VM branch trace construction process, if the VM opcode does not exist in the VM branch instruction list (step S113: No), or after step S114 is completed, it is determined whether all entries of the VM execution trace have been processed (step S115).

[0148] In the VM branch trace construction process, if all the entries of the VM execution trace have not been processed (step S115: No), the next entry of the VM execution trace is extracted (step S116). Then, in the VM branch trace construction process, the process returns to step S113 and determines whether the VM opcode of the next entry exists in the VM branch instruction list.

[0149] On the other hand, in the VM branch trace construction process, if all the entries of the VM execution trace have been processed (step S115: Yes), a hook using a hook handler is inserted at the hook point (step S117).

[0150] [Control flow graph construction process] 25 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 S121), an entry of the VM branch trace is extracted (step S122).

[0151] 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 S123). 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 S124). In the control flow graph construction process, it is determined whether all entries of the VM branch trace have been processed (step S125).

[0152] In the control flow graph construction process, if all the entries of the VM branch trace have not been processed (step S125: No), the next entry of the VM execution trace is extracted (step S126). Then, in the control flow graph construction process, the process returns to step S123, and for the next entry, a basic block starting from the branch destination address is added to the control flow graph as a node.

[0153] In the control flow graph construction process, when all entries of the VM branch trace have been processed (step S125: Yes), the constructed control flow graph is output (step S127).

[0154] [Basic block skip processing] 26 is a flowchart showing the procedure of the basic block skip processing. In the basic block skip processing, the control flow graph constructed in the control flow graph construction processing is received as an input (step S131).

[0155] In the basic block skip process, the node currently pointed to by the VPC (when the exception occurred) is confirmed (step S132). In the basic block skip process, the edge is traced from the currently pointed to node, and the next node is extracted (step S133).

[0156] In the basic block skip process, it is determined whether or not there are multiple next nodes (step S134). In the basic block skip process, if there are multiple next nodes (step S134: Yes), one node is selected as the next node, and the other nodes are selected for the next execution (step S135). The selection rule for the next node is preset.

[0157] In the basic block skip process, if there are no multiple next nodes (step S134: No), or after the process of step S135 is completed, the value of the VPC is changed to point to the beginning of the next node (step S136).

[0158] [Exception handler insertion process] A description will be given of the flow of the exception handler insertion process shown in Fig. 15. Fig. 27 is a flowchart showing the processing procedure of the exception handler insertion process shown in Fig. 15.

[0159] The exception handler insertion unit 1232 receives a script to be analyzed as an input (step S141). The exception handler insertion unit 1232 analyzes the script to be analyzed using a predetermined method, and extracts an entry point (step S142).

[0160] The exception handler insertion unit 1232 extracts one entry point (step S143). The exception handler insertion unit 1232 adds an exception handler code (for example, see FIG. 1) so that an exception can be caught in the code after the entry point (step S144).

[0161] The exception handler insertion unit 1232 determines whether or not the exception handler has been added to all the entry points (step S145). If the exception handler has not been added to all the entry points (step S145: No), the exception handler insertion unit 1232 extracts the next entry point (step S146) and proceeds to step S144 to add the code of the exception handler.

[0162] If the exception handlers have been added to all the entry points (step S145: Yes), the exception handler insertion unit 1232 ends the process.

[0163] [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 hook point, 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.

[0164] Then, based on the obtained architecture information, the analysis function-imparting device 10 applies a hook to the hook point of the script engine, which includes a process for changing the VPC's pointing destination to the beginning of the basic block immediately following the basic block where the exception occurred, when an exception occurs, thereby imparting an analysis function including an exception handling function.

[0165] Specifically, the analysis function-imparting device 10 imparts an exception handling function to a script to be analyzed by inserting an exception handler that forcibly transfers processing to a VM area when an exception occurs, in the script to be analyzed. The analysis function-imparting device 10 performs hooking in the VM area using a hook handler that includes a process for changing the VPC's pointing destination to the beginning of the basic block immediately following the basic block in which the exception occurred. In this way, the analysis function-imparting device 10 prevents execution from being stopped due to an exception by skipping the basic block in which the exception occurred.

[0166] As a result, the analysis function-adding device 10 can detect various architectural information by analysis based on the acquisition of execution traces and VM execution traces, even for proprietary script engines for which only binaries are available, and can add exception handling functions without the need for manual reverse engineering.

[0167] Furthermore, the analysis function adding device 10 can automatically add an exception handling function to various script engines as long as a test script is prepared, so that the exception handling function can be added without requiring individual design or implementation.

[0168] As described above, the analysis function-imparting device 10 is useful for analyzing the behavior of malicious scripts written in a wide variety of script languages, and is suitable for analyzing the behavior of malicious scripts whose execution stops due to an exception during the analysis without being affected by the exception. Therefore, by using the analysis function-imparting device 10 to impart an exception handling function to various script engines, it is possible to analyze the behavior of malicious scripts while suppressing the execution from stopping due to the exception even when an exception occurs, and therefore it is possible to utilize this for measures such as detection.

[0169] The analysis function-imparting device 10 can similarly catch exceptions in multi-path execution due to forced execution paths, and continue analysis while preventing unintended stops of execution.

[0170] [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.

[0171] 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.

[0172] 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.

[0173] [program] 28 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.

[0174] 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.

[0175] 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).

[0176] 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.

[0177] 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.

[0178] 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]

[0179] 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 Functionality Department 131 Execution Trace Database (DB) 132 Architecture Information DB 133 VM Execution Trace DB 1211 Execution trace acquisition unit 1212 Hook / tap point detector 1213 VM instruction boundary detection unit 1214 Virtual Program Counter Detector 1215 Dispatcher Detector 1221 VM Execution Trace Acquisition Unit 1222 Branch VM instruction detection unit 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 hook point, which is a point where an analysis code is inserted by hooking, and 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 attaching step of attaching an analysis function by attaching a hook to the hook point of the script engine based on the virtual program counter and the branch virtual machine instruction, which are architecture information obtained by the analyses in the first and second analysis steps, the hook including a process of changing the pointing destination of the virtual program counter to the beginning of the basic block immediately following the basic block in which the exception occurred, when an exception occurs; A method for imparting an analytical function, comprising:

2. The applying step includes: a first insertion step of inserting an exception handler into a script to be analyzed, the exception handler having a function of transferring processing to a virtual machine area when an exception has occurred; a second insertion step of inserting a hook into the hook point of the script engine using a hook handler including a process of changing the destination of the virtual program counter in the virtual machine area to the beginning of a basic block immediately following the basic block in which the exception occurred; 2. The method for providing an analysis function according to claim 1, further comprising:

3. The second analysis step includes: a first acquisition step of acquiring a virtual machine execution trace, which is an execution trace executed in the virtual machine, in which a virtual machine opcode is virtually assigned as an identifier, and a pointer to an executed virtual machine instruction handler and the virtual program counter are recorded; a first detection step of detecting the branch virtual machine instruction based on a variation in a change amount of a virtual program counter for each virtual machine opcode in the virtual machine execution trace; Including, The hook handler: a first process of detecting a branch virtual machine instruction from the virtual machine execution trace by referring to a list of the branch virtual machine instructions detected by the first detection step, and constructing a virtual machine branch trace in which the virtual program counter before and after execution of the detected branch virtual machine instruction are associated with each other; a second process of constructing a control flow graph using the virtual machine branch trace, with the basic blocks as nodes and the branches of the virtual machine branch trace as edges; a third process for determining, when the exception occurs, to which part of the control flow graph the exception corresponds, and changing the pointing destination of the virtual program counter to the beginning of the basic block immediately following the basic block in which the exception occurred; 3. The method for providing an analysis function according to claim 2, further comprising:

4. The first analysis step includes: a second acquisition step of acquiring a plurality of execution traces by changing execution conditions; a second detection step of analyzing the execution trace to detect the hook points; a third detection step of clustering the execution trace to detect boundaries of each virtual machine instruction; a fourth detection step of analyzing the execution traces using a differential execution analysis focusing on the number of memory reads and the boundaries of each virtual machine instruction detected in the third detection step, and detecting the virtual program counter; a fifth detection step of analyzing the binary of the script engine based on the boundaries of each virtual instruction detected in the first detection step, and detecting a dispatcher; 4. The method for providing an analysis function according to claim 3, further comprising:

5. 5. The analytical function providing method according to claim 1, wherein the first analysis step and the second analysis step perform analysis using a test script.

6. a first analysis unit that analyzes a virtual machine of a script engine and obtains a hook point, which is a point where an analysis code is inserted by hooking, and a virtual program counter, which 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 attaches an analysis function by applying a hook to the hook point of the script engine based on the virtual program counter and the branch virtual machine instruction, which are architecture information obtained by the analysis by the first analysis unit and the second analysis unit, the hook including a process of changing the destination of the virtual program counter to the beginning of a basic block immediately following the basic block in which the exception occurred, when an exception occurs; An analysis function-imparting device comprising:

7. a first analysis step of analyzing a virtual machine of a script engine and acquiring a hook point, which is a point where an analysis code is inserted by hooking, and a virtual program counter, which is a variable indicating an instruction of the virtual machine to be executed next; 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 attaching step of attaching an analysis function by attaching a hook including a process of changing a destination of the virtual program counter to the beginning of a basic block immediately following a basic block in which an exception has occurred, to the hook point of the script engine when an exception has occurred, 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; A program that provides analytical functions to enable a computer to execute the above.

Citation Information

Patent Citations

  • 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