SlideShare a Scribd company logo
1 of 31
Download to read offline
Are You Sure Your Site Is Secure?

                                        Security 202




Confoo 2011 Edition
By Arne Blankerts, thePHP.cc
What is this talk about?

                  Myths in web security
                  Broken configurations
                  Typical implementation
                   issues
Session data




  “I can always trust my session data
      since I know what I did store”
Session data

[theseer@rikka ~] $ grep "session.save_path" /etc/php.ini | grep -v ";"

session.save_path = "/var/lib/php/session"



    Identical for all php instances unless
     specifically overwritten
        Read and write access from php code
    May be crafted in shared hosting
        Session-id takeover from vhost to vhost
        Session-Content can be modified
        Can even lead to code execution
Session hijacking




   “To protect my users from session
      hijacking, I did implement a
           validation check”
Session hijacking

    session.php
01   <?php
02   session_start();
03   $success = true;
04   if (($_SESSION['IP'] != $_SERVER['REMOTE_ADDR'])
05      or ($_SESSION['VIA'] != $_SERVER['HTTP_VIA'])
06      or ($_SESSION['FORWARD'] != $_SERVER['HTTP_X_FORWARDED_FOR'])
07      or ($_SESSION['AGENT'] != $_SERVER['HTTP_USER_AGENT'])) {
08   // ...
09   }
Session hijacking – what to do?

   Determine if hijacking is a problem
   Regenerate id on every request
       Doesn't block it but makes it harder to exploit
   Fully switch to https for transport
       Alternatively use a separate id in ssl context
Cross Site Request Forgery




 “I have an anti CSRF token in my forms
        – So I'm well protected”
CSRF

   csrftoken.php
    01   <?php
    02
    03   session_start();
    04   $_SESSION['CSRF']=md5(time());
    05
    06   //...


   validate.php
    01   <?php
    02
    03   session_start();
    04   if ($_SESSION['CSRF']==$_GET['CSRF']) {
    05      // ...
    06   }
CSRF

   Regenerate token for every form?
       Do you keep a backlog of tokens?


   Do you validate your session?
       Session fixation may violate CSRF tokens


   What do you base the token on?
CAPTCHA




  “I'm using a captcha to protect my
   forms from abuse – So I'm save.”
CAPTCHA

   Conceptual Problems
       Distortion often unreadable
       Not the least bit accessible


   Breaking can be “crowd sourced”


   Implementation issues
CAPTCHA

   captcha.php
     01   <?php
     02   session_start();
     03   require 'captchaHelper.php';
     04
     05   $code = generateCaptchaCode();
     06   $_SESSION['CAPTCHA'] = $code;
     07
     08   header('Content-type: image/jpeg');
     09   echo createCaptchaImage($code);

   validation.php
     01   <?php
     02   session_start();
     03
     04   if ($_SESSION['CAPTCHA'] != $_REQUEST['code']) {
     05      die('Captcha value wrong');
     06   }
     07   echo 'Welcome!';
Prepared Statements




    “I'm using prepared statements
 so I'm protected from sql injections”
Prepared Statements

01   <?php
02
03   $db = new PDO(....);
04   $query = $db->prepare('SELECT ... WHERE NAME=:name');
05   $query->bindParam(':name', $_GET['name']);
06
07   //...
Prepared Statements

   What about fieldnames?
   Variable table names?
   Do you sort your results?
   Any need for limits?


   Still use ext/mysql?
       Sprintf based implementations?
Drawbacks of sprintf

   Manual escaping needed
    
        mysql_escape_string vs. mysql_real_escape_string
   PDO::quote() does not work with ODBC
   No knowledge of fieldtype
       String vs. Integer exploits
       PDO::quote vs. mysql(i)_real_escape_string
Password storage



 “I know storing clear text passwords
    is a bad idea. That's why I'm only
    storing hashes of passwords to
            protect my users.”
Password storage

01   <?php
02
03   $db = new PDO(....);
04   $query = $db->prepare(
05      'UPDATE user SET PASSWD=:pwd WHERE UID=:uid'
06   );
07   $query->bindParam(':uid', $_SESSION['uid']);
08   $query->bindParam(':pwd', sha1($_POST['pwd']));
09
10   //...
Most favorite passwords

   123456           Abc123
   12345            Qwertz / Qwerty
   123456789        Dragon
   Password         Sexgod
   iloveyou         Football
   princess         1234
   rockyou          Pussy
   1234567          Letmein
   12345678         admin
