Finding Security Vulnerabilities in Java Applications with Static Analysis Benjamin Livshits and Monica S. Lam Stanford University.

Slides:



Advertisements
Similar presentations
Web 2.0 Programming 1 © Tongji University, Computer Science and Technology. Web Web Programming Technology 2012.
Advertisements

1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 1 Introduction to Perl and CGI.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Runtime Prevention & Recovery Protect existing applications Advantages: Prevents vulnerabilities from doing harm Safe mode for Web application execution.
Nick Feamster CS 6262 Spring 2009
SecuBat: An Automated Web Vulnerability Detection Framework
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
All You Ever Wanted to Know About Dynamic Taint Analysis & Forward Symbolic Execution (but might have been afraid to ask) Edward J. Schwartz, ThanassisAvgerinos,
Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
Incident Handling & Log Analysis in a Web Driven World Manindra Kishore.
Configuration management
What is code injection? Code injection is the exploitation of a computer bug that is caused by processing invalid data. Code injection can be used by.
Page 1 of 30 To the Create Assignment Request Online Training Course An assignment request is created by an assignor to initiate the electronic assignment.
ITEC200 Week04 Lists and the Collection Interface.
MySQL Access Privilege System
Social Web Design 1 Darby Chang Social Web Design.
Molecular Biomedical Informatics Web Programming 1.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Closing the Gap: Analyzing the Limitations of Web Application Vulnerability Scanners David Shelly Randy Marchany Joseph Tront Virginia Polytechnic Institute.
The World Wide Web. 2 The Web is an infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that.
© 2008 Security Compass inc. 1 Firefox Plug-ins for Application Penetration Testing Exploit-Me.
Chapter 10 Software Testing
HI-TEC 2011 SQL Injection. Client’s Browser HTTP or HTTPS Web Server Apache or IIS HTML Forms CGI Scripts Database SQL Server or Oracle or MySQL ODBC.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Infosec 2012 | 25/4/12 Application Performance Monitoring Ofer MAOR CTO Infosec 2012.
Xiao Zhang and Wenliang Du Dept. of Electrical Engineering & Computer Science Syracuse University.
GATEKEEPER MOSTLY STATIC ENFORCEMENT OF SECURITY AND RELIABILITY PROPERTIES FOR JAVASCRIPT CODE Salvatore Guarnieri & Benjamin Livshits Presented by Michael.
Creating Stronger, Safer, Web Facing Code JPL IT Security Mary Rivera June 17, 2011.
Finding Security Errors in Java Applications Using Lightweight Static Analysis Benjamin Livshits Computer Science Lab Stanford University.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
ReferencesReferences DiscussionDiscussion Vulnerability Example: SQL injection Auditing Tool for Eclipse LAPSE: a Security Auditing Tool for Eclipse IntroductionIntroductionResultsResults.
1 Static Analysis for Bug Finding Benjamin Livshits.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
It’s always better live. MSDN Events Securing Web Applications Part 1 of 2 Understanding Threats and Attacks.
Chapter 6: Hostile Code Guide to Computer Network Security.
Secure Software Engineering: Input Vulnerabilities
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
AMNESIA: Analysis and Monitoring for NEutralizing SQL- Injection Attacks Published by Wiliam Halfond and Alessandro Orso Presented by El Shibani Omar CS691.
Computer Security and Penetration Testing
OSI and TCP/IP Models And Some Vulnerabilities AfNOG th May 2011 – 10 th June 2011 Tanzania By Marcus K. G. Adomey.
Attacking Applications: SQL Injection & Buffer Overflows.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Web Application Security ECE ECE Internetwork Security What is a Web Application? An application generally comprised of a collection of scripts.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
OWASP Top Ten #1 Unvalidated Input. Agenda What is the OWASP Top 10? Where can I find it? What is Unvalidated Input? What environments are effected? How.
Attacking Data Stores Brad Stancel CSCE 813 Presentation 11/12/2012.
October 3, 2008IMI Security Symposium Application Security through a Hacker’s Eyes James Walden Northern Kentucky University
nd Joint Workshop between Security Research Labs in JAPAN and KOREA Marking Scheme for Semantic- aware Web Application Security HPC.
Web Applications Testing By Jamie Rougvie Supported by.
Building Secure Web Applications With ASP.Net MVC.
Finding Security Vulnerabilities in Java Applications with Static Analysis Reviewed by Roy Ford.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
Michael Dalton, Christos Kozyrakis, and Nickolai Zeldovich MIT, Stanford University USENIX 09’ Nemesis: Preventing Authentication & Access Control Vulnerabilities.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Example – SQL Injection MySQL & PHP code: // The next instruction prompts the user is to supply an ID $personID = getIDstringFromUser(); $sqlQuery = "SELECT.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
Database and Cloud Security
SQL Injection.
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Module 30 (Unix/Linux Security Issues II)
Static Detection of Cross-Site Scripting Vulnerabilities
A Security Review Process for Existing Software Applications
Marking Scheme for Semantic-aware Web Application Security
CS5123 Software Validation and Quality Assurance
Lecture 34: Testing II April 24, 2017 Selenium testing script 7/7/2019
Presentation transcript:

