SlideShare a Scribd company logo
Ruby on Rails
Building and Breaking Rails App
http://www.3SLabs.com
• Released to the world as ‘extracted’ from BaseCamp
(37Signals) by @dhh during July 2004.
• Merged with Merb Project during December 2008 and Rails
3.0 was released.
• Two supported branch of development currently:
– Rails 3.x
– Rails 4.x
Acceptance of RoR
.. and LOT more
Building Web Applications using Ruby on Rails
RoR Application Structure
Image Source: http://blog.ifuturz.com/ruby-on-rails/ruby-on-rails-mvc-learn-with-fun.html
Building a RoR App
1. Ruby & Ruby Gem Installation
2. Generate RoR Project
3. Design ERD
4. Generate Scaffolds
5. Define Relationships
6. Create Database Schema
7. Start Application Server
RoR: Web Blog Example
Our Blog is a web application where one or more Users
can self-register and sign-in using their registered
credentials.
Upon sign-in each User should be able to publish Blog
Post that is visible to any user or visitor of the portal.
Any User or Visitor of the portal should optionally
Comment on any Blog Post.
RoR: Web Blog ERD
Step1: Generate Project
Step2: Generate Scaffolds
Step3: Setup Database Schema
Step4: Launch App Server
http://m.xkcd.org/844/
Now write some
code or customize
the views..
After some love of Bootstrap3
Learning Ruby on Rails
• Ruby on Rails Official Guide
– http://guides.rubyonrails.org/
• Agile Web Development with Rails
– http://pragprog.com/book/rails4/agile-web-development-with-rails
• Ruby on Rails Podcasts
– http://podcast.rubyonrails.org/
• Rails Code School
– https://www.codeschool.com/courses/rails-for-zombies-redux
• Rails Cast
– http://railscasts.com/
Breaking Ruby on Rails Applications
Image (Karate) by Nicholas Riggle from The Noun Project CC By 2.0
Penetration Testing Rails App
• Black/Gray Box Approach
– Conventional Testing
– Fingerprinting Rails Framework
– Rails specific Vulnerability Testing
– Rails specific Weakness Testing
• White Box Approach
– Automated Scan for known Vulnerabilities
• Brakeman
– Attack Surface enumeration through Routes
– Authentication & Authorization Testing
– Common Rails information disclosures (secret_token.rb)
– Model Attributes Security
– Custom/Unconventional SQL Queries Audit
– Responsive View Audit
Fingerprinting Rails Applications
• No generic and definitive technique!
– It’s a cat & mouse game really.
• Heuristics
– Session Identifier
– Asset Pipeline
– [ … ]
Fingerprinting Rails Application
Not so easy for an application served with a reverse
proxy which is almost always the case in production.
Fingerprinting Rails Application
Leveraging the assets pipeline which is enabled by default from Rails 3.1
Automated Testing: Brakeman
http://brakemanscanner.org/
Need source code access !
Automated Testing: grep(1)
eval
instance_eval class_eval
DRb.start_server
find_by_sql
system exec
popen
You will be surprised to see how effective this is !
/`(.*)`/
Attack Surface: Routes
Attack Surface: Routes
• Default Routing
– <Resource> is handled by app/controllers/<resources>_controller.rb
– CRUD on Resource
Session Security
• A whole set of attacks are possible on Session
Management functionality of any Web
Application.
– Session Hijack, Session Fixation, Session Id Prediction, Session
Data Tampering, Leveraging Session Data for RCE etc.
• Rails provide inbuilt Session Management
– The session object is available to application
developer as a Hash/Map to store arbitrary data.
– The session object is serialized and stored in
corresponding session storage as per configuration.
– Signed cookie is used for session storage by default.
Session Security
http://robertheaton.com/2013/07/22/how-to-hack-a-rails-app-using-its-secret-token/
Not a Good idea !
Session Security: Best Practices
Enforce SSL in order to avoid sniffing of session id
Re-generate session after authentication to avoid session fixation
Store session in database instead of Cookie which is default
Cookie based Session Store are susceptible to Replay Attacks
Authentication
• Multiple Popular Authentication Plugin
– Devise
– RESTful Authentication
– […]
• Devise
– Auto-generated Registration, Confirmation, Login,
Forgot Password etc.
– Controller filter for enforcing authentication.
Testing Authentication
• Generic Issues
– Weak Session Management
– Weak Authentication Enforcement
– Weak Password Encryption
• Plugin/Gem Specific
– Devise Vulnerabilities
– Lack of Authentication Enforcement
– Timing Attacks
– Information Gathering through default message
Are all controllers protected by Authentication System?
Authorization
• Not provided by default in the framework.
– Encourages RESTful design.
• Easy to implement RBAC on Resources
– Multiple Gem/Plugin available
Example usage of CanCan for Authorization
https://github.com/ryanb/cancan
Testing Authorization
• Authorization Plugin or Custom Coded?
• Every functionality is RESTful?
• Query scoping in Controller
Rails CSRF Protection
CSRF Token generation and checking is enforced by default.
• Application must use Rails Form Tag Helps to
generate forms rather than HTML directly.
• HTTP GET is not protected !
Killing Rails CSRF Protection
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/
Rails Model Security
• The Business Logic Layer
– Database Abstraction through ORM
– Entity Relationship Definition
– Business Logic
• Common Security Issues
– Attribute Mass Assignment
• Mitigated by default in newer version of Rails
– Custom (insecure) SQL Queries
– Business Logic Vulnerabilities
Rails Model: Attribute Mass Assignment
The Model
The Controller
The Malicious Input
Rails Model: SQL Queries
Model Scope
Chained Query Interface (ActiveRelation)
Parameterized Qury
Rails Model: Insecure SQL Queries
The application developer should ensure that the Query Interface
understand the difference between Query and Data.
Rails Model: SQL Injection Vectors
• ActiveRecord does not escape parameters for
certain options:
Source: http://rails-sqli.org/
View Rendering
• Dynamic parameters are encoded by default
unless explicitly marked as safe.
• There are scope for Reflected XSS
– Strings marked explicitly with html_safe method.
– Textile/Markdown Injection
– Insecure used of content_tag
Secure Headers
• Rails 3.x is vulnerable to Clickjacking & UI
Redressing Type of attacks in default
configuration.
– Easy Mitigation
• gem ‘secureheaders’ in Gemfile
– https://github.com/twitter/secureheaders
Rails: Framework Vulnerabilities
http://www.cvedetails.com/vulnerability-list/vendor_id-12043/product_id-22568/Rubyonrails-Ruby-On-Rails.html
References
• Ruby on Rails Security Guide
– http://guides.rubyonrails.org/security.html
• Brakeman Scanner
– http://brakemanscanner.org/
• Rails SQLi Examples
– http://rails-sqli.org/
• OWASP Cheatsheet for RoR
– https://www.owasp.org/index.php/Ruby_on_Rails_Cheatsheet
• Ruby Security Configuration
– http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/
• Ruby Mechanize
– http://mechanize.rubyforge.org/
• Ruby Nokogiri
– http://nokogiri.org/
• The Noun Project
– http://thenounproject.com/

