Security patch detection method for Android application upgrade

By restoring the structural hierarchy of Android applications and matching disassembly codes, establishing control flow graphs, analyzing data flow and control dependencies, we solve the limitations of Android application update patch analysis in the existing technology, and realize the analysis of complex security patches. Effective positioning and rapid detection reduce the burden of security audits.

CN114090461BActive Publication Date: 2024-10-01SHANGHAI JIAOTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111474991.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2024-10-01
Estimated Expiration
2041-12-06

Smart Images

  • Figure CN114090461B_ABST
    Figure CN114090461B_ABST
Patent Text Reader

Abstract

A security patch detection method for Android application upgrades, by restoring the Android application structural hierarchy and disassembly code feature values ​​before and after the upgrade, performing function matching between Android applications before and after the upgrade, performing data flow analysis on all call points of the function where the update patch is located, establishing control flow graphs of the two versions of the function before and after the upgrade where the update patch is located, extracting data dependencies and control dependencies related to variable parameters on the control flow graph, and obtaining security detection results based on the dependency relationship. The present invention can obtain security-related patches existing in program analysis by differentially analyzing the Android application versions before and after the upgrade, thereby achieving the goal of reducing the analysis of security auditors and the goal of learning new vulnerability patterns. The goal of security worker analysis is greatly reduced. It can resist common program obfuscation and does not require invasive changes to the source code. It does not need to rely on the experience of security workers to define security patch patterns, and can locate more complex security patches.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a technology in the field of information security, and in particular to a security patch detection method for Android application upgrades. Background Art

[0002] Most existing solutions for distinguishing between security patches and functional updates of programs are to match through specific patterns or to use detailed update information for analysis. However, these solutions have many limitations in real scenarios: the pattern matching method can only extract update patches of specific patterns, and cannot cope with code repairs introduced by complex real scenarios. The defined pattern needs to be based on the experience of security analysts. Except for open source projects, the update description of Android applications is very brief, usually with only a prompt to "fix known issues." Summary of the invention

[0003] In view of the shortcomings of the prior art in application update patch analysis, the present invention proposes a security patch detection method for Android application upgrades, which can obtain security-related patches in program analysis by differentially analyzing the Android application versions before and after the upgrade, thereby achieving the goal of reducing the analysis of security auditors and learning new vulnerability patterns. It greatly reduces the analysis goals of security workers. It can resist common program obfuscation and does not require invasive changes to the source code. It does not need to rely on the experience of security workers to define security patch patterns, and can locate more complex security patches.

[0004] The present invention is achieved through the following technical solutions:

[0005] The present invention relates to a security patch detection method for Android application upgrades. The method restores the structural hierarchy of Android application programs before and after the upgrade and the characteristic values ​​of disassembled codes, performs function matching between Android application programs before and after the upgrade, performs data flow analysis on all call points of the function where the update patch is located, establishes control flow graphs of the two versions of the function where the update patch is located before and after the upgrade, extracts data dependencies and control dependencies related to variable parameters on the control flow graph, and obtains security detection results based on the dependency relationship.

[0006] The structural hierarchy includes: the hierarchical structure of packages, the inclusion relationship between packages and classes, the belonging relationship between classes and nested classes, and the member variable fields and member methods contained in the class.

[0007] The present invention relates to a system for implementing the above method, comprising: a patch positioning module, a call point analysis module and a patch determination module, wherein: the patch positioning module locates the function where the upgrade patch is located, the call point analysis module locates the call site of the patch function and determines whether variable parameters are accepted, and the patch determination unit determines whether the update of the function is related to security.

[0008] Technical Effects

[0009] The present invention establishes the relationship between a class and its nested classes through a patch positioning module, thereby reducing false positives when matching nested classes with fewer features between two versions; and considers the features of the function in the program structure to match the two versions, thereby obtaining an effect that is superior to the existing method of directly matching between functions. The patch determination module does not use the traditional pattern matching method to match the pattern of the security patch, but judges whether the patch is a security patch by comparing the consistency of the use of variable parameters in the function before and after the update, and can locate more complex security patches. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] Figure 1 It is the overall flow chart of the present invention;