Password storage

   Always salt hashes
       Prepend and/or append additional values


   Stretch your passwords
       Re-apply and calculate the hash
       400.000 iterations take <1sec on my laptop


   Do a quality check on user supplied codes
Validation




  “I know using blacklists is pointless.
That's why I use regular expressions to
   check for valid chars in a string”
Validation

01   <?php
02
03   $name = isset($_GET['name']) ? $_GET['name'] : 'Anonymous User';
04
05   if (ereg("^[a-zA-Z0-9 +-]*$", $name)) {
06       echo "Welcome, $name";
07   } else {
08       echo "Sorry, that name contains invalid chars";
09   }
10
11   ?>
Clickjacking



   “To make sure my site cannot be a
    victim of clickjacking, I have a
     Javascript to Break out from
          frames or iframes”
Clickjacking

   Old style frame busting code
    01   <script type=”text/javascript”>
    02   if (top != self) { top.location.replace(self.location.href); }
    03   </script>
Clickjacking

   Old style frame busting code
    01   <script type=”text/javascript”>
    02   if (top != self) { top.location.replace(self.location.href); }
    03   </script>



   Frame buster busting code
    01   <script type=”text/javascript”>
    02   var prevent_bust = 0
    03   window.onbeforeunload = function() { prevent_bust++ }
    04   setInterval(function() {
    05       if (prevent_bust > 0) {
    06           prevent_bust -= 2
    07           window.top.location = 'http://attacker/204.php';
    08       }
    09     }, 1);
    10   </script>
Clickjacking – what works

   JavaScript & CSS
       Hide content by use display:none
       Switch to visible if frametest succeeds


   Use X-FRAME-OPTIONS header
       Set to DENY for no iframe embedding
       Set to SAMEORIGIN to allow from same host
Lessons learned?

   Tiny problems add up
       Some attacks are only effective if various
        vectors get combined
       Combinations of attack vectors may render
        your solution useless


   Security requires a fully secure eco system
Q & A
Congrats!
Contact
   Slides will be available
        http://talks.thephp.cc

   Please rate this talk
        http://joind.in/talk/view/2785

   Contact options
        Email: team@thePHP.cc / arne@thePHP.cc

   Follow us on twitter:
        @arneblankerts / @thePHPcc

More Related Content

What's hot

Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Fabien Potencier
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebookguoqing75
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010Fabien Potencier
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201Fabien Potencier
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Fabien Potencier
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in actionJace Ju
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기JeongHun Byeon
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)Fabien Potencier
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 

What's hot (20)

Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
Fatc
FatcFatc
Fatc
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
New in php 7
New in php 7New in php 7
New in php 7
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 

Viewers also liked

Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in RubyConFoo
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101ConFoo
 
The business behind open source
The business behind open sourceThe business behind open source
The business behind open sourceConFoo
 
Writing a Ruby Gem for beginners
Writing a Ruby Gem for beginnersWriting a Ruby Gem for beginners
Writing a Ruby Gem for beginnersConFoo
 
Anatomy of a large Django site
Anatomy of a large Django siteAnatomy of a large Django site
Anatomy of a large Django siteConFoo
 
Opensource Authentication and Authorization
Opensource Authentication and AuthorizationOpensource Authentication and Authorization
Opensource Authentication and AuthorizationConFoo
 

Viewers also liked (6)

Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
 
The business behind open source
The business behind open sourceThe business behind open source
The business behind open source
 
Writing a Ruby Gem for beginners
Writing a Ruby Gem for beginnersWriting a Ruby Gem for beginners
Writing a Ruby Gem for beginners
 
Anatomy of a large Django site
Anatomy of a large Django siteAnatomy of a large Django site
Anatomy of a large Django site
 
Opensource Authentication and Authorization
Opensource Authentication and AuthorizationOpensource Authentication and Authorization
Opensource Authentication and Authorization
 

Similar to Security 202 - Are you sure your site is secure?

Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10Sastry Tumuluri
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And AnishOSSCube
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSlawomir Jasek
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSecuRing
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web SecurityChris Shiflett
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesCarol McDonald
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 
Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.Nelson Gomes
 
