SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Heiko Webers, bauland42


Hacking Ruby on Rails
Heiko Webers




 CEO of bauland42: Secure and innovative web
  applications, security code audits:
  http://www.bauland42.de
 Ruby on Rails Security Project: Blog and Book
  at http://www.rorsecurity.info
Cross-Site Scripting in Rails 3
 Before: <%= h @project.name %>
 After: <%= @project.name %>
 Unless you want to allow HTML:
   <%= raw @project.name %>

 Automatically safe:
  <%= content_tag(:div, text) + tag(:br) %>
 Mark as safe:
    <%= content_tag(:div, text) + “<br />“.html_safe! %>
Hit list: Mass assignment
 User.new(params[:user])
 params[:user] #=
   {:login => “admin“, :admin => true}
 attr_accessible :login
Hit list: Privilege escalation
 def edit
 @user = User.find(prams[:id])
 end
 restful-authentication plugin has authorization module
Hit list
 filter_parameter_logging :password, :credit_card_no, :b
  ank_account_no
 Don‘t deploy/SVN database.yml
 Enforce TLS during transmission of sensitive
  information: credit card numbers, passwords
 Test security: Authentication, authorization, SQL
  Injection, XSS
Hit list
 The entire application is only as secure as the weakest
  link
 Update server software frequently: phpMyAdmin,
  OpenSSL, gems, web server
 Review the signup and login process
    No weak security questions when password forgotten
    Block account when too many wrong passwords
    Require to enter the (old) password when changing a
     password/e-mail address
Hit list
   Proactively check the server security with Nessus
Hit list: Cryptography
 Don‘t store sensitive information in the clear
 Use a one-way cryptographic hash function to compare
  passwords
   assert_equal OpenSSL::Digest::Digest.new('SHA1',
    entered_password), @user.password
   Generate an individual SALT value for each user
    record
   Add the SALT to the password string and encrypt it
 Use only secure ciphers (no DES or MD5)
Hit list: Cryptography
 Use symmetric cryptography to encrypt large amounts
  of data, for example AES, 128 key length
 Asymmetric cryptography can be used if another
  application decrypts the information
Hello admin panel
Admin panel
   Admin panel security is even more important
     Vulnerabilities are harder to exploit, but more destructive
     I‘ve seen XSS holes in spam reports, user names, ...
        Can be used to steal an administrator‘s session

   Social engineering may help to get access
       Hack the e-mail account of an employee to request the
        admin password
   In most admin panels attackers can run completely riot
    and CRUD everything
Admin panel
   Inside the panel
     Take precautions for the worst case: Introduce different
      admin roles or require to enter another password for serious
      actions
     Validate/Filter input and output just as in the main
      application
Admin panel
   Authentication
       Put the panel to another sub-domain
          A stolen admin cookie from www. doesn‘t work in admin.

       Don‘t authenticate with user name and password from the
        main application
Admin panel
   Authentication
    Block the admin account for 15 minutes after 3 unsuccessful
     logins
 Authenticate with something you have, not with something you
  know
    Allow access only from certain IP addresses (check
     request.remote_ip)
       Allow access only from certain machines with client SSL
        certificates
File uploads
   Everything allowed:
    class Company < ActiveRecord::Base
      has_attachment :storage => :file_system,
       :path_prefix => 'public/files'
    end
File uploads
   Allow only images:
    class Company < ActiveRecord::Base
      has_attachment :storage => :file_system,
       :path_prefix => 'public/files',
       :content_type => :image

   validates_as_attachment
  end
 Now upload logo.html.jpg
 IE displays the HTML
File Uploads and Apache
 Now upload logo.php.jpg
 Address the file and see the executed PHP

    LoadModule php4_module modules/libphp4.so
    AddType application/x-httpd-php .php

   It‘s a common misconception that this will enable the
    module only for files ending in .php
File Uploads Countermeasures
 Store uploaded files outside DocumentRoot directory if
  you can
 Come up with a random/artificial filename if you can
 Use AV scanners to check the file before allowing
  access to it

   But how to check for the correct MIME type?
File Uploads MIME Type
 Problem: Checking the file name and MIME type
  provided by the user is not reliable
 logo.jpg may still be evil




 This file contains a PNG signature: %PNG
 And a JavaScript comment:
  <script>alert('You are vulnerable!');</script>
MIME Type Sniffing
 Internet Explorer will sniff the first 256 bytes for its
  MIME type if it‘s disputed
 IE assumes text/html if these strings are found: <html,
  <head, <body, <plaintext, <pre, <table, <a href, <title,
  <img src, <script
 Only carried out when the file URL is opened directly -
  not when requested by an image tag
File Uploads Countermeasures
 The easy way: Convert uploaded images to JPEG
 Not allowed? What about other file types?