[0011] Figure 2 To locate the process of the function where the patch is located;

[0012] Figure 3 Analyze the call point of the function where the patch is located;

[0013] Figure 4 The process of determining whether a patch is a security patch. DETAILED DESCRIPTION

[0014] like Figure 1 As shown, a security patch detection method for Android application upgrades involved in this embodiment includes the following steps:

[0015] Step 1: Figure 2 As shown in the figure, by restoring the structural hierarchy and disassembled code feature values ​​of the Android application before and after the upgrade, function matching is performed between the application before and after the upgrade, specifically including:

[0016] Step 101. Unpack the Android application files before and after the upgrade, and disassemble the bytecode of the program, wherein: the disassembled code of the Android application is Smali code; after the application is disassembled, each class of the program exists in the form of a separate file with a ".smali" suffix.

[0017] Step 102. Construct the structural hierarchy of the program: After unpacking the Android installation package file, traverse the file directory to obtain the hierarchy of packages and the inclusion relationship between packages and classes; obtain the member fields and member methods contained in the class by parsing the single Smali file after disassembly, and obtain the relationship between classes and nested classes through the annotation class of the Smali code or through heuristic rules.

[0018] The member field starts with the identifier ".field", and the content of the member method starts with the identifier ".method" and ends with ".end method".

[0019] In the annotation class of the Smali code, the annotation class containing the nested class relationship is:

[0020] Ldalvik / annotation / MemberClasses, Ldalvik / annotation / EnclosingClass and Ldalvik / annotation / EnclosingMethod.

[0021] The heuristic rules are for unannotated classes (mostly Lambda expressions) to determine whether they are nested classes. The rules include:

[0022] a. Only called in one class or its class;

[0023] b. Implement an interface;

[0024] c. A class with a static initialization method has only 1 or 2 member variables, all of which are static members, one of which is itself. A class without a static initialization method must have a constructor, and the constructor's parameter list includes all its members, with the first one in the parameter list being the class to which it belongs.

[0025] Step 103. After the custom identifier, resource constant id, and instruction jump address are obfuscated, the fuzzy hash of the function and the fuzzy hash value of its basic block are calculated as the disassembled code feature value, specifically: first, the basic block of the function is divided, and the operator and constant string of the instruction in the basic block, as well as the constants involved in the operation and other parts that are not easily affected by program confusion are extracted as the features of the basic block. The hash of the basic block feature is calculated as the feature value of the basic block. After the basic block feature values ​​are sorted, the hash is calculated again to obtain the hash that is independent of the basic block position, and then the function parameter type and function attribute flag are added to calculate the feature value of the function.

[0026] Step 104. Compare the disassembled code feature values ​​of the two versions of the program, traverse the hierarchical structure restored in step 102, match the function sets with equivalent relationships in the hierarchical structures of the two applications, and use the function with the highest feature value similarity as the matching function, output the function matching relationship, mark all functions as one of the following: added, deleted, changed, or the same, and the functions marked as changed are regarded as the functions where the potential patch is located.

[0027] In the function marking, ① function pairs with exactly the same eigenvalues ​​are marked as the same; for functions with different eigenvalues, the similarity of the functions is calculated by the eigenvalues ​​of the basic blocks, that is, the ratio of the sum of the lengths of the basic blocks with the same eigenvalues ​​to the length of the entire function; ② functions whose eigenvalue similarity exceeds 0.2 and is not equal to 1 (which can be adjusted according to the accuracy requirements) are considered to be similar functions; the function with the highest similarity is considered to be changed; ③ functions that do not have the same / changed functions in the new version of the application are marked as newly added; ④ functions that do not have the same / changed functions in the old version of the application are marked as deleted.

[0028] Step 2: Figure 3 As shown, data flow analysis is performed on all call points of the function where the patch is located to determine whether the function where the patch is located accepts external variable parameters at the call point, including:

