Secure Programming and! #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" Common Errors! PART I" Who am I?" !!Director and CSO of Integrating Web LTD! !!Bachelor Degree in Internet Sciences! brought to you by Michele “AntiSnatchOr” Orrù !!Independent Security Researcher! and Integrating Web LTD! !!Owner of http://antisnatchor.com security Computer System Security course lead by Prof. Ozalp Babaoglu! advisory blog! 3 December 2009! !!JEE developer" ! Outline

!" 2 of 44!

#$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345"

Seminar outline (part I)" What we will discuss:"

!!Discuss the most relevant SANS top 25 !!CWE-20: Improper Input Validation ! ! !!CWE-116: Improper Encoding or Escaping of Output !

errors that concern Web Applications! ! !!Practical demonstrations of some !!CWE-209: Error Message Information Leak ! vulnerable Real World web applications !!CWE-89: Failure to Preserve SQL Query Structure (my totally independent security research)! (SQL injection) ! !!Understand the impact of these threats !!CWE-79: Failure to Preserve Web Page Structure on the most valuable web-app assets! (XSS) ! !!CWE-352: Cross-Site Request Forgery (XSRF)" Seminar outline (part I) What we will discuss

3 of 44! 4 of 44! #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" CWE-20: CWE-20: Improper ! ! Input Validation" Example"

!! 8e6 R3000 Internet Filter (commercial HTTP(S) !! The biggest issue on today’s Internet Proxy filter solution)! Applications (not just WebApps)!

!! Improper Input Validation can lead to security ! vulnerabilities when attackers can modify input in unexpected ways for the application!

!! The only way to protect our applications is by understanding that all input can be malicious! CWE-20: Improper Input Validation Improper Input CWE-20: Example CWE-20:

5 of 44! 6 of 44!

#$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" CWE-20: CWE-20: Example" Mitigation"

!! Credits: nnposter! !! Understand every potential attack areas:

!! DNS based website blacklist can be bypassed by parameters, arguments, cookies, headers, files, databases... ! providing a forged request with custom HTTP ! ! header! !! Whitelist approach instead of blacklist (you are Http request:! certainly going to miss some character encoding variants)!

GET / HTTP/1.1! !! WebApp case: use a WebApp Firewall X-DecoyHost: www.milw0rm.org! (ModSecurity/F5) or an Input Validation Host: www.blocked.org!

CWE-20: Example CWE-20: Framework for your language.! Mitigation CWE-20:

7 of 44! 8 of 44! #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" ! CWE-20: Mitigation! CWE-20:MITIGATION ! ModSecurity" OWASP ESAPI"

!! A common set of interfaces for security controls ModSecurity such as:!

!! Authentication! !! Access Control! !! Input Validation! !! Output Encoding! !! Cryptography! !! Error handling/logging! CWE-20: Mitigation with CWE-20: ESAPI OWASP CWE-20:MITIGATION

9 of 44! 10 of 44! ! #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" CWE-116: Improper ! CWE-20: MITIGATION Encoding/Escaping !

PHPIDS" ! of Output"

!! Insufficient output encoding is the often-ignored sibling to poor input validation! EncodingEscaping !! Input validation framework for PHP based applications! !! Even if input has been filtered, application output could not be safe: it need to be encoded !! Developed by skilled hackers (Mario Heiderich - .mario on sla.ckers.org)! too!

!! Common examples: HTML/JavaScript injection ! !! Try their demo with your nasty attack vectors here: http://demo.php-ids.org! on web based applications! !! Integrated as a module in Drupal, works with the powerful Zend Framework (http://forum.php- CWE-116: Improper CWE-116: of Output ids.org/comments.php?DiscussionID=113)! PHPIDS MITIGATION CWE-20: 11 of 44! 12 of 44! #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" #$%&''((()*+,-./01+.(-2)345" #$%&''0+16+0,3#4/)345" CWE-116: CWE-116: Example" Example"

!! Eclipse BIRT (reporting system that integrates !! Credits: antisnatchor [http://antisnatchor.com/ with /JEE applications)! 2008/12/18/eclipse-birt-reflected-xss]! !! Java Exception stack trace was not HTML-

! encoded, so we can inject an iframe! ! !!GET! !!/birt-viewer/run?__report='">