Securing ASP.NET 2.0 Web Applications Svetlin Nakov National Academy for Software Development.

Slides:



Advertisements
Similar presentations
© 2008 Security Compass inc. 1 Firefox Plug-ins for Application Penetration Testing Exploit-Me.
Advertisements

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.
Creating Stronger, Safer, Web Facing Code JPL IT Security Mary Rivera June 17, 2011.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
WebGoat & WebScarab “What is computer security for $1000 Alex?”
COMP 321 Week 12. Overview Web Application Security  Authentication  Authorization  Confidentiality Cross-Site Scripting Lab 12-1 Introduction.
9/9/2005 Developing "Secure" Web Applications 1 Methods & Concepts for Developing “Secure” Web Applications Peter Y. Hammond, Developer Wasatch Front Regional.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
IDAsec copyright - all rights reserved1 Web Vulnerabilities in the real world.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
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.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
Sara SartoliAkbar Siami Namin NSF-SFS workshop July 14-18, 2014.
Security in SQL Jon Holmes CIS 407 Fall Outline Surface Area Connection Strings Authenticating Permissions Data Storage Injections.
© 2003 School of Computing, University of Leeds SY32 Secure Computing, Lecture 14 Implementation Flaws Part 2: Malicious Input and Data Validation Issues.
Jonas Thomsen, Ph.d. student Computer Science University of Aarhus Best Practices and Techniques for Building Secure Microsoft.
March Intensive: XSS Exploits
Lecture 16 Page 1 CS 236 Online Cross-Site Scripting XSS Many sites allow users to upload information –Blogs, photo sharing, Facebook, etc. –Which gets.
CROSS SITE SCRIPTING..! (XSS). Overview What is XSS? Types of XSS Real world Example Impact of XSS How to protect against XSS?
Handling Security Threats in Kentico CMS Karol Jarkovsky Sr. Solution Architect Kentico Software
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Varun Sharma Security Engineer | ACE Team | Microsoft Information Security
Designing Security In Web Applications Andrew Tomkowiak 10/8/2013 UW-Platteville Software Engineering Department
D ATABASE S ECURITY Proposed by Abdulrahman Aldekhelallah University of Scranton – CS521 Spring2015.
Introduction to Application Penetration Testing
Secure Software Engineering: Input Vulnerabilities
PHP Security.
Security.NET Chapter 1. How Do Attacks Occur? Stages of attack Examples of attacker actions 1. FootprintRuns a port scan on the firewall 2. PenetrationExploits.
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.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
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.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
A Security Review Process for Existing Software Applications
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
©2008 Gotham Digital Science Secure Parameter Filter (SPF) (AKA Protecting Vulnerable Applications with IIS7) Justin Clarke, Andrew Carey Nairn.
Lecture 16 Page 1 CS 236 Online SQL Injection Attacks Many web servers have backing databases –Much of their information stored in a database Web pages.
3-Protecting Systems Dr. John P. Abraham Professor UTPA.
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.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
Sofia, Bulgaria | 9-10 October Writing Secure Code for ASP.NET Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen Forte CTO,
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.
SEC835 Runtime authentication Secure session management Secure use of cryptomaterials.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
Web Applications Testing By Jamie Rougvie Supported by.
Building Secure Web Applications With ASP.Net MVC.
ITGS Databases.
DAT356 Hackers Paradise SQL Injection Attacks Doug Seven, Microsoft MVP Cofounder of SqlJunkies.com
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
OWASP Building Secure Web Applications And the OWASP top 10 vulnerabilities.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
What Is XSS ? ! Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications. XSS enables attackers to.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
ASP.NET 2.0 Security Alex Mackman CM Group Ltd
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,
Carrie Estes Collin Donaldson.  Zero day attacks  “zero day”  Web application attacks  Signing up for a class  Hardening the web server  Enhancing.
Page 1 Ethical Hacking by Douglas Williams. Page 2 Intro Attackers can potentially use many different paths through your application to do harm to your.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Group 18: Chris Hood Brett Poche
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
A Security Review Process for Existing Software Applications
Cross Sight scripting: Type-2
Lecture 2 - SQL Injection
Presentation transcript:

