click to edit master title style drupal’and...

24
Drupal and Security Nathan Rambeck Crown Partners @nrambeck drupal.org/user/92967

Upload: others

Post on 06-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

7/27/12 © 2011 Crown Partners. All Rights Reserved. 1

Click to edit Master title style

7/27/12 © 2011 Crown Partners. All Rights Reserved. 1

Drupal  and  Security  Nathan  Rambeck  Crown  Partners  @nrambeck  drupal.org/user/92967  

Page 2: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Security  Concerns  !  Hackers  

–  Cross  site  scripting  (XSS)  80%  of  vulnerabilities  web-­‐wide  –  SQL  Injection  –  Cross  Site  Request  Forgeries  

!  Spammers  !  Brute  Force  Attacks  !  Exposing  Unintended  Data  !  Drupal  Security  is  Just  One  Layer  !  Over-­‐securing  alienates  users  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 2

Page 3: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Drupal’s  Security  Methodology  !  Security  through  transparency  vs  obscurity  !  Dedicated  security  team  -­‐  http://drupal.org/security-­‐team  !  Reporting  -­‐  [email protected]  !    Security  releases  and  announcements  -­‐          http://drupal.org/security  !  Security  advisory  feed  !  Security  email  list  !  Update  Status  module  

7/28/12 © 2012 Crown Partners. All Rights Reserved. 3

Page 4: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

7/27/12 © 2011 Crown Partners. All Rights Reserved. 4

Security  for  Site  Admins  

Page 5: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Overview  for  Admins  !  Choose  modules  carefully  !  Keep  code  up-­‐to-­‐date  !  Be  careful  with  roles  and  permissions  !  Limit  the  kind  of  HTML  yours  users  can  contribute  to  the  site  !  Beef  up  security  with  contrib  modules  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 5

Page 6: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Choose  modules  carefully  !  Some  modules  are  more  secure  than  others  !  Is  the  module  actively  maintained?  !  Is  it  popular?  http://drupal.org/project/usage  !  Are  issues  in  the  issue  queue  addressed  in  a  timely  manner?  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 6

Page 7: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Keep  code  up-­‐to-­‐date  !  Turn  on  the  Update  Status  module  !  Conaigure  Update  Status  to  email  you  !  Security  updates  are  most  important  !  Use  drush  to  update  modules  !  Use  Git  or  a  shell  script  to  update  core  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 7

Page 8: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Roles  and  Permissions  !  Should  self-­‐registration  be  allowed?  !  Carefully  create  roles  to  divide  trusted  users  from  untrusted  !  Review  the  permissions  page  carefully  !  Edit  permissions  one  role  at  a  time  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 8

Page 9: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Input  formats  and  ailters  !  Don’t  turn  on  PHP  ailter  unless  it’s  required  ever  !  Be  careful  with  the  Full  HTML  ailter  and  don’t  ever  make  it  the  default  !  Untrusted  user  should  never  be  allowed  to  use  the  following  tags:  <img>  <script>  <iframe>  <embed>  <object>  <input>  <link>  <style>  <meta>  <frameset>  <div>  <base>  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 9

Page 10: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Images  and  media  !  Allowing  users  the  alexibility  to  post  any  kind  of  media  also  opens  your  site  up  to  hackers/spammers  ! Contrib  modules  provide  a  safe  way  to  allow  users  to  contribute  images  and  other  media  !  Image  Field  –  Users  upload  their  own  images  !  Media  module  –  Users  may  embed  media  from  a  pre-­‐selected  group  of  3rd  parties  (ie.  Youtube,  Vimeo,  etc.)  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 10