OWASP Top 10 at International PHP Conference 2014 in Berlin
OWASP Top 10 at International PHP Conference 2014 in BerlinOWASP Top 10 at International PHP Conference 2014 in Berlin
OWASP Top 10 at International PHP Conference 2014 in BerlinTobias Zander
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web AppsFrank Kim
 
OWASP San Diego Training Presentation
OWASP San Diego Training PresentationOWASP San Diego Training Presentation
OWASP San Diego Training Presentationowaspsd
 

Similar to Security 202 - Are you sure your site is secure? (20)

Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
 
PHPUG Presentation
PHPUG PresentationPHPUG Presentation
PHPUG Presentation
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
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
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Php Security
Php SecurityPhp Security
Php Security
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web Security
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.
 
Rails Security
Rails SecurityRails Security
Rails Security
 
OWASP Top 10 at International PHP Conference 2014 in Berlin
OWASP Top 10 at International PHP Conference 2014 in BerlinOWASP Top 10 at International PHP Conference 2014 in Berlin
OWASP Top 10 at International PHP Conference 2014 in Berlin
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
OWASP San Diego Training Presentation
OWASP San Diego Training PresentationOWASP San Diego Training Presentation
OWASP San Diego Training Presentation
 

More from ConFoo

Debugging applications with network security tools
Debugging applications with network security toolsDebugging applications with network security tools
Debugging applications with network security toolsConFoo
 
OWASP Enterprise Security API
OWASP Enterprise Security APIOWASP Enterprise Security API
OWASP Enterprise Security APIConFoo
 
Introduction à la sécurité des WebServices
Introduction à la sécurité des WebServicesIntroduction à la sécurité des WebServices
Introduction à la sécurité des WebServicesConFoo
 
Le bon, la brute et le truand dans les nuages
Le bon, la brute et le truand dans les nuagesLe bon, la brute et le truand dans les nuages
Le bon, la brute et le truand dans les nuagesConFoo
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHPConFoo
 
Décrire un projet PHP dans des rapports
Décrire un projet PHP dans des rapportsDécrire un projet PHP dans des rapports
Décrire un projet PHP dans des rapportsConFoo
 
Server Administration in Python with Fabric, Cuisine and Watchdog
Server Administration in Python with Fabric, Cuisine and WatchdogServer Administration in Python with Fabric, Cuisine and Watchdog
Server Administration in Python with Fabric, Cuisine and WatchdogConFoo
 
Think Mobile First, Then Enhance
Think Mobile First, Then EnhanceThink Mobile First, Then Enhance
Think Mobile First, Then EnhanceConFoo
 
As-t-on encore besoin d'un framework web ?
As-t-on encore besoin d'un framework web ?As-t-on encore besoin d'un framework web ?
As-t-on encore besoin d'un framework web ?ConFoo
 
Pragmatic Guide to Git
Pragmatic Guide to GitPragmatic Guide to Git
Pragmatic Guide to GitConFoo
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
An Overview of Flash Storage for Databases
An Overview of Flash Storage for DatabasesAn Overview of Flash Storage for Databases
An Overview of Flash Storage for DatabasesConFoo
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump StartConFoo
 
Develop mobile applications with Flex
Develop mobile applications with FlexDevelop mobile applications with Flex
Develop mobile applications with FlexConFoo
 
WordPress pour le développement d'aplications web
WordPress pour le développement d'aplications webWordPress pour le développement d'aplications web
WordPress pour le développement d'aplications webConFoo
 
Graphs, Edges & Nodes: Untangling the Social Web
Graphs, Edges & Nodes: Untangling the Social WebGraphs, Edges & Nodes: Untangling the Social Web
Graphs, Edges & Nodes: Untangling the Social WebConFoo
 
Rendre son CMS conforme au SGQRI 008 en 20 étapes
Rendre son CMS conforme au SGQRI 008 en 20 étapesRendre son CMS conforme au SGQRI 008 en 20 étapes
Rendre son CMS conforme au SGQRI 008 en 20 étapesConFoo
 

More from ConFoo (17)

Debugging applications with network security tools
Debugging applications with network security toolsDebugging applications with network security tools
Debugging applications with network security tools
 
OWASP Enterprise Security API
OWASP Enterprise Security APIOWASP Enterprise Security API
OWASP Enterprise Security API
 
Introduction à la sécurité des WebServices
Introduction à la sécurité des WebServicesIntroduction à la sécurité des WebServices
Introduction à la sécurité des WebServices
 