Finding Security Vulnerabilities in Java Applications with Static Analysis Benjamin Livshits and Monica S. Lam Stanford University

SecurityFocus.com Vulnerabilities… 1. PHPList Admin Page SQL Injection Vulnerability 2. Fetchmail POP3 Client Buffer Overflow Vulnerability 3. Zlib Compression Library Buffer Overflow Vulnerability 4. NetPBM PSToPNM Arbitrary Code Execution Vulnerability 5. OpenLDAP TLS Plaintext Password Vulnerability 6. Perl RMTree Local Race Condition Vulnerability 7. Perl Local Race Condition Privilege Escalation Vulnerability 8. Vim ModeLines Further Variant Arbitrary Command Execution Vulnerability 9. Zlib Compression Library Decompression Buffer Overflow Vulnerability 10. Jabber Studio JabberD Multiple Remote Buffer Overflow Vulnerabilities 11. Netquery Multiple Remote Vulnerabilities 12. Multiple Vendor Telnet Client LINEMODE Sub-Options Remote Buffer Overflow Vulnerability 13. Apache mod_ssl SSLCipherSuite Restriction Bypass Vulnerability 14. Multiple Vendor Telnet Client Env_opt_add Heap-Based Buffer Overflow Vulnerability 15. MySQL Eventum Multiple Cross-Site Scripting Vulnerabilities 16. MySQL Eventum Multiple SQL Injection Vulnerabilities 17. AderSoftware CFBB Index.CFM Cross-Site Scripting Vulnerability 18. Cisco IOS IPv6 Processing Arbitrary Code Execution Vulnerability 19. ChurchInfo Multiple SQL Injection Vulnerabilities 20. PHPFreeNews Multiple Cross Site Scripting Vulnerabilities 21. Nullsoft Winamp Malformed ID3v2 Tag Buffer Overflow Vulnerability 22. PHPFreeNews Admin Login SQL Injection Vulnerability 23. Apple Mac OS X Font Book Font Collection Buffer Overflow Vulnerability 24. OpenBook Admin.PHP SQL Injection Vulnerability 25. PowerDNS LDAP Backend Query Escape Failure Vulnerability 26. PowerDNS Recursive Query Denial of Service Vulnerability 27. ProFTPD Shutdown Message Format String Vulnerability 28. ProFTPD SQLShowInfo SQL Output Format String Vulnerability 29. Info-ZIP UnZip Privilege Escalation Vulnerability 30. Trend Micro OfficeScan POP3 Module Shared Section Insecure Permissions Vulnerability August 1 st 2005

Buffer Overrun in zlib (August 1 st, 2005)