More Related Content

PDF
Secure Code Review 101
PDF
Spring Security
PPTX
Appium Presentation
PDF
Local File Inclusion to Remote Code Execution
PDF
Java Deserialization Vulnerabilities - The Forgotten Bug Class
PPTX
Getting Started with API Security Testing
PDF
Bug Bounty Hunter Methodology - Nullcon 2016
PDF
Web application security & Testing
Secure Code Review 101
Spring Security
Appium Presentation
Local File Inclusion to Remote Code Execution
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Getting Started with API Security Testing
Bug Bounty Hunter Methodology - Nullcon 2016
Web application security & Testing

What's hot (20)

PDF
Hacking Adobe Experience Manager sites
PDF
Exploiting Deserialization Vulnerabilities in Java
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PDF
Nullcon Goa 2016 - Automated Mobile Application Security Testing with Mobile ...
PPTX
Cross-Site Scripting (XSS)
PPTX
Secure Coding 101 - OWASP University of Ottawa Workshop
PPT
Introduction To OWASP
PDF
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
PDF
Hunting for Privilege Escalation in Windows Environment
PDF
Mobile Application Security
PDF
Api security-testing
PDF
OWASP Top 10 Web Application Vulnerabilities
PPTX
Linux privilege escalation
PPTX
SSRF For Bug Bounties
PPT
Owasp Top 10 And Security Flaw Root Causes
PPTX
Metasploit
PPTX
Secure coding practices
PDF
Api Gateway
PDF
Building Advanced XSS Vectors
PDF
Secure coding presentation Oct 3 2020
Hacking Adobe Experience Manager sites
Exploiting Deserialization Vulnerabilities in Java
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Nullcon Goa 2016 - Automated Mobile Application Security Testing with Mobile ...
Cross-Site Scripting (XSS)
Secure Coding 101 - OWASP University of Ottawa Workshop
Introduction To OWASP
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Hunting for Privilege Escalation in Windows Environment
Mobile Application Security
Api security-testing
OWASP Top 10 Web Application Vulnerabilities
Linux privilege escalation
SSRF For Bug Bounties
Owasp Top 10 And Security Flaw Root Causes
Metasploit
Secure coding practices
Api Gateway
Building Advanced XSS Vectors
Secure coding presentation Oct 3 2020
Ad

