The present invention relates generally to computer software, and particularly to automatic detection of security breaches in computer software.
Application-level software code is prone to security vulnerabilities: Sections of the code, when executed, may allow external inputs to cause improper or undesired behavior, which can compromise data privacy and proper system operation. Examples of vulnerabilities include buffer overflow, race conditions, and privilege escalation. Such vulnerabilities may be introduced intentionally by programmers or accidentally, due to improper programming practice.
Methods for detection of software vulnerabilities are known in the art. For example, U.S. Patent Application Publication 2010/0083240, whose disclosure is incorporated herein by reference, describes a tool that automatically analyzes source code for application-level vulnerabilities. Operation of the tool is based on static analysis, but it makes use of a variety of techniques, for example methods of dealing with obfuscated code.
Sequence mining is a type of structured data mining that is concerned with finding statistically relevant patterns in data examples in which values occur in sequence. It may be applied both to strings of symbols and to ordered sequences of items (such as words, phrases, tags, or events).
A variety of sequence mining algorithms are known in the art. For example, the popular GSP algorithm is described by Srikant and Agrawal in “Mining Sequential Patterns: Generalizations and Performance Improvements,” EDBT '96 Proceedings of the 5th International Conference on Extending Database Technology: Advances in Database Technology (Springer-Verlag, 1996), pages 3-17, which is incorporated herein by reference. Another algorithm, known as SPADE, is described by Zaki in “SPADE: An Efficient Algorithm for Mining Frequent Sequences,”Machine Learning 42 (2001), pages 31-60, which is also incorporated herein by reference. Yet another examiner is PrefixSpan, which is described by Pei et al., in “ Mining Sequential Patterns by Pattern-Growth: The PrefixSpan Approach,” IEEE Transactions on Knowledge and Data Engineering 16:10 (2004), pages 1424-1440, which is also incorporated herein by reference. Further algorithms are referenced in the above-mentioned provisional patent application.
Embodiments of the present invention that are described hereinbelow apply sequence mining techniques in order to find patterns in software source code that may be indicative of vulnerabilities.
There is therefore provided, in accordance with an embodiment of the present invention, a method for software code analysis, which includes automatically processing a body of software source code by a computer in order to identify a group of sequences of instructions that are characterized by a common pattern. A sequence is found within the group containing a deviation from a norm of the common pattern. The deviation is reported as a potential vulnerability in the software source code.
In a disclosed embodiment, processing the body of the software code includes creating a document object model (DOM) of the code, and applying the DOM in identifying the sequences.
In some embodiments, processing the body of the software code includes normalizing the code, and identifying the sequences in the normalized code. Typically, normalizing the code includes finding in the code names of entities of a given type, and replacing the names appearing in the code with an indicator of the type. The entities whose names are replaced with the indicator of the type may be variables and/or constants. Additionally or alternatively, when the code is written in an object-oriented language, the entities whose names are replaced may be classes and/or members.
Further additionally or alternatively, normalizing the code may include finding in the code control blocks of a given type, each control block containing lines of the code, and replacing the lines of the code with a series of tags corresponding to the lines of the code in a format that is predefined for the type of the control block.
In disclosed embodiments, processing the body of the software code includes converting the code into a series of tags, and applying a sequence mining algorithm to identify the sequences in the group that occur within the series of the tags.
Typically, the group of the sequences is a stochastic group, which is characterized by the norm and by a distribution of respective distances of the sequences from the norm, and finding the sequence containing the deviation includes finding one or more of the sequences whose respective distances from the norm are beyond a predefined threshold.
The deviation in the sequence may include, for example, a missing operation in the software code, a failure to check a permission to perform a sensitive operation, a failure to follow a prescribed invocation sequence, a backdoor left in the code, or an error in business logic that is implemented in the code.
There is also provided, in accordance with an embodiment of the present invention, apparatus for software code analysis, including a memory, which is configured to store a body of software source code, and a processor, which is configured to automatically process the software source code in order to identify a group of sequences of instructions that are characterized by a common pattern. The processor is configured to find a sequence within the group containing a deviation from a norm of the common pattern, and to report the deviation as a potential vulnerability in the software source code.
There is additionally provided, in accordance with an embodiment of the present invention, a computer software product, including a computer-readable medium in which program instructions are stored, which instructions, when read by a computer, cause the computer to process a body of software source code in order to identify a group of sequences of instructions that are characterized by a common pattern, to find a sequence within the group containing a deviation from a norm of the common pattern, and to report the deviation as a potential vulnerability in the software source code.
The present invention will be more fully understood from the following detailed description of the embodiments thereof, taken together with the drawings in which:
Certain software analysis tools that are known in the art, such as those described in the above-mentioned U.S. Patent Application Publication 2010/0083240, extract and analyze the structure and flow of software code in a manner that enables a user to conveniently search for and identify security breaches. These tools assume, however, that the user knows what to look for, i.e., that problematic patterns of structure and flow can be defined in advance and then searched for in the code structure.
Embodiments of the present invention that are described hereinbelow overcome this limitation by finding potentially-problematic patterns in the code automatically, without requiring a priori definition or even knowledge of the patterns. The disclosed methods use sequence mining tools that are known in the art but have not been applied in the past to analysis of computer software. Generally speaking, sequence mining works best on sequences of symbols or tags that are drawn from a limited alphabet or constellation and are organized in a uniform format. Therefore, in the embodiments disclosed below, the software code is normalized—converted into a corresponding sequence of tags of predefined form—before sequence mining is applied. In the context of the present patent application and in the claims, the term “tag” means a textual label.
In the embodiments that are described hereinbelow, a computer automatically processes a body of software source code using sequence mining to identify one or more groups of sequences of instructions that are characterized by respective common patterns. The patterns need not be defined in advance, but rather may be identified based on the statistical properties of the code (or specifically of the corresponding tag sequence). A group of sequences identified by this sequence mining is typically a stochastic group, meaning that the sequences in the group are statistically similar but not identical. Such a group may be characterized by a norm, corresponding generally to the average pattern in the group, and by a distribution of respective distances of the sequences from the norm. “Distance” in this context typically means an edit distance, such as the Levenshtein distance, corresponding to the number of differences (such as insertions, deletions, and replacements) between the tags in a given sequence and the norm.
To identify possible vulnerabilities, the computer finds sequences in the group that deviate significantly from the norm, i.e., sequences whose respective distances from the norm are beyond a certain threshold (which may be set by the user). These deviations are sometimes indicative of vulnerabilities, such as a failure to carry out the appropriate permission check before performing a sensitive operation; failure to follow a prescribed invocation sequence; backdoors left in the code by a programmer; or errors in business logic that is implemented in the code. The computer reports deviations from the norm of the group as potential vulnerabilities in the software source code.
In some embodiments of the present invention, the normalization process includes “smoothing” certain types of differences between sequences in the code, i.e., substituting a common term or structure for many variants of the same type of term or structure that occur in the code. This process generalizes the code, so that similar sequences become more nearly identical and can then be identified by sequence mining. The level of generalization is chosen so as to facilitate finding meaningful groups of sequences without masking differences that could be indicative of vulnerabilities. The inventor has found, for example, that effective normalization can be performed by finding names of entities of a given type, such as variables, constants, classes and/or members, and replacing the names appearing in the code with an indicator of the type. Additionally or alternatively, the lines of code in control blocks may be replaced with a series of tags in a format that is predefined for the type of the control block.
Although the embodiments that are described herein refer, for the sake of illustration, to certain particular normalization techniques, other applicable code normalization techniques will be apparent to those skilled in the art upon reading the present patent application and are considered to be within the scope of the present invention. The appropriate choice of normalization techniques and of sequence mapping algorithms depends on the nature of the code under analysis and the vulnerabilities of concern, which can be determined by the skilled user in each case on the basis of the present disclosure.
References is now made to
System 20 comprises a processor 22, typically embodied in a general-purpose or special-purpose computer, which is programmed in software to carry out the functions that are described herein. The software may be downloaded to processor 22 in electronic form, over a network, for example. Additionally or alternatively, the software may be provided and/or stored on tangible, non-transitory computer-readable media, such as magnetic, optical, or electronic memory. Further additionally or alternatively, at least some of the functions of processor 22 may be carried out by suitable programmable logic circuits.
Processor 22 receives a body of source code 23 for analysis. The processor activates a code analysis and normalization module 24 (typically implemented as a software module) to pre-process the code in preparation for sequence mining. Module 24 typically derives a document object model (DOM) and flow graphs of the code, at a code analysis step 40. The flow graphs may include a data flow graph (DFG), a control flow graph (CFG), and a control dependence graph (CDG). Derivation of the DOM and these graphs is described, for example, in U.S. Patent Application Publication 2010/0083240. Processor 22 stores the analysis results in a memory 26, typically in the form of a database to enable convenient access to the data thereafter.
Listing I in Appendix A below presents a source code listing of a simple function, which is used in illustrating DOM construction and subsequent normalization, in accordance with an embodiment of the present invention. The resulting DOM is presented in Listing II in Appendix A. The remaining listings show successive stages in normalization of the DOM, as explained below.
Module 24 normalizes the source code, at a normalization step 42. The normalization may be applied to the code itself or to the DOM (or both); and for the sake of simplicity and completeness, all of these forms of normalization are referred to herein as code normalization, and the term “normalized code” refers the normalized form of the source code itself or of any derivative of the source code, including the DOM. Optionally, elements of the flow graphs may be normalized for sequence mining, as well.
A sequence mining module 28 scans over the normalized code to find stochastic sequence patterns, at a sequence mining step 44. Module 28 may use any suitable sequence mining algorithm or combination of algorithms that is known in the art. Examples of such algorithms include the GSP, SPADE and PrefixSpan algorithms that are mentioned in the Background section above, as well as SPAM, LAPIN, CloSpan and BIDE. (Java™ code implementing a number of these algorithms is available for download from the SPMF Web site.) Typically at step 44, module 28 processes the normalized DOM that was created in steps 40 and 42. Alternatively or additionally, module 28 may process the source code and/or one or more of the flow graphs.
Sequence mining module 28 identifies groups of sequences of instructions that are characterized by common patterns. Users of system 20 may typically set the radius of the groups that module is to find, i.e., the maximum difference (using appropriate distance measures) between members of a given group. Within each such group, module 28 may find one or more sequences that deviate from the norm of the common pattern in the group by more than a given threshold, which may likewise be set by the user. Appendix B below presents further details and an example of sequence mining techniques that may be used in this context.
Module 28 reports these deviations via an output device 30, such as a data display, at a reporting step 46. The report may simply comprise an identification of the code segments that are suspected as potential vulnerabilities in the source code, leaving the job of understanding and repairing the vulnerabilities to the user of system 20. Additionally or alternatively, module 28 may analyze the deviant patterns further in order to point out the specific flaws in the deviant sequences.
Normalization step 42 typically includes a number of different operations on the code. For example, names, values, assignments and conditions in the code may be normalized as follows:
As another part of the normalization process, control statements in the code are recast in a format that is predefined for each type of control block, so that each control block is represented as a sequence of tags with a consistent format. For example, if statements of the form:
if (<cond>) <then> else <else>;
can be recast as tag sequences in the following format:
<cond>, IF, <then>, ELSE, <else>, END-IF
(as illustrated by the sequence of tags “IF . . . ELSE . . . END-IF” within sequence 72 in
As another example,
for (<init>; <cond>; <inc>) <body>;
is recast as the corresponding tag sequence 50:
<init>, <cond>, LOOP, <body>, <inc>, <cond>, END-LOOP.
<cond>, LOOP, <body>, <cond>, END-LOOP.
Sequence 62 also illustrates normalization of an if statement and conversion of names and constants to types, as described above. For instance, the variable expression “int d=0” in segment 60 is converted into the tag “int=ZERO” in sequence 62.
Although the examples shown in the figures illustrate normalization of actual source code, in practice these normalization techniques may typically be applied to the DOM that is created from the source code. Converting control blocks into tag sequences has the effect of flattening the initial hierarchical structure of the DOM. Listing IV shows the effect of applying this sort of flattening to the control statements in the DOM of Listings II and III.
The normalization rules (some of which are illustrated in
The normalization rules for member names (also illustrated in
Once the above normalization steps have been performed on the DOM derived from the software source code, the DOM is effectively flattened into a sequence of tags, in place of its original hierarchical, functional structure. Listing V in Appendix A shows this sort of fully-flattened DOM.
The inventor has found sequence mining on a normalized DOM to be effective in detecting a variety of code vulnerabilities, including (but not limited to) the following examples:
It will be appreciated that the embodiments described above are cited by way of example, and that the present invention is not limited to what has been particularly shown and described hereinabove. Rather, the scope of the present invention includes both combinations and subcombinations of the various features described hereinabove, as well as variations and modifications thereof which would occur to persons skilled in the art upon reading the foregoing description and which are not disclosed in the prior art.
As a preliminary to sequence mining of a tag sequence derived from software code, the operator of system 20 defines three “constants” (parameter values):
Suppose a body of code contains the sequences listed in the table below: The code sequence “f1( ); f2( ); f3( );” appears 80 times in the code; the sequence “f1( ); f4( ); f2( ); f3( );” appears 20 times; and so forth:
To process these sequences, sequence mining module 28 first finds the number of times each (sub)sequence appear. The module may start with single-item sequences:
According to the “a-priori” rule, a sequence cannot appear more times than any of its sub-sequences. (For example, a sequence that contains F5( ) cannot appear more times than F5( ) itself) Thus, module 28 can eliminate all sub-sequences that do not meet our defined support level (60), leaving the following:
Now, module 28 builds all possible two-items sequences based on the above items. In this context:
A. Order does matter.
B. The two items do not have to be adjacent.
Removing zeros, module 28 is left with:
Since we defined the minimum-length as 3, and our sequences so far are only of length 2, module 28 repeats the sequence-building step again to obtain:
Thus, the only common sequence that meets both the support and minimal length criteria is f1( ), f2( ), f3( ).
Returning now to the original table, module 28 filters instances of the common sequence f1( ), f2( ), f3( ) whose confidence is lower than the preset value:
Out of the 100 occurrences of the sequence (f1-f2-f3), 20% have f4 between the first two items, while 80% do not. Therefore, the sequence f1-f4-f2-f3 contains a common-sequence, but does not meet the confidence level we defined. Consequently, module 28 will identify this latter sequence as a deviation, which may be indicative of a vulnerability in the software code.
This application claims the benefit of U.S. Provisional Patent Application 61/376,260, filed Aug. 24, 2010, which is incorporated herein by reference.
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/IB2011/053671 | 8/22/2011 | WO | 00 | 1/20/2013 |
Publishing Document | Publishing Date | Country | Kind |
---|---|---|---|
WO2012/025865 | 3/1/2012 | WO | A |
Number | Name | Date | Kind |
---|---|---|---|
5107418 | Cramer et al. | Apr 1992 | A |
5485616 | Burke et al. | Jan 1996 | A |
5586328 | Caron et al. | Dec 1996 | A |
5586330 | Knudsen et al. | Dec 1996 | A |
5701489 | Bates et al. | Dec 1997 | A |
5742811 | Agrawal et al. | Apr 1998 | A |
5778233 | Besaw et al. | Jul 1998 | A |
5790858 | Vogel | Aug 1998 | A |
5875334 | Chow et al. | Feb 1999 | A |
5881290 | Ansari et al. | Mar 1999 | A |
5978588 | Wallace | Nov 1999 | A |
6442748 | Bowman-Amuah | Aug 2002 | B1 |
7210133 | Souloglou et al. | Apr 2007 | B2 |
7284274 | Walls et al. | Oct 2007 | B1 |
7363616 | Kalyanaraman | Apr 2008 | B2 |
7392545 | Weber et al. | Jun 2008 | B1 |
7447666 | Wang | Nov 2008 | B2 |
7565631 | Banerjee et al. | Jul 2009 | B1 |
7860842 | Bronnikov et al. | Dec 2010 | B2 |
7971193 | Li et al. | Jun 2011 | B2 |
8510237 | Cascaval et al. | Aug 2013 | B2 |
8881288 | Levy et al. | Nov 2014 | B1 |
8949271 | Kocher et al. | Feb 2015 | B2 |
20020178281 | Aizenbud-Reshef et al. | Nov 2002 | A1 |
20030056192 | Burgess | Mar 2003 | A1 |
20040255277 | Berg et al. | Dec 2004 | A1 |
20050015752 | Alpern et al. | Jan 2005 | A1 |
20050198626 | Kielstra et al. | Sep 2005 | A1 |
20050204344 | Shinomi | Sep 2005 | A1 |
20050273861 | Chess et al. | Dec 2005 | A1 |
20060070048 | Li et al. | Mar 2006 | A1 |
20060085858 | Noel et al. | Apr 2006 | A1 |
20060253841 | Rioux | Nov 2006 | A1 |
20060282453 | Tjong et al. | Dec 2006 | A1 |
20070006170 | Hasse et al. | Jan 2007 | A1 |
20070083933 | Venkatapathy et al. | Apr 2007 | A1 |
20070143759 | Ozgur et al. | Jun 2007 | A1 |
20070294281 | Ward et al. | Dec 2007 | A1 |
20090187992 | Poston | Jul 2009 | A1 |
20090254572 | Redlich et al. | Oct 2009 | A1 |
20100011441 | Christodorescu et al. | Jan 2010 | A1 |
20100043072 | Rothwell | Feb 2010 | A1 |
20100050260 | Nakakoji et al. | Feb 2010 | A1 |
20100083240 | Siman | Apr 2010 | A1 |
20100088770 | Yerushalmi et al. | Apr 2010 | A1 |
20100229239 | Rozenberg et al. | Sep 2010 | A1 |
20100251210 | Amaral et al. | Sep 2010 | A1 |
20100279708 | Lidsrom et al. | Nov 2010 | A1 |
20110004631 | Inokuchi et al. | Jan 2011 | A1 |
20120240185 | Kapoor et al. | Sep 2012 | A1 |
20130167241 | Siman | Jun 2013 | A1 |
20150013011 | Brucker et al. | Jan 2015 | A1 |
Number | Date | Country |
---|---|---|
2200812 | Sep 1998 | CA |
2003050722 | Feb 2003 | JP |
2005121953 | Dec 2005 | WO |
Entry |
---|
European Application # 11819494.3 Search Report dated Apr. 4, 2014. |
Zhenmin et al, “PR-Miner: Automatically Extracting Implicit Programming Rules and Detecting Violations in Large Software Code”, ACM Sigsoft Software Engineering Notes, vol. 30, No. 5, pp. 306-315, Sep. 1, 2005. |
Thummalapenta et al, “Alattin: Mining Alternative Patterns for detecting Neglected Conditions”, 24th IEEE/ACM International Conference on IEEE Automated Software Engineering, pp. 283-294, Nov. 16, 2009. |
Kim et al, “Supporting software development through declaratively codified programming patterns”, Expert Systems with Applications, vol. 23, No. 4, pp. 405-413, Nov. 1, 2002. |
U.S. Appl. No. 12/443,824 office action dated Aug. 22, 2013. |
U.S. Appl. No. 13/772,377 office action dated Sep. 25, 2013. |
Skedzielewski et al., “Data flow graph optimization in IF1”, Functional programming languages and computer architecture (book), publisher Springer Berlin Heidelberg, pp. 17-34, year 1985. |
SAP, Java web application security best practice guide, SAP,Document version 2.0, pp. 1-48, May 2006. |
Siman, M., International Application PCT/IB2013/058741 filed Sep. 22, 2013. |
International Application PCT/IL2007/001233 Search Report dated Aug. 27, 2008. |
Sreedhar et al., “A New Framework for Elimination-Based Data Flow Analysis Using DJ Graphs”, ACM Transactions on Programming Languages and Systems, vol. 20, No. 2, pp. 368-407, Mar. 1998. |
Helmer et al., “A Software Fault Tree Approach to Requirements Analysis of an Intrusion Detection System”, 1st Symposium on Requirements Engineering for Information Security, Indianapolis, Indiana, USA, Mar. 5-6, 2001. |
Redgate, “.NET Reflector: Explore, Browse, and Analyze .NET assemblies”, 2009 (www.red-gate.com/productors/reflector). |
European Patent Application # 07827207.7 Search Report dated Sep. 29, 2011. |
Srikant et al., “Mining Sequential Patterns: Generalizations and Performance Improvements”, EDBT '96 Proceedings of the 5th International Conference on Extending Database Technology: Advances in Database Technology, pp. 3-17, Avignon, France, Mar. 25-29, 1996. |
Zaki, M., “SPADE: An Efficient Algorithm for Mining Frequent Sequences”, Machine Learning, vol. 42, pp. 31-60, year 2001. |
Pei et al., in “Mining Sequential Patterns by Pattern-Growth: The PrefixSpan Approach,” IEEE Transactions on Knowledge and Data Engineering, vol. 16, No. 10, pp. 1424-1440, Oct. 2004. |
Martin et al., “Finding Application Errors and Security Flaws Using PQL: a Program Query Language”, OOPSLA'05, pp. 365-383, San Diego, USA, Oct. 16-20, 2005. |
Yang et al., “Effective Sequential Pattern Mining Algorithms for Dense Database”, National Data Engineering Workshops (DEWS), year 2006. |
Ayres et al., “Sequential Pattern Mining using A Bitmap Representation”, Proceedings of the eighth ACM SIGKDD international conference on Knowledge discovery and data mining, Edmonton, Canada, Jul. 23-26, 2002. |
Wang et al., “BIDE: Efficient Mining of Frequent Closed Sequence”, Proceedings of 2010 International Conference on Information Retrieval & Knowledge Management, pp. 270-275, Sham Alam, Selangor, Mar. 17-18, 2010. |
Yan et al., “CloSpan: Mining Closed Sequential Patterns in Large Datasets”, Proceedings of 2003 SIAM International Conference on Data Mining, San Francisco, USA, May 1-3, 2003. |
Japanese Patent Application # 2009532956 Official Action dated Mar. 21, 2012. |
International Application PCT/IB2011/053671 Search Report dated Jan. 9, 2012. |
U.S. Appl. No. 12/443,824 Official Action dated Dec. 19, 2012. |
U.S. Appl. No. 12/443,824 Official Action dated Apr. 6, 2012. |
U.S. Appl. No. 12/443,824 Official Action dated Oct. 11, 2011. |
Lange et al., “Comparing Graph-based Program Comprehension Tools to Relational Database-based Tools”, IEEE 0-7695-1131-7/01, pp. 209-218, year 2001. |
Beyer et al., “The BLAST Query Language for Software Verification”, Springer-Verlag Berlin Heidelberg, pp. 2-18, year 2004. |
Pingali et al., “Optimal Control Dependence Computation and the Roman Chariots Problem”, ACM Transactions on Programming Languages and Systems, vol. 19, No. 3, pp. 462-485, May 1997. |
Siman, M., U.S. Appl. No. 61/705,157, filed Sep. 25, 2012. |
Ford et al., “Analyzing and Detecting Malicious Flash Advertisements”, Proceedings of ACSAC '09—Annual Computer Security Applications Conference, pp. 363-372, Honolulu, Hawaii, Dec. 7-11, 2009. |
“Design flaw in AS3 socket handling allows port probing”, 2 pages, Oct. 15, 2008 (downloaded from http://scan.flashsec.org/). |
Symantec Corporation, “Symantec Ad Vantage: Dynamic Anti-Malvertising Solution”, Data Sheet, 4 pages, year 2012. |
“Zero-day attack”, 4 pages, year 2008 (downloaded from http://en.wikipedia.org/wiki/Zero-day—attack). |
Ashish et al., “Network Intrusion Detection Sequence mining—stide methodology”, IT 608, Data Mining and Warehousing, Indian Institute of Technology, 8 pages, Apr. 20, 2005. |
Ford et al., “Analyzing and Detecting Malicious Flash Advertisements”, ACSAC Proceedings of the 2009 Annual Computer Security Applications Conference, pp. 363-372 , 2009. |
Yamada et al., “A defect Detection Method for Object-Oriented Programs using Sequential Pattern Mining”, vol. 2009-CSEC-45, pp. 1-8, Jun. 15, 2009. |
JP Patent Application # 2013-525394 Office Action dated Jun. 3, 2015. |
Yamada et al., “A defect Detection Method for Object-Oriented Programs using Sequential Pattern Mining”, Information Processing Society of Japan (IPSJ) SIG Technical Report, vol. 2009-CSEC-45, pp. 1-8, Jun. 15, 2009. |
Number | Date | Country | |
---|---|---|---|
20130239219 A1 | Sep 2013 | US |
Number | Date | Country | |
---|---|---|---|
61376260 | Aug 2010 | US |