35
Rails Security

ATLRUG Security Workshop - 9/10/2014

  • Upload
    jasnow

  • View
    65

  • Download
    4

Embed Size (px)

DESCRIPTION

4-hour ATLRUG Rails Security Workshop on 9/10/2014 by Ken Johnson

Citation preview

Page 1: ATLRUG  Security Workshop - 9/10/2014

Rails Security

Page 2: ATLRUG  Security Workshop - 9/10/2014

Introductions

• Jack Mannino – CEO @nVisium

– Lives in the JVM

– Beats up on mobile + wearables

– Scala, Swift, Java (Android)

• Ken Johnson – CTO @nVisium

– Former LivingSocialite

– Develop heavily in Rails

– Railsgoat Co-Author

Page 3: ATLRUG  Security Workshop - 9/10/2014

Why are we all here?

• Us?

– MINASWAN

• You?

– Hopefully to have some fun

Page 4: ATLRUG  Security Workshop - 9/10/2014

Before we begin

• Machine assignment & RDP

• Credentials

– Username: trainee

– Password: tr41n1ng

• Source code: ~/pentest/railsgoat

• Text Editor: type subl

• Burp: ~/Desktop/burp/

Page 5: ATLRUG  Security Workshop - 9/10/2014

Course Outline

• Model Layer

• Presentation Layer (View)

• Logic Layer (Controller)

• Unit-Tests

• Defensive Tools

Page 6: ATLRUG  Security Workshop - 9/10/2014

Course Outline (Model)

• Model Layer

– Mass Assignment

– MetaProgramming

– Hashing / Encryption

– SQL Injection

Page 7: ATLRUG  Security Workshop - 9/10/2014

Course Outline (Presentation)

• Cross-Site Scripting

• Browser Behavior

• Error Messages & Enumeration

Page 8: ATLRUG  Security Workshop - 9/10/2014

Course Outline (Logic)

• Insecure Direct Object Reference

• Remote Code Execution

• Logic Flaws

• CSRF

• Session Handling

• Redirection

• Authentication Tips

Page 9: ATLRUG  Security Workshop - 9/10/2014

Let’s get started

• First though, let’s walk through a few things you’ll need to know in this course:

– What is an intercepting proxy?

• FAQ (No, SSL is not a problem, let me explain why)

– Instructions on getting started

– Start Railsgoat

Page 10: ATLRUG  Security Workshop - 9/10/2014

MODEL LAYER

Page 11: ATLRUG  Security Workshop - 9/10/2014

Model Layer – Mass Assignment

• Mass- Assignment

– Not a huge issue in Rails 4… unless you instantiate models with data *outside* of the controller

– Rails 2 & 3 (don’t be ashamed, someone in this room is running 2.x) – Yes, very much a problem

– Audit for fun & profit

– Ready, set, hack!

Page 12: ATLRUG  Security Workshop - 9/10/2014

Model Layer - MetaProgramming

• Code that writes code, sweet!

• Code that writes code based off user input, dangerous!

• Examples:

– Constantize

– Send

Page 13: ATLRUG  Security Workshop - 9/10/2014

Model Layer – Hashing/Encryption

• Hashing vs. Encryption

• Strong hashing algorithms

• Strong encryption algorithms

• Rack::Utils.secure_compare vs. “==“

• Be careful how you re-use

Page 14: ATLRUG  Security Workshop - 9/10/2014

Model Layer – SQL Injection

• ActiveRecord - Safe… well, sort of

• http://rails-sqli.org/

• “SQLMap Hacker Fun Time”

Page 15: ATLRUG  Security Workshop - 9/10/2014

PRESENTATION LAYER

Page 16: ATLRUG  Security Workshop - 9/10/2014

Presentation Layer – XSS

• XSS = Cross-Site Scripting (aka – html injection)

• DOM

• html_safe

• JSON 3.2x

• Ready, set, hack

Page 17: ATLRUG  Security Workshop - 9/10/2014

Presentation Layer – Browser Behavior

• Cookies

– Flags

– Client-side vs. Server-side

• Caching

– Browser Caching Headers

• Headers

– CSP

– secure_headers

Page 18: ATLRUG  Security Workshop - 9/10/2014

Presentation Layer – Error Messages

• Enumeration

• Common places

– Forgot Password Features

– Sign Up

– Profile Updates

– Login

Page 19: ATLRUG  Security Workshop - 9/10/2014

LOGIC LAYER

Page 20: ATLRUG  Security Workshop - 9/10/2014

Logic Layer – Insecure DOR

• Do not trust users

• Prevention

• Ready, Set, Hack

Page 21: ATLRUG  Security Workshop - 9/10/2014

Logic Layer - RCE

• Remote Code Execution

– YAML

– Marshal

Page 22: ATLRUG  Security Workshop - 9/10/2014

Logic Layer – Logic Flaws

• Example 1:

– Bidding site and account lock-out

• Example 2:

– 3 step checkout, skip step 2?

• Example 3:

– Spot the bug!

Page 23: ATLRUG  Security Workshop - 9/10/2014

Logic Layer - CSRF

• Somewhat well known aspects

– Meta tag helper

– On by default

– protect_from_forgery filter

• Not so well known…

– `match` routes bypass

– Chain of execution is not halted

Page 24: ATLRUG  Security Workshop - 9/10/2014

Logic Layer – Session Handling

• Logout

– reset_session

– Clear session values

• Login

– reset_session

• before_filter(s)

– Take a whitelist approach

• Base access decisions off the current_user

Page 25: ATLRUG  Security Workshop - 9/10/2014

Logic Layer - Redirection

• redirect_to …. You scoundrel

• Why does this matter?

• URI.parse()

Page 26: ATLRUG  Security Workshop - 9/10/2014

Logic Layer – Authentication Tips

• Account Lock-Out

• Password Complexity

• Enumeration

• Password Hashing

• (heads-up) – Covering Devise auth in upcoming release of Railsgoat

Page 27: ATLRUG  Security Workshop - 9/10/2014

UNIT-TESTS & REGRESSION

Page 28: ATLRUG  Security Workshop - 9/10/2014

Unit-Tests / Regression Testing

• Railsgoat has examples

– RSpec

• Regression Testing

– Why

– How

Page 29: ATLRUG  Security Workshop - 9/10/2014

DEFENSIVE TOOLS

Page 30: ATLRUG  Security Workshop - 9/10/2014

Defensive Tools

• Brakeman

• Bundler-Audit

• Ensnare

• Rack-attack

Page 31: ATLRUG  Security Workshop - 9/10/2014

Q&A

Page 32: ATLRUG  Security Workshop - 9/10/2014

Free Subscription

• Send an email to [email protected]

• Subject line – ATLRUG Free Sub

– We will setup on Friday

Page 33: ATLRUG  Security Workshop - 9/10/2014

Contact

• Twitter: – @cktricky

– @jack_mannino

– @mccabe615

• Email:– [email protected]

[email protected]

• Railsgoat– http://railsgoat.cktricky.com

Page 34: ATLRUG  Security Workshop - 9/10/2014

Thanks!

• A big “Thank you” is in order to Al Snow

Page 35: ATLRUG  Security Workshop - 9/10/2014

THANK YOU ATLRUG