Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Nick Feamster CS 6262 Spring 2009
PHP I.
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.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
4.01 How Web Pages Work.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
WebGoat & WebScarab “What is computer security for $1000 Alex?”
1 Topic 1 – Lesson 3 Network Attacks Summary. 2 Questions ► Compare passive attacks and active attacks ► How do packet sniffers work? How to mitigate?
Network & Computer Attacks (Part 2) February 11, 2010 MIS 4600 – MBA © Abdou Illia.
Web server security Dr Jim Briggs WEBP security1.
SQL Injection and Buffer overflow
Computer Security and Penetration Testing
Lesson 9-Securing a Network. Overview Identifying threats to the network security. Planning a secure network.
Chapter 6: Hostile Code Guide to Computer Network Security.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
INTRODUCTION TO WEB DATABASE PROGRAMMING
1 Chap 10 Malicious Software. 2 Viruses and ”Malicious Programs ” Computer “Viruses” and related programs have the ability to replicate themselves on.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Brad Baker CS526 May 7 th, /7/ Project goals 2. Test Environment 3. The Problem 4. Some Solutions 5. ModSecurity Overview 6. ModSecurity.
Prevent Cross-Site Scripting (XSS) attack
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
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.
Network Security Introduction Some of these slides have been modified from slides of Michael I. Shamos COPYRIGHT © 2003 MICHAEL I. SHAMOS.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
AMNESIA: Analysis and Monitoring for NEutralizing SQL- Injection Attacks Published by Wiliam Halfond and Alessandro Orso Presented by El Shibani Omar CS691.
Copyright 2007 © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Web Server Administration Web Services XML SOAP. Overview What are web services and what do they do? What is XML? What is SOAP? How are they all connected?
1 Internet Browsing Vulnerabilities and Security ECE4112 Final Lab Ye Yan Frank Park Scott Kim Neil Joshi.
CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
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.
 Chapter 14 – Security Engineering 1 Chapter 12 Dependability and Security Specification 1.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
Beyond negative security Signatures are not always enough Or Katz Trustwave ot.com/
Security. Security Flaws Errors that can be exploited by attackers Constantly exploited.
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
Denial of Service Sharmistha Roy Adversarial challenges in Web Based Services.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Copyright © The OWASP Foundation This work is available under the Creative Commons SA 2.5 license The OWASP Foundation OWASP Denver February 2012.
WebWatcher A Lightweight Tool for Analyzing Web Server Logs Hervé DEBAR IBM Zurich Research Laboratory Global Security Analysis Laboratory
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Lesson 10—Networking BASICS1 Networking BASICS The Internet and Its Tools Unit 3 Lesson 10.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
By Collin Donaldson. Hacking is only legal under the following circumstances: 1.You hack (penetration test) a device/network you own. 2.You gain explicit,
IST 210: PHP Basics IST 210: Organization of Data IST2101.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
Denial of Service in the Cloud Computing Era MSSD-3 — третья по счету конференция, посвященная всестороннему обсуждению популярной и важной темы – минимизация.
An Introduction to Web Application Security
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Automatic Web Security Unit Testing: XSS Vulnerability Detection Mahmoud Mohammadi, Bill Chu, Heather Richter, Emerson Murphy-Hill Presenter:
WWW and HTTP King Fahd University of Petroleum & Minerals
Web Application Firewall Bypassing – an approach for pentesters
A Security Review Process for Existing Software Applications
Secure Software Development: Theory and Practice
MIS Professor Sandvig MIS 324 Professor Sandvig
Speaker: Shane Jahnke CS 6910 – Advanced System Security & Design
Chap 10 Malicious Software.
Security in Java Real or Decaf? cs205: engineering software
Regular Expressions
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Chap 10 Malicious Software.
Presentation transcript:

Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation OWASP Regular Expression Denial of Service Alex Roichman Chief Architect, Checkmarx Adar Weidman Senior Programmer, Checkmarx Israel 2009

OWASP  DoS attack  Regex and DoS - ReDoS  Exploiting ReDoS: Why, Where & How  Leveraging ReDoS to Web attacks  Server-side ReDoS  Client-side ReDoS  Preventing ReDoS  Conclusions Agenda

OWASP DoS Attack  The goal of Information Security is to preserve  Confidentiality  Integrity  Availability  The final element in the CIA model, Availability, is often overlooked  Attack on Availability - DoS  DoS attack attempts to make a computer resource unavailable to its intended users