SecurityFocus.com Vulnerabilities… 1. PHPList Admin Page SQL Injection Vulnerability 2. Fetchmail POP3 Client Buffer Overflow Vulnerability 3. Zlib Compression Library Buffer Overflow Vulnerability 4. NetPBM PSToPNM Arbitrary Code Execution Vulnerability 5. OpenLDAP TLS Plaintext Password Vulnerability 6. Perl RMTree Local Race Condition Vulnerability 7. Perl Local Race Condition Privilege Escalation Vulnerability 8. Vim ModeLines Further Variant Arbitrary Command Execution Vulnerability 9. Zlib Compression Library Decompression Buffer Overflow Vulnerability 10. Jabber Studio JabberD Multiple Remote Buffer Overflow Vulnerabilities 11. Netquery Multiple Remote Vulnerabilities 12. Multiple Vendor Telnet Client LINEMODE Sub-Options Remote Buffer Overflow Vulnerability 13. Apache mod_ssl SSLCipherSuite Restriction Bypass Vulnerability 14. Multiple Vendor Telnet Client Env_opt_add Heap-Based Buffer Overflow Vulnerability 15. MySQL Eventum Multiple Cross-Site Scripting Vulnerabilities 16. MySQL Eventum Multiple SQL Injection Vulnerabilities 17. AderSoftware CFBB Index.CFM Cross-Site Scripting Vulnerability 18. Cisco IOS IPv6 Processing Arbitrary Code Execution Vulnerability 19. ChurchInfo Multiple SQL Injection Vulnerabilities 20. PHPFreeNews Multiple Cross Site Scripting Vulnerabilities 21. Nullsoft Winamp Malformed ID3v2 Tag Buffer Overflow Vulnerability 22. PHPFreeNews Admin Login SQL Injection Vulnerability 23. Apple Mac OS X Font Book Font Collection Buffer Overflow Vulnerability 24. OpenBook Admin.PHP SQL Injection Vulnerability 25. PowerDNS LDAP Backend Query Escape Failure Vulnerability 26. PowerDNS Recursive Query Denial of Service Vulnerability 27. ProFTPD Shutdown Message Format String Vulnerability 28. ProFTPD SQLShowInfo SQL Output Format String Vulnerability 29. Info-ZIP UnZip Privilege Escalation Vulnerability 30. Trend Micro OfficeScan POP3 Module Shared Section Insecure Permissions Vulnerability August 1 st /30=73% of vulnerabilities are due to input validation

Input Validation in Web Apps Lack of input validation: #1 source of security errors Buffer overruns One of the most notorious Occurs in C/C++ programs Common in server-side daemons Web applications are a common attack target Easily accessible to attackers, especially on public sites Java – common development language Many large apps written in Java Modern language – no buffer overruns But can still have input validation vulnerabilities

Simple Web App A Web form that allows the user to look up account details Underneath – a Java Web application serving the requests

SQL Injection Example Happy-go-lucky SQL statement: Leads to SQL injection One of the most common Web application vulnerabilities caused by lack of input validation But how? Typical way to construct a SQL query using string concatenation Looks benign on the surface But lets play with it a bit more… String query = SELECT Username, UserID, Password FROM Users WHERE username = + user + AND password = + password;

Injecting Malicious Data (1) query = SELECT Username, UserID, Password FROM Users WHERE Username = 'bob' AND Password = ******** Press Submit

Injecting Malicious Data (2) query = SELECT Username, UserID, Password FROM Users WHERE Username = 'bob-- AND Password = Press Submit

Injecting Malicious Data (3) query = SELECT Username, UserID, Password FROM Users WHERE Username = 'bob; DROP Users-- AND Password = Press Submit

Heart of the Issue: Tainted Input Data Web App hacker browser application evil input database output input evil Insert input checking! cross-site scripting SQL injections

Outline Application-level vulnerabilities More kinds of vulnerabilities Existing strategies Our static analysis system Results & Conclusions