Viewers also liked (6)

PPTX
Django Web Application Security
PDF
Hacking Ruby on Rails at Railswaycon09
PPTX
IE Memory Protector
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
DOCX
Nullcon HackIM 2012 Solutions
PPT
Ruby On Rails
Django Web Application Security
Hacking Ruby on Rails at Railswaycon09
IE Memory Protector
Case Study of Django: Web Frameworks that are Secure by Default
Nullcon HackIM 2012 Solutions
Ruby On Rails
Ad

Similar to Ruby on Rails Penetration Testing (20)

PDF
Ruxmon feb 2013 what happened to rails
PDF
Securing Rails
PDF
Ruby on Rails Security
PDF
Ruby on Rails Security
PDF
Rails Security
PDF
RoR Workshop - Web applications hacking - Ruby on Rails example
PDF
Rails Security
PDF
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
PDF
Ruby on-rails-security
PDF
Security Goodness with Ruby on Rails
PPT
Ruby Security
 
PDF
Ruby On Rails Security 9984
PDF
Ruby on Rails Security Guide
PDF
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
PDF
Startup Institute NY - Authentication, Validation, and Basic Testing
PDF
Rails Security
PPT
Defending Against Attacks With Rails
ODP
Security on Rails
PDF
HES2011 - joernchen - Ruby on Rails from a Code Auditor Perspective
KEY
Rails 3 and OAuth for Barcamp Tampa
Ruxmon feb 2013 what happened to rails
Securing Rails
Ruby on Rails Security
Ruby on Rails Security
Rails Security
RoR Workshop - Web applications hacking - Ruby on Rails example
Rails Security
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Ruby on-rails-security
Security Goodness with Ruby on Rails
Ruby Security
 
Ruby On Rails Security 9984
Ruby on Rails Security Guide
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Startup Institute NY - Authentication, Validation, and Basic Testing
Rails Security
Defending Against Attacks With Rails
Security on Rails
HES2011 - joernchen - Ruby on Rails from a Code Auditor Perspective
Rails 3 and OAuth for Barcamp Tampa

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PDF
System and Network Administraation Chapter 3
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administration Chapter 2
PDF
Digital Strategies for Manufacturing Companies
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Introduction to Artificial Intelligence
PPTX
L1 - Introduction to python Backend.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Nekopoi APK 2025 free lastest update
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
ai tools demonstartion for schools and inter college
PPTX
ISO 45001 Occupational Health and Safety Management System
medical staffing services at VALiNTRY
System and Network Administraation Chapter 3
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Online Work Permit System for Fast Permit Processing
How to Migrate SBCGlobal Email to Yahoo Easily
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administration Chapter 2
Digital Strategies for Manufacturing Companies
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction to Artificial Intelligence
L1 - Introduction to python Backend.pptx
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Nekopoi APK 2025 free lastest update
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ai tools demonstartion for schools and inter college
ISO 45001 Occupational Health and Safety Management System

