SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Auditing
              PHP
           applications

            Audit des
           applications
             en PHP
vendredi 13 novembre 2009   1
Agenda                        Ordre du jour
             Workshop presentation     Présentation de l’atelier

             Black box audit           Audit boîte noire

             Source code audit         Audit à code ouvert




vendredi 13 novembre 2009                                          2
Who speak?                         Qui parle?
             Philippe Gamache            Philippe Gamache

             Parler Haut, Interagir      Parler Haut, Interagir
             Librement :                 Librement :
             Web development, security   Développement Web, audit
             audit, training             de sécurité, formations

             info@ph-il.ca               info@ph-il.ca

             @SecureSymfony              @SecureSymfony




vendredi 13 novembre 2009                                           3
Security book
       Livre de sécurité
             New 2009 edition
             Comprehensive review of security
             system for MySQL, PHP, etc.
             Published in French
                   Planning translation


             Nouvelle édition 2009
             Bilan complet de la sécurité :
             système, MySQL, PHP, etc.
             Édité chez Eyrolles
             Dédicaces sur demande


vendredi 13 novembre 2009                       4
Yes, I take question
              Je réponds aux questions
vendredi 13 novembre 2009                5
Why?                                     Pourquoi?
             Confidence does not                La confiance n'exclut pas le
             exclude control™                  contrôle™
                                                 Pour valider un travail
                   To validate external work
                                                 externe
                   To validate internal work     Pour valider un travail
                   Round-up                      interne
                                                 Pour faire le point
                   For an external
                                                 Pour avoir un regard
                   perspective
                                                 externe
                   As often as possible          Aussi souvent que
                                                 possible

vendredi 13 novembre 2009                                                    6
Full audit synopsis
       Synopsis d’un audit
             Identification of the audit   Identification des objectifs
             goals                        d'audit

             Interview with the           Entretien avec les équipes
             development teams            de développement

             Black box testing            Test boîte noire

             Open Code audit              Audit de code

             Report                       Rapport



vendredi 13 novembre 2009                                               7
Identification of the audit goals
       Identification des objectifs d’audit
             Audit scope          Étendue de l'audit

                   Security         Sécurité

                   Performance      Performance

                   Code quality     Qualité du code




vendredi 13 novembre 2009                              8
Interview with the development teams
       Entretien avec les équipes de développement

             Check if development          Vérifiez si l’équipe de
             teams knows what to           développement sait ce qu’il
             secure                        faut sécurisé
             Have the design explained     Demandez d’expliquer la
             first                          conception
             Have them explains their      Demandez d’expliquer leur
             approach                      approche
                   Check what they say       Vérifiez ce qu'ils disent
                   Check what they don’t     Vérifiez ce qu'ils ne
                   say                       disent pas

vendredi 13 novembre 2009                                                9
The shy version
       La version timide
             We know there are security        Nous savons qu’il y a des
             problems                          problèmes de sécurité :
                   but we have no time to        mais nous n'avons pas le
                   secure them                   temps de les sécuriser
                   this app has been written     ce logiciel a été écrit il y a
                   years ago                     quelques années
                   we can’t keep up with         nous ne pouvons pas
                   the threats                   suivre les menaces




vendredi 13 novembre 2009                                                         10
The strong version
       La version forte
             We have secured the              Nous avons sécurisé
             application                      l'application
                                                 Nous utilisons le
                   We use SSL and crypto
                                                 protocole SSL et la
                   All content is validated      cryptographie
                   and filtered                   Tout le contenu est validé
                                                 et filtré
                   We don’t do any
                                                 Nous ne faisons aucune
                   dynamical include             inclusion dynamique
                   Our frameworks doesn’t        Nos cadres
                   allow this                    d’applications sont
                                                 sécurisées

vendredi 13 novembre 2009                                                     11
Black box testing
       Test boîte noire
             Easy to set up               Facile de mise en place

             Take into account the        Prendre en compte le
             context of the application   contexte de la demande

             Often spectacular            Souvent spectaculaires

             Generally shallow            Généralement peu
                                          profondes




vendredi 13 novembre 2009                                           12
Black box testing
       Test boîte noire
             Finding informations       Recherche d’informations

             Look for vulnerabilities   Rechercher les
                                        vulnérabilités
                   Automatic scanners
                                          Scanneurs automatiques
                   By hand
                                          À la main
                   Fuzzing
                                          Fuzzing
                   Scenarios              Scénarios

             Strikes                    Attaquer