File Uploads Countermeasures
   Validate the file name and MIME type from the client
   Do the same on the server: shared-mime-info gem
      See MIME sniffing countermeasures blog post
      There may be problems with unknown file types
   Attachment_fu: Height and Width must not be NULL for
    images
   Check the first 256 bytes for HTML
   Use send_file :disposition => 'attachment' if possible
Questions?

Contenu connexe

Tendances

Secure Web Services
Secure Web ServicesSecure Web Services
Secure Web ServicesRob Daigneau
 
Owasp top 10 web application security hazards - Part 1
Owasp top 10 web application security hazards - Part 1Owasp top 10 web application security hazards - Part 1
Owasp top 10 web application security hazards - Part 1Abhinav Sejpal
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
WordPress Security - WordPress Meetup Copenhagen 2013
WordPress Security - WordPress Meetup Copenhagen 2013WordPress Security - WordPress Meetup Copenhagen 2013
WordPress Security - WordPress Meetup Copenhagen 2013Thor Kristiansen
 
WordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
WordCamp Chicago 2011 - WordPress End User Security - Dre ArmedaWordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
WordCamp Chicago 2011 - WordPress End User Security - Dre ArmedaDre Armeda
 
How To Lock Down And Secure Your Wordpress
How To Lock Down And Secure Your WordpressHow To Lock Down And Secure Your Wordpress
How To Lock Down And Secure Your WordpressChelsea O'Brien
 
Security Presentation for Boulder WordPress Meetup
Security Presentation for Boulder WordPress MeetupSecurity Presentation for Boulder WordPress Meetup
Security Presentation for Boulder WordPress MeetupAngela Bowman
 
Building an API Security Ecosystem
Building an API Security EcosystemBuilding an API Security Ecosystem
Building an API Security EcosystemPrabath Siriwardena
 
WordPress Security WordCamp OC 2013
WordPress Security WordCamp OC 2013WordPress Security WordCamp OC 2013
WordPress Security WordCamp OC 2013Brad Williams
 
Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Michele Butcher-Jones
 
WordPress Security Presentation
WordPress Security PresentationWordPress Security Presentation
WordPress Security PresentationAndrew Paton
 
WordPress End-User Security - WordCamp Las Vegas 2011
WordPress End-User Security - WordCamp Las Vegas 2011WordPress End-User Security - WordCamp Las Vegas 2011
WordPress End-User Security - WordCamp Las Vegas 2011Dre Armeda
 
WordPress Security Updated - NYC Meetup 2009
WordPress Security Updated - NYC Meetup 2009WordPress Security Updated - NYC Meetup 2009
WordPress Security Updated - NYC Meetup 2009Brad Williams
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress SecurityShawn Hooper
 
Word press security 101
Word press security 101  Word press security 101
Word press security 101 Kojac801
 

Tendances (20)

Secure Web Services
Secure Web ServicesSecure Web Services
Secure Web Services
 
Owasp top 10 web application security hazards - Part 1
Owasp top 10 web application security hazards - Part 1Owasp top 10 web application security hazards - Part 1
Owasp top 10 web application security hazards - Part 1
 
Make profit with UI-Redressing attacks.
Make profit with UI-Redressing attacks.Make profit with UI-Redressing attacks.
Make profit with UI-Redressing attacks.
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
WordPress Security - WordPress Meetup Copenhagen 2013
WordPress Security - WordPress Meetup Copenhagen 2013WordPress Security - WordPress Meetup Copenhagen 2013
WordPress Security - WordPress Meetup Copenhagen 2013
 
WordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
WordCamp Chicago 2011 - WordPress End User Security - Dre ArmedaWordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
WordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
 
How To Lock Down And Secure Your Wordpress
How To Lock Down And Secure Your WordpressHow To Lock Down And Secure Your Wordpress
How To Lock Down And Secure Your Wordpress
 
Security Presentation for Boulder WordPress Meetup
Security Presentation for Boulder WordPress MeetupSecurity Presentation for Boulder WordPress Meetup
Security Presentation for Boulder WordPress Meetup
 
Building an API Security Ecosystem
Building an API Security EcosystemBuilding an API Security Ecosystem
Building an API Security Ecosystem
 
WordPress Security WordCamp OC 2013
WordPress Security WordCamp OC 2013WordPress Security WordCamp OC 2013
WordPress Security WordCamp OC 2013
 
Facebook + Ruby
Facebook + RubyFacebook + Ruby
Facebook + Ruby
 
WordPress Security
WordPress SecurityWordPress Security
WordPress Security
 
HTTPS and HTTP/2
HTTPS and HTTP/2HTTPS and HTTP/2
HTTPS and HTTP/2
 
Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?
 