Le bon, la brute et le truand dans les nuages
Le bon, la brute et le truand dans les nuagesLe bon, la brute et le truand dans les nuages
Le bon, la brute et le truand dans les nuages
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
 
Décrire un projet PHP dans des rapports
Décrire un projet PHP dans des rapportsDécrire un projet PHP dans des rapports
Décrire un projet PHP dans des rapports
 
Server Administration in Python with Fabric, Cuisine and Watchdog
Server Administration in Python with Fabric, Cuisine and WatchdogServer Administration in Python with Fabric, Cuisine and Watchdog
Server Administration in Python with Fabric, Cuisine and Watchdog
 
Think Mobile First, Then Enhance
Think Mobile First, Then EnhanceThink Mobile First, Then Enhance
Think Mobile First, Then Enhance
 
As-t-on encore besoin d'un framework web ?
As-t-on encore besoin d'un framework web ?As-t-on encore besoin d'un framework web ?
As-t-on encore besoin d'un framework web ?
 
Pragmatic Guide to Git
Pragmatic Guide to GitPragmatic Guide to Git
Pragmatic Guide to Git
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
An Overview of Flash Storage for Databases
An Overview of Flash Storage for DatabasesAn Overview of Flash Storage for Databases
An Overview of Flash Storage for Databases
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump Start
 
Develop mobile applications with Flex
Develop mobile applications with FlexDevelop mobile applications with Flex
Develop mobile applications with Flex
 
WordPress pour le développement d'aplications web
WordPress pour le développement d'aplications webWordPress pour le développement d'aplications web
WordPress pour le développement d'aplications web
 
Graphs, Edges & Nodes: Untangling the Social Web
Graphs, Edges & Nodes: Untangling the Social WebGraphs, Edges & Nodes: Untangling the Social Web
Graphs, Edges & Nodes: Untangling the Social Web
 
Rendre son CMS conforme au SGQRI 008 en 20 étapes
Rendre son CMS conforme au SGQRI 008 en 20 étapesRendre son CMS conforme au SGQRI 008 en 20 étapes
Rendre son CMS conforme au SGQRI 008 en 20 étapes
 

