ATLRUG Rails Security Presentation - 9/10/2014

32
Railsgoat

description

ATLRUG RailsGoat Security Evening Presentation on 9/10/2014 by Ken Johnson

Transcript of ATLRUG Rails Security Presentation - 9/10/2014

Page 1: ATLRUG Rails Security Presentation - 9/10/2014

Railsgoat

Page 2: ATLRUG Rails Security Presentation - 9/10/2014

Introductions

• Ken Johnson – CTO @nVisium– Former LivingSocialite – Develop heavily in Rails– Railsgoat Co-Author

• Mike – Director of ProServ @nVisium– Former LivingSocialite– Isn’t here to defend himself, I can say what I want– Paler than me– Trendsetter of the “Skhaki”

Page 3: ATLRUG Rails Security Presentation - 9/10/2014

Why?

• Why not?• Lack of quality training available• Assist all of you!

Page 4: ATLRUG Rails Security Presentation - 9/10/2014

RAILSGOAT CONFIG

Page 5: ATLRUG Rails Security Presentation - 9/10/2014

Railsgoat Current Config

• Rails 3.x• Custom Authentication• MySQL (optional) & SQLite • Mailcatcher• RSpec tests• **Easy to find credentials**

Page 6: ATLRUG Rails Security Presentation - 9/10/2014

Railsgoat Upcoming Config

• Rails 4.x• Devise Authentication (w/ Tutorials)• MySQL & SQLite (optional)• Mailcatcher• RSpec• Open to suggestions

Page 7: ATLRUG Rails Security Presentation - 9/10/2014

MODEL LAYER

Page 8: ATLRUG Rails Security Presentation - 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 9: ATLRUG Rails Security Presentation - 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 10: ATLRUG Rails Security Presentation - 9/10/2014

Model Layer – SQL Injection

• ActiveRecord - Safe… well, sort of• http://rails-sqli.org/

Page 11: ATLRUG Rails Security Presentation - 9/10/2014

PRESENTATION LAYER

Page 12: ATLRUG Rails Security Presentation - 9/10/2014

Presentation Layer – XSS

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

• html_safe• JSON 3.2x

Page 13: ATLRUG Rails Security Presentation - 9/10/2014

Presentation Layer – Browser Behavior

• Cookies– Client-side vs. Server-side

• Headers– CSP– secure_headers

Page 14: ATLRUG Rails Security Presentation - 9/10/2014

LOGIC LAYER

Page 15: ATLRUG Rails Security Presentation - 9/10/2014

Logic Layer – Insecure DOR

• Do not trust users• Prevention

Page 16: ATLRUG Rails Security Presentation - 9/10/2014

Logic Layer - RCE

• Remote Code Execution– YAML– Marshal

Page 17: ATLRUG Rails Security Presentation - 9/10/2014

Logic Layer – Regexp

• Be careful with your Regular Expression• Subtle Logic Flaw (demo)

Page 18: ATLRUG Rails Security Presentation - 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 19: ATLRUG Rails Security Presentation - 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 20: ATLRUG Rails Security Presentation - 9/10/2014

Logic Layer - Redirection

• redirect_to …. You scoundrel• Why does this matter?• URI.parse()

Page 21: ATLRUG Rails Security Presentation - 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 22: ATLRUG Rails Security Presentation - 9/10/2014

UNIT-TESTS & REGRESSION

Page 23: ATLRUG Rails Security Presentation - 9/10/2014

Unit-Tests / Regression Testing

• Railsgoat has examples– RSpec

• Regression Testing– Why– How

Page 24: ATLRUG Rails Security Presentation - 9/10/2014

DEFENSIVE TOOLS

Page 25: ATLRUG Rails Security Presentation - 9/10/2014

Defensive Tools

• Brakeman• Bundler-Audit• Ensnare• Rack-attack

Page 26: ATLRUG Rails Security Presentation - 9/10/2014

ROADMAP

Page 27: ATLRUG Rails Security Presentation - 9/10/2014

Roadmap

• Use GitHub Issue Tracker• Recap of upgrade effort• Extensible so looking for more contributors

Page 28: ATLRUG Rails Security Presentation - 9/10/2014

Q&A

• Questions?

Page 29: ATLRUG Rails Security Presentation - 9/10/2014

Free Subscription

• Send an email to [email protected]• Subject line – ATLRUG Free Sub– We will setup on Friday

Page 30: ATLRUG Rails Security Presentation - 9/10/2014

Contact

• Twitter: – @cktricky – @mccabe615

• Email:– [email protected][email protected]

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

Page 31: ATLRUG Rails Security Presentation - 9/10/2014

Thanks to the following

• Al Snow• Jim Manico• Jack Mannino• Justin Collins• Neil Matatall• …and a bunch of other folks as well

Page 32: ATLRUG Rails Security Presentation - 9/10/2014

THANK YOU ATLRUG