vendredi 13 novembre 2009                                          13
Black box testing
       Test boîte noire
             Usual directories                  Répertoires habituels
                   includes, include, inc,        includes, include, inc,
                   com, classes, lib, library     com, classes, lib, library
                   admin, adm,                    admin, adm,
                   administrator                  administrateur
                   tmp, TMP, ext, var             tmp, TMP, ext, var
                   data, db, conf, config          data, db, conf, config,
                                                  configuration
                   uploads, install
                                                  uploads, install


vendredi 13 novembre 2009                                                      14
Black box testing
       Test boîte noire
             Typical files                        Fichiers typiques

                   .phps, .inc, .class             .phps, .inc, .class

                   xml, ini, yaml, cfg             xml, ini, yaml, cfg

                   .tar, .gz, .zip, .rar, .bz2     .tar, .gz, .zip, .rar, .bz2

                   Apache Alias : /icons/          Apache Alias : /icons/

                   robots.txt                      robots.txt




vendredi 13 novembre 2009                                                        15
Open Code audit
       Audit de code
             Look into the PHP code       Rechercher dans le code
                                          PHP
             Search for hidden problems
                                          Rechercher les problèmes
             Usually less spectacular     cachés
             than black box               Habituellement, moins
                                          spectaculaire que les tests
             Easy to loose focus
                                          boîte noire
             Tempting to audit            Facile de perdre sa
             everything                   concentration
                                          Tentant de tout vérifier

vendredi 13 novembre 2009                                               16
Approch                             Approche
             What to search for?          Que rechercher?
                                          Quels sont les points
             What are the entry points?
                                          d'entrée?
             What are the exit points?    Quels sont les points de
                                          sortie?
             Open-mindedness and
                                          Ouverture d’esprit et
             discovery
                                          découverte
             How can they be exploited    Comment peuvent-ils être
                                          exploités
                   Or protected ?
                                            Ou protégés?

vendredi 13 novembre 2009                                            17
Assessing the code
       Évaluer le code
             One liners                           En une ligne
               One line of code is                  Une ligne de code est
               sufficiently to be bad                suffisamment pour être
             Even though                            mauvais
               you must follow the code           Malgré tous
                 forward (for input)                vous devez suivre le code
                 in reverse (for output)              vers l’avant (entrées)
                                                      sens inverse (sorties)
                     <?php
                     $action = $_POST['action'];
                     $query_string = "action=$action";
                     $link = "index.php?$query_string";
                     ?>
                     <a href="<?php echo $link; ?>"> Click Here </a>

vendredi 13 novembre 2009                                                       18
What to search for?
       Que rechercher?
             Injections     Injections

                   PHP        PHP

                   SQL        SQL

                   HTML       HTML

                   system     système




vendredi 13 novembre 2009                19
Tools                                         Outils
             Your eyes                  Vos yeux

             Text editors               Éditeurs de texte

             grep                       grep

                   Fast, available,       Rapide, disponible,
                   convenient             pratique

             Tokenizer                  Tokenizer

                   Semantic, accurate     Sémantique, précis


vendredi 13 novembre 2009                                       20
Tokenizer
       <?php print ("hello $world!"); ?>
             [1] => Array
                 (                   [6] => Array
                     [0] => 266          (
                     [1] => print            [0] => 309
                     [2] => 1                [1] => $world
                 )                           [2] => 1
                                         )
             [2] => Array
                 (                   [7] => Array
                     [0] => 370          (
                     [1] =>                  [0] => 314
                     [2] => 1                [1] => !
                 )                           [2] => 1
                                         )
             [3] => (
                                                             [1] => Array
             [4] => "                [8] => "
                                                                 (
             [5] => Array            [9] => )
                                                                      [0] => PHP token
                 (                   [10] => ;
                                                                      [1] => PHP code
                      [0] => 314
                                                                      [2] => Script line
                      [1] => hello
                                                                 )
                      [2] => 1
                                                             [2] => "
                 )