Securing ASP.NET 2.0 Web Applications Svetlin Nakov National Academy for Software Development

About Me Svetlin NakovSvetlin Nakov Director training and consulting activities, National Academy for Software Development (NASD)Director training and consulting activities, National Academy for Software Development (NASD) 15 years of developer experience15 years of developer experience 8 year as a professional software engineer, trainer and consultant8 year as a professional software engineer, trainer and consultant Author of 4 books, 20 articles, and 50 seminar lecturesAuthor of 4 books, 20 articles, and 50 seminar lectures Lecturer in Sofia University, NBULecturer in Sofia University, NBU

Agenda Threat modeling: bang for your buckThreat modeling: bang for your buck Online security resources from P&POnline security resources from P&P Security principles for design and codingSecurity principles for design and coding User input from unlikely placesUser input from unlikely places Control vs. data channelsControl vs. data channels Are you *really* safe?Are you *really* safe? SQL injectionSQL injection Cross-site scripting (XSS)Cross-site scripting (XSS) Tamper detection for client-side stateTamper detection for client-side state

Threat Modeling

Is Your Application “Secure”? Ever have anyone ask you this?Ever have anyone ask you this? There’s an easy answer: NOThere’s an easy answer: NO There are no “Secure” appsThere are no “Secure” apps But there are apps that are secure enoughBut there are apps that are secure enough How to achieve enough security?How to achieve enough security?

What Does “Secure Enough” Mean to You? Nobody has an infinite security budgetNobody has an infinite security budget Many folks would be happy if they had any budgetMany folks would be happy if they had any budget Be practical!Be practical! Get the most bang for your buckGet the most bang for your buck Threat modeling will help you do this!Threat modeling will help you do this!

Threat Modeling Threat modeling helps you find what is “secure enough”Threat modeling helps you find what is “secure enough” What are you trying to protect?What are you trying to protect? Who is likely to attack you?Who is likely to attack you? What avenues of attack exist?What avenues of attack exist? Which vulnerabilities are the highest risk?Which vulnerabilities are the highest risk? Go after the high risk vulnerabilities first!Go after the high risk vulnerabilities first!

Approaches to Threat Modeling Do you have security modeling expertise?Do you have security modeling expertise? Get a tool and start building threat modelsGet a tool and start building threat models Microsoft has a free threat modeling toolsMicrosoft has a free threat modeling tools us/security/aa aspxhttp://msdn2.microsoft.com/en- us/security/aa aspxhttp://msdn2.microsoft.com/en- us/security/aa aspxhttp://msdn2.microsoft.com/en- us/security/aa aspx Figure out your assets, trust levels, entry points, threats, diagram threat treesFigure out your assets, trust levels, entry points, threats, diagram threat trees Find vulnerabilitiesFind vulnerabilities

Microsoft Threat Modeling Tools: Demo

Approaches to Threat Modeling Don’t have a security expert?Don’t have a security expert? Use Microsoft Patterns & PracticesUse Microsoft Patterns & Practices Threat Modeling Web ApplicationsThreat Modeling Web Applications us/library/ms aspxhttp://msdn2.microsoft.com/en- us/library/ms aspxhttp://msdn2.microsoft.com/en- us/library/ms aspxhttp://msdn2.microsoft.com/en- us/library/ms aspx Security guidance put together by well- known expertsSecurity guidance put together by well- known experts Complete guide to threat modeling ASP.NET applications; much easier to use than the threat modeling tool!Complete guide to threat modeling ASP.NET applications; much easier to use than the threat modeling tool!

Designing and Coding for Security