Attacks Techniques 1. Inject (taint sources) Parameter manipulation Hidden field manipulation Header manipulation Cookie poisoning 2. Exploit (taint sinks) SQL injections Cross-site scripting HTTP request splitting Path traversal Command injection 1. Header manipulation + 2. HTTP splitting = vulnerability See the paper for more information on these

Related Work: Runtime Techniques Client-side validation Done using JavaScript in the browser Can be easily circumvented! Runtime techniques (application firewalls) Input filters – very difficult to make complete Dont work for many types of vulnerabilities

Related Work: Static Techniques Manual code reviews Effective – find errors before they manifest Very labor-intensive and time-consuming Automatic techniques Metal by Dawson Englers group at Stanford PreFix used within Microsoft Unsound! May miss potential vulnerabilities Can never guarantee full security Automate code review process with static analysis Develop a sound analysis

Summary of Contributions Unification: Formalize existing vulnerabilities within a unified framework Extensibility: Users can specify their own new vulnerabilities Soundness: Guaranteed to find all vulnerabilities captured by the specification Precision: Introduce static analysis improvements to further reduce false positives Results: Finds many bugs, few false positives

Outline Application-level attacks Our static analysis system Detecting vulnerabilities statically Pointer analysis Specifying vulnerabilities using PQL: sources, sinks... Results & Conclusions

Why Pointer Analysis? // get Web form parameter String param = request.getParameter(…); // execute query con.executeQuery(query); Can these variables refer to the same object? Imagine manually auditing an application Two statements somewhere in the program Question answered by pointer analysis

Pointers in Java? Yes, remember the NullPointerException ? Java references are pointers in disguise ? ? ? Stack Heap

What Does Pointer Analysis Do for Us? Statically, the same object can be passed around in the program: Passed in as parameters Returned from functions Deposited to and retrieved from data structures All along it is referred to by different variables Pointer analysis summarizes these operations: Doesnt matter what variables refer to it We can follow the object throughout the program

Pointer Analysis Background Question: Determine what objects a given variable may refer to A classic compiler problem for over 20 years Our goal is to have a sound approach If there is a vulnerability at runtime, it will be detected statically No false negatives Until recently, sound analysis implied lack of precision We want to have both soundness and precision Context-sensitive inclusion-based analysis by Whaley and Lam [PLDI04] Recent breakthrough in pointer analysis technology An analysis that is both scalable and precise Context sensitivity greatly contributes to the precision

Importance of Context Sensitivity (1) String id(String str) { return str; } c1c1 c2c2 tainted untainted c1c1 c2c2

Importance of Context Sensitivity (2) String id(String str) { return str; } tainted untainted tainted Excessive tainting!!

Pointer Analysis Object Naming Need to do some approximation Unbounded number of dynamic objects Finite number of static entities for analysis Allocation-site object naming Dynamic objects are represented by the line of code that allocates them Can be imprecise – two dynamic objects allocated at the same site have the same static representation

Imprecision with Default Object Naming 700: String toLowerCase(String str) { … 725: return new String(…); 726: } foo.java:45 bar.java:30 String.java: : String toLowerCase(String str) { … 725: return new String(…); 726: } String.java:725 2 String.java:725

Improved Object Naming We introduced an enhanced object naming Containers – HashMap, Vector, LinkedList, etc. Factory functions Very effective at increasing precision Avoids false positives in all apps but one All false positives caused by a single factory method Improving naming further gets rid of all false positives

Specifying Vulnerabilities Many kinds of input validation vulnerabilities Lots of ways to inject data and perform exploits New ones are emerging Give the power to the user: Allow the user to specify vulnerabilities Use a query language PQL [OOPSLA05] User is responsible for specifying Sources – cookies, parameters, URL strings, etc. Sinks – SQL injection, HTTP splitting, etc.

SQL Injections in PQL Simple example SQL injections caused by parameter manipulation Looks like a code snippet Automatically translated into static analysis Real queries are longer and more involved Please refer to the paper query simpleSQLInjection returns object String param, derived; uses object HttpServletRequest req; object Connection con; object StringBuffer temp; matches { param = req.getParameter(_); temp.append(param); derived = temp.toString(); con.executeQuery(derived); }

