46
Secure your Drupal site by first hacking into it

Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

  • Upload
    nyccamp

  • View
    30.682

  • Download
    4

Embed Size (px)

DESCRIPTION

Over 70% of the security issues in Drupal sites are either XSS, CSRF, or SQL Injection. Let's talk about how sites get hacked and how you can write secure Drupal code and maintain security throughout your development process and live maintenance. About the Presenter: Ben Jeavons is a member of the Drupal Security team and co-author of the Drupal Security Report. As an engineer at Acquia he works on the Acquia Network including the security and performance analysis tool, Acquia Insight. Experience Level: Intermediate

Citation preview

Page 1: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Secure your Drupal site by first hacking into it

Page 2: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Think like a hacker

http://www.flickr.com/photos/31246066@N04/4252587897/

Page 3: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

How sites get hacked

XSS

Insecure environment

Stolen access

Outdated code, known vulnerabilities

Page 4: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

XSS Demo

• Malicious Javascript is entered

• Admin unknowingly executes

• Javascript alters admin-only settings

• Changes admin password

• Puts site offline

http://www.flickr.com/photos/paolo_rosa/5088971947/

Page 5: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

https://vimeo.com/15447718

Page 6: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Ben Jeavons

Drupaler for 5 years

Member of Drupal Security Team

@benswords

Page 7: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Drupal vulnerabilities by popularity

XSS Access Bypass CSRFAuthentication/Session Arbitrary Code Execution SQL InjectionOthers

48%

16%

10%

3%

4%

7%

12%

reported in core and contrib SAs from 6/1/2005 through 3/24/2010

Page 8: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Cross Site Scripting

Page 9: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Cross Site Scripting

XSS

Javascript

Performing actions without your intent

Everything you can do XSS can do faster

Page 10: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stored XSS Step 1

DrupalAttacker

Request

JS

DBJS

Page 11: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stored XSS Step 2

DrupalVictim

Request

Response

JS JS

DB

Page 12: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stored XSS Step 3

DrupalVictim Request

JS

DB

JS

Page 13: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

$node = node_load($nid);$title = $node->title;drupal_set_title($title);...(later, in page.tpl.php)...<h1><?php print $title; ?></h1>

Page 14: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Fixing XSS

Identify where the data came from

User input!

Page 15: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 16: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 17: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 18: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

user agentlanguagetime zonereferrer& more HTTP request headers

Lots of tools/ways to modifythese for requests

Page 19: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Fixing XSS

Identify where the data came from

Is that data being filtered or escaped before output?

Page 20: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 21: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

RawInput

FilteredOutput

Page 22: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 23: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

$node = node_load($nid);$title = $node->title;$safe = check_plain($title);drupal_set_title($safe);...(later, in page.tpl.php)...<h1><?php print $title; ?></h1>

Page 24: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

XSS in Themes

<div class=”stuff”><?php print $node->field_stuff[0][‘value’];?>

Page 25: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

<div class=”stuff”><?phpprint $node->field_stuff[0][‘safe’];// OR$stuff = $node->field_stuff[0];print content_format(‘field_stuff’, $stuff);

?>

Page 26: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Sanitize user input for output

$msg = variable_get(‘my_msg’,‘’);

print check_plain($msg);

Page 27: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

<script>alert(‘xss yo’)</script>

github.com / unn / vuln

Test for XSS vulnerability

Page 28: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Insecure Environment

Page 29: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Insecure Environment

Lock down your stack

Admin tools and access to them

Principle of least privilege

Give out only necessary permissions

Page 30: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 31: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Insecure Environment

/devel/variable

/phpMyAdmin

Page 32: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Insecure Environment

Make backups

Test that they work

Secure access to backups

Page 33: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Center for Health Transformation’s records were“found by The New York Times in an unsecured archived version of the site”

http://www.flickr.com/photos/mjb/208218519/http://www.nytimes.com/2011/11/30/us/politics/gingrich-gave-push-to-clients-not-just-ideas.html

Page 34: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Insecure Environment

/sites/default/files/backup_migrate/

Page 35: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stolen Access

Page 36: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 37: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Page 38: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

SSL

Run Drupal on full TLS/SSL

securepages & securepages_prevent_hijack

http://drupalscout.com/node/17

Use a valid certificate

Page 39: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

SFTP

“Secure” FTP

Your host should provide it

If not, consider a new one

Page 40: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stay up-to-date

Page 41: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Stay up-to-date

Know and apply security updates

Security Advisories

Not just Drupal

third-party libraries (TinyMCE)

PHP, operating system

Page 42: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

/CHANGELOG.txt

Page 43: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Automation

http://www.flickr.com/photos/hubmedia/2141860216/

Page 44: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Steps to a mostly automated review

Security Review: drupal.org/project/security_review

Hacked: drupal.org/project/hacked

Coder: drupal.org/project/coder

Secure Code Review

drupal.org/project/secure_code_review

Vuln: github.com/unn/vuln

More: http://drupalscout.com/node/11

Page 45: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

in-depth, hands-on security trainingdrupalcon.org

bit.ly/drupalcon-security

Page 46: Hack Into Drupal Sites (or, How to Secure Your Drupal Site)

Read

drupal.org/security/writing-secure-code

drupalscout.com

crackingdrupal.com

Converse

groups.drupal.org/best-practices-drupal-security

[email protected]

@benswords