35
Security of Web Applications TOP 6 RISKS TO AVOID

Security of Web Applications: Top 6 Risks To Avoid

Embed Size (px)

DESCRIPTION

A modest Web application security introduction to .NET developers.

Citation preview

Page 1: Security of Web Applications: Top 6 Risks To Avoid

Security of Web Applications

TOP 6 RISKS TO AVOID

Page 2: Security of Web Applications: Top 6 Risks To Avoid

Console.WriteLine(“Hello World”);

I'm Audrius Kovalenko

.NET Developer

Hack for fun

@slicklash

http://www.notreallycode.com

Page 3: Security of Web Applications: Top 6 Risks To Avoid

Forecasts for Upcoming Years

VERY CLOUDY

SaaS GROWTH

WEB APPLICATIONS IN HIGH-DEMAND

Page 4: Security of Web Applications: Top 6 Risks To Avoid

Web Application Security Today

Source: Web Hacking Incident Database (WHID)

Distribution of Attack Methods in 2011

Page 5: Security of Web Applications: Top 6 Risks To Avoid

Puzzle

How to pour all liquid into the glass?

Page 6: Security of Web Applications: Top 6 Risks To Avoid

IMPOSSIBLE

Everyone knows it

Page 7: Security of Web Applications: Top 6 Risks To Avoid

How to deliver secure product knowing little about application security?

Who's bag is it then?If that's my bag

SQLi

XSS

CSRF

HD Moore

Bruce

Schneier

Troy

Hunt

Michał Zalewski

Agile

TDD

Refactoring DI

Kent BeckREST

Steve

Freeman

DesignPatterns

Martin

Fowler

Builder vs Breaker

Page 8: Security of Web Applications: Top 6 Risks To Avoid

Problem

We don't know what we don't know

Page 9: Security of Web Applications: Top 6 Risks To Avoid

The Unknowns

WHAT ARE THE COUNTERMEASURES?

WHAT TO LOOK FOR?

WHAT ARE THE MAJOR RISKS?

Page 10: Security of Web Applications: Top 6 Risks To Avoid

CWE/SANS Top 25 Most Dangerous Software Errors

https://cwe.mitre.org/top25

Page 11: Security of Web Applications: Top 6 Risks To Avoid

Open Web Application Security Project

OWASPhttps://www.owasp.org

Page 12: Security of Web Applications: Top 6 Risks To Avoid

What is a risk anyway?

Page 13: Security of Web Applications: Top 6 Risks To Avoid

The OWASP Top 10 6 Web Risks

A3 BROKEN AUTHENTICATION AND SESSION MANAGEMENT

A1 INJECTION

A2 CROSS SITE SCRIPTING (XSS)

A4 INSECURE DIRECT OBJECT REFERENCES

A5 CROSS SITE REQUEST FORGERY (CSRF)

A6 SECURITY MISCONFIGURATION

Page 14: Security of Web Applications: Top 6 Risks To Avoid

Injections

Breaking out of a data context into a code context

Why is SQLi still around?

Page 15: Security of Web Applications: Top 6 Risks To Avoid

Injections (2)

var catId = Request.QueryString["Category"];var sql = "SELECT * FROM Products WHERE [CategoryId] = " + catId;

Page 16: Security of Web Applications: Top 6 Risks To Avoid

Anti-Injection

ORM

PARAMETERIZED QUERIES

DON'T BE LAZY

Page 17: Security of Web Applications: Top 6 Risks To Avoid

Cross Site Scripting (XSS)

Injection of client-side code into Web pages viewed by other users

public static MvcHtmlString DeviceInfoEvil(this HtmlHelper helper){ string s = "<span>" + helper.ViewContext.HttpContext.Request.UserAgent + "</span>"; return MvcHtmlString.Create(s);}

[...]

Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5;)<script>alert(1);</script>

[...]

public static MvcHtmlString DeviceInfoGood(this HtmlHelper helper){ TagBuilder userAgent = new TagBuilder("span"); userAgent.SetInnerText(helper.ViewContext.HttpContext.Request.UserAgent); return MvcHtmlString.Create(userAgent.ToString());}