vendredi 13 novembre 2009                                                                  21
PHP injections
       Injections PHP
             dynamical inclusion          Inclusions dynamiques
                                          d'inclusion
                   include, require and
                   *_once                   include, require and
                                            *_once
                   back ticks (`)
                                            `
                   eval
                                            eval




vendredi 13 novembre 2009                                          22
Input                             Entrées
             HTML Forms:       Formulaire HTML:

                   form          form

                   input         input

                   $_GET         $_GET

                   $_POST        $_POST

                   $_REQUEST     $_REQUEST




vendredi 13 novembre 2009                          23
Input                               Entrées
             Databases:            Bases de données:

                   mysql_query()     mysql_query()

                   SELECT            SELECT

             HTTP Headers:         Entête HTTP:

                   $_COOKIE          $_COOKIE

                   $_SERVER          $_SERVER




vendredi 13 novembre 2009                              24
Input                                          Entrées
             register_globals strikes back   register_globals contre-
                                             attaque
                   Foreach and $$
                                               Foreach and $$
                   extract
                                               extract
                   import_request_var
                                               import_request_var
                   $GLOBALS
                                               $GLOBALS
                   parse_str
                                               parse_str
                   (ini_get
                                               (ini_get
                   (‘register_globals’))
                                               (‘register_globals’))

vendredi 13 novembre 2009                                               25
Output                             Sorties
             Client:          Client:

                   echo         echo

                   print        print

                   <?=          <?=

                   die          die

                   print_r      print_r

                   var_dump     var_dump

vendredi 13 novembre 2009                           26
Output                                          Sorties
             Databases:                     Bases de données:

                   mysql_query()              mysql_query()

                   mysqli_multi_query         mysqli_multi_query

                   update, delete, insert     update, delete, insert

             Headers                        En-têtes

                   header()                   header()




vendredi 13 novembre 2009                                              27
Output                              Sorties
             System:            Système:

                   exec()         exec()

                   passthru()     passthru()

                   system()       system()




vendredi 13 novembre 2009                            28
Gotchas                                        Pièges
             Trust of HTTP Headers:       Confiance des en-têtes
                                          HTTP :
                   Referer
                                            Referer
             Trust of $_SERVER:
                                          Confiance de $_SERVER :
                   $_SERVER['PHP_SELF']
                                            $_SERVER['PHP_SELF']
             Trust of Client-Side         Confiance des restrictions
             Restrictions:                clients:

                   maxlength                maxlength


vendredi 13 novembre 2009                                             29
Report                                Rapport
                  Vulnerability   Critical      Load

             register_globals      High         High

                     Injections    High        Medium

                SQL injection     Medium        High

                       headers     Low          Low



vendredi 13 novembre 2009                               30
Questions?

             info@ph-il.ca

             http://www.ph-il.ca

             http://www.ph-il.ca/en/conferences

             http://www.ph-il.ca/fr/conferences




vendredi 13 novembre 2009                         31
vendredi 13 novembre 2009   32
vendredi 13 novembre 2009   33

Contenu connexe

En vedette

Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continuePhilippe Gamache
 
Symfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleSymfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleAbdelkader Rhouati
 
Comment construire un environnement e-commerce complet avec Symfony 2 ?
Comment construire un environnement e-commerce complet avec Symfony 2 ? Comment construire un environnement e-commerce complet avec Symfony 2 ?
Comment construire un environnement e-commerce complet avec Symfony 2 ? Fabien Gasser
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesNoel GUILBERT
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2RomainKuzniak
 
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Sofien Benrhouma
 

En vedette (6)

Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continue
 
Symfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleSymfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation Générale
 
Comment construire un environnement e-commerce complet avec Symfony 2 ?
Comment construire un environnement e-commerce complet avec Symfony 2 ? Comment construire un environnement e-commerce complet avec Symfony 2 ?
Comment construire un environnement e-commerce complet avec Symfony 2 ?
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiques
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2
 
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
 

Plus de Philippe Gamache

Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Philippe Gamache
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Philippe Gamache
 
Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Philippe Gamache
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Philippe Gamache
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Philippe Gamache
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 Philippe Gamache
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Philippe Gamache
 
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017Philippe Gamache
 
Entreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealEntreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealPhilippe Gamache
 
Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Philippe Gamache
 
Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Philippe Gamache
 
Une application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuveUne application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuvePhilippe Gamache
 
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Philippe Gamache
 
One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009Philippe Gamache
 
Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Philippe Gamache
 

Plus de Philippe Gamache (16)

Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0
 
Mentor et votre équipe
Mentor et votre équipeMentor et votre équipe
Mentor et votre équipe
 
Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017
 
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
 
Entreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealEntreprise Security API - OWASP Montreal
Entreprise Security API - OWASP Montreal
 
Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011
 
Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011
 
Une application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuveUne application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de Mainsonneuve
 
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
 
One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009
 
Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009
 

Auditing and securing PHP applications - FRHACK 2009

  • 1. Auditing PHP applications Audit des applications en PHP vendredi 13 novembre 2009 1
  • 2. Agenda Ordre du jour Workshop presentation Présentation de l’atelier Black box audit Audit boîte noire Source code audit Audit à code ouvert vendredi 13 novembre 2009 2
  • 3. Who speak? Qui parle? Philippe Gamache Philippe Gamache Parler Haut, Interagir Parler Haut, Interagir Librement : Librement : Web development, security Développement Web, audit audit, training de sécurité, formations info@ph-il.ca info@ph-il.ca @SecureSymfony @SecureSymfony vendredi 13 novembre 2009 3
  • 4. Security book Livre de sécurité New 2009 edition Comprehensive review of security system for MySQL, PHP, etc. Published in French Planning translation Nouvelle édition 2009 Bilan complet de la sécurité : système, MySQL, PHP, etc. Édité chez Eyrolles Dédicaces sur demande vendredi 13 novembre 2009 4
  • 5. Yes, I take question Je réponds aux questions vendredi 13 novembre 2009 5
  • 6. Why? Pourquoi? Confidence does not La confiance n'exclut pas le exclude control™ contrôle™ Pour valider un travail To validate external work externe To validate internal work Pour valider un travail Round-up interne Pour faire le point For an external Pour avoir un regard perspective externe As often as possible Aussi souvent que possible vendredi 13 novembre 2009 6
  • 7. Full audit synopsis Synopsis d’un audit Identification of the audit Identification des objectifs goals d'audit Interview with the Entretien avec les équipes development teams de développement Black box testing Test boîte noire Open Code audit Audit de code Report Rapport vendredi 13 novembre 2009 7
  • 8. Identification of the audit goals Identification des objectifs d’audit Audit scope Étendue de l'audit Security Sécurité Performance Performance Code quality Qualité du code vendredi 13 novembre 2009 8
  • 9. Interview with the development teams Entretien avec les équipes de développement Check if development Vérifiez si l’équipe de teams knows what to développement sait ce qu’il secure faut sécurisé Have the design explained Demandez d’expliquer la first conception Have them explains their Demandez d’expliquer leur approach approche Check what they say Vérifiez ce qu'ils disent Check what they don’t Vérifiez ce qu'ils ne say disent pas vendredi 13 novembre 2009 9
  • 10. The shy version La version timide We know there are security Nous savons qu’il y a des problems problèmes de sécurité : but we have no time to mais nous n'avons pas le secure them temps de les sécuriser this app has been written ce logiciel a été écrit il y a years ago quelques années we can’t keep up with nous ne pouvons pas the threats suivre les menaces vendredi 13 novembre 2009 10
  • 11. The strong version La version forte We have secured the Nous avons sécurisé application l'application Nous utilisons le We use SSL and crypto protocole SSL et la All content is validated cryptographie and filtered Tout le contenu est validé et filtré We don’t do any Nous ne faisons aucune dynamical include inclusion dynamique Our frameworks doesn’t Nos cadres allow this d’applications sont sécurisées vendredi 13 novembre 2009 11
  • 12. Black box testing Test boîte noire Easy to set up Facile de mise en place Take into account the Prendre en compte le context of the application contexte de la demande Often spectacular Souvent spectaculaires Generally shallow Généralement peu profondes vendredi 13 novembre 2009 12
  • 13. Black box testing Test boîte noire Finding informations Recherche d’informations Look for vulnerabilities Rechercher les vulnérabilités Automatic scanners Scanneurs automatiques By hand À la main Fuzzing Fuzzing Scenarios Scénarios Strikes Attaquer vendredi 13 novembre 2009 13
  • 14. Black box testing Test boîte noire Usual directories Répertoires habituels includes, include, inc, includes, include, inc, com, classes, lib, library com, classes, lib, library admin, adm, admin, adm, administrator administrateur tmp, TMP, ext, var tmp, TMP, ext, var data, db, conf, config data, db, conf, config, configuration uploads, install uploads, install vendredi 13 novembre 2009 14
  • 15. Black box testing Test boîte noire Typical files Fichiers typiques .phps, .inc, .class .phps, .inc, .class xml, ini, yaml, cfg xml, ini, yaml, cfg .tar, .gz, .zip, .rar, .bz2 .tar, .gz, .zip, .rar, .bz2 Apache Alias : /icons/ Apache Alias : /icons/ robots.txt robots.txt vendredi 13 novembre 2009 15
  • 16. Open Code audit Audit de code Look into the PHP code Rechercher dans le code PHP Search for hidden problems Rechercher les problèmes Usually less spectacular cachés than black box Habituellement, moins spectaculaire que les tests Easy to loose focus boîte noire Tempting to audit Facile de perdre sa everything concentration Tentant de tout vérifier vendredi 13 novembre 2009 16
  • 17. Approch Approche What to search for? Que rechercher? Quels sont les points What are the entry points? d'entrée? What are the exit points? Quels sont les points de sortie? Open-mindedness and Ouverture d’esprit et discovery découverte How can they be exploited Comment peuvent-ils être exploités Or protected ? Ou protégés? vendredi 13 novembre 2009 17
  • 18. Assessing the code Évaluer le code One liners En une ligne One line of code is Une ligne de code est sufficiently to be bad suffisamment pour être Even though mauvais you must follow the code Malgré tous forward (for input) vous devez suivre le code in reverse (for output) vers l’avant (entrées) sens inverse (sorties) <?php $action = $_POST['action']; $query_string = "action=$action"; $link = "index.php?$query_string"; ?> <a href="<?php echo $link; ?>"> Click Here </a> vendredi 13 novembre 2009 18
  • 19. What to search for? Que rechercher? Injections Injections PHP PHP SQL SQL HTML HTML system système vendredi 13 novembre 2009 19
  • 20. Tools Outils Your eyes Vos yeux Text editors Éditeurs de texte grep grep Fast, available, Rapide, disponible, convenient pratique Tokenizer Tokenizer Semantic, accurate Sémantique, précis vendredi 13 novembre 2009 20
  • 21. Tokenizer <?php print ("hello $world!"); ?> [1] => Array ( [6] => Array [0] => 266 ( [1] => print [0] => 309 [2] => 1 [1] => $world ) [2] => 1 ) [2] => Array ( [7] => Array [0] => 370 ( [1] => [0] => 314 [2] => 1 [1] => ! ) [2] => 1 ) [3] => ( [1] => Array [4] => " [8] => " ( [5] => Array [9] => ) [0] => PHP token ( [10] => ; [1] => PHP code [0] => 314 [2] => Script line [1] => hello ) [2] => 1 [2] => " ) vendredi 13 novembre 2009 21
  • 22. PHP injections Injections PHP dynamical inclusion Inclusions dynamiques d'inclusion include, require and *_once include, require and *_once back ticks (`) ` eval eval vendredi 13 novembre 2009 22
  • 23. Input Entrées HTML Forms: Formulaire HTML: form form input input $_GET $_GET $_POST $_POST $_REQUEST $_REQUEST vendredi 13 novembre 2009 23
  • 24. Input Entrées Databases: Bases de données: mysql_query() mysql_query() SELECT SELECT HTTP Headers: Entête HTTP: $_COOKIE $_COOKIE $_SERVER $_SERVER vendredi 13 novembre 2009 24
  • 25. Input Entrées register_globals strikes back register_globals contre- attaque Foreach and $$ Foreach and $$ extract extract import_request_var import_request_var $GLOBALS $GLOBALS parse_str parse_str (ini_get (ini_get (‘register_globals’)) (‘register_globals’)) vendredi 13 novembre 2009 25
  • 26. Output Sorties Client: Client: echo echo print print <?= <?= die die print_r print_r var_dump var_dump vendredi 13 novembre 2009 26
  • 27. Output Sorties Databases: Bases de données: mysql_query() mysql_query() mysqli_multi_query mysqli_multi_query update, delete, insert update, delete, insert Headers En-têtes header() header() vendredi 13 novembre 2009 27
  • 28. Output Sorties System: Système: exec() exec() passthru() passthru() system() system() vendredi 13 novembre 2009 28
  • 29. Gotchas Pièges Trust of HTTP Headers: Confiance des en-têtes HTTP : Referer Referer Trust of $_SERVER: Confiance de $_SERVER : $_SERVER['PHP_SELF'] $_SERVER['PHP_SELF'] Trust of Client-Side Confiance des restrictions Restrictions: clients: maxlength maxlength vendredi 13 novembre 2009 29
  • 30. Report Rapport Vulnerability Critical Load register_globals High High Injections High Medium SQL injection Medium High headers Low Low vendredi 13 novembre 2009 30
  • 31. Questions? info@ph-il.ca http://www.ph-il.ca http://www.ph-il.ca/en/conferences http://www.ph-il.ca/fr/conferences vendredi 13 novembre 2009 31