Security 202 - Are you sure your site is secure?

  • 1. Are You Sure Your Site Is Secure? Security 202 Confoo 2011 Edition By Arne Blankerts, thePHP.cc
  • 2. What is this talk about?  Myths in web security  Broken configurations  Typical implementation issues
  • 3. Session data “I can always trust my session data since I know what I did store”
  • 4. Session data [theseer@rikka ~] $ grep "session.save_path" /etc/php.ini | grep -v ";" session.save_path = "/var/lib/php/session"  Identical for all php instances unless specifically overwritten  Read and write access from php code  May be crafted in shared hosting  Session-id takeover from vhost to vhost  Session-Content can be modified  Can even lead to code execution
  • 5. Session hijacking “To protect my users from session hijacking, I did implement a validation check”
  • 6. Session hijacking  session.php 01 <?php 02 session_start(); 03 $success = true; 04 if (($_SESSION['IP'] != $_SERVER['REMOTE_ADDR']) 05 or ($_SESSION['VIA'] != $_SERVER['HTTP_VIA']) 06 or ($_SESSION['FORWARD'] != $_SERVER['HTTP_X_FORWARDED_FOR']) 07 or ($_SESSION['AGENT'] != $_SERVER['HTTP_USER_AGENT'])) { 08 // ... 09 }
  • 7. Session hijacking – what to do?  Determine if hijacking is a problem  Regenerate id on every request  Doesn't block it but makes it harder to exploit  Fully switch to https for transport  Alternatively use a separate id in ssl context
  • 8. Cross Site Request Forgery “I have an anti CSRF token in my forms – So I'm well protected”
  • 9. CSRF  csrftoken.php 01 <?php 02 03 session_start(); 04 $_SESSION['CSRF']=md5(time()); 05 06 //...  validate.php 01 <?php 02 03 session_start(); 04 if ($_SESSION['CSRF']==$_GET['CSRF']) { 05 // ... 06 }
  • 10. CSRF  Regenerate token for every form?  Do you keep a backlog of tokens?  Do you validate your session?  Session fixation may violate CSRF tokens  What do you base the token on?
  • 11. CAPTCHA “I'm using a captcha to protect my forms from abuse – So I'm save.”
  • 12. CAPTCHA  Conceptual Problems  Distortion often unreadable  Not the least bit accessible  Breaking can be “crowd sourced”  Implementation issues
  • 13. CAPTCHA  captcha.php 01 <?php 02 session_start(); 03 require 'captchaHelper.php'; 04 05 $code = generateCaptchaCode(); 06 $_SESSION['CAPTCHA'] = $code; 07 08 header('Content-type: image/jpeg'); 09 echo createCaptchaImage($code);  validation.php 01 <?php 02 session_start(); 03 04 if ($_SESSION['CAPTCHA'] != $_REQUEST['code']) { 05 die('Captcha value wrong'); 06 } 07 echo 'Welcome!';
  • 14. Prepared Statements “I'm using prepared statements so I'm protected from sql injections”
  • 15. Prepared Statements 01 <?php 02 03 $db = new PDO(....); 04 $query = $db->prepare('SELECT ... WHERE NAME=:name'); 05 $query->bindParam(':name', $_GET['name']); 06 07 //...
  • 16. Prepared Statements  What about fieldnames?  Variable table names?  Do you sort your results?  Any need for limits?  Still use ext/mysql?  Sprintf based implementations?
  • 17. Drawbacks of sprintf  Manual escaping needed  mysql_escape_string vs. mysql_real_escape_string  PDO::quote() does not work with ODBC  No knowledge of fieldtype  String vs. Integer exploits  PDO::quote vs. mysql(i)_real_escape_string
  • 18. Password storage “I know storing clear text passwords is a bad idea. That's why I'm only storing hashes of passwords to protect my users.”
  • 19. Password storage 01 <?php 02 03 $db = new PDO(....); 04 $query = $db->prepare( 05 'UPDATE user SET PASSWD=:pwd WHERE UID=:uid' 06 ); 07 $query->bindParam(':uid', $_SESSION['uid']); 08 $query->bindParam(':pwd', sha1($_POST['pwd'])); 09 10 //...
  • 20. Most favorite passwords  123456  Abc123  12345  Qwertz / Qwerty  123456789  Dragon  Password  Sexgod  iloveyou  Football  princess  1234  rockyou  Pussy  1234567  Letmein  12345678  admin
  • 21. Password storage  Always salt hashes  Prepend and/or append additional values  Stretch your passwords  Re-apply and calculate the hash  400.000 iterations take <1sec on my laptop  Do a quality check on user supplied codes
  • 22. Validation “I know using blacklists is pointless. That's why I use regular expressions to check for valid chars in a string”
  • 23. Validation 01 <?php 02 03 $name = isset($_GET['name']) ? $_GET['name'] : 'Anonymous User'; 04 05 if (ereg("^[a-zA-Z0-9 +-]*$", $name)) { 06 echo "Welcome, $name"; 07 } else { 08 echo "Sorry, that name contains invalid chars"; 09 } 10 11 ?>
  • 24. Clickjacking “To make sure my site cannot be a victim of clickjacking, I have a Javascript to Break out from frames or iframes”
  • 25. Clickjacking  Old style frame busting code 01 <script type=”text/javascript”> 02 if (top != self) { top.location.replace(self.location.href); } 03 </script>
  • 26. Clickjacking  Old style frame busting code 01 <script type=”text/javascript”> 02 if (top != self) { top.location.replace(self.location.href); } 03 </script>  Frame buster busting code 01 <script type=”text/javascript”> 02 var prevent_bust = 0 03 window.onbeforeunload = function() { prevent_bust++ } 04 setInterval(function() { 05 if (prevent_bust > 0) { 06 prevent_bust -= 2 07 window.top.location = 'http://attacker/204.php'; 08 } 09 }, 1); 10 </script>
  • 27. Clickjacking – what works  JavaScript & CSS  Hide content by use display:none  Switch to visible if frametest succeeds  Use X-FRAME-OPTIONS header  Set to DENY for no iframe embedding  Set to SAMEORIGIN to allow from same host
  • 28. Lessons learned?  Tiny problems add up  Some attacks are only effective if various vectors get combined  Combinations of attack vectors may render your solution useless  Security requires a fully secure eco system
  • 31. Contact  Slides will be available  http://talks.thephp.cc  Please rate this talk  http://joind.in/talk/view/2785  Contact options  Email: team@thePHP.cc / arne@thePHP.cc  Follow us on twitter:  @arneblankerts / @thePHPcc