Qualys, Inc. · NASDAQ:QLYS

Qualys — Technical Presentation (2012)

52 slides from Qualys's technical presentation, Oct 18, 2012

  1. Slide 1: Protocol-Level Evasion of Web Application Firewalls

    Protocol-Level Evasion of Web Application Firewalls USA2012 Ivan Ristic Director of Engineering

  2. Slide 2: True Evasion Story

    True Evasion Story  Once, a long time ago, I evaded a web application firewall by adding a single character to a valid request. Can you spot it below? GET /myapp/admin.php?userid=1001 HTTP/1.1 Host: www.example.com. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.

  3. Slide 3: True Evasion Story

    True Evasion Story  Once, a long time ago, I evaded a web application firewall by adding a single character to a valid request. Can you spot it below? GET /myapp/admin.php?userid=1001 HTTP/1.1 Host: www.example.com. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.

  4. Slide 4: Why Do I Care?

    Why Do I Care?  Spent years developing WAFs and related software: − Built ModSecurity (2002-2009) − Built libhtp (2009-2010) − Now working on IronBee (not coding, though) libhtp  WAF concepts are powerful, but the field needs more research and the market needs more transparency 3 BLACK HAT USA 201

  5. Slide 5: Introduction to Protocol-Level Evasion

    INTRODUCTION TO PROTOCOL-LEVEL EVASION Protocol-Level Evasion of Web Application Firewalls BLACK HAT USA 2012

  6. Slide 6: Impedance Mismatch

    Impedance Mismatch  Impedance mismatch, in the context of security monitoring, refers to the problem of different interpretations of the same data stream − The security tool sees one thing − The backend server sees another  Possible causes: − Ambiguous standards − Partial and “Works for me” backen

  7. Slide 7: Protocol-Level Evasion Overview

    Protocol-Level Evasion Overview  HTTP − Message parsing Method Path Query string Protocol − Request line − Request headers Header name Header value − Cookies SP Header value  Hostname  Path Header name Header value  Parameters Header name Header value  Request body − Urlencoded Request body − M

  8. Slide 8: Protocol-Level Evasion Overview

    Protocol-Level Evasion Overview  HTTP − Message parsing Method Path Query string Protocol − Request line − Request headers Header name Header value − Cookies SP Header value  Hostname  Path Header name Header value  Parameters Header name Header value  Request body − Urlencoded Request body − M

  9. Slide 9: Virtual Patching

    Virtual Patching  Virtual patching is probably the most widely used WAF feature 1. You know you have a problem 2. You can’t resolve it, or can’t resolve it in a timely manner 3. You deploy a WAF as a short-term mitigation measure  Challenge: − To support the narrow focus of virtual patches, WAFs h

  10. Slide 10: Path Evasion

    PATH EVASION Protocol-Level Evasion of Web Application Firewalls BLACK HAT USA 2012

  11. Slide 11: Attacking Patch Activation

    Attacking Patch Activation  An application entry point might look like this: /myapp/admin.php?userid=1001  And the virtual patch, using Apache and ModSecurity, like this: <Location /myapp/admin.php> # Allow only numbers in userid SecRule ARGS:userid "!^\d+$" </Location> BLACK HAT USA 2012

  12. Slide 12: PATH_INFO and Path Parameters

    PATH_INFO and Path Parameters  Surprisingly, some WAFs* still don’t know about PATH_INFO: /myapp/admin.php/xyz?userid=X  If PATH_INFO is not supported by the backend server, you might want to try path parameters (e.g., works on Tomcat): /myapp/admin.php;random=value?userid=X (*) Neither approach w

  13. Slide 13: Self-Contained ModSecurity Rules

    Self-Contained ModSecurity Rules  Rules written like this are very easy to find: SecRule REQUEST_FILENAME "@streq /myapp/admin.php“ \ "chain,phase:2,deny" SecRule ARGS:userid "!^\d+$"  Problems: − The use of @streq misses PATH_INFO and path parameters attacks − Apache may not handle all obfuscatio

  14. Slide 14: Self-Contained ModSecurity Rules

    Self-Contained ModSecurity Rules  Here’s a better version of the same patch: SecRule REQUEST_FILENAME \ "@beginsWith /myapp/admin.php" \ "chain,phase:2,t:normalizePath,deny" SecRule ARGS:userid "!^\d+$“  Improvements: − Use @beginsWith (@contains is good, too) − Use transformation function normali

  15. Slide 15: Backend Feature Variations

    Backend Feature Variations  In a proxy deployment, you have to watch for impedance mismatch with various backend features: /myapp\admin.php /myapp/AdMiN.php  Using Apache and ModSecurity: <Location ~ (?i)^[\x5c/]+myapp[\x5c/]+admin\.php> SecRule ARGS:userid "!^\d+$" </Location> BLACK HAT USA 2012

  16. Slide 16: Backend Feature Variations

    Backend Feature Variations  In a proxy deployment, you have to watch for impedance mismatch with various backend features: /myapp\admin.php /myapp/AdMiN.php  ModSecurity only: SecRule REQUEST_FILENAME \ "@beginsWith /myapp/admin.php" \ "chain,phase:2,t:lowercase,t:normalizePathWin,deny" SecRule AR

  17. Slide 17: Path Parameters Again

    Path Parameters Again  Path parameters are actually path segment parameters, and can be used with any segment: /myapp;param=value/admin.php?userid=X  New patch version: <Location ~ (?i)^[\x5c/]+myapp(;[^\x5c/]*)? [\x5c/]+admin\.php(;[^\x5c/]*)?> SecRule ARGS:userid "!^\d+$" </Location>  ModSecuri

  18. Slide 18: Short Filenames on Windows

    Short Filenames on Windows  Windows uses short filenames to support legacy applications. For example: admin.aspx becomes ADMIN~1.ASP  Ideal for virtual patch evasion under right circumstances: − Does not work with IIS − But does work with Apache running on Windows BLACK HAT USA 2012

  19. Slide 19: Path Evasion against IIS 5.1

    Path Evasion against IIS 5.1  IIS 5.1 (and, presumably, earlier) are very flexible when it comes to path processing: 1. Overlong 2- or 3-byte UTF-8 representing either / or \ 2. In fact, any overlong UTF-8 character facilitates evasion 3. Best-fit mapping of UTF-8 characters; for example U+0107 bec

  20. Slide 20: Path Handling of Major Platforms

    Path Handling of Major Platforms BLACK HAT USA 2012

  21. Slide 21: Path Handling of Major Platforms

    Path Handling of Major Platforms 42 TESTS BLACK HAT USA 2012

  22. Slide 22: Parameter Evasion

    PARAMETER EVASION Protocol-Level Evasion of Web Application Firewalls BLACK HAT USA 2012

  23. Slide 23: Parameter Cardinality and Case

    Parameter Cardinality and Case  In the simplest case, supplying multiple parameters or varying the case of parameter names may work: /myapp/admin.php?userid=1&userid=2 /myapp/admin.php?uSeRiD=1&userid=2  However, these techniques are more likely to work against custom-coded defenses; WAFs will hav

  24. Slide 24: PHP's Cookies as Parameters

    PHP’s Cookies as Parameters  PHP can be configured to treat cookies as parameters, and place them in the $_REQUEST array: GET /myapp/admin.php Cookie: userid=X  This is still the default behaviour in the code, with an override in the default php.ini (which can easily be misconfigured). BLACK HAT U

  25. Slide 25: HTTP Parameter Pollution

    HTTP Parameter Pollution  Depending on the backend and the code used, the WAF may not know exactly that the application sees: /myapp/admin.php?userid=1&userid=2 Technology Behaviour Result ASP Concatenate userid=1,2 PHP Last occurrence userid=2 Java First occurrence userid=1 A better overview is av

  26. Slide 26: Tricks with PHP Parameter Names

    Tricks with PHP Parameter Names  PHP will change parameter names when they contain some characters it does not like: − Whitespace at the beginning is removed − Whitespace, dot, and open bracket characters in the middle converted to underscores /myapp/admin.php?+userid=X BLACK HAT USA 2012

  27. Slide 27: Invalid URL Encoding

    Invalid URL Encoding  Different platforms react differently to invalid encoding.  ASP removes a % character that is not followed by 2 hexadecimal digits: /myapp/admin.php?user%id=X  In the old days, many C-based applications had incorrect decoding routines, which lacked error detection. /myapp/ad

  28. Slide 28: Content Type Evasion

    Content Type Evasion  When parameters are transported in request body, you can attack the encoding detection mechanism − Attack applications that hard-code processing:  Omit the Content-Type request header  Place an arbitrary value in it  Use multipart/form-data, and craft the request body to be

  29. Slide 29: ModSecurity Bypass

    ModSecurity Bypass  By default, ModSecurity ignores unknown MIME types − With Apache Commons FileUpload, send a request body with multipart/whatever MIME type − Request bodies using encodings other than Urlencoded and Multipart are completely ignored  Possible improvements to ModSecurity: − Fail c

  30. Slide 30: Multipart Evasion

    MULTIPART EVASION Protocol-Level Evasion of Web Application Firewalls BLACK HAT USA 2012

  31. Slide 31: Multipart Format Overview

    Multipart Format Overview POST / HTTP/1.0 1 2 Content-Type: multipart/form-data; boundary=0000 Host: www.example.com Content-Length: 10269 --0000 3 Content-Disposition: form-data; name="name" 4 John Smith 5 --0000 Content-Disposition: form-data; name="email" john.smith@example.com --0000 Content-Dis

  32. Slide 32: Apache Commons FileUpload

    Apache Commons FileUpload  Define constant for later use: public static final String MULTIPART = "multipart/";  Determine if Multipart request body is present: if (contentType.toLowerCase(). startsWith(MULTIPART)) { return true; } 31 BLACK HAT USA 2012

  33. Slide 33: ModSecurity CRS Bypass

    ModSecurity CRS Bypass  ModSecurity Core Rules will attempt to restrict MIME types, but not always successfully: − With Apache Commons FileUpload, send a request body with multipart/ MIME type. − Reported as fixed in CRS 2.2.5.  The flaw was in this rule, where the check was not strict enough: Sec

  34. Slide 34: Content-Type Evasion

    Content-Type Evasion  Trick the WAF into not seeing a Multipart request body  Examples: Content-Type: multipart/form-data ; boundary=0000 Content-Type: mUltiPart/ForM-dATa; boundary=0000 Content-Type: multipart/form-dataX; boundary=0000 Content-Type: multipart/form-data, boundary=0000 Content-Type

  35. Slide 35: PHP Source Code

    PHP Source Code 1 boundary = strstr(content_type, "boundary"); if (!boundary) { /* 2 Lowercase header and try again */ } if (!boundary || 3 !(boundary = strchr(boundary, '='))) { /* Return with error */ } 34 BLACK HAT USA 2012

  36. Slide 36: Boundary Evasion

    Boundary Evasion  Trick the WAF into seeing a different boundary  Examples: Content-Type: multipart/form-data; boundary =0000; boundary=1111 Content-Type: multipart/form-data; boundaryX=0000; boundary=1111 Content-Type: multipart/form-data; boundary=0000; boundary=1111 Content-Type: multipart/form

  37. Slide 37: Part Evasion

    Part Evasion  Boundary evasion leads to part evasion, but even when you get the boundary right you can still miss things  In 2009, Stefan Esser reported that PHP continues to process the parts that appear after the “last” part --0000 Content-Disposition: form-data; name="name" John Smith --0000--

  38. Slide 38: Parameter Name Evasion

    Parameter Name Evasion  Focuses on differences in parameter name parsing.  Example attacks: Content-Disposition: form-data; name="n1"; name="n2" Content-Disposition: form-data; name="n1"; name ="n2"  How PHP parses parameter names: Content-Disposition: form-data; name="n1"; name="n2" Content-Disp

  39. Slide 39: Parameter Type Evasion

    Parameter Type Evasion  WAFs may treat files differently. For example: − ModSecurity has different inspection controls for files − No file inspection in the CRS  ModSecurity bypass reported by Stefan Esser in 2009 − Thought to have been fixed (I was not involved) − Stefan’s original payload below

  40. Slide 40: Parameter Type Evasion

    Parameter Type Evasion  This is what ModSecurity saw: Content-Disposition: form-data; name=';filename="';name=payload;" name filename  This is what PHP sees: Content-Disposition: form-data; name=';filename="';name=payload;" name (ignored) name 39 BLACK HAT USA 2012

  41. Slide 41: Parameter Type Evasion

    Parameter Type Evasion  Flaw thought to have been fixed  I rediscovered the problem during my evasion research  The original problem had been misunderstood and addressed incorrectly:  ModSecurity added support for single quotes in parameter values  PHP supports single-quote escaping anywhere wi

  42. Slide 42: Multipart Evasion Summary

    Multipart Evasion Summary  Complex and vaguely specified format  Implementations are often: − Quick & dirty (whatever works) − Focused on real-life use cases (not the specification)  Rife opportunities for evasion  There are 37 tests available in the repository 37 − Tested against ModSecurity an

  43. Slide 43: What Next?

    WHAT NEXT? Protocol-Level Evasion of Web Application Firewalls BLACK HAT USA 2012

  44. Slide 44: Future Work

    Future Work  At this time: − Path handling has good coverage (tests + results) − Parameter handling and multipart test cases in good shape  Need to test major platforms  Future activity − Complete other areas of protocol-level evasion  HTTP parsing  Character set issues  Hostname evasion − Doc

  45. Slide 45: Where to Go From Here

    Where to Go From Here  More information in the accompanying whitepaper >100  Get the tools and docs from GitHub: TESTS https://github.com/ironbee/waf-research − Path handling research − Baseline, path, and multipart test cases  Test your security products  Contribute your results 44 BLACK HAT US

  46. Slide 46: Thank You

    USA2012 Thank You Ivan Ristic iristic@qualys.com Twitter: @ivanristic

  47. Slide 47: How to Write a Good Virtual Patch

    How to Write a Good Virtual Patch  Take these steps to write a good virtual patch: 1. Study the problem, ideally by reading source code  If the source code is not available, do what you can by analyzing the advisory, the exploit, and by attacking the application 2. Use a path that can withstand ev

  48. Slide 48: Baseline Tests

    Baseline Tests  In the repository, there is a set of baseline tests designed to determine if all parts of a HTTP requests are inspected by a WAF  Instructions: 1. Find one payload that is blocked by the WAF 2. Submit payload in every different logical location 3. Determine locations that are not m

  49. Slide 49: Why Should You Care?

    Why Should You Care?  Researchers: − Fascinating new data, and effort to systematically and collaboratively analyse how WAFs perform in this area  Testers (breakers): − Lots of practical assessment techniques  Defenders: − Lots of practical information about Apache and ModSecurity − A better pict

  50. Slide 50: Donald Knuth on Email

    Donald Knuth on Email “Email is a wonderful thing for people whose role in life is to be on top of things. But not for me; my role is to be on the bottom of things.” 49 BLACK HAT USA 2012

  51. Slide 51: Previous Work

    Previous Work  A look at whisker’s anti-IDS tactics Rain Forest Puppy (1999)  Bypassing Content Filtering Software 3APA3A (2002)  HTTP IDS Evasions Revisited Daniel J. Roelker (2003)  Snort's README.http_inspect Sourcefire et al (2005)  Shocking News in PHP Exploitation Stefan Esser (2009)  HT

  52. Slide 52: About Ivan Ristic

    About Ivan Ristic Ivan is a compulsive developer, application security researcher, writer, publisher, and entrepreneur.  Apache Security, O’Reilly (2005)  ModSecurity, open source web application firewall  SSL Labs, SSL/TLS, and PKI research  ModSecurity Handbook, Feisty Duck (2010)  IronBee, a

Qualys — Technical Presentation (2012) on 6ix