Page 11: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Security  related  modules  !  Security  Review  (http://drupal.org/project/security_review)  !  Flood  Control  (http://drupal.org/project/alood_control)  !  Secure  Login  (http://drupal.org/project/securelogin)  !  Persistent  Login  (http://drupal.org/project/persistent_login)  !  Password  Policy  (http://drupal.org/project/password_policy)  

7/28/12 © 2012 Crown Partners. All Rights Reserved. 11

Page 12: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

7/27/12 © 2011 Crown Partners. All Rights Reserved. 12

Security  for  Devs  

Page 13: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Overview  for  Developers  !  Learn  the  Drupal  API  !  Input  ailter  functions  !  Query  data  ailtering  !  User  access  !  Forms  !  Filter  Access  !  URLs  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 13

Page 14: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Learning  the  Drupal  API  !  Drupal  has  security  layers  built  in  to  the  API,  but  they  are  of  no  use,  if  they  are  not  used.  !  Review  the  code  in  Drupal  core  or  popular  contrib  modules  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 14

Page 15: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Filtering  Input  !  Input  from  users  should  always  be  treated  as  potentially  malicious  ! check_plain()  –  ailters  text  as  plain  text;  used  for  aields  like  the  title  of  a  post  which  doesn’t  allow  HTML  ! check_markup()  –  ailter  text  as  HTML  according  to  the  rules  of  a  speciaic  ailter  deained  in  Drupal  ! 7ilter_xss()  –  allows  most  HTML,  but  ailters  for  Cross  Site  Scripting  attacks.  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 15

Page 16: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Filtering  Input  !  t()  –  Translate  function  uses  tokens  to  allow  easy  ailtering  of  mixed  static/variable  text.  t(“You  just  entered  @title  as  the  title”,  array(“@title”  =>  $title);  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 16

Page 17: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Filtering  for  queries  !  INCORRECT:  db_query(‘SELECT * FROM users WHERE name LIKE “’. $username .’”’);!  CORRECT:  db_query(‘SELECT * FROM users WHERE name LIKE “%s”’, $username);

7/27/12 © 2012 Crown Partners. All Rights Reserved. 17

Page 18: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

User  Access  ! user_access()  –  Determine  if  a  user  has  a  speciaic  permission  if (user_access(‘access content’)) { // Do this } else { drupal_access_denied(); }

! hook_perm()  to  deaine  your  own  permissions  !  User  access  in  menu  items  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 18

Page 19: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

User  Access  !  Global  $user  object  !  Because  it  is  global,  it  is  easy  to  access,  but  also  easy  to  modify  

global $user; if ($user->uid = 1) { print_r($variable); }!  Oops.  Now,  all  visitors  to  your  site  will  become  user  1  with  unlimited  access  

7/28/12 © 2012 Crown Partners. All Rights Reserved. 19

Page 20: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

URLs  ! check_url()  –  strips  user  input  urls  of  dangerous  protocols  and  encodes  for  output  to  HTML  !  Use  con7irm_form()  in  callbacks  for  urls  that  take  permanent  action.  This  prevents  malicious  urls  like  below  from  eating  your  lunch.  !  <img  src=“/user/1/delete”  />  (CSRF  vulnerabilities)  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 20

Page 21: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Forms  !  Use  the  Form  API  !  It  may  seem  difaicult  to  use,  but  is  quite  alexible  and  provides  a  robust  layer  of  security  !  To  prevent  Cross  Site  Forgery  Requests  (CSFR)  Drupal  generates  tokens  for  each  form  !  Select  aield  data  cannot  be  manipulated  !  Validate  variable  form  input  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 21

Page 22: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Flood  Control  !  Prevent  users  from  executing  actions  too  frequently  !  Already  built-­‐in  to  public  forms  (like  contact  form)  !  Prevents  form  to  email  spam  !  Prevents  dictionary  attacks  to  guess  passwords  !  http://api.drupal.org/api/search/7/alood  

7/28/12 © 2012 Crown Partners. All Rights Reserved. 22

Page 23: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

Security  Resources  !  http://drupal.org/security  !  http://drupal.org/writing-­‐secure-­‐code  !  Twitter:  @drupalsecurity  !  http://ha.ckers.org/xss.html  ! http://crackingdrupal.com  

7/27/12 © 2012 Crown Partners. All Rights Reserved. 23

Page 24: Click to edit Master title style Drupal’and Securitynrambeck.s3.amazonaws.com/blog/drupal-security.pdfSecurityConcerns! Hackers – Cross’site’scripting’(XSS)’80%’of’vulnerabilities’webwide’

7/27/12 © 2011 Crown Partners. All Rights Reserved. 24

Click to edit Master title style

7/27/12 © 2011 Crown Partners. All Rights Reserved. 24

Questions?  Nathan  Rambeck  @nrambeck  crownpartners.com