Google Hacking Basics
Google Hacking BasicsGoogle Hacking Basics
Google Hacking Basics
 
WordPress Security Presentation
WordPress Security PresentationWordPress Security Presentation
WordPress Security Presentation
 
WordPress End-User Security - WordCamp Las Vegas 2011
WordPress End-User Security - WordCamp Las Vegas 2011WordPress End-User Security - WordCamp Las Vegas 2011
WordPress End-User Security - WordCamp Las Vegas 2011
 
WordPress Security Updated - NYC Meetup 2009
WordPress Security Updated - NYC Meetup 2009WordPress Security Updated - NYC Meetup 2009
WordPress Security Updated - NYC Meetup 2009
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress Security
 
Word press security 101
Word press security 101  Word press security 101
Word press security 101
 

Similaire à Hacking Ruby on Rails at Railswaycon09

Application Security
Application SecurityApplication Security
Application Securitynirola
 
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Bastian Grimm
 
How LinkedIn changed its security model in order to offer an API
How LinkedIn changed its security model  in order to offer an APIHow LinkedIn changed its security model  in order to offer an API
How LinkedIn changed its security model in order to offer an APILinkedIn
 
Defcon9 Presentation2001
Defcon9 Presentation2001Defcon9 Presentation2001
Defcon9 Presentation2001Miguel Ibarra
 
Web Application Security - "In theory and practice"
Web Application Security - "In theory and practice"Web Application Security - "In theory and practice"
Web Application Security - "In theory and practice"Jeremiah Grossman
 
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...CODE BLUE
 
Defending Against Attacks With Rails
Defending Against Attacks With RailsDefending Against Attacks With Rails
Defending Against Attacks With RailsTony Amoyal
 
Django Web Application Security
Django Web Application SecurityDjango Web Application Security
Django Web Application Securitylevigross
 
WordPress End-User Security
WordPress End-User SecurityWordPress End-User Security
WordPress End-User SecurityDre Armeda
 
Security Checklist for TYPO3
Security Checklist for TYPO3Security Checklist for TYPO3
Security Checklist for TYPO3jweiland
 
Php My Sql Security 2007
Php My Sql Security 2007Php My Sql Security 2007
Php My Sql Security 2007Aung Khant
 
Presentation on Top 10 Vulnerabilities in Web Application
Presentation on Top 10 Vulnerabilities in Web ApplicationPresentation on Top 10 Vulnerabilities in Web Application
Presentation on Top 10 Vulnerabilities in Web ApplicationMd Mahfuzur Rahman
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Brian Huff
 

Similaire à Hacking Ruby on Rails at Railswaycon09 (20)

Application Security
Application SecurityApplication Security
Application Security
 
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
 
How LinkedIn changed its security model in order to offer an API
How LinkedIn changed its security model  in order to offer an APIHow LinkedIn changed its security model  in order to offer an API
How LinkedIn changed its security model in order to offer an API
 
Defcon9 Presentation2001
Defcon9 Presentation2001Defcon9 Presentation2001
Defcon9 Presentation2001
 
Web Application Security - "In theory and practice"
Web Application Security - "In theory and practice"Web Application Security - "In theory and practice"
Web Application Security - "In theory and practice"
 
secure php
secure phpsecure php
secure php
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
 
Defending Against Attacks With Rails
Defending Against Attacks With RailsDefending Against Attacks With Rails
Defending Against Attacks With Rails
 
Django Web Application Security
Django Web Application SecurityDjango Web Application Security
Django Web Application Security
 
Web Security
Web SecurityWeb Security
Web Security
 
WordPress End-User Security
WordPress End-User SecurityWordPress End-User Security
WordPress End-User Security
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Unusual Web Bugs
Unusual Web BugsUnusual Web Bugs
Unusual Web Bugs
 
Web Bugs
Web BugsWeb Bugs
Web Bugs
 
Security Checklist for TYPO3
Security Checklist for TYPO3Security Checklist for TYPO3
Security Checklist for TYPO3
 
Php My Sql Security 2007
Php My Sql Security 2007Php My Sql Security 2007
Php My Sql Security 2007
 
Presentation on Top 10 Vulnerabilities in Web Application
Presentation on Top 10 Vulnerabilities in Web ApplicationPresentation on Top 10 Vulnerabilities in Web Application
Presentation on Top 10 Vulnerabilities in Web Application
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)
 
Rails Security
Rails SecurityRails Security
Rails Security
 