Design for Security What should I be thinking about when I’m designing a Web application?What should I be thinking about when I’m designing a Web application? Software is as secure as its weakest linkSoftware is as secure as its weakest link Run with least privilegeRun with least privilege Keep it simpleKeep it simple Promote privacyPromote privacy Hiding secrets is hardHiding secrets is hard Prepare for failurePrepare for failure For more detail, see Viega & McGrawFor more detail, see Viega & McGraw Building Secure Software ( Secure Software (

Coding for Security “What should I think about when I’m coding my Web application?”“What should I think about when I’m coding my Web application?” User input is evil until proven otherwise!User input is evil until proven otherwise! No, that’s not a typo – it’s really importantNo, that’s not a typo – it’s really important If the user can touch it, he’ll tamper with itIf the user can touch it, he’ll tamper with it Filter and sandbox input (more on this later)Filter and sandbox input (more on this later) Pay close attention to filenames and pathsPay close attention to filenames and paths

User Input Is Evil!

User Input from Unlikely Places Form fieldsForm fields URLURL Query stringQuery string CookiesCookies View stateView state Database recordsDatabase records File contentsFile contents

Filtering and Sandboxing Input Filter inputFilter input Use strong typesUse strong types Range check numerical data (including dates)Range check numerical data (including dates) Use regular expressions to check stringsUse regular expressions to check strings Look for what is good, not what you think is bad!Look for what is good, not what you think is bad! Sandbox inputSandbox input Look for control and data channelsLook for control and data channels Keep untrusted input out of control channels (think of “sandboxing” it in a data channel)Keep untrusted input out of control channels (think of “sandboxing” it in a data channel) int age = int.Parse(Request.Form[“age”])

SQL Injection: Demo

Recognizing Control and Data Channels printf(a, b, c, d) SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = a; b, SqlDbType.VarChar); Process.Start(a, b);

Case Study: SQL Injection How would you fix the following BAD CODE?How would you fix the following BAD CODE? string name = Request.Form["name"]; cmd.CommandText = "select * from users where name='" + name + "'"; string n = Request.Form["name"]; if (!nameRegex.IsMatch(n)) throw... cmd.CommandText = "select * from users where SqlDbType.VarChar).Value = n; SqlDbType.VarChar).Value = n; Filter Sandbox Danger, control channel! This is much better:This is much better:

SQL Injection and Stored Procedures If you always use stored procedures, are you safe?If you always use stored procedures, are you safe? This code unnecessary dynamic SQL and allows SQL injection!This code unnecessary dynamic SQL and allows SQL injection! string name = Request.Form["Name"]; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "find_user"; SqlDbType.VarChar).Value = name; SqlDbType.VarChar).Value = name; create proc varchar(200)) as exec('select * from users where name=''' + exec('select * from users where name=''' + + '''')

Cross-Site Scripting (XSS)

XSS is where a website allows a user to inject arbitrary HTML codeXSS is where a website allows a user to inject arbitrary HTML code Attacker submits some data containing HTMLAttacker submits some data containing HTML This HTML might include undesirable graphics, text, and/or malicious scriptsThis HTML might include undesirable graphics, text, and/or malicious scripts Victim requests a page and gets the attacker’s HTML along with the pageVictim requests a page and gets the attacker’s HTML along with the page

ASP.NET Protects Me From XSS, Right? ASP.NET has some built-in protection to help deter XSS attacksASP.NET has some built-in protection to help deter XSS attacks Will it save you? Nope!Will it save you? Nope! Don’t assume that some piece of infrastructure will “protect” youDon’t assume that some piece of infrastructure will “protect” you Turn it off and escape the output:Turn it off and escape the output: In Web.config: In the ASPX pages:

Cross-Site Scripting: Demo

XSS Vulnerability “I want users to be able to include some markup in their content, so I allow HTML”“I want users to be able to include some markup in their content, so I allow HTML” Unsuspecting developer assumes the data in the DB is trusted…Unsuspecting developer assumes the data in the DB is trusted… …and an XSS vulnerability is born!…and an XSS vulnerability is born! string content = Request.Form["Content"]; StoreContentInDatabase(content); string content = RetrieveContentFromDatabase(); Response.Write(content);

Fixing the XSS Vulnerability...while still allowing certain types of markup!...while still allowing certain types of markup! The most effective solution is to filter outputThe most effective solution is to filter output Any untrusted data injected into your HTML stream should be encoded!Any untrusted data injected into your HTML stream should be encoded! string tainted = RetrieveContentFromDatabase(); string cleaned = Server.HtmlEncode(tainted); // Allow a bit of safe markup through cleaned = cleaned.Replace("<b>", " "); cleaned = cleaned.Replace("<i>", " "); Response.Write(cleaned);

Tamper Detection

Cookies and URL Mangling Do you use cookies or URL mangling to stash state on the user’s computer?Do you use cookies or URL mangling to stash state on the user’s computer? What would happen if a clever user manipulated that state?What would happen if a clever user manipulated that state? What you need is tamper detectionWhat you need is tamper detection AddToCart.aspx?itemId=22&price= AddToCart.aspx?itemId=22&price=449.90

Tamper Detection via HMAC HMAC is a great way to protect yourselfHMAC is a great way to protect yourself Hashed Message Authentication CodeHashed Message Authentication Code What it is:What it is: HMAC hashes the data along with a secret key that only your Web server knowsHMAC hashes the data along with a secret key that only your Web server knows Resulting hash is included as part of the stateResulting hash is included as part of the state Web server validates the hash to ensure the state is not tamperedWeb server validates the hash to ensure the state is not tampered Forms authentication does this for cookies encryptionForms authentication does this for cookies encryption

Sample Tamper Detection Code using System.Text; using System.Configuration; using System.Security.Cryptography; public static string AddTamperDetectionHMAC(string s) { byte[] data = Encoding.UTF8.GetBytes(s); byte[] data = Encoding.UTF8.GetBytes(s); byte[] hash = GetKeyedHash().ComputeHash(data); byte[] hash = GetKeyedHash().ComputeHash(data); return Convert.ToBase64String(hash) + '|' + s; return Convert.ToBase64String(hash) + '|' + s;} static HMACSHA1 GetKeyedHash() { string skey = ConfigurationSettings.AppSettings["key"]; string skey = ConfigurationSettings.AppSettings["key"]; byte[] key = Convert.FromBase64String(skey); byte[] key = Convert.FromBase64String(skey); return new HMACSHA1(key); return new HMACSHA1(key);} “Hello World”  “xXyU/Q0a2K5nbMfhzozk4Yczt4Y=|Hello world” “xXyU/Q0a2K5nbMfhzozk4Yczt4Y=|Hello world”

Simple Tamper Detection Code (2) public static string CheckAndRemoveHMAC(string s) { int i = s.IndexOf('|'); int i = s.IndexOf('|'); if (i == -1) throw new Exception("Malformed string"); if (i == -1) throw new Exception("Malformed string"); string prefix = s.Substring(0, i); string prefix = s.Substring(0, i); string suffix = s.Substring(i+1); string suffix = s.Substring(i+1); byte[] hash = Convert.FromBase64String(prefix); byte[] hash = Convert.FromBase64String(prefix); byte[] data = Encoding.UTF8.GetBytes(suffix); byte[] data = Encoding.UTF8.GetBytes(suffix); byte[] computedHash = GetKeyedHash().ComputeHash(data); byte[] computedHash = GetKeyedHash().ComputeHash(data); if (!isEqual(hash, computedHash)) if (!isEqual(hash, computedHash)) throw new Exception("String has been modified!"); throw new Exception("String has been modified!"); return suffix; return suffix;} public static string GenerateRandomKey() { byte[] rnd = new byte[16]; // 128 bits byte[] rnd = new byte[16]; // 128 bits new RNGCryptoServiceProvider().GetBytes(rnd); new RNGCryptoServiceProvider().GetBytes(rnd); return Convert.ToBase64String(rnd); return Convert.ToBase64String(rnd);}

References OnlineOnline msdn.com/securityguidancemsdn.com/securityguidance BooksBooks Threat Modeling (Swiderski & Snyder)Threat Modeling (Swiderski & Snyder) Secure Coding: Principles & Practices (Graff & van Wyk)Secure Coding: Principles & Practices (Graff & van Wyk) Writing Secure Code, 2 nd Edition (Howard & LeBlanc)Writing Secure Code, 2 nd Edition (Howard & LeBlanc) Building Secure Software (Viega & McGraw)Building Secure Software (Viega & McGraw)

Securing ASP.NET 2.0 Web Applications: Questions

Securing ASP.NET 2.0 Web Applications