OWASP Brute-Force DoS  Sending many requests such that the victim cannot respond to legitimate traffic, or responds so slowly as to be rendered effectively unavailable  Flooding  DDoS  Brute-force DoS is an old-fashion attack  It is network oriented  It can be easily detected/prevented by existing tools  It is hard to execute (great number of requests, zombies…)  Amount of traffic is required to overload the server is big

OWASP Sophisticated DoS  Hurting the weakest link of the system  Application bugs  Buffer overflow  Fragmentation of Data Structures  Hash Table  Algorithm worst case  Sophisticated DoS is a new approach  It is application oriented  Hard to prevent/detect  Easy to execute (few request, no botnets)  Amount of traffic that is required to overload the server - little

OWASP From Sophisticated DoS to Regex DoS  One kind of sophisticated DoS is DoS by Regex or ReDoS  It is believed that Regex performance is fast, but the truth is that the Regex worst case is exponential  In this presentation we will show how an attacker can easily exploit the Regex worst case and cause an application DoS  We will show how an application can be ReDoSed by sending only one small message

OWASP ReDoS on the Web  The fact that some evil Regexes may result on DoS was mentioned in 2003 by [1]  In our research we want to revisit an old attack and show how we can leverage it on the Web  If unsafe Regexes run on inputs which cannot be matched, then the Regex engine is stuck  The art of attacking the Web by ReDoS is by finding inputs which cannot be matched by the above Regexes and on these Regexes a Regex- based Web systems will get stuck [1]

OWASP Regular Expressions  Regular Expressions (Regexes) provide a concise and flexible means for identifying strings  Regexes are written in a formal language that can be interpreted by a Regex engine  Regexes are widely used  Text editors  Parsers/Interpreters/Compilers  Search engines  Text validations  Pattern matchers…

OWASP Regex engine algorithm  The Regex engine builds Nondeterministic Finite Automata (NFA) for a given Regex  For each input symbol NFA transitions to a new state until all input symbols have been consumed  On an input symbol NFA may have several possible next states  Regex deterministic algorithm try all paths of NFA one after the other until it reachs an accepting state (match) or all paths are tried (no match)

Regex Complexity  In general case the number of different paths is exponential on input length  Regex: ^(a+)+$  Payload: “aaaaX”  # of different paths: 16  Regex worst case is exponential  How many paths we have for “aaaaaaaaaaX”: 1024  And for “aaaaaaaaaaaaaaaaaaaaX”?...

OWASP Evil Regex Patterns  Regex is called evil if it can be stuck on specially crafted input  Each evil Regex pattern should contain:  Grouping construct with repetition  Inside the repeated group should appear  Repetition  Alternation with overlapping  Evil Regex pattern examples 1.(a+)+ 2.([a-zA-Z]+)* 3.(a|aa)+ 4.(a|a?)+ 5.(.*a){x} | for x > 10 Payload: “aaaaaaaaaaaaaaaaaaX”

OWASP Real examples of ReDoS  OWASP Validation Regex Repository [2]  Person Name  Regex: ^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$  Payload: “aaaaaaaaaaaaaaaaaaaaaaaaaaaa!”  Java Classname  Regex: ^(([a-z])+.)+[A-Z]([a-z])+$  Payload: “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!” [2]

Real examples of ReDoS  Regex Library [3]  Validation  Regex: Z])*\.)+[a-zA-Z]{2,9})$  Payload:  Multiple address validation  Regex: ^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z  Payload: aaaaaaaaaaaaaaaaaaaaaaaa!  Decimal validator  Regex: ^\d*[0-9](|.\d*[0-9]|)*$  Payload: !  Pattern Matcher  Regex: ^([a-z0-9]+([\-a-z0-9]*[a-z0-9]+)?\.){0,}([a-z0-9]+([\-a-z0-9]*[a-z0- 9]+)?){1,63}(\.[a-z0-9]{2,7})+$  Payload: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! [3]

OWASP Exploiting ReDoS: Why  The art of writing robust Regexes is obscure and difficult  Programmers are not aware of Regex threats  QA generally check for valid inputs, attackers exploit invalid inputs on which Regex engine will try all existing paths until it rejects the input  Security experts are not aware of DoS on Regexes  There are no tools for ReDoS-safety validation  By bringing a Regex engine to its worst exponential case, an attacker can easily exploit DoS.