Caveat: Derivation Routines HttpServletRequest request =...; String userName = request.getParameter("name"); String query = "SELECT * FROM Users " + "WHERE name = '" + userName + "'"; Connection con =... con.executeQuery(query.toUpperCase()); Derivation rules that propagate taint String concatenation String.toLowerCase, String.substring, etc. We dont analyze them: Implemented using native routines Low-lever character manipulation Become part of the PQL query

System Overview User-provided PQL queries Pointer analysis expressed in Datalog bddbddb Datalog solver Datalog Java bytecode Vulnerability warnings

Outline Application-level vulnerabilities Our static analysis system Results & Conclusions Our benchmarks Vulnerabilities found False positives & effect of analysis features Conclusions

Benchmarks for Our Experiments Benchmark suite: Stanford SecuriBench We made them publicly available: Google for Stanford SecuriBench Suite of nine large open-source Java benchmark applications Reused the same J2EE PQL query for all Widely used programs Most are blogging/bulletin board applications Installed at a variety of Web sites Thousands of users combined

Classification of Errors Sinks Sources SQL injection HTTP splitting Cross-site scripting Path traversal Total Header manipulation Parameter manipulation Cookie poisoning10001 Non-Web inputs20035 Total

Classification of Errors Sinks Sources SQL injection HTTP splitting Cross-site scripting Path traversal Total Header manipulation Parameter manipulation Cookie Poisoning10001 Non-Web inputs20035 Total

Classification of Errors Total of 29 vulnerabilities found Were are sound: all analysis versions report them Refer to the paper for more details Sinks Sources SQL injection HTTP splitting Cross-site scripting Path traversal Total Header manipulation Parameter manipulation Cookie poisoning10001 Non-Web inputs20035 Total

Some Interesting Attack Vectors TRACE vulnerability in J2EE Found a vulnerability in J2EE sources Appears in four of our benchmarks Known as cross-site tracing attacks Session.find vulnerability in hibernate ver.2 Causes two application vulnerabilities Common situation: attack vectors in libraries should be removed or at least documented More details in the paper

Validating the Vulnerabilities Reported issues back to program maintainers Most of them responded Most reported vulnerabilities confirmed as exploitable More that a dozen code fixes Often difficult to convince that a statically detected vulnerability is exploitable Had to convince some people by writing exploits Library maintainers blamed application writers for the vulnerabilities

Low False Positive Rate Very high precision With context sensitivity + improved object naming combined Still have some false positives Only 12 false positives in 9 benchmark applications Have the same cause and can be fixed easily: Slight modification of our object-naming scheme One-line change to the pointer analysis However, may have false positives: We ignore predicates, which may be important Better object naming may still be needed No disambiguation of objects in a container

Analysis Version Compared Default object naming Improved object naming Context-insensitive Least precise Context-sensitive Most precise

False Positives Remaining 12 false positives for the most precise analysis version

Related Work Penetration testing Exploit or crash an app by feeding it malicious input values Inherently incomplete: what inputs havent been tried Application firewalls Observe user and application interaction Provide a model of valid behavior White-listing Black-listing Good model is very difficult to contruct Static analysis for security Improvements on grep [ITS4, RATS] JFlow – type system approach, requires annotations Previous work on detecting SQL injection statically hasnt been shown to scale Sound/unsound upfront to where I talk about sound/unsound

Conclusions A static technique based on a CS pointer analysis for finding input validation vulnerabilities in Web-based Java applications Results: Found 29 security violations Most reported vulnerabilities confirmed by maintainers Only 12 false positives with most precise analysis version

Project Status For more details, we have a TR Stanford SecuriBench recently released SecuriFly: preventing vulnerabilities on the fly Runtime prevention of vulnerabilities in Web apps See Martin, Livshits, and Lam [OOPSLA05]