[0029] Step 201. Cache the functions marked as changed obtained in step 1 and mark them as tainted slot functions, and perform taint analysis in each function of the application, specifically: establish a function control flow graph with statements as single nodes, and traverse each node of the control flow graph: when the statement contains any of the use of function parameters, member variables, or external function calls, and the statement has a left value, then mark the left value variable of the statement as a tainted value, otherwise analyze whether the right value expression of the statement contains the use of a tainted value, if the right value expression uses a tainted value, then the left value is regarded as tainted, otherwise the left value is defined as untainted; when the node contains a call to a pre-defined tainted slot function, then save the taint status of the parameters used by the current slot function.

[0030] The control flow graph has a node which is an instruction of a function.

[0031] The taint slot function is a function call that the taint analysis focuses on to determine whether it will be contaminated. Here, the change function output from the patch positioning module is used as the taint slot function.

[0032] This step is implemented based on the taint analysis engine in the open source Android vulnerability detection tool (Find Security Bugs). The original taint analysis engine will only report a tainted parameter used by a statement containing a slot function. The present invention extracts whether all parameters of the tainted function are tainted to support the result aggregation of step 202.

[0033] Step 202. Aggregate the recorded results according to the calling points of the slot function and output the indexes of all contaminated parameters corresponding to the slot function of the same calling point and the function where the calling point is located, specifically: determine whether all parameters of the slot function of the same calling point are contaminated; for the same calling point, merge the contamination results obtained by different contamination paths.

[0034] Step 3: Figure 4 As shown, the data dependency and control dependency related to the variable parameters are extracted on the control flow graph, and the security detection results are obtained according to the dependency relationship, including:

[0035] Step 301. Extract the slot functions that can be tainted in the updated version. When the corresponding function in the old version is also a slot function that can be tainted, match the call points of the two slot functions to confirm whether the functions where the call points are located have a matching relationship, that is, they are the same or changed functions. If there is a matching relationship, it is considered that there is a matching relationship between this call point of the function pair and its tainted state, and the next step of analysis is performed; otherwise, the match of this tainted state will not be used for the next step of analysis.

[0036] Step 302. Establish control flow graphs for the two versions before and after the update, where a node of the control flow graph is an instruction. Extract dependencies within the function for the function pairs that can match the call point and the taint state that matches the call point on the control flow graph; traverse the control flow graphs of the two functions separately, mark all nodes that have direct and indirect data dependencies with the contaminated parameters on the control flow graph, record all control dependency nodes of these nodes, and merge the control dependency and data dependency results according to the basic blocks of the function.

[0037] The data dependency relationship includes: direct data dependency and indirect data dependency; the left value variable of the assignment expression has a direct data dependency relationship with all variables used in the right value expression, and the data dependency is transitive. When variable a depends on b, and b depends on c, then c has an indirect data dependency on a; the instructions in the conditional branch statement have a control dependency relationship with the conditional branch statement. When traversing to the branch convergence point, the subsequent instructions have no control dependency relationship with the conditional branch.

[0038] Step 303. Match the functions that can match the call points based on the control flow graph structure and its basic block instructions. Specifically, first convert the control flow graph at the single instruction level used in step 302 into a control flow graph with basic blocks as nodes, traverse the control flow graphs of the two functions respectively, use the traversal order of the basic blocks on the control flow graph and the characteristic instructions contained in the basic blocks as the characteristics of the basic blocks, and match the basic blocks between the two functions.

[0039] The basic blocks are traversed in a breadth-first order, and the traversal is stopped when a loop structure or a function exit point is encountered.

[0040] The characteristic instructions include: function calls, return statements, conditional statements, exception statements, array access statements and statements containing constant values ​​other than resource IDs.

[0041] Due to the change in the control flow structure of the two functions, there may be one-to-one, one-to-many, or many-to-many matching results between basic blocks in the matching results.

[0042] Step 304. Generate security test results, specifically: compare the data dependencies and control dependencies involved in the matching basic blocks. When all control dependencies and data dependencies extracted between the matching basic blocks between the function pairs are the same, the update of the function is regarded as a non-security patch; when they are different, it is regarded as a security patch.