Dernier

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
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 Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 educationjfdjdjcjdnsjd
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Dernier (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - 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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Hacking Ruby on Rails at Railswaycon09

  • 2. Heiko Webers  CEO of bauland42: Secure and innovative web applications, security code audits: http://www.bauland42.de  Ruby on Rails Security Project: Blog and Book at http://www.rorsecurity.info
  • 3. Cross-Site Scripting in Rails 3  Before: <%= h @project.name %>  After: <%= @project.name %>  Unless you want to allow HTML: <%= raw @project.name %>  Automatically safe: <%= content_tag(:div, text) + tag(:br) %>  Mark as safe: <%= content_tag(:div, text) + “<br />“.html_safe! %>
  • 4. Hit list: Mass assignment  User.new(params[:user])  params[:user] #= {:login => “admin“, :admin => true}  attr_accessible :login
  • 5. Hit list: Privilege escalation  def edit  @user = User.find(prams[:id])  end  restful-authentication plugin has authorization module
  • 6. Hit list  filter_parameter_logging :password, :credit_card_no, :b ank_account_no  Don‘t deploy/SVN database.yml  Enforce TLS during transmission of sensitive information: credit card numbers, passwords  Test security: Authentication, authorization, SQL Injection, XSS
  • 7. Hit list  The entire application is only as secure as the weakest link  Update server software frequently: phpMyAdmin, OpenSSL, gems, web server  Review the signup and login process  No weak security questions when password forgotten  Block account when too many wrong passwords  Require to enter the (old) password when changing a password/e-mail address
  • 8. Hit list  Proactively check the server security with Nessus
  • 9. Hit list: Cryptography  Don‘t store sensitive information in the clear  Use a one-way cryptographic hash function to compare passwords  assert_equal OpenSSL::Digest::Digest.new('SHA1', entered_password), @user.password  Generate an individual SALT value for each user record  Add the SALT to the password string and encrypt it  Use only secure ciphers (no DES or MD5)
  • 10. Hit list: Cryptography  Use symmetric cryptography to encrypt large amounts of data, for example AES, 128 key length  Asymmetric cryptography can be used if another application decrypts the information
  • 12. Admin panel  Admin panel security is even more important  Vulnerabilities are harder to exploit, but more destructive  I‘ve seen XSS holes in spam reports, user names, ...  Can be used to steal an administrator‘s session  Social engineering may help to get access  Hack the e-mail account of an employee to request the admin password  In most admin panels attackers can run completely riot and CRUD everything
  • 13. Admin panel  Inside the panel  Take precautions for the worst case: Introduce different admin roles or require to enter another password for serious actions  Validate/Filter input and output just as in the main application
  • 14. Admin panel  Authentication  Put the panel to another sub-domain  A stolen admin cookie from www. doesn‘t work in admin.  Don‘t authenticate with user name and password from the main application
  • 15. Admin panel  Authentication Block the admin account for 15 minutes after 3 unsuccessful logins  Authenticate with something you have, not with something you know  Allow access only from certain IP addresses (check request.remote_ip)  Allow access only from certain machines with client SSL certificates
  • 16. File uploads  Everything allowed: class Company < ActiveRecord::Base has_attachment :storage => :file_system, :path_prefix => 'public/files' end
  • 17. File uploads  Allow only images: class Company < ActiveRecord::Base has_attachment :storage => :file_system, :path_prefix => 'public/files', :content_type => :image validates_as_attachment end  Now upload logo.html.jpg  IE displays the HTML
  • 18. File Uploads and Apache  Now upload logo.php.jpg  Address the file and see the executed PHP LoadModule php4_module modules/libphp4.so AddType application/x-httpd-php .php  It‘s a common misconception that this will enable the module only for files ending in .php
  • 19. File Uploads Countermeasures  Store uploaded files outside DocumentRoot directory if you can  Come up with a random/artificial filename if you can  Use AV scanners to check the file before allowing access to it  But how to check for the correct MIME type?
  • 20. File Uploads MIME Type  Problem: Checking the file name and MIME type provided by the user is not reliable  logo.jpg may still be evil  This file contains a PNG signature: %PNG  And a JavaScript comment: <script>alert('You are vulnerable!');</script>
  • 21. MIME Type Sniffing  Internet Explorer will sniff the first 256 bytes for its MIME type if it‘s disputed  IE assumes text/html if these strings are found: <html, <head, <body, <plaintext, <pre, <table, <a href, <title, <img src, <script  Only carried out when the file URL is opened directly - not when requested by an image tag
  • 22. File Uploads Countermeasures  The easy way: Convert uploaded images to JPEG  Not allowed? What about other file types?
  • 23. File Uploads Countermeasures  Validate the file name and MIME type from the client  Do the same on the server: shared-mime-info gem  See MIME sniffing countermeasures blog post  There may be problems with unknown file types  Attachment_fu: Height and Width must not be NULL for images  Check the first 256 bytes for HTML  Use send_file :disposition => 'attachment' if possible