"Efficient and Flexible Discovery of PHP Application Vulnerabilities"

"Efficient and Flexible Discovery of PHP Application Vulnerabilities"

Efficient and Flexible Discovery of PHP Application Vulnerabilities Michael Backes∗y, Konrad Rieckz, Malte Skoruppa∗, Ben Stock∗, Fabian Yamaguchiz ∗CISPA, Saarland University yMax Planck Institute for Software Systems Saarland Informatics Campus Saarland Informatics Campus Email: fbackes, skoruppa, [email protected] zBraunschweig University of Technology Email: fk.rieck, [email protected] Abstract—The Web today is a growing universe of pages and Web, PHP therefore constitutes a prime target for automated applications teeming with interactive content. The security of security analyses to assist developers in avoiding critical such applications is of the utmost importance, as exploits can mistakes and consequently improve the overall security of have a devastating impact on personal and economic levels. applications on the Web. Indeed, a considerable amount of The number one programming language in Web applications is research has been dedicated to identifying vulnerable infor- PHP, powering more than 80% of the top ten million websites. mation flows in a machine-assisted manner [15, 16,4,5]. Yet it was not designed with security in mind and, today, All these approaches successfully identify different types bears a patchwork of fixes and inconsistently designed func- of PHP vulnerabilities in Web applications. However, all of tions with often unexpected and hardly predictable behavior these approaches have only been evaluated in a controlled that typically yield a large attack surface. Consequently, it environment of about half a dozen projects. Therefore it is is prone to different types of vulnerabilities, such as SQL unclear how scalable they are and how well they perform Injection or Cross-Site Scripting. In this paper, we present in much less controlled environments of very large sets of an interprocedural analysis technique for PHP applications arbitrary PHP projects. (See Section 7 on related work for based on code property graphs that scales well to large amounts details). In addition, these approaches are hardly customiz- of code and is highly adaptable in its nature. We implement able, in the sense that they cannot be configured to look for our prototype using the latest features of PHP 7, leverage an various different kinds of vulnerabilities. efficient graph database to store code property graphs for PHP, The research question of how to detect PHP applica- and subsequently identify different types of Web application tion vulnerabilities at large scale in an efficient manner, vulnerabilities by means of programmable graph traversals. whilst maintaining an acceptable precision and the ability We show the efficacy and the scalability of our approach by to customize the detection process as needed, has received reporting on an analysis of 1,854 popular open-source projects, significantly less attention so far. Yet it is a question that is crucial to cope with, given the rapidly increasing number of comprising almost 80 million lines of code. Web applications. 1. Introduction Our Contributions. We propose a highly scalable and flexible approach for analyzing PHP applications that may The most popular and widely deployed language for consist of millions of lines of code. To this end, we leverage Web applications is undoubtedly PHP, powering more than the recently proposed concept of code property graphs [35]: 80% of the top ten million websites [29], including widely These graphs constitute a canonical representation of code used platforms such as Facebook, Wikipedia, Flickr, or incorporating a program’s syntax, control flow, and data Wordpress, and contributing to almost 140,000 open-source dependencies in a single graph structure, which we further projects on GitHub [38]. Yet from a security standpoint, enrich with call edges to allow for interprocedural analysis. the language is poorly designed: It typically yields a large These graphs are then stored in a graph database that lays attack surface (e.g., every PHP script on a server can po- the foundation for efficient and easily programmable graph tentially be used as an entry point by an attacker) and bears traversals amenable to identifying flaws in program code. inconsistently designed functions with often surprising side As we show in this paper, this approach is well-suited effects [22], all of which a programmer must be aware of to discover vulnerabilities in high-level, dynamic scripting and keep in mind while developing a PHP application. languages such as PHP at a large scale. In addition, it is As a result of its confusing and inconsistent APIs, PHP is highly flexible: The bulk work of generating code property particularly prone to programming mistakes that may lead to graphs and importing them into a database is done in a Web application vulnerabilities such as SQL injections and fully automated manner. Subsequently, an analyst can write Cross-Site Scripting. Combined with its prevalence on the traversals to query the database as desired so as to find var- ious kinds of vulnerabilities: For instance, one may look to CFGs, PDGs, and call graphs. In Section 3, we present detect common code patterns or look for specific flows from a conceptual overview of our approach, follow up with given types of attacker-controller sources to given security- the necessary techniques to represent and query PHP code critical function calls that are not appropriately sanitized; property graphs in a graph database, and discuss how typical what sources, sinks, and sanitizers are to be considered may classes of vulnerabilities can be modeled using traversals. be easily specified and adapted as needed. Subsequently, Section 4 presents the implementation of our We show how to model typical Web application vulner- approach, while Section 5 presents the evaluation of our abilities using such graph traversals that can be efficiently large-scale study. Following this, Section 6 discusses our run by the database backend. We evaluate our approach on technique, Section 7 presents related work, and Section 8 a set of 1,854 open-source PHP projects on GitHub. Our concludes. three main contributions are as follows: • Introduction of PHP code property graphs. We are the 2. Code Property Graphs first to employ the concept of code property graphs for a high-level, dynamic scripting language such as Our work builds on the concept of code property graphs, PHP. We implement code property graphs for PHP a joint representation of a program’s syntax, control flow, using static analysis techniques and additionally aug- and data flow, first introduced by Yamaguchi et al. [35] ment them with call edges to allow for interprocedural to discover vulnerabilities in C code. The key idea of this analysis. These graphs are stored in a graph database approach is to merge classic program representations into that can subsequently be used for complex queries. a so-called code property graph, which makes it possible The generation of these graphs is fully automated, that to mine code for patterns via graph traversals. In particular, is, all that users have to do to implement their own syntactical properties of code are derived from abstract syn- interprocedural analyses is to write such queries. We tax trees, control flow from control flow graphs, and finally, make our implementation publicly available to facilitate data flow from program dependence graphs. In addition, independent research. we enrich the resulting structure with call graphs so as to • Modeling Web application vulnerabilities. We show enable interprocedural analysis. In this section, we briefly that code property graphs can be used to find typi- review these concepts to provide the reader with technical cal Web application vulnerabilities by modeling such background required for the remainder of the paper. flaws as graph traversals, i.e., fully programmable al- We consider the PHP code listing shown in Figure 1 as a gorithms that travel along the graph to find specific pat- running example. For the sake of illustration, it suffers from terns. These patterns are undesired flows from attacker- a trivial SQL injection vulnerability. Using the techniques controlled input to security-critical function calls with- presented in this paper, this vulnerability can be easily out appropriate sanitization routines. We detail such discovered. patterns precisely for attacks targeting both server and client, such as SQL injections, command injections, 2.1. Abstract Syntax Trees (AST) code injections, arbitrary file accesses, cross-site script- ing and session fixation. While these graph traversals demonstrate the feasibility of our technique, we em- Abstract syntax trees are a representation of program phasize that more traversals may easily be written by syntax commonly generated by compiler frontends. These PHP application developers and analysts to detect other trees offer a hierarchical decomposition of code into its kinds of vulnerabilities or patterns in program code. syntactical elements. The trees are abstract in the sense that they do not account for all nuances of concrete program • Large-scale evaluation. To evaluate the efficacy of our approach, we report on a large-scale analysis of 1,854 formulation, but only represent how programming constructs popular PHP projects on GitHub totaling almost 80 mil- are nested to form the final program. For instance, whether lion lines of code. In our analysis, we find that our variables are declared as part of a declaration list or as a approach scales well to the size of the analyzed code. consecutive chain of declarations is a detail in the formula- In total, we found 78 SQL injection vulnerabilities, tion that does not lead to different abstract syntax trees. 6 command injection vulnerabilities, 105 code injection vulnerabilities, 6 vulnerabilities allowing an attacker to <?php access arbitrary files on the server, and one session fixa- function foo() { tion vulnerability. XSS vulnerabilities are very common $x= $_GET["id"]; and our tool generated a considerable number of reports in our large-scale evaluation for this class of attack. if(isset($x)) { $sql= "SELECT * FROM users We inspected only a small sample (under 2%) of these WHERE id = '$x'"; reports and found 26 XSS vulnerabilities.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us