Detection device, detection method, and detection program
The detection device addresses the limitations of conventional methods by using a database of linked hash values and common keyword analysis to efficiently detect and accurately determine software dependencies, improving the identification of implicit dependencies in software.
Patent Information
- Application Number
- PCT/JP2023/008193
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-03
- Publication Date
- 2024-09-12
AI Technical Summary
Conventional methods for detecting implicit dependencies in software, such as CENTRIS, fail to accurately identify software with implicit dependency relationships due to issues like modified source code causing hash value mismatches and false positive detections, leading to missed detections and incorrect dependency determinations.
A detection device and method that divides software source code into code blocks, calculates hash values, and generates a database linking these values to detect implicit dependencies by using a distance index database to efficiently search for similar code blocks and exclude false positives through common keyword analysis.
The solution effectively reduces missed detections and false positives by efficiently searching for similar code blocks and accurately determining dependency relationships, enhancing the precision of identifying software with implicit dependencies.
Smart Images

Figure JP2023008193_12092024_PF_FP
Abstract
Description
Detection device, detection method, and detection program
[0001] The present invention relates to a detection device, a detection method, and a detection program.
[0002] Software is used not only in IT systems, but also in controlling machines that affect human life, such as automobiles and aircraft, and critical infrastructure such as electricity and water, which are essential to daily life. To accommodate a wide range of applications and requirements, the functionality required of software is increasing, and its complexity is also growing. During the software development lifecycle, various relationships arise that affect the behavior of the software. There are explicit and implicit relationships that affect the behavior of software.
[0003] An explicit relationship is one in which the relationship to the software is clearly defined in information. Examples of explicit relationships include relationships in which the author is clearly stated, and relationships in which other software or libraries used are clearly stated in the package information. Explicit relationships make it possible to instantly determine whether or not a problem will affect users if a problem occurs with the software they use, increasing the likelihood that damage can be minimized.
[0004] On the other hand, an implicit relationship is one in which the relationship with the software is not explicitly defined. Examples of implicit relationships include relationships in which the software author is unknown, relationships in which software or libraries are used but this is not explicitly stated, and relationships in which the software author, etc. is listed but cannot be identified by others. In the case of an implicit relationship, even if a problem occurs in the software, the user does not know whether it has affected them. As a result, users may continue the relationship without realizing the existence of a security risk, which may delay the investigation of the cause of the software problem and exacerbate the damage.
[0005] For these reasons, reducing implicit relationships and making them explicit is crucial to preventing the spread of damage. In other words, in a society where software is distributed transparently, it is important that the original software is safe and reliable. For example, if open source software is incorporated into new software, and the open source software contains a virus, if the virus is implicitly associated with the software, the resulting software could have a negative impact and cause widespread damage. In contrast, when libraries are incorporated into software using #import, it is clear which libraries are included, and if there is a problem with the library, users can immediately become aware of the impact.
[0006] Among the relationships that affect the operation of software, the usage relationship between software and source code is called a dependency relationship. For example, Bash (Bourne Again Shell), the standard terminal provided by GNU, uses libc (Linux (registered trademark) C Library), a standard library for the C language, and ncurses (new curses), a library for manipulating the cursor and screen. Therefore, Bash depends on libc and ncurses.
[0007] Dependency relationships can be classified into explicit and implicit relationships; a dependency relationship that is both explicit and implicit is called an explicit dependency, and a dependency relationship that is both implicit and explicit is called an implicit dependency. An explicit dependency is a dependency that is written in software package information. An example of an explicit dependency is the relationship between software and items such as Depends and Build-Depends in a deb package. An implicit dependency is a dependency that does not appear explicitly. An example of an implicit dependency is a relationship in which the index software and the detection target software contain matching code clones, and the detection target software depends on the index software.
[0008] When software has implicit dependencies, the software can have a negative effect on the original software without users noticing the problems, which can lead to greater damage. For example, if library code or functions are directly copied into the source code, the relationship with the library is not clear, and users will not be able to notice if there is a problem with the other library.
[0009] To avoid the above-mentioned problems, there have been techniques for detecting implicit dependencies in advance. For example, there is a tool called CENTRIS that detects information about target software that has an implicit dependency relationship with a software from a candidate software that contains a code clone that matches the code clone of the software (see, for example, Patent Document 1).
[0010] An example of processing by conventional technology such as CENTRIS will be described below with reference to Fig. 8. Fig. 8 is a diagram for explaining an example of processing by conventional technology.
[0011] First, CENTRIS indexes the source code of the index software. Specifically, as shown in FIG. 8 , CENTRIS divides the source code of the software into multiple code blocks (code block units), such as code block F1, code block F2, ..., code block Fn. CENTRIS may divide the source block into multiple functions instead of multiple code blocks. CENTRIS generates a locality sensitive hash (LSH) for each code block, such as code block F1, code block F2, ..., code block Fn. Next, CENTRIS associates hash values, such as hash value LSH1, hash value LSH2, ..., hash value LSHn, indicated by each LSH with the name and version of the software and registers them in a database.
[0012] Next, CENTRIS separates the unique source code from the detection candidate software. Specifically, as shown in Figure 8, CENTRIS detects the unique source code of the detection candidate software by excluding in advance from the source code of the detection candidate software those parts that have a nested dependency structure that could cause false detections. In this way, CENTRIS detects source code that has a nested dependency structure with the detection candidate software, reducing the risk of incorrectly detecting dependencies that are caused by not understanding the nested structure and therefore not correctly determining the dependency relationship between the indicator software and the detection candidate software.
[0013] Next, as shown in Fig. 8, CENTRIS divides the unique source code included in the software of the detection candidate into multiple code blocks such as code block F1x, code block F2x, ..., code block Fnx, similar to the source code of the software of the indicator. Then, CENTRIS generates an LSH for each code block such as code block F1x, code block F2x, ..., code block Fnx.
[0014] Next, as shown in Figure 8, CENTRIS compares the hash values indicated by each LSH, such as hash value LSH1x, hash value LSH2x, ..., hash value LSHnx, etc., with the hash values stored in the database, such as hash value LSH1, hash value LSH2, ..., hash value LSHn, etc. If these hash values match, CENTRIS determines that the code blocks corresponding to these hash values are similar. If the number of similar code blocks is equal to or greater than a predetermined percentage Θ, CENTRIS detects the detection candidate software as detection target software that has an implicit dependency relationship with the indicator software.
[0015] Seunghoon Woo, Sunghan Park, Seulbae Kim, Heejo Lee, and Hakjoo Oh. CENTRIS : A Precise and Scalable Approach for Identifying Modified Open-Source Software Reuse. In ICSE, 2021
[0016] However, conventional techniques for detecting implicit dependencies such as the above-mentioned CENTRIS may not be able to reduce the number of missed detections of software that is implicitly dependent on the software being detected. An example of a problem with the conventional technique will be described below with reference to FIG. 9. FIG. 9 is a diagram for explaining an example of a problem with the conventional technique.
[0017] For example, as shown in the diagram of missed detections in FIG. 9 , conventional technology simply determines whether hash value LSH1 and hash value LSH1X match, and if they match, determines that the code blocks corresponding to these hash values are similar. Even if the source code is slightly altered, the hash value LSH1X corresponding to that code block will become a different hash value LSH1X'. Therefore, conventional technology cannot determine that a code block corresponding to hash value LSH1X', which does not completely match hash value LSH1, is similar to the code block corresponding to hash value LSH1. In other words, when source code is altered, conventional technology cannot detect that the code blocks are similar to each other, which can lead to missed detection of software that is implicitly dependent on the software being detected.
[0018] In order to solve the above-mentioned problems and achieve the objectives, the detection device is characterized by having a division unit that divides the source code of software into multiple code blocks, a calculation unit that calculates a hash value for each of the multiple code blocks divided by the division unit, a generation unit that generates a database in which the hash values for each of the multiple code blocks calculated by the calculation unit are linked to values based on the hash values, and a detection unit that detects information about software to be detected that has a dependency relationship with the software based on the database generated by the generation unit.
[0019] According to the present invention, it is possible to reduce the number of missed detections of software that is an object of detection and has an implicit dependency relationship with the software.
[0020] FIG. 1 is a diagram showing an example of the configuration of a detection system. FIG. 2 is a diagram for explaining an overview of a server. FIG. 3 is a diagram for explaining an overview of a server. FIG. 4 is a diagram showing an example of a database. FIG. 5 is a flow diagram showing an example of the flow of a database generation process. FIG. 6 is a flow diagram showing an example of the flow of a detection process for a detection target. FIG. 7 is a diagram showing an example of the configuration of a computer that executes a detection program. FIG. 8 is a diagram for explaining an example of processing according to conventional technology. FIG. 9 is a diagram for explaining an example of a problem with conventional technology.
[0021] DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings. In the following embodiments, the same elements are designated by the same reference numerals, and redundant description may be omitted.
[0022] [Example of Detection System Configuration] An example of the configuration of a detection system 1 according to this embodiment will be described using Fig. 1. Fig. 1 is a diagram showing an example of the configuration of a detection system. The detection system 1 divides software source code into a plurality of code blocks, calculates a hash value for each of the plurality of code blocks, generates a database in which the hash values of each of the plurality of code blocks are linked to values based on the hash values, and detects information about software to be detected that has a dependency relationship with the software based on the database.
[0023] Dependencies refer to relationships that affect the behavior of software, particularly usage relationships between software and source code. Examples of dependencies include code clones that match between the indicator software and the detection target software, and implicit dependencies in which the detection target software depends on the indicator software. Information about the detection target software refers to values that are similar to the hash values of multiple code blocks in the software's source code, and the detection target software that has these similar values.
[0024] In the example shown in FIG. 1, the detection system 1 includes a client 20 and a server 10 that functions as a detection device, but instead of these, the detection system 1 may include the following components of the server 10 and only have a client 20 that functions as a detection device.
[0025] [Example of Client Configuration] The client 20 transmits input software information to the server 10. An example of the client 20 is a terminal. In the example shown in FIG. 1 , the client 20 has an input unit 21, a control unit 22, a communication unit 23, and a storage unit 24. The software information refers to information about various software such as indicator software, detection target software detected by the server 10, and detection candidate software that is a candidate for the software. The software information also includes information about a group of software registered in the software database DB2 by the server 10.
[0026] The input unit 21 is used by a user to input information related to the software. Examples of the input unit 21 include a keyboard and a touch panel of a terminal.
[0027] The control unit 22 controls the entire client 20. For example, the control unit 22 is configured with one or more processors having an internal memory in which programs defining various processing procedures and control data are stored. The processor executes each process using the programs and internal memory. Examples of the control unit 22 include electron diffraction devices such as a central processing unit (CPU), a micro processing unit (MPU), and a graphics processing unit (GPU), as well as integrated circuits such as an application specific integrated circuit (ASIC) and a field programmable gate array (FPGA).
[0028] The communication unit 23 transmits information related to the software to the server 10. For example, the communication unit 23 transmits the information related to the software to the communication unit 11 of the server 10 via a telecommunications line such as a local area network (LAN) or the Internet. An example of the communication unit 23 is a network interface card (NIC).
[0029] The storage unit 24 stores various information such as information related to software input to the input unit 21. Examples of the storage unit 24 include storage devices such as HDDs (Hard Disk Drives), SSDs (Solid State Drives), and optical disks, as well as data-rewritable semiconductor memories such as RAMs (Random Access Memory), flash memories, and NVSRAMs (Non Volatile Static Random Access Memory). The storage unit 24 stores an OS (Operating System) and various programs executed by the client 20.
[0030] [Example of Server Configuration] The server 10 functions as a detection device that divides software source code into multiple code blocks, calculates a hash value for each of the multiple code blocks, generates a database in which the hash values of each of the multiple code blocks are linked to values based on the hash values, and detects information about software that is a detection target and has a dependency relationship with the software, based on the database. Below, problems with the conventional technology will be explained using Figures 2 and 9, and then an overview of the server 10 will be explained using Figures 2 and 3. Figures 2 and 3 are diagrams for explaining an overview of the detection device.
[0031] 9, in the prior art, it was determined simply whether the hash values LSH1 and LSH1X matched each other, and if they matched, it was determined that the code blocks corresponding to these hash values were similar. Therefore, in the prior art, when source code was altered, it was not possible to detect that the code blocks were similar to each other, which could lead to a detection miss for software that was implicitly dependent on the software being detected.
[0032] 2, when the hash value LSH includes hash values LSH1, LSH2, and LSH3, and the hash value LSH' includes hash values LSH1', LSH2', and LSH3', the conventional technology compares these hash values in a brute-force manner. For example, the conventional technology compares whether the hash values LSH1, LSH2, and LSH3 match the hash values LSH1', LSH2', and LSH3', respectively. As a result, the conventional technology sometimes cannot efficiently search for software to be detected that has code blocks similar to code blocks of source code.
[0033] Furthermore, conventional techniques have sometimes erroneously detected software that is the target of detection. For example, in the example of a false detection shown in FIG. 9 , software A includes software C, and software B includes software C, and the relationship between software A and software C and the relationship between software B and software C are N:1 dependency relationships. Furthermore, in the example shown in FIG. 9 , software C is not registered in the database. In this case, conventional techniques may erroneously detect that software A depends on software B, or that software B depends on software A. As such, conventional techniques may erroneously detect that multiple pieces of software include code clones of the same software or source code, and therefore have an implicit dependency relationship with each other.
[0034] In response to this, the server 10 adds an algorithm to the conventional technology that detects information about target software that has a dependency relationship with the software by using a database in which the hash values of multiple code blocks are linked to values based on the hash values. This allows the server 10 to solve the problem of reducing missed detections and detect target software that has an implicit dependency relationship with the indicator software with high accuracy. Furthermore, the server 10 may also add an algorithm to the conventional technology that detects candidate software as target software when the code clone path does not contain a common keyword. By adding these two algorithms to the server 10, the server 10 can further reduce false positives.
[0035] For example, to address the problem of missed detection, the server 10 searches for software to be detected using a distance index database DB1 that has been generated in advance for each hash value of a plurality of code blocks, as shown in Fig. 2. The distance index database DB1 is a database that associates each hash value of a plurality of code blocks in the software with a value based on the hash value.
[0036] Here, a value based on a hash value refers to a value obtained by converting a hash value using a predetermined algorithm, such as a value formed by combining parts of a code sequence represented as the hash value. Therefore, an example of the distance index database DB1 is a database in which the hash values of multiple code blocks in the index software are linked to the respective values formed by combining parts of the code sequence represented as the hash values.
[0037] The server 10 uses the distance index database DB1 to search for values whose Hamming distance between each of the hash values LSH1, LSH2, and LSH3 and each value formed by combining portions of the code strings represented as these hash values is less than a predetermined value. The Hamming distance is a distance that represents the number of locations where codes differ at the same position in the code string represented as a hash value. This allows the server 10 to significantly reduce the Hamming distance calculation process and the detection candidate software, and efficiently search for values similar to the hash values of the code blocks of the indicator software. In other words, the server 10 can search for code blocks similar to the code blocks of the indicator software. As a result, the server 10 can efficiently search for detection target software that has code blocks similar to code blocks of the source code.
[0038] 3, for false detection, the server 10 determines whether software A and detection candidate software B contain common keywords in paths such as directory names and file names of software C, which is a code clone that matches these software. Based on this determination, the server 10 determines whether to detect detection candidate software B as software to be detected. In other words, the server 10 determines whether detection candidate software B has a dependency relationship with software A, or whether it has a dependency relationship with another software.
[0039] More specifically, the server 10 generates keywords from the directory name and file name of the code clone software C, and determines whether software A, the source of the code clone, and software B, the destination of the code clone, contain common keywords. If software A and software B contain common keywords, the server 10 determines that there is no dependency between these software programs and excludes software B from the list of dependency candidates. In this case, the server 10 infers, for example, that the common keyword is the path name of software C, which is not included in software A and software B registered in the software database DB2 and is in a different dependency relationship (a new dependency).
[0040] Next, the configuration of the server 10 will be described with reference to Fig. 1. In the example shown in Fig. 1, the server 10 includes a communication unit 11, an input receiving unit 12, a control unit 13, an output unit 14, and a storage unit 15.
[0041] The communication unit 11 receives information about software from the client 20. For example, the communication unit 11 receives information about software from the client 20 via a telecommunications line such as a LAN or the Internet. An example of the communication unit 11 is a NIC.
[0042] The input receiving unit 12 receives input of information relating to software input to the input unit 21 of the client 20 via the communication unit 11 and the communication unit 23 of the client 20 .
[0043] The control unit 13 controls the entire server 10. For example, the control unit 13 is configured with one or more processors having an internal memory in which programs defining various processing procedures and control data are stored, and the processor executes each process using the programs and the internal memory. Examples of the control unit 13 include electron diffraction devices such as a CPU, MPU, and GPU, as well as integrated circuits such as an ASIC and FPGA. In the example shown in FIG. 1 , the control unit 13 has a division unit 131, a calculation unit 132, a generation unit 133, and a detection unit 134.
[0044] The dividing unit 131 divides the source code of the software. In the example shown in FIG.
[0045] The indexing unit 1311 divides the software source code into a plurality of code blocks. That is, the indexing unit 1311 divides the software source code into code block units. The source code to be divided is not particularly limited as long as the software source code is indexed. For example, the indexing unit 1311 may divide the software source code into a plurality of functions, i.e., into function units, instead of into a plurality of code blocks.
[0046] The code dividing unit 1312 divides unique source code from software such as detection candidate software. For example, the code dividing unit 1312 detects the unique source code of the detection candidate software by excluding in advance parts of the source code of the detection candidate software that have a nested dependency structure that may cause false detection. In this way, the code dividing unit 1312 detects source code that has a nested dependency structure with the detection candidate software, reducing the possibility of incorrect dependency detection due to an inability to grasp the nested structure and an incorrect determination of the dependency relationship between the software and the detection candidate software.
[0047] The calculation unit 132 calculates a hash value for each of the multiple code blocks divided by the division unit 131. For example, the calculation unit 132 generates a locality sensitive hash (LSH) for each of the multiple code blocks and calculates a hash value for each LSH.
[0048] The generation unit 133 generates a database in which the hash values of each of the multiple code blocks calculated by the calculation unit 132 are linked to values based on the hash values. For example, the generation unit 133 generates a distance index database DB1 in which the hash values of each of the multiple code blocks are linked to values formed by combining parts of the code sequences represented as the hash values. The generation unit 133 may further generate a software database DB2 in which information on software such as index software and software to be detected by the server 10 and software candidates for detection is registered.
[0049] An example of the generation of the distance index database DB1 by the generation unit 133 will be described below using mathematical expressions. For example, the generation unit 133 generates the distance index database DB1 by performing the following processes (1) to (4): (1) The generation unit 133 divides the hash value H registered in the distance index database DB1 into n(d+a) parts, and sets the hash value H = (h_1, ..., h_n). d is a Hamming distance value desired by the user, and may be, for example, a threshold value that falls within a range similar to the hash value H. a is a constant. (2) The generation unit 133 selects a values k from the hash value H = (h_1, ..., h_n) to generate a value k = (h'_1, ..., h'_a), and adds the hash value H to the associative array list M[k][i][j] of the distance index database DB1. k is a value based on the hash value, and specifically, is a value formed by combining parts of the code sequence represented as the hash value H.
[0050] i is a value representing the ordinal number of the left-hand code of the two codes generated based on the hash value H, counting from the left, with the left end being zero, in the code sequence represented as the hash value H. j is a value representing the ordinal number of the right-hand code of the two codes generated based on the hash value H, counting from the left, with the left end being zero, in the code sequence represented as the hash value H. For example, if the hash value H=34fe and k=34, the i corresponding to 3 corresponds to the zeroth number at the left end of the hash value H, so i=0, and the j corresponding to 4 corresponds to the immediately right-hand side of the left end of the hash value H, so j=1. (3) The generation unit 133 repeats the process of (2) for C(n, a) values of k. (4) The generation unit 133 repeats the processes of (1) to (3) described above as many times as the number of hash values registered in the distance index database DB1.
[0051] An example of generation of the distance index database DB1 by the generation unit 133 will be described below with reference to FIG. 4. FIG. 4 is a diagram illustrating an example of a database. In the example of the software database DB2 illustrated in FIG. 4, software X has two code blocks, and the hash values of these code blocks are 34fe and 54fe, respectively. In this case, the generation unit 133 registers the hash values 34fe and 54fe in the distance index database DB1 as lists M[k][i][j].
[0052] First, the generation unit 133 registers the hash value H=34fe by performing the following processes (I) to (III). (I) The generation unit 133 divides the hash value H into four parts (n=d+a=2+2) and sets the hash value H=(3, 4, f, e). Here, d is 2 and a is 2. (II) The generation unit 133 selects two parts (a=2) from the hash value H=(3, 4, f, e) to generate the value k, and adds 34fe to the list M[k][i][j]. (III) The generation unit 133 repeats the process (II) above for the C(4, 2) values k=(34, 3f, 3e, 4f, 4e, fe).
[0053] Next, the generation unit 133 registers the hash value H=54fe by performing the following processes (i) to (iii). (i) The generation unit 133 divides the hash value H into four parts (n=d+a=2+2) and sets the hash value H=(5, 4, f, e). Here, d is 2 and a is 2. (ii) The generation unit 133 selects two parts (a=2) from the hash value H=(5, 4, f, e) to generate the value k, and adds 54fe to the list M[k][i][j]. (iii) The generation unit 133 repeats the process (ii) above for the C(4, 2) values k=(54, 5f, 5e, 4f, 4e, fe).
[0054] The generating unit 133 generates the distance index database DB1 shown in the diagram of the distance index database DB1 in FIG. 4 by registering the hash values 34fe and 54fe of the two code blocks of the software X as described above.
[0055] The generating unit 133 may generate a software database DB2 in which information about software is associated with a hash value of the software. For example, as shown in FIG. 4 , the generating unit 133 generates a software database DB2 in which a software name x and a software version 1.0 are associated with a hash value 34fe.
[0056] The detection unit 134 detects information about software that is a dependency of the software to be detected based on the database generated by the generation unit 133. The detection unit 134 may detect information about the software to be detected based further on the Hamming distance between each hash value of a plurality of code blocks and each value formed by combining portions of the code sequences represented as the hash values. For example, the detection unit 134 determines whether the Hamming distance between each hash value of a plurality of code blocks in the software of the index stored in the distance index database DB1 and each value formed by combining portions of the code sequences represented as the hash values is equal to or less than a predetermined value. The detection unit 134 detects values for which the Hamming distance is equal to or less than the predetermined value as information about the software to be detected.
[0057] The detection unit 134 may detect information about the software to be detected based on the number of values for which the Hamming distance to each hash value of a plurality of code blocks is equal to or less than a predetermined value. For example, the detection unit 134 detects, as the software to be detected, software to be detected that has a predetermined number or more of values for which the Hamming distance to each hash value of a plurality of code blocks in the software to be detected that is equal to or less than the predetermined value. In other words, the detection unit 134 detects, as the software to be detected, software to be detected that has a predetermined percentage or more of code blocks similar to the code blocks in the software to be detected.
[0058] The detection unit 134 may further detect information related to the software to be detected by using the software database DB2. For example, the detection unit 134 uses the names and hash values of the software of the index and the names and hash values of the software of the detection candidate stored in the software database DB2 and the distance index database DB1 to search for values similar to the hash values of each of the multiple code blocks of the software of the index.
[0059] An example of a search by the detection unit 134 will be described below using mathematical expressions. Hereinafter, the detection unit 134 searches the distance index database DB1 for a value whose Hamming distance to the hash value Q is less than or equal to d. In this case, the detection unit 134 searches the distance index database DB1 by the following processes (A) to (C). (A) The detection unit 134 divides the hash value Q into n=(d+a) parts, and sets the hash value Q=(q_1, ..., q_n). (B) The detection unit 134 selects a values k from the hash value Q=(q_1, ..., q_n) and generates a value k=(q'_1, ..., q'_a). Next, the detection unit 134 compares the hash value Q with all values included in the list M[k][i][j] in the distance index database DB1. If the Hamming distance to the hash value Q is equal to or less than d, the detection unit 134 detects the corresponding value as a value corresponding to each of the multiple code blocks of the software to be detected, and stores the result list in the storage unit 15. (C) The detection unit 134 repeats the process of (B) above for C(n, a) values k, and causes the output unit 14 to output the result list.
[0060] An example of a search by the detection unit 134 will be described below with reference to FIG. 4 . Here, the case will be described where software Y has one code block, and the hash value Q of this code block is hash value Q=54ef. Also, the case will be described where the detection unit 134 searches the distance index database DB1 for a value at a Hamming distance d=2 or less from the hash value Q. In this case, the detection unit 134 searches the distance index database DB1 by the following processes (a) to (c): (a) The detection unit 134 divides the hash value Q into four parts (n=d+a=2+2) and sets the hash value Q=(5, 4, e, f). (b) The detection unit 134 selects two values k from the hash value Q=(5, 4, e, f) to generate the value k. Next, the detection unit 134 compares the distance between the hash value Q and all values included in the list M[k][i][j] in the distance index database DB1. (c) The detection unit 134 repeats the process of (b) above for C(n, a) values k=(54, 5e, 5f, 4e, 4f, ef) and causes the output unit 14 to output a result list.
[0061] For example, if, as a result of repeating the process of (b) above in (c) above, a value of list M[k][i][j] exists only when k=54, i=0, and j=1, the detection unit 134 compares all values [54fe] included in list M
[54] [0][1] with the hash value Q. If the Hamming distance d of these hash values is ham(54ef, 54fe)=2, the Hamming distance d is less than or equal to 2, so the detection unit 134 stores the value [54fe] in the storage unit 15 as a result list and outputs the result list to the output unit 14.
[0062] 4, two hash values are registered in the software database DB2, so if a brute force comparison of hash values were to be performed as in the prior art, two comparisons would have been necessary. In contrast, by utilizing the distance index database DB1, the detection unit 134 can search for values with a Hamming distance d of 2 or less by comparing hash values once.
[0063] The detection unit 134 may detect the detection candidate software as the software to be detected if the paths of the code clones that match between the software and the detection candidate software do not contain a common keyword. Furthermore, the detection unit 134 may detect the detection candidate software as the software to be detected if the directory names or file names of the code clones do not contain a common keyword.
[0064] The detection unit 134 may exclude the detection candidate software from dependency relationship candidates when a common keyword is included in the path of the code clone. The detection unit 134 excludes the detection candidate software from dependency relationship candidates when a common keyword is included in the path of the code clone and the common keyword is not included in the software name of the software and the software name of the detection candidate software. For example, in this case, the detection unit 134 determines that the detection candidate software has a dependency relationship with another software, and excludes the detection candidate software from the candidates having a dependency relationship with the software.
[0065] An example of detection by the detection unit 134 will be described below using mathematical expressions. In the following, the detection unit 134 performs the following processes (A) to (Γ) on each piece of detection candidate software Y, thereby determining whether or not a dependency relationship exists between software Z that is different from index software X and the detection candidate software Y. If the detection unit 134 determines that a dependency relationship exists between the different software Z and the detection candidate software Y, it excludes the detection candidate software Y from the candidates that have a dependency relationship with index software X.
[0066] (A) Keyword Generation The detection unit 134 generates a path P = (p1, p2, ...) by combining a path S = (s1, s2, ...) of the code clone of the index software X and a path D = (d1, d2, ...) of the code clone of the detection candidate software Y. The detection unit 134 splits each element p_i of the path P using the path delimiter, and normalizes the code strings (e.g., character strings) of the split directory names and file names. The detection unit 134 stores the split code strings of the directory names and file names as keywords K = (k1, k2, ...).
[0067] (B) Extraction of Common Keywords For each k (k1, k2, ...) that is a code sequence of keyword K, the detection unit 134 determines whether each k is included in each of path S and path D. In this case, the detection unit 134 calculates the number of occurrences of each k for each of path S and path D as C_s = (cs_1, ..., cs_k) and C_d = (cd_1, ..., cd_k). The detection unit 134 divides the calculated values of C_s = (cs_1, ..., cs_k) and C_d = (cd_1, ..., cd_k) by the number of code sequences for each of path S and path D. As a result, the detection unit 134 calculates the probability of occurrence of each k for path S as H_s = (hs_1, ..., hs_k) = (cs_1 / |S|, ..., cs_k / |S|). The detection unit 134 also calculates the appearance probability of each k for path D as H_d = (hd_1, ..., hd_k) = (cd_1 / |D|, ..., cd_k / |D|). The detection unit 134 extracts common keywords K' = (k'1, k'2, ...) where {h|hs_i>T and hd_j>T}, where T is a threshold for the appearance probability of each k.
[0068] (Γ) Determination of Dependency Relationship If a common keyword K' is not extracted, the detection unit 134 may detect the detection candidate software Y as software to be detected that has a dependency relationship with the index software X. If a common keyword K' is extracted, the detection unit 134 determines whether each k' (k'1, k'2, ...), which is the code sequence of the common keyword K', is included in the software name of the index software X and the software name of the detection candidate software Y.
[0069] If each k' is not included in the software name of the index software X and the software name of the detection candidate software Y, the detection unit 134 determines that there is no relationship of index software X -> detection candidate software Y, in which the detection candidate software Y depends on the index software X. Then, the detection unit 134 determines that there is a relationship of index software X -> other software Z, in which the index software X depends on another software Z. Furthermore, the detection unit 134 determines that there is a relationship of detection candidate software Y -> other software Z, in which the detection candidate software Y depends on another software Z other than the index software X. The detection unit 134 excludes the detection candidate software Y from the dependency relationship candidates.
[0070] The detection unit 134 determines the dependencies of all detection candidate software Y, and outputs the remaining detection candidate software Y that is in a dependency relationship with the index software X to the output unit 14 as the software to be detected.
[0071] Next, another example of detection by the detection unit 134 will be described using mathematical expressions. In the following, the detection unit 134 performs the following processes (α) to (γ) on each piece of detection candidate software Y to determine whether a dependency relationship exists between software other than the index software X and the detection candidate software Y. For example, if the detection unit 134 determines, through the processes (A) to (Γ) described above, that there is a dependency relationship between the index software X and the detection candidate software Y (index software X --> detection candidate software Y), it again determines whether there is a dependency relationship.
[0072] (α) Keyword Generation The detection unit 134 generates a path P = S + D by combining a path S = ( / sdk / bzip / compress.c, / sdk / bzip / decompress.c) of the code clone of the index software X and a path D = ( / src / bzip2 / compress.c, / src / bzip2 / decompress.c) of the code clone of the detection candidate software Y. Specifically, the detection unit 134 generates a path P = ( / sdk / bzip / bzlib.c, / sdk / bzip / decompress.c, / src / bzip2 / bzlib.c, / src / bzip2 / decompress.c). The detection unit 134 splits each element of the path P by the path delimiter and obtains a set of code strings of the split directory names and file names with extensions removed. The detection unit 134 normalizes this set from which predefined excluded keywords have been removed, and stores the normalized set as keyword K=(sdk, bzip, bzlib, decompress, src, bzip2).
[0073] (β) Extraction of Common Keywords For each k (k1, k2, ...) that is a code sequence of keyword K, the detection unit 134 determines whether each k is included in each of path S and path D. In this case, the detection unit 134 calculates the number of occurrences of each k for each of path S and path D as Cs = (2, 2, 1, 1, 0, 0) and Cd = (0, 2, 1, 1, 2, 2). The detection unit 134 divides the calculated values of Cs = (2, 2, 1, 1, 0, 0) and Cd = (0, 2, 1, 1, 2, 2) by the number of code sequences for each of path S and path D. As a result, the detection unit 134 calculates the probability of occurrence of each k for path S as HS = (2 / 2, 2 / 2, 1 / 2, 1 / 2, 0 / 2, 0 / 2). Furthermore, the detection unit 134 calculates the occurrence probability of each k for the path D as HD=(0 / 2, 2 / 2, 1 / 2, 1 / 2, 2 / 2, 2 / 2). When the threshold T for the occurrence probability of each k is T=0.5, the detection unit 134 extracts a common keyword K′=(bzip) such that {h|hs_i>T and hd_j>T}.
[0074] (γ) Determination of Dependency Relationship When a common keyword K' is not extracted, the detection unit 134 may detect the detection candidate software Y as software to be detected that has a dependency relationship with the index software X. When a common keyword K' is extracted, the detection unit 134 determines whether each k' (k'1, k'2, ...), which is the code sequence of the common keyword K', is included in the software name of the index software X and the software name of the detection candidate software Y.
[0075] If each k' is not included in the software name of the index software X and the software name of the detection candidate software Y, the detection unit 134 determines that the common keyword K'=(bzip) is not included in the index software X and the detection candidate software Y. In other words, the detection unit 134 determines that there is no relationship of index software X -> detection candidate software Y, in which the detection candidate software Y depends on the index software X.
[0076] The detection unit 134 then determines that the index software X depends on another software bzip, that is, the relationship is index software X -> another software bzip. The detection unit 134 also determines that the detection candidate software Y depends on another software bzip from the index software X, that is, the relationship is detection candidate software Y -> another software bzip. The detection unit 134 excludes the detection candidate software Y from the dependency relationship candidates. This enables the detection unit 134 to reduce false detections of index software X -> detection candidate software Y.
[0077] The detection unit 134 may detect a detection candidate software as software to be detected if the number of values for which the Hamming distance to each hash value of a plurality of code blocks is equal to or less than a predetermined value is equal to or greater than a predetermined number, and if the paths of code clones that match between the software and the detection candidate software do not contain any common keywords. For example, the detection unit 134 determines that a detection candidate software has a dependency relationship with the index software if the index software contains more than a predetermined percentage of code blocks that are similar to the code blocks in the index software, and if the paths of the code clones do not contain any common keywords. Then, the detection unit 134 detects the detection candidate software as software to be detected.
[0078] The output unit 14 outputs data on the detection results obtained by the detection unit 134. As one example, when the detection unit 134 detects a value similar to the hash value of a code block of the index software, the output unit 14 outputs a result list showing the results of the similar value. As another example, the output unit 14 outputs information on software to be detected by the detection unit 134 that has a dependency relationship with the index software.
[0079] The storage unit 15 stores various information such as the distance index database DB1 generated by the generation unit 133, the software database DB2, and the detection results by the detection unit 134 (for example, a result list showing results with similar values). Examples of the storage unit 15 include storage devices such as HDDs, SSDs, and optical disks, as well as data-rewritable semiconductor memories such as RAMs, flash memories, and NVSRAMs. The storage unit 15 stores the OS and various programs executed by the server 10.
[0080] [Example of Processing Flow by Server] The following describes the processing flow by the server 10 functioning as a detection device. First, the flow of database generation processing among the processing by the server 10 will be described with reference to Fig. 5. Fig. 5 is a flow diagram showing an example of the flow of database generation processing.
[0081] As shown in FIG. 5, the indexing unit 1311 divides the source code of the software into a plurality of code blocks (step S1).
[0082] The calculation unit 132 calculates a hash value for each of the multiple code blocks divided by the indexing unit 1311 (step S2).
[0083] The generating unit 133 generates a distance index database DB1 in which the hash values of the code blocks calculated by the calculating unit 132 are linked to values based on the hash values (step S3).
[0084] The code dividing unit 1312 divides the software's own source code from the software's source code (step S4).
[0085] The generation unit 133 generates a software database DB2 based on the unique source code divided by the code division unit 1312 (step S5). For example, the generation unit 133 generates a software database DB2 in which the name and version of software having unique source code are linked to the hash value of the software.
[0086] Next, the flow of the detection process of software that is a detection target and has a dependency relationship with the software, performed by the server 10, will be described with reference to Fig. 6. Fig. 6 is a flow chart showing an example of the flow of the detection process of the detection target.
[0087] As shown in FIG. 6, the indexing unit 1311 divides the source code of the software into a plurality of code blocks (step S11).
[0088] The calculation unit 132 calculates a hash value for each of the code blocks divided by the indexing unit 1311 (step S12).
[0089] The detection unit 134 searches for values similar to the hash values of the multiple code blocks calculated by the calculation unit 132, based on the distance index database DB1 generated by the generation unit 133 (step S13). For example, the detection unit 134 uses the distance index database DB1 to search for values whose Hamming distance to the hash values of the multiple code blocks is equal to or less than a predetermined value.
[0090] The detection unit 134 detects information about the software as a detection candidate based on the number of values similar to the hash values of each of the multiple code blocks calculated by the calculation unit 132 (step S14). For example, the detection unit 134 detects, as a detection candidate software, software for which the number of values whose Hamming distance to each of the hash values of the multiple code blocks is equal to or less than a predetermined value is equal to or greater than a predetermined value.
[0091] The detection unit 134 determines whether a common keyword is included in the path of the code clone that matches between the software and the detection candidate software. If the detection unit 134 determines that a common keyword is not included in the path of the code clone (Yes in step S15), the detection unit 134 detects the detection candidate software as software to be detected that has a dependency relationship with the index software (step S16).
[0092] If the detection unit 134 determines that the paths of the code clones contain a common keyword (No in step S15), it excludes the detection candidate software from dependency relationship candidates (step S17). For example, if the detection unit 134 determines that the paths of the code clones contain a common keyword and that the common keyword is not included in the software name of the software and the software name of the detection candidate software, it excludes the detection candidate software from dependency relationship candidates. In this case, the detection unit 134 determines that the detection candidate software has a dependency relationship with another software, and excludes the detection candidate software from the candidates having a dependency relationship with the software.
[0093] [Effects] The server (detection device) 10 according to this embodiment includes a division unit 131 that divides the source code of the software into multiple code blocks, a calculation unit 132 that calculates a hash value for each of the multiple code blocks divided by the division unit 131, a generation unit 133 that generates a database in which the hash values of each of the multiple code blocks calculated by the calculation unit 132 are linked to values based on the hash values, and a detection unit 134 that detects information about software that is a dependency of the software to be detected, based on the database generated by the generation unit 133.
[0094] Here, conventional technologies have only detected software that has a code block whose hash value matches each of the hash values of multiple code blocks as target software, which may have made it impossible to reduce missed detections. In contrast, server 10, based on a database that associates each hash value of multiple code blocks with a value based on that hash value, detects not only the target software but also software that has a code block whose value is similar to each of the hash values of multiple code blocks as target software. This allows server 10 to reduce missed detections of target software.
[0095] Furthermore, in conventional technology, the hash values of each of the software's multiple code blocks are compared with the hash values of each of the multiple code blocks of the detection candidate software in a brute-force manner. In contrast, the server 10 can use a database to quickly search for values similar to the hash values of each of the multiple code blocks. This allows the server 10 to significantly reduce the Hamming distance calculation process and the detection candidate software, and efficiently search for values similar to the hash values of the code blocks of the indicator software. In other words, the server 10 can search for code blocks similar to the code blocks of the indicator software. As a result, the server 10 can efficiently search for software to be detected that has code blocks similar to code blocks of the source code. In this way, the server 10 can reduce the number of missed detections of software to be detected and shorten the time required to search for software to be detected.
[0096] In the server 10 according to this embodiment, the generation unit 133 generates a database in which the hash values of each of a plurality of code blocks are linked to values formed by combining parts of the code sequences represented as the hash values, thereby enabling the server 10 to efficiently generate a database containing values similar to hash values.
[0097] In the server 10 according to this embodiment, the detection unit 134 may detect information about the target software based on the Hamming distance between the hash value of each of the code blocks and each value formed by combining parts of the code sequence represented as the hash value. This allows the server 10 to detect information about the target software that includes a code block having a value similar to the hash value of each of the code blocks.
[0098] In the server 10 according to this embodiment, the detection unit 134 detects the detection candidate software as software to be detected if the paths of the code clones that match between the software and the detection candidate software do not contain a common keyword. For example, if the paths of the code clones contain a common keyword, the server 10 determines that the code clones included in the index software and the detection candidate software match and that these pieces of software do not have a mutual dependency relationship. The server 10 then determines that the detection candidate software has a mutual dependency relationship with another piece of software other than the index software, and excludes the detection candidate software from the dependency relationship candidates. If the paths of the code clones do not contain a common keyword, the server 10 determines that the code clones included in the index software and the detection candidate software do not match and that these pieces of software have a mutual dependency relationship. The server 10 then detects the detection candidate software as software to be detected.
[0099] This allows the server 10 to reduce false positives of the index software and the detection candidate software being implicitly dependent on each other even when they contain code clones.The server 10 also uses two algorithms: an algorithm that detects information about detection target software that is dependent on the software based on a database in which the hash values of multiple code blocks are linked to values based on those hash values, and an algorithm that detects detection candidate software as detection target software when the paths of the code clones do not contain common keywords, thereby reducing false positives and missed detections.
[0100] In the server 10 according to this embodiment, the detection unit 134 detects a detection candidate software as software to be detected if the directory names or file names of the code clones do not contain a common keyword. That is, the server 10 detects a detection candidate software as software to be detected if the directory names or file names of the code clones do not contain a common keyword in the paths of the code clones. This allows the server 10 to further reduce false detection of software to be detected.
[0101] In the server 10 according to this embodiment, the detection unit 134 excludes the detection candidate software from dependency relationship candidates when a common keyword is included in the path of the code clone and the common keyword is not included in the software name of the software or the software name of the detection candidate software. That is, the server 10 performs a two-stage determination: determining whether the common keyword is included in the path of the code clone and determining whether the common keyword is included in the software name of the software and the software name of the detection candidate software. In this case, for example, the server 10 determines that the detection candidate software has a dependency relationship with another software and excludes the detection candidate software from the dependency relationship candidates. This allows the server 10 to further reduce false positives of the software to be detected.
[0102] [Program] A program written in a computer-executable language may be created to execute the processes performed by the server 10 according to the above-described embodiment. In this case, the same effects as those of the above-described embodiment may be achieved by having a computer execute the program. Furthermore, such a program may be recorded on a computer-readable recording medium, and the program recorded on the recording medium may be read and executed by a computer to achieve the same processes as those of the above-described embodiment.
[0103] 7 is a diagram showing an example of a computer that executes a detection program. The computer 1000 includes, for example, a memory 1010, a CPU 1020, 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.
[0104] The memory 1010 includes a ROM (Read Only Memory) 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 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.
[0105] 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, the program that defines each process of the server 10 is implemented as a program module 1093 in which computer-executable code is written. The program module 1093 is stored, for example, in the hard disk drive 1090. For example, a program module 1093 for executing processes similar to those of the functional configuration of the server 10 is stored in the hard disk drive 1090. The hard disk drive 1090 may be replaced with an SSD.
[0106] Furthermore, setting data used in the processing of the above-described embodiment is stored as program data 1094, for example, in the memory 1010 or the hard disk drive 1090. Then, the CPU 1020 reads the program module 1093 or the program data 1094 stored in the memory 1010 or the hard disk drive 1090 into the RAM 1012 as necessary, and executes the processing of the above-described embodiment.
[0107] The program module 1093 and program data 1094 are not limited to being stored in the hard disk drive 1090, but may also 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 program data 1094 may be stored in another computer connected via a network (such as a LAN or a WAN (Wide Area Network)). The program module 1093 and program data 1094 may then be read by the CPU 1020 from the other computer via the network interface 1070.
[0108] REFERENCE SIGNS LIST 1 Detection system 10 Server (detection device) 11, 23 Communication unit 12 Input reception unit 13, 22 Control unit 14 Output unit 15, 24 Storage unit 20 Client 21 Input unit 131 Division unit 132 Calculation unit 133 Generation unit 134 Detection unit 1311 Indexing unit 1312 Code division unit DB1 Distance index database DB2 Software database
Claims
1. A detection device comprising: a division unit that divides software source code into multiple code blocks; a calculation unit that calculates a hash value for each of the multiple code blocks divided by the division unit; a generation unit that generates a database in which the hash values for each of the multiple code blocks calculated by the calculation unit are linked to values based on the hash values; and a detection unit that detects information about software to be detected that has a dependent relationship with the software, based on the database generated by the generation unit.
2. The detection device described in claim 1, characterized in that the generation unit generates the database in which each hash value of the multiple code blocks is linked to each value that is composed of a combination of parts of the code sequence represented as the hash value.
3. The detection device described in claim 2, characterized in that the detection unit detects information about the software to be detected based further on the Hamming distance between each hash value of the multiple code blocks and each value formed by a combination of parts of the code sequences represented as the hash values.
4. A detection device as described in any one of claims 1 to 3, characterized in that the detection unit detects the detection candidate software as the software to be detected if the paths of code clones that match between the software and the detection candidate software do not contain any common keywords.
5. The detection device according to claim 4, characterized in that the detection unit detects the detection candidate software as the detection target software if the directory names or file names of the code clones do not contain any common keywords.
6. The detection device described in claim 4, characterized in that the detection unit excludes the detection candidate software from the dependency candidates when the path of the code clone contains the common keyword and the common keyword is not included in the software name of the software and the software name of the detection candidate software.
7. A detection method executed by a detection device, comprising: a division step of dividing software source code into a plurality of code blocks; a calculation step of calculating a hash value for each of the plurality of code blocks divided by the division step; a generation step of generating a database in which the hash value for each of the plurality of code blocks calculated by the calculation step is linked to a value based on the hash value; and a detection step of detecting information regarding software to be detected that has a dependent relationship with the software, based on the database generated by the generation step.
8. A detection program that causes a computer to execute the following steps: a division step of dividing software source code into multiple code blocks; a calculation step of calculating a hash value for each of the multiple code blocks divided by the division step; a generation step of generating a database in which the hash value for each of the multiple code blocks calculated by the calculation step is linked to a value based on the hash value; and a detection step of detecting information about software to be detected that has a dependent relationship with the software, based on the database generated by the generation step.
Citation Information
Patent Citations
Information processing device, information processing method, program, and information processing system
WO2022034919A1