[0043] After specific practical experiments, tests were carried out on a server equipped with Ubuntu 20.04 system, AMD Ryzen Threadripper 3970X processor, and 256G RAM. The test data set contained 441 pairs of Android application versions before and after the update. The results showed that among a total of 36,337,758 functions, 224,112 functions were located as changed functions, and a total of 39,081 functions were reported to contain security patches, indicating that the present invention can greatly reduce the goal of security audits; manual analysis of random sampling results confirmed that there are multiple mode security patches in the report results, including but not limited to null pointer reference checks, exception capture, black / white list filtering, removal of hard-coded key usage in programs, etc.; in terms of time overhead, 83.64% of the update pairs of applications can be analyzed within 5 minutes, 89.55% of the update pairs can be analyzed within 10 minutes, and 96.17% of the update pairs can be analyzed within 20 minutes, indicating that this invention can be used in real scenarios.

[0044] The above-mentioned specific implementation can be partially adjusted in different ways by those skilled in the art without departing from the principle and purpose of the present invention. The protection scope of the present invention shall be based on the claims and shall not be limited by the above-mentioned specific implementation. Each implementation scheme within its scope shall be subject to the constraints of the present invention.

Claims

1. A security patch detection method for Android application upgrade, characterized in that: By restoring the structural hierarchy and disassembled code feature values ​​of the Android application before and after the upgrade, function matching is performed between the Android applications before and after the upgrade, data flow analysis is performed on all call points of the function where the update patch is located, and control flow graphs of the two versions of the function where the update patch is located before and after the upgrade are established. Data dependencies and control dependencies related to variable parameters are extracted from the control flow graph and security detection results are obtained based on the dependency relationship. The structural hierarchy includes: the hierarchical structure of packages, the inclusion relationship between packages and classes, the belonging relationship between classes and nested classes, and the member variable fields and member methods contained in classes; The data flow analysis includes: Step 201. Cache the functions marked as changed and mark them as tainted slot functions, and perform taint analysis in each function of the application, specifically: establish a function control flow graph with statements as single nodes, and traverse each node of the control flow graph: when a statement contains any of the use of function parameters, member variables, or external function calls, and the statement has an left value, then mark the left value variable of the statement as a tainted value, otherwise analyze whether the right value expression of the statement contains the use of the tainted value, if the right value expression uses the tainted value, then the left value is regarded as tainted, otherwise the left value is determined to be untainted; when a node contains a call to a pre-defined tainted slot function, then save the taint status of the parameters used by the current slot function; Step 202. Aggregate the recorded results according to the calling point of the slot function and output the indexes of all polluted parameters corresponding to the slot function of the same calling point and the function where the calling point is located, specifically: determine whether all parameters of the slot function of the same calling point are polluted; for the same calling point, merge the pollution results obtained by different pollution paths; The safety test results are obtained in the following ways: Step 301. Extract the slot functions that can be tainted in the updated version. When the corresponding function in the old version is a slot function that can also be tainted, match the call points of the two slot functions to confirm whether the functions where the call points are located have a matching relationship, that is, they are the same or changed functions; if there is a matching relationship, it is considered that there is a matching relationship between this call point of the function pair and its pollution state, and the next step of analysis is performed; otherwise, the match of this pollution state will not be used for the next step of analysis; Step 302. Create control flow graphs of the two versions before and after the update, where a node of the control flow graph is an instruction. On the control flow graph, extract the dependencies within the function for the function pairs that can match the call point and the taint state that matches the call point; traverse the control flow graphs of the two functions respectively, mark all nodes that have direct and indirect data dependencies with the tainted parameters on the control flow graph, record all control dependency nodes of these nodes, and merge the control dependency and data dependency results according to the basic blocks of the function; Step 303. Match the functions whose call points can be matched based on the control flow graph structure and its basic block instructions, specifically: first convert the control flow graph at the single instruction level used in step 302 into a control flow graph with basic blocks as nodes, traverse the control flow graphs of the two functions respectively, use the traversal order of the basic blocks on the control flow graph and the characteristic instructions contained in the basic blocks as the characteristics of the basic blocks, and match the basic blocks between the two functions; Step 304. Generate security test results, specifically: compare the data dependencies and control dependencies involved in the matching basic blocks. When all control dependencies and data dependencies extracted between the matching basic blocks between the function pairs are the same, the update of the function is regarded as a non-security patch; when they are different, it is regarded as a security patch.