Page 18: Security of Web Applications: Top 6 Risks To Avoid

Cross Site Request Forgery (CSRF)

Forged requests executed by tricking authenticated victim

<img src="https://bank.com/smth?param=1" />

<iframe src="https://bank.com/smth?param=1" />

<body onload="document.forms[0].submit"> <form method="post" action="https://bank.com/smth"> <input type="hidden" name="param" value="1" /> </form></body>

Page 19: Security of Web Applications: Top 6 Risks To Avoid

Anti-XSS

INPUT FILTERING

OUTPUT FILTERING

MICROSOFT AntiXSS

OUTPUT FILTERING

ANTIFORGERY TOKENS

Page 20: Security of Web Applications: Top 6 Risks To Avoid

Broken Authentication andSession Management

Poor implementation of authentication and session management

6.5 MILLION HASHES

PLAIN SHA1

450 000 PASSWORDS

PLAIN TEXT

June 2012 July 2012

Page 21: Security of Web Applications: Top 6 Risks To Avoid

Be careful

OUTPUT FILTERING

HASH + SALT + STRECHING

NO HARDCODED “SHORTCUTS”

TLS

Use #if DEBUG

bcrypt/scrypt

https://www.cookiecadger.com

DON'T REINVENT THE WHEEL

Page 22: Security of Web Applications: Top 6 Risks To Avoid

Insecure Direct Object References

Unauthorized access of exposed reference to an internal implementation

MASS ASSIGNMENT VULNERABILITY

Page 23: Security of Web Applications: Top 6 Risks To Avoid

Insecure Direct Object References (2)

public class User{ public string UserName { get; set; } public bool IsAdmin { get; set; }}

[Authorize][AcceptVerbs(HttpVerbs.Post)]public ActionResult UpdateUser(User model){ if (ModelState.IsValid) { var user = db.Users.Single(u => u.UserName == model.UserName); if (TryUpdateModel(user)) { db.SaveChanges(); } } return View();}

Page 24: Security of Web Applications: Top 6 Risks To Avoid

Insecure Direct Object References (3)

public ActionResult UpdateUser([Bind(Exclude="IsAdmin")] User model) //Black Listing - NO

[...]

public ActionResult UpdateUser([Bind(Include="UserName")] User model) //White Listing – OK

[...]

public class UserViewModel //Secure by Design - BEST{ public string UserName { get; set; }}

Page 25: Security of Web Applications: Top 6 Risks To Avoid

Countermeasures

CODE REVIEWS

ACCESS CHECKS

NO COPY-PASTE

Page 26: Security of Web Applications: Top 6 Risks To Avoid

Security Misconfiguration

Improper application configuration

Page 27: Security of Web Applications: Top 6 Risks To Avoid

Web.Config Security Analyzer

https://sourceforge.net/projects/wcsa

Page 28: Security of Web Applications: Top 6 Risks To Avoid

Introducing in development

DEDICATED PERSON

SPECIAL TRAINING

SELF TRAINING LEARN

PRACTICE

UNDERSTAND

?

Page 29: Security of Web Applications: Top 6 Risks To Avoid

Common Excuses

TIGHT DEADLINESS Budget

NO ONE WILL HACK US Ignorance

Page 30: Security of Web Applications: Top 6 Risks To Avoid

The Real Issue

WRONG PERSON IN WRONG PLACE Architect

Manager

Lazy Co-Worker

Page 31: Security of Web Applications: Top 6 Risks To Avoid

Security is hard but possiblewhen you know

Page 32: Security of Web Applications: Top 6 Risks To Avoid

Drowning is your personal problem

Don't forget

Page 33: Security of Web Applications: Top 6 Risks To Avoid

Further Reading

Page 34: Security of Web Applications: Top 6 Risks To Avoid

Highly Recommended

ACADEMIC

ENTERPRISE

HACKER

Page 35: Security of Web Applications: Top 6 Risks To Avoid

Learning From The Breakers

http://www.irongeek.com

Hacking IllustratedVideo from Security Conferences