Ruby on Rails Penetration Testing

  • 1. Ruby on Rails Building and Breaking Rails App http://www.3SLabs.com
  • 2. • Released to the world as ‘extracted’ from BaseCamp (37Signals) by @dhh during July 2004. • Merged with Merb Project during December 2008 and Rails 3.0 was released. • Two supported branch of development currently: – Rails 3.x – Rails 4.x
  • 3. Acceptance of RoR .. and LOT more
  • 4. Building Web Applications using Ruby on Rails
  • 5. RoR Application Structure Image Source: http://blog.ifuturz.com/ruby-on-rails/ruby-on-rails-mvc-learn-with-fun.html
  • 6. Building a RoR App 1. Ruby & Ruby Gem Installation 2. Generate RoR Project 3. Design ERD 4. Generate Scaffolds 5. Define Relationships 6. Create Database Schema 7. Start Application Server
  • 7. RoR: Web Blog Example Our Blog is a web application where one or more Users can self-register and sign-in using their registered credentials. Upon sign-in each User should be able to publish Blog Post that is visible to any user or visitor of the portal. Any User or Visitor of the portal should optionally Comment on any Blog Post.
  • 14. After some love of Bootstrap3
  • 15. Learning Ruby on Rails • Ruby on Rails Official Guide – http://guides.rubyonrails.org/ • Agile Web Development with Rails – http://pragprog.com/book/rails4/agile-web-development-with-rails • Ruby on Rails Podcasts – http://podcast.rubyonrails.org/ • Rails Code School – https://www.codeschool.com/courses/rails-for-zombies-redux • Rails Cast – http://railscasts.com/
  • 16. Breaking Ruby on Rails Applications Image (Karate) by Nicholas Riggle from The Noun Project CC By 2.0
  • 17. Penetration Testing Rails App • Black/Gray Box Approach – Conventional Testing – Fingerprinting Rails Framework – Rails specific Vulnerability Testing – Rails specific Weakness Testing • White Box Approach – Automated Scan for known Vulnerabilities • Brakeman – Attack Surface enumeration through Routes – Authentication & Authorization Testing – Common Rails information disclosures (secret_token.rb) – Model Attributes Security – Custom/Unconventional SQL Queries Audit – Responsive View Audit
  • 18. Fingerprinting Rails Applications • No generic and definitive technique! – It’s a cat & mouse game really. • Heuristics – Session Identifier – Asset Pipeline – [ … ]
  • 19. Fingerprinting Rails Application Not so easy for an application served with a reverse proxy which is almost always the case in production.
  • 20. Fingerprinting Rails Application Leveraging the assets pipeline which is enabled by default from Rails 3.1
  • 22. Automated Testing: grep(1) eval instance_eval class_eval DRb.start_server find_by_sql system exec popen You will be surprised to see how effective this is ! /`(.*)`/
  • 24. Attack Surface: Routes • Default Routing – <Resource> is handled by app/controllers/<resources>_controller.rb – CRUD on Resource
  • 25. Session Security • A whole set of attacks are possible on Session Management functionality of any Web Application. – Session Hijack, Session Fixation, Session Id Prediction, Session Data Tampering, Leveraging Session Data for RCE etc. • Rails provide inbuilt Session Management – The session object is available to application developer as a Hash/Map to store arbitrary data. – The session object is serialized and stored in corresponding session storage as per configuration. – Signed cookie is used for session storage by default.
  • 27. Session Security: Best Practices Enforce SSL in order to avoid sniffing of session id Re-generate session after authentication to avoid session fixation Store session in database instead of Cookie which is default Cookie based Session Store are susceptible to Replay Attacks
  • 28. Authentication • Multiple Popular Authentication Plugin – Devise – RESTful Authentication – […] • Devise – Auto-generated Registration, Confirmation, Login, Forgot Password etc. – Controller filter for enforcing authentication.
  • 29. Testing Authentication • Generic Issues – Weak Session Management – Weak Authentication Enforcement – Weak Password Encryption • Plugin/Gem Specific – Devise Vulnerabilities – Lack of Authentication Enforcement – Timing Attacks – Information Gathering through default message Are all controllers protected by Authentication System?
  • 30. Authorization • Not provided by default in the framework. – Encourages RESTful design. • Easy to implement RBAC on Resources – Multiple Gem/Plugin available Example usage of CanCan for Authorization https://github.com/ryanb/cancan
  • 31. Testing Authorization • Authorization Plugin or Custom Coded? • Every functionality is RESTful? • Query scoping in Controller
  • 32. Rails CSRF Protection CSRF Token generation and checking is enforced by default. • Application must use Rails Form Tag Helps to generate forms rather than HTML directly. • HTTP GET is not protected !
  • 33. Killing Rails CSRF Protection http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/
  • 34. Rails Model Security • The Business Logic Layer – Database Abstraction through ORM – Entity Relationship Definition – Business Logic • Common Security Issues – Attribute Mass Assignment • Mitigated by default in newer version of Rails – Custom (insecure) SQL Queries – Business Logic Vulnerabilities
  • 35. Rails Model: Attribute Mass Assignment The Model The Controller The Malicious Input
  • 36. Rails Model: SQL Queries Model Scope Chained Query Interface (ActiveRelation) Parameterized Qury
  • 37. Rails Model: Insecure SQL Queries The application developer should ensure that the Query Interface understand the difference between Query and Data.
  • 38. Rails Model: SQL Injection Vectors • ActiveRecord does not escape parameters for certain options: Source: http://rails-sqli.org/
  • 39. View Rendering • Dynamic parameters are encoded by default unless explicitly marked as safe. • There are scope for Reflected XSS – Strings marked explicitly with html_safe method. – Textile/Markdown Injection – Insecure used of content_tag
  • 40. Secure Headers • Rails 3.x is vulnerable to Clickjacking & UI Redressing Type of attacks in default configuration. – Easy Mitigation • gem ‘secureheaders’ in Gemfile – https://github.com/twitter/secureheaders
  • 42. References • Ruby on Rails Security Guide – http://guides.rubyonrails.org/security.html • Brakeman Scanner – http://brakemanscanner.org/ • Rails SQLi Examples – http://rails-sqli.org/ • OWASP Cheatsheet for RoR – https://www.owasp.org/index.php/Ruby_on_Rails_Cheatsheet • Ruby Security Configuration – http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/ • Ruby Mechanize – http://mechanize.rubyforge.org/ • Ruby Nokogiri – http://nokogiri.org/ • The Noun Project – http://thenounproject.com/