2. The security patch detection method for Android application upgrade according to claim 1, characterized in that: The function matching specifically includes: Step 101. Unpack the Android application files before and after the upgrade, and disassemble the bytecode of the program, wherein: the disassembled code of the Android application is Smali code; after the disassembled application, each class of the program exists in the form of a separate file with a ".smali" suffix; Step 102. Construct the structural hierarchy of the program: after unpacking the Android installation package file, traverse the file directory to obtain the hierarchical structure of packages and the inclusion relationship between packages and classes; obtain the member fields and member methods contained in the class by parsing the single Smali file after disassembly, and obtain the relationship between classes and nested classes through the annotation class of the Smali code or through heuristic rules; Step 103. After the custom identifier, resource constant id, and instruction jump address are obfuscated, the fuzzy hash of the function and the fuzzy hash value of its basic block are calculated as the disassembled code feature value, specifically: firstly, the basic block of the function is divided, and the operator and constant string of the instruction in the basic block, as well as the constants involved in the operation that are not easily affected by program confusion are extracted as the features of the basic block; the hash of the features of the basic block is calculated as the feature value of the basic block; the feature values ​​of the basic block are sorted and the hash is calculated again to obtain the hash that is independent of the position of the basic block, and then the parameter type and function attribute flag of the function are added to calculate the feature value of the function; Step 104. Compare the disassembled code feature values ​​of the two versions of the program, traverse the hierarchical structure restored in step 102, match the function sets with equivalent relationships in the hierarchical structures of the two applications, and use the function with the highest feature value similarity as the matching function, output the function matching relationship, mark all functions as added, deleted, changed, or the same, and one of the functions marked as changed is regarded as the function where the potential patch is located.

3. The security patch detection method for Android application upgrade according to claim 2 is characterized in that: The member field begins with the identifier ".field", the member method content begins with the identifier ".method" and ends with ".end method".

4. The security patch detection method for Android application upgrade according to claim 2, characterized in that: In the annotation classes of the Smali code, the annotation classes containing nested class relationships are: Ldalvik / annotation / MemberClasses, Ldalvik / annotation / EnclosingClass and Ldalvik / annotation / EnclosingMethod.

5. The security patch detection method for Android application upgrade according to claim 2, characterized in that: The heuristic rules are used to determine whether a class without annotations is a nested class. The rules include: a. It is only called in one class or the class to which it belongs; b. It implements a certain interface; c. A class with a static initialization method has only 1 or 2 member variables, and all of them are static members, one of which is of itself; A class without a static initialization method must have a constructor, and the parameter list of the constructor includes all its members, with the first one in the parameter list being the class to which it belongs.

6. The security patch detection method for Android application upgrade according to claim 2, characterized in that: In the function marking, ① a pair of functions with exactly the same eigenvalues ​​are marked as the same; for functions with different eigenvalues, the similarity of the functions is calculated by the eigenvalues ​​of the basic blocks, that is, the ratio of the sum of the lengths of the basic blocks with the same eigenvalues ​​to the length of the entire function; ② functions whose eigenvalue similarity exceeds 0.2 and is not equal to 1 are considered to be similar functions; Functions with the highest similarity are considered changed; ③ Functions that do not have the same / changed functions in the new version of the application are marked as added; ④ Functions that do not have the same / changed functions in the old version of the application are marked as deleted.

7. The security patch detection method for Android application upgrade according to claim 1, characterized in that: The data dependency relationship includes: direct data dependency and indirect data dependency; the left value variable of the assignment expression has a direct data dependency relationship with all variables used in the right value expression, and the data dependency is transitive. When variable a depends on b, and b depends on c, then c has an indirect data dependency on a; the instructions in the conditional branch statement have a control dependency relationship with the conditional branch statement. When traversing to the branch convergence point, the subsequent instructions have no control dependency relationship with the conditional branch.

8. A system for implementing the security patch detection method for Android application upgrades as described in any one of claims 1 to 7, characterized in that: include: The patch positioning module, the call point analysis module and the patch determination module include: the patch positioning module locates the function where the upgrade patch is located, the call point analysis module locates the call site of the patch function and determines whether it accepts variable parameters, and the patch determination unit determines whether the update of the function is security-related.