OWASP Exploiting ReDoS: How  There are two ways to ReDoS a system:  Crafting a special input for an existing system Regex  Build a string for which a system Regex has no match and on this string a Regex machine will try all available paths until it rejects the string –Regex: (a+)+ –Payload: aaaaaaaaX  Injecting a Regex if a system builds it dynamically  Build Regex with many paths which will “stuck-in” on a system string by using all these paths until it rejects the string –Payload : (.+)+\u001

 Regexes are ubiquitous now – web is Regex- based Exploiting ReDoS: Where

OWASP Web application ReDoS – Regex validations  Regular expressions are widely used for implementing application validation rules.  There are two main strategies for validating inputs by Regexes:  Accept known good-  Regex should begin with “^” and end with “$” character to validate an entire input and not only part of it  Very tight Regex will cause False Positives (DoS for a legal user!)  Reject known bad-  Regex can be used to identify an attack fingerprint  Relaxed Regex can cause False Negatives

OWASP Web application ReDoS – malicious inputs  Crafting malicious input for a given Regex  Blind attack – Regex is unknown to an attacker:  Try to understand which Regex can be used for a selected input  Try to divide Regex into groups  For each group try to find a string which cannot be matched  Not blind attack - many applications are open source; many times the same Regex appears both in client-side and in server-side:  Understand a given Regex and build a malicious input

OWASP Web application ReDoS – attack 1  A server side application can be stuck in when a client-side validations are backed-up on a server side  Application ReDoS attack vector 1:  Open a source of Html  Find evil Regex in JavaScript  Craft a malicious input for a found Regex  Submit a valid value via intercepting proxy and change the request to contain a malicious input  You are done!

OWASP Web application ReDoS – malicious Regexs  Crafting malicious Regex for a given string.  Many applications receive a search key in format of Regex  Many applications build Regex by concatenating user inputs  Regex Injection [4] like other injections is a common application vulnerability  Regex Injection can be used to stuck an application [4] C. Wenz: Regular Expression Injection

OWASP Web application ReDoS – attack 2  Application ReDoS attack vector 2:  Find a Regex injection vulnerable input by submitting an invalid escape sequence like “\m”  If the following message is received: “invalid escape sequence”, then there is Regex injection  Submit “(.+)+\u0001”  You are done!

OWASP Google CodeSearch Hacking  Google CodeSearch involves using advance operators and Regexes in the Google search engine to locate specific strings of text within open sources [5]:  Meta-Regex is a Regex which can be used to find evil Regexes in a source code:  Regex.+\(\.\*\)\+  Regex.+\(.\.\*\)\*  Google CodeSearch Hacking – involves using meta-Regexes to find evil Regexes in open sources [5]

OWASP Web application ReDoS Example  DataVault [6]:  Regex: ^\[(,.*)*\]$  Payload: [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,  WinFormsAdvansed [7]:  Regex: \A([A-Z,a-z]*\s?[0-9]*[A-Z,a-z]*)*\Z  Payload: aaaaaaaaaaaaaaaaaa!  EntLib [8]:  Regex: ^([^\"]+)(?:\\([^\"]+))*$  Payload: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" [6] /DataVault.Tesla/Impl/TypeSystem/AssociationHelper.cs [7] /WinFormsAdvansed/RegeularDataToXML/Form1.cs [8] /Src/Configuration/Manageability/Adm/AdmContentBuilder.cs

OWASP Client-side ReDoS  Internet browsers spend many efforts to prevent DoS.  Between issues that browsers prevent:  Infinite loops  Long iterative statements  Endless recursions  But what about Regex?  Relevant for Java/JavaScript based browsers

OWASP Client-side ReDoS – Browser ReDoS  Browsers ReDoS attack vector:  Deploy a page containing the following JavaScript code: myregexp = new RegExp(/^(a+)+$/); mymatch = myregexp.exec("aaaaaaaaaaaaaaaaaaaaaaaaaaaX");  Trick a victim to browse this page  You are done!

OWASP Preventing ReDoS  ReDoS vulnerability is serious so we should be able to prevent/detect it  Dynamically built input-based Regex should not be used or should use appropriate sanitizations  Any Regex should be checked for ReDoS safety prior to using it  The following tools should be developed for Regex safety testing:  Dynamic Regex testing, pen testing/fuzzing  Static code analysis tools for unsafe-Regex detection

OWASP Conclusions  The web is Regex-based  The border between safe and unsafe Regex is very ambiguous  In our research we show that the Regex worst exponential case may be easily leveraged to DoS attacks on the web  In our research we revisited ReDoS and tried:  to expose the problem to the application security community  to encourage development of Regex-safe methodologies and tools

ReDoS – Q&A Thank you, Alex Roichman