SlideShare una empresa de Scribd logo
1 de 97
Descargar para leer sin conexión
Audit Sécurité



vendredi 13 novembre 2009                    1
Ordre du jour

                            •   Présentation de l’atelier

                            •   Audit boîte noire

                            •   Audit à code ouvert




vendredi 13 novembre 2009                                   2
Qui parle?

                            •   Philippe Gamache

                            •   Parler haut, interagir librement :
                                audit de sécurité, formations

                            •   Caviste de cidres de glace

                            •   info@ph-il.ca




vendredi 13 novembre 2009                                            3
Qui parle?
                            •   Damien Seguy

                            •   Alter Way Consulting :
                                services experts en
                                logiciels libres

                            •   Editeur de calendriers

                            •   damien.seguy@alterway.fr




vendredi 13 novembre 2009                                  4
Livre sécurité
                            •   Nouvelle édition 2009

                            •   Bilan complet de la
                                sécurité : système,
                                MySQL, PHP, etc

                            •   Edité chez Eyrolles

                            •   Dédicaces sur demande




vendredi 13 novembre 2009                               5
Cligraph CRM
                                  •   CRM/GRC Open Source

                                  •   Version 0.991

                                  •   Activement développé

                                  •   Soutenu par Cogivea
                                      http://www.cogivea.com/

                                  •   Léger, rapide et puissant

                                  •   http://www.cligraphcrm.com/


vendredi 13 novembre 2009                                           6
Cligraph CRM

                            •   Technologies PHP et MySQL, Javascript

                            •   Code développé depuis 5 ans

                            •   4970 fichiers

                            •   1200 fichiers PHP

                            •   320 000 lignes de code



vendredi 13 novembre 2009                                               7
L’atelier sécurité

                            •   Réveillez-vous : vous avez du travail!

                            •   Analyse des logs et identification des problèmes

                            •   Discussion des stratégies de protection et contextes

                            •   http://192.168.3.73/ de démonstration




vendredi 13 novembre 2009                                                              8
Tests boîte noire



                                                9
vendredi 13 novembre 2009                           9
Tests boîte noire

                            •   Recherche d’informations

                                •   Trouver de l’information sur l’application

                                    •   Que puis-je faire sur cette application?

                                    •   Où sont les points d'entrée les plus
                                        populaires?


                                                                                   10
vendredi 13 novembre 2009                                                               10
Tests boîte noire
                            •   Trouver des vulnérabilités

                                •   Trouver les trous dans l’application

                                    •   Scanneurs automatiques

                                    •   À la main

                                    •   Fuzzing

                                    •   Scénarios

                                •   Comment puis-je l'utiliser à mon avantage?


                                                                                 11
vendredi 13 novembre 2009                                                             11
Tests boîte noire

                            •   Attaquer

                                •   Attaquer une
                                    vulnérabilité avec
                                    un but précis




                                                         12
vendredi 13 novembre 2009                                     12
Recherche
                                    d’informations
                            •   Moteurs de recherches

                                •   Facebook, LinkedIn, Joboom, Monster

                                    •   Langage de programmation

                                    •   Logiciels utilisés




                                                                          13
vendredi 13 novembre 2009                                                      13
Recherche
                                    d’informations
                            •   Moteurs de recherches (suite)

                                •   Google : phpinfo, "Zend engine”,
                                    site:nomsite.com

                                    •   Divulgation de renseignements

                                <b>Notice</b>: undefined </b> on line <b>
                                <b>Warning</b>: </b> on line <b>



                                                                           14
vendredi 13 novembre 2009                                                       14
Recherche
                                    d’informations
                            •   Moteurs de recherches (suite)

                                •   Krugle : echo $_GET

                            •   Bases de données de vulnérabilités

                                •   BUGTRAQ
                                •   CERT
                                •   CVE
                                •   Milw0rm


                                                                     15
vendredi 13 novembre 2009                                                 15
Recherche
                                     d’informations
                            •   Google codesearch :

                                •   XSS
                                    lang:php (echo|print).*$_(GET|POST|COOKIE|
                                    REQUEST)

                                •   Injection SQL
                                    lang:php query(.*$_(GET|POST|COOKIE|
                                    REQUEST).*)

                                •   Injection de code
                                    lang:php (include|include_once| require|
                                    require_once).*$_(GET| POST|COOKIE|REQUEST)



                                                                                   16
vendredi 13 novembre 2009                                                               16
Recherche
                                     d’informations
                            •   Google codesearch :

                                •   Injection d'en-tête HTTP
                                    lang:php headers*(.*$_(SERVER| GET|POST|
                                    COOKIE|REQUEST).*)

                                •   Fixation de session
                                    lang:php session_start()
                                    lang:php session_regenerate_id()




                                                                                  17
vendredi 13 novembre 2009                                                              17
Recherche
                                     d’informations
                            •   Google codesearch :

                                •   Affichage arbitraire de fichiers

                                    lang:php (fopen|readfile|file_get_contents)s*
                                    (.*$(_GET|_POST|HTTP_GET_VARS|
                                    HTTP_POST_VARS).*)




                                                                                    18
vendredi 13 novembre 2009                                                                18
Recherche
                                    d’informations
                            •   Google codesearch :

                                •   Mots de passes

                                filetype:sql INSERT
                                intitle:"phpinfo()" +".default_password"
                                ! +"Zend Scripting Language Engine"
                                lang:php _connects*(.*,.*,("|').*("|').*)
                                lang:php "VBULLETIN IS NOT FREE SOFTWARE"
                                lang:php "XCART_SESSION_START"
                                lang:php $passw+s*=s*('|")w+('|");




                                                                               19
vendredi 13 novembre 2009                                                           19
Recherche
                                     d’informations
                            •   robots.txt

                            •   Alias Apache

                                •   /icons/

                            •   Signatures dans les en têtes

                                •   curl, wget, Firefox, Rex Swain's HTTP Viewer

                            •   .phps


                                                                                   20
vendredi 13 novembre 2009                                                               20
Recherche
                                     d’informations
                            •   https

                            •   Page 404

                            •   Page blanche

                                •   arrêt de code sans affichage d'erreur




                                                                           21
vendredi 13 novembre 2009                                                       21
Recherche
                                    d’informations
                            •   Répertoires courants
                                •   includes
                                •   admin
                                •   tmp
                                •   data
                                •   db
                                •   uploads



                                                       22
vendredi 13 novembre 2009                                   22
Recherche
                                    d’informations
                            •   theHarvester
                                http://www.edge-security.com/theHarvester.php

                            •   MetaGoofil
                                http://www.edge-security.com/metagoofil.php

                            •   Nikto
                                http://www.cirt.net/

                            •   SEAT (Search Engine Assessment Tool)
                                http://midnightresearch.com/projects/search-
                                engine-assessment-tool/



                                                                                23
vendredi 13 novembre 2009                                                            23
Recherche
                                    d’informations

                            •   Subdomainer
                                http://www.edge-security.com/subdomainer.php




                                                                               24
vendredi 13 novembre 2009                                                           24
Recherche
                                   d’informations
                            •   http://www.cligraphcrm.com/




vendredi 13 novembre 2009                                     25
Recherche
                            d’informations




vendredi 13 novembre 2009                    26
Recherche
                                   d’informations

                            •   Google

                            •   Google codesearch

                            •   Milm0rm




vendredi 13 novembre 2009                           27
Trouver des
                                      vulnérabilités
                            •   Où trouver des vulnérabilités?

                                •   XSS

                                •   CSRF

                                •   Injections

                                •   Remplacement de fichiers

                                •   etc.


                                                                 28
vendredi 13 novembre 2009                                             28
Trouver des
                                     vulnérabilités

                            •   Comment exploiter cette faiblesse?

                            •   Que faire avec cette faille?




                                                                     29
vendredi 13 novembre 2009                                                 29
Outils manuels
                            •   Firefox
                                •   Access Me
                                •   Firebug
                                •   Firecookie
                                •   FirePHP
                                •   HackBar
                                •   Header Spy
                                •   JavaScript Debugger


                                                          30
vendredi 13 novembre 2009                                      30
Outils manuels
                            •   Firefox
                                •   Poster
                                •   SQL Inject Me
                                •   SQL Injection!
                                •   User Agent Switcher
                                •   Web Developer
                                •   X-Forwarded-For Spoofer
                                •   XSS Me Data


                                                              31
vendredi 13 novembre 2009                                          31
Outils manuels


                            •   Rex Swain's HTTP Viewer
                                http://www.rexswain.com/httpview.html




                                                                        32
vendredi 13 novembre 2009                                                    32
Scanneurs
                                       automatiques
                            •   Simple à mettre en oeuvre

                            •   Permets de trouver les attaques les plus courantes

                            •   Doivent être adaptés

                                •   Mis à jour régulièrement

                                •   Personnalisables



                                                                                     33
vendredi 13 novembre 2009                                                                 33
Scanneurs
                                       automatiques
                            •   Acunetix Web Vulnerability Scanner
                                http://www.acunetix.com/vulnerability-scanner/

                            •   BeEF
                                http://www.bindshell.net/tools/beef/

                            •   Burp Suite
                                http://portswigger.net/suite/

                            •   Metasploit
                                http://www.metasploit.com/




                                                                                 34
vendredi 13 novembre 2009                                                             34
Scanneurs
                                automatiques
                •     Nikto
                      http://www.cirt.net/

                •     PBlind
                      http://www.edge-security.com/pblind.php

                •     Scrawlr
                      https://download.spidynamics.com/Products/scrawlr/

                •     SCRT Mini MySqlat0r
                      http://www.scrt.ch/pages_en/minimysqlator.html


                                                                           35
vendredi 13 novembre 2009                                                       35
Scanneurs
                                      automatiques

                            •   SCRT Webshag
                                http://www.scrt.ch/pages_en/outils.html

                            •   XSSploit
                                http://www.scrt.ch/pages_en/xssploit.html




                                                                            36
vendredi 13 novembre 2009                                                        36
Fuzzing

                            •   Test par valeur aléatoire

                            •   Stress des formulaires

                                •   Bases de données

                            •   Test décomplexé




                                                            37
vendredi 13 novembre 2009                                        37
Fuzzing
                            •   Tous les caractères de 0 à x255

                            •   Tous les caractères Unicode

                            •   Les nombres 1, 0, -1, 0.99, extrêmes, infinis

                            •   Chaînes

                                •   Longues

                                •   courtes


                                                                               38
vendredi 13 novembre 2009                                                           38
Fuzzing
                            •   Dictionnaires de valeurs

                                •   de vulnérabilités

                            •   GET, POST, COOKIE

                            •   Des variables tableaux

                                •   c[]=1




                                                           39
vendredi 13 novembre 2009                                       39
Fuzzing
                            •   Excédents de variables

                                •   debug=1, task=view


                            •   Manque de variables

                            •   Encodages variés

                                •   UTF-8, Latin1, HTML, hexa



                                                                40
vendredi 13 novembre 2009                                            40
Fuzzing
                            •   Burp Suite
                                http://portswigger.net/suite/

                            •   SCRT Webshag
                                http://www.scrt.ch/pages_en/outils.html

                            •   WebSlayer
                                http://www.edge-security.com/webslayer.php

                            •   Wfuzz
                                http://www.edge-security.com/wfuzz.php




                                                                             41
vendredi 13 novembre 2009                                                         41
Scénarios
                            •   Des tests plus adaptés

                                •   fragiles

                            •   Automatiser les tests

                            •   À utiliser avec le fuzzing

                            •   À utiliser avec des serveurs mandataires



                                                                           42
vendredi 13 novembre 2009                                                       42
Scénarios
                            •   Burp Suite
                                http://portswigger.net/suite/

                            •   Firefox
                                •   Selenium IDE
                            •   Funkload
                                http://funkload.nuxeo.org/

                            •   ProxyStrike
                                http://www.edge-security.com/proxystrike.php



                                                                               43
vendredi 13 novembre 2009                                                           43
Scénarios
                            •   SCRT Webshag
                                http://www.scrt.ch/pages_en/outils.html

                            •   WebScarab
                                http://www.owasp.org/index.php/
                                Category:OWASP_WebScarab_Project




                                                                          44
vendredi 13 novembre 2009                                                      44
Facilitez votre vie
                            •   Backtrack
                                http://www.remote-exploit.org/backtrack.html




vendredi 13 novembre 2009                                                      45
Facilitez votre vie
                            •   Samurai Web Testing Framework
                                http://samurai.inguardians.com/




vendredi 13 novembre 2009                                         46
Sécure ?
vendredi 13 novembre 2009              47
Les prolèmes

                            •   Faux sentiment
                                sécurité

                            •   Ne marche pas
                                toujours




vendredi 13 novembre 2009                           48
Notre cas

                            •   La sécurité par
                                l’insécurité

                            •   La sécurité par
                                l’instabilité




vendredi 13 novembre 2009                              49
Que faire?

                            •   Tests manuels

                            •   Les sources

                                •   Installer l’application




vendredi 13 novembre 2009                                     50
Les fichiers
                            total 592
                            drwxrwxrwx    25   user   group    850   23   Feb   12:03   accueil
                            drwxrwxrwx    67   user   group   2278   23   Feb   12:03   action
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   agent
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   biblio
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   compte
                            -rwxrwxrwx     1   user   group   7692   11   Sep   02:44   connect.php
                            -rwxrwxrwx     1   user   group   3856   11   Sep   02:44   err_navig.php
                            -rwxrwxrwx     1   user   group   3165   11   Sep   02:44   erreur404.php
                            drwxrwxrwx    76   user   group   2584   23   Feb   12:03   etat
                            drwxrwxrwx   171   user   group   5814   23   Feb   12:03   fonctions
                            drwxrwxrwx     8   user   group    272   23   Feb   12:03   images
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   include
                            -rwxrwxrwx     1   user   group   2784   11   Sep   02:44   index.php
                            drwxrwxrwx    27   user   group    918   23   Feb   12:03   install
                            drwxrwxrwx    80   user   group   2720   23   Feb   12:03   inter_pages
                            drwxrwxrwx     6   user   group    204   23   Feb   12:03   langue
                            …
                            drwxrwxrwx     7 user     group    238 2 Mar 18:15 log
                            drwxrwxrwx    36 user     group   1224 23 Feb 12:03 mail




vendredi 13 novembre 2009                                                                               51
Les fichiers
                            total 592
                            drwxrwxrwx    25   user   group    850   23   Feb   12:03   accueil
                            drwxrwxrwx    67   user   group   2278   23   Feb   12:03   action
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   agent
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   biblio
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   compte
                            -rwxrwxrwx     1   user   group   7692   11   Sep   02:44   connect.php
                            -rwxrwxrwx     1   user   group   3856   11   Sep   02:44   err_navig.php
                            -rwxrwxrwx     1   user   group   3165   11   Sep   02:44   erreur404.php
                            drwxrwxrwx    76   user   group   2584   23   Feb   12:03   etat
                            drwxrwxrwx   171   user   group   5814   23   Feb   12:03   fonctions
                            drwxrwxrwx     8   user   group    272   23   Feb   12:03   images
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   include
                            -rwxrwxrwx     1   user   group   2784   11   Sep   02:44   index.php
                            drwxrwxrwx    27   user   group    918   23   Feb   12:03   install
                            drwxrwxrwx    80   user   group   2720   23   Feb   12:03   inter_pages
                            drwxrwxrwx     6   user   group    204   23   Feb   12:03   langue
                            …
                            drwxrwxrwx     7 user     group    238 2 Mar 18:15 log
                            drwxrwxrwx    36 user     group   1224 23 Feb 12:03 mail




vendredi 13 novembre 2009                                                                               52
Les fichiers
                            total 592
                            drwxrwxrwx    25   user   group    850   23   Feb   12:03   accueil
                            drwxrwxrwx    67   user   group   2278   23   Feb   12:03   action
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   agent
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   biblio
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   compte
                            -rwxrwxrwx     1   user   group   7692   11   Sep   02:44   connect.php
                            -rwxrwxrwx     1   user   group   3856   11   Sep   02:44   err_navig.php
                            -rwxrwxrwx     1   user   group   3165   11   Sep   02:44   erreur404.php
                            drwxrwxrwx    76   user   group   2584   23   Feb   12:03   etat
                            drwxrwxrwx   171   user   group   5814   23   Feb   12:03   fonctions
                            drwxrwxrwx     8   user   group    272   23   Feb   12:03   images
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   include
                            -rwxrwxrwx     1   user   group   2784   11   Sep   02:44   index.php
                            drwxrwxrwx    27   user   group    918   23   Feb   12:03   install
                            drwxrwxrwx    80   user   group   2720   23   Feb   12:03   inter_pages
                            drwxrwxrwx     6   user   group    204   23   Feb   12:03   langue
                            …
                            drwxrwxrwx     7 user     group    238 2 Mar 18:15 log
                            drwxrwxrwx    36 user     group   1224 23 Feb 12:03 mail




vendredi 13 novembre 2009                                                                               53
Les fichiers
                            total 592
                            drwxrwxrwx    25   user   group    850   23   Feb   12:03   accueil
                            drwxrwxrwx    67   user   group   2278   23   Feb   12:03   action
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   agent
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   biblio
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   compte
                            -rwxrwxrwx     1   user   group   7692   11   Sep   02:44   connect.php
                            -rwxrwxrwx     1   user   group   3856   11   Sep   02:44   err_navig.php
                            -rwxrwxrwx     1   user   group   3165   11   Sep   02:44   erreur404.php
                            drwxrwxrwx    76   user   group   2584   23   Feb   12:03   etat
                            drwxrwxrwx   171   user   group   5814   23   Feb   12:03   fonctions
                            drwxrwxrwx     8   user   group    272   23   Feb   12:03   images
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   include
                            -rwxrwxrwx     1   user   group   2784   11   Sep   02:44   index.php
                            drwxrwxrwx    27   user   group    918   23   Feb   12:03   install
                            drwxrwxrwx    80   user   group   2720   23   Feb   12:03   inter_pages
                            drwxrwxrwx     6   user   group    204   23   Feb   12:03   langue
                            …
                            drwxrwxrwx     7 user     group    238 2 Mar 18:15 log
                            drwxrwxrwx    36 user     group   1224 23 Feb 12:03 mail




vendredi 13 novembre 2009                                                                               54
Les fichiers
                            total 592
                            drwxrwxrwx    25   user   group    850   23   Feb   12:03   accueil
                            drwxrwxrwx    67   user   group   2278   23   Feb   12:03   action
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   agent
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   biblio
                            drwxrwxrwx    39   user   group   1326   23   Feb   12:03   compte
                            -rwxrwxrwx     1   user   group   7692   11   Sep   02:44   connect.php
                            -rwxrwxrwx     1   user   group   3856   11   Sep   02:44   err_navig.php
                            -rwxrwxrwx     1   user   group   3165   11   Sep   02:44   erreur404.php
                            drwxrwxrwx    76   user   group   2584   23   Feb   12:03   etat
                            drwxrwxrwx   171   user   group   5814   23   Feb   12:03   fonctions
                            drwxrwxrwx     8   user   group    272   23   Feb   12:03   images
                            drwxrwxrwx    13   user   group    442   23   Feb   12:03   include
                            -rwxrwxrwx     1   user   group   2784   11   Sep   02:44   index.php
                            drwxrwxrwx    27   user   group    918   23   Feb   12:03   install
                            drwxrwxrwx    80   user   group   2720   23   Feb   12:03   inter_pages
                            drwxrwxrwx     6   user   group    204   23   Feb   12:03   langue
                            …
                            drwxrwxrwx     7 user     group    238 2 Mar 18:15 log
                            drwxrwxrwx    36 user     group   1224 23 Feb 12:03 mail




vendredi 13 novembre 2009                                                                               55
Les fichiers
                            cligraphcrm/include/fpdf:
                            total 376
                            -rwxrwxrwx   1 user group   46002   26   Jan   02:41   fpdf.php
                            -rwxrwxrwx   1 user group     705   11   Sep   02:44   fpdf_entete.php
                            -rwxrwxrwx   1 user group   47404   26   Jan   18:07   fpdf_facture.php
                            -rwxrwxrwx   1 user group   14922   26   Jan   14:50   fpdf_html2pdf.php
                            -rwxrwxrwx   1 user group    5238   11   Sep   02:44   fpdf_mem_image.php
                            -rwxrwxrwx   1 user group    7629   11   Sep   02:44   fpdf_memoire.php
                            -rwxrwxrwx   1 user group    1243   11   Sep   02:44   fpdf_table_def.inc
                            -rwxrwxrwx   1 user group   27075   11   Sep   02:44   fpdf_tableau.php
                            -rwxrwxrwx   1 user group    4317   11   Sep   02:44   fpdf_texte.php
                            -rwxrwxrwx   1 user group   12852   11   Sep   02:44   fpdf_writetag.php




vendredi 13 novembre 2009                                                                               56
Les fichiers
                            cligraphcrm/include/fpdf:
                            total 376
                            -rwxrwxrwx   1 user group   46002   26   Jan   02:41   fpdf.php
                            -rwxrwxrwx   1 user group     705   11   Sep   02:44   fpdf_entete.php
                            -rwxrwxrwx   1 user group   47404   26   Jan   18:07   fpdf_facture.php
                            -rwxrwxrwx   1 user group   14922   26   Jan   14:50   fpdf_html2pdf.php
                            -rwxrwxrwx   1 user group    5238   11   Sep   02:44   fpdf_mem_image.php
                            -rwxrwxrwx   1 user group    7629   11   Sep   02:44   fpdf_memoire.php
                            -rwxrwxrwx   1 user group    1243   11   Sep   02:44   fpdf_table_def.inc
                            -rwxrwxrwx   1 user group   27075   11   Sep   02:44   fpdf_tableau.php
                            -rwxrwxrwx   1 user group    4317   11   Sep   02:44   fpdf_texte.php
                            -rwxrwxrwx   1 user group   12852   11   Sep   02:44   fpdf_writetag.php




vendredi 13 novembre 2009                                                                               57
Les fichiers
                            cligraphcrm/install/sql/tables:
                            total 928
                            -rwxrwxrwx    1 user group 4750     29   Jan   10:44   acces.sql
                            -rwxrwxrwx    1 user group 4802     29   Jan   10:44   acces_type.sql
                            -rwxrwxrwx    1 user group    190   23   Nov   20:12   admin_crm.sql
                            -rwxrwxrwx    1 user group 1111      3   Feb   14:45   adresse.sql
                            -rwxrwxrwx    1 user group 1637     15   Jan   11:24   affaire.sql
                            -rwxrwxrwx    1 user group    578   17   Jan   19:27   affaire_intvt.sql
                            -rwxrwxrwx    1 user group 1544     22   Oct   17:49   affaire_pdt.sql
                            -rwxrwxrwx    1 user group 3231      3   Dec   19:15   agent.sql
                            -rwxrwxrwx    1 user group    581   22   Oct   17:49   argument.sql
                            -rwxrwxrwx    1 user group 3062     25   Jan   09:45   avoir.sql
                            -rwxrwxrwx    1 user group 1605     21   Jan   06:30   avoir_detail.sql
                            -rwxrwxrwx    1 user group    741   22   Oct   17:49   campagne.sql
                            -rwxrwxrwx    1 user group    701   22   Oct   17:49   campagne_promo.sql
                            -rwxrwxrwx    1 user group    537   22   Oct   17:49   categorie_pdt.sql
                            -rwxrwxrwx    1 user group    527   27   Jan   11:36   cgv.sql
                            -rwxrwxrwx    1 user group    547   11   Sep   02:44   civilite.sql
                            -rwxrwxrwx    1 user group 4871     22   Oct   17:49   client.sql




vendredi 13 novembre 2009                                                                               58
Installation




vendredi 13 novembre 2009                  59
Installation




vendredi 13 novembre 2009                  60
Installation




vendredi 13 novembre 2009                  61
Installation




vendredi 13 novembre 2009                  62
Installation




vendredi 13 novembre 2009                  63
Installation




vendredi 13 novembre 2009                  64
Installation




vendredi 13 novembre 2009                  65
Installation




vendredi 13 novembre 2009                  66
Audit de code



vendredi 13 novembre 2009                   67
Ordre du jour

                            •   Lire les logs et repérer les vulnérabilités

                            •   Caractériser et supprimer les failles

                            •   Evaluation du volume de correction




vendredi 13 novembre 2009                                                     68
Approche
                            •   Un point d’entrée

                            •   Lecture du code

                            •   Ouverture d’esprit et découverte

                            •   Identifier la faille

                            •   Comment l’exploiter




vendredi 13 novembre 2009                                          69
Outils existants
                   •        Rats
                            http://www.fortifysoftware.com/security-resources/rats.jsp

                   •        Yasca
                            http://www.yasca.org

                       /accueil/accueil.php:478: High: fopen
                       /action/facture_trt.php:170: High: eval
                       /include/pear/File_Archive/Archive/Reader/Bzip2.php:80:
                          High: bzopen
                       /mail/mess_suppr_trt.php:193: High: mail
                       /include/pear/PEAR/RunTest.php:449: High: system
                       /fonctions/gallery.func.php:95: Medium: is_dir
                       /include/pear/PEAR/Remote.php:296: Medium: fsockopen



vendredi 13 novembre 2009                                                                70
Trois moteurs

                            •   Grep

                            •   Les expressions rationnelles

                            •   Le tokenizer




vendredi 13 novembre 2009                                      71
Approches
                                                             Sémantique      Rapide

                                                       700
                            •   Sémantique : proche
                                des concepts PHP et    525
                                de programmation
                                                       350
                            •   Rapide à mettre
                                en place et exécuter   175

                                                         0
                                                          Grep       Regex     Tokenizer




vendredi 13 novembre 2009                                                                  72
Occurrences
                                     $_GET $_POST $_REQUEST

                            Grep     137    604     2650

                            Regex    139    667     3279

                            Token     11    617     1518



vendredi 13 novembre 2009                                     73
Choix

                            •   One-liner contre temps de développement

                            •   Précision sémantique face à recherche brute

                            •   Rejouable ou jetable




vendredi 13 novembre 2009                                                     74
Points d’intérêt
                            •   index.php

                            •   index_bis.php

                            •   err_nav.php

                            •   out.php

                            •   erreur404.php

                            •   verif.php



vendredi 13 novembre 2009                             75
Points d’intérêt

                               Entrée      Filtrage


                             Traitement     Suivi


                               Sortie     Protection



vendredi 13 novembre 2009                              76
Cheminement

                            $_GET   pdo_query




                                    pdo_fetch
                            echo




vendredi 13 novembre 2009                       77
Interfaces
                            •   Navigateur        •   Système

                            •   URL               •   Processus

                            •   Cookies           •   PHP

                            •   JavaScript        •   XML

                            •   SQL               •   LDAP ...




vendredi 13 novembre 2009                                         78
Navigateur
                            •   Entrées

                                •   $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE

                            •   Sorties

                                •   echo, print, var_dump

                            •   Protections

                                •   htmlentities, htmlspecialchars, strip_tags
                                    ext/xmlwriter


vendredi 13 novembre 2009                                                          79
URL
                            •   Entrées

                                •   parse_url, urldecode, rawurldecode

                            •   Sorties

                                •   echo, print, http_build_url, http_build_query,
                                    http_build_str

                            •   Protections

                                •   url_encode, rawurlencode


vendredi 13 novembre 2009                                                            80
Cookies
                            •   Entrées

                                •   $_COOKIES, $HTTP_COOKIE_VARS,
                                    http_parse_cookies, session_name

                            •   Sorties

                                •   setcookies, setrawcookie, stream_context_create,
                                    httpRequest::setcookies, http_build_cookie

                            •   Protections


vendredi 13 novembre 2009                                                              81
JavaScript
                            •   Entrées

                                •   json_decode

                            •   Sorties

                                •   json_encode, echo, print

                            •   Protections

                                •   Rien vraiment



vendredi 13 novembre 2009                                      82
SQL
                            •   Entrées

                                •   pdo_query, mysqli_query, query,

                            •   Sorties

                                •   *fetch*, mysqli_error

                            •   Protections

                                •   pdo_quote, mysqli_real_escape_string, etc.



vendredi 13 novembre 2009                                                        83
Fichiers
                            •   Entrées

                                •   fopen, file_get_contents, passthru

                            •   Sorties

                                •   fwrite, fread, mkdir,

                            •   Protections

                                •   pathinfo, realpath



vendredi 13 novembre 2009                                               84
PHP
                            •   Entrées

                                •   eval, include, require et _once, dl, preg_replace,
                                    assert

                            •   Sorties

                                •   var_export

                            •   Protections

                                •   Aucune pour le code, fichiers pour les autres.


vendredi 13 novembre 2009                                                                85
Système
                            •   Entrées

                                •   ini_get, set_limit, getenv, getmypid, phpversion,
                                    phpinfo,

                            •   Sorties

                                •   ini_set, setenv

                            •   Protections

                                •   Aucune prévue


vendredi 13 novembre 2009                                                               86
Trouvailles



vendredi 13 novembre 2009                 87
Register_globals

                            •   Register globals via fct_urldecode dans fonctions/
                                fonctions_gen.php

                            •   Utilisation des superglobales, puis intuition sur le
                                nom de la fonction

                            •   $GLOBALS[$k] et affectation




vendredi 13 novembre 2009                                                              88
Injections SQL

                            •   $query="select theme_nom from theme where
                                theme_id="".$_REQUEST['theme_id'].""";

                            •   Passer par les requêtes SQL, et chercher les variables
                                globales

                            •   Lire le contexte et repérer les variables sans filtrage




vendredi 13 novembre 2009                                                                89
err_nav.php XSS


                            •   init_chem_crm est injecté directement

                            •




vendredi 13 novembre 2009                                               90
Téléchargements

                            •   Via les fonctions header()

                            •   Téléchargement de fichiers dans lanceur_dl.php

                            •   Pas de protection des variables, ni par session




vendredi 13 novembre 2009                                                         91
$_REQUEST DOS

                            •   $_REQUEST est utilisé pour le logout

                            •   if(isset($_REQUEST['opt']) && $_REQUEST['opt']==1)


                            •   $_REQUEST == $_GET && $_POST && $_COOKIE

                            •   Que se passe-t-il quand on pose un cookie ‘opt’ de 1?




vendredi 13 novembre 2009                                                               92
include
                            •   $format=$_REQUEST['exp_formdoc'];

                            •   include(fct_lien_page_custom("action/facture_".
                                $format.".php","abs"));

                            •   Maitrise du chemin d’inclusion

                            •   $exp_formdoc = "/../action/facture_fiche";
                                <- auto-inclusion!

                            •   ou bien, tentative d’inclusion d’un phpinfo qui traine



vendredi 13 novembre 2009                                                                93
eval

                            •   $nom=addslashes($_REQUEST['nom']);

                            •    eval('insert_action_agent("'.$LANG_AGENT
                                ['cgv_mod'].'",66,'.$param_id.',"","'.$date_du_jour.'",
                                2);');

                            •   PHP injection!




vendredi 13 novembre 2009                                                                 94
die

                            •   $result2=$_SESSION['cligraph']->request($query2)
                                or die($_SESSION['cligraph']->errormsg)

                            •   Interruption de script en cas de problème de
                                requêtes

                            •   errormsg ne contient pas de message intéressant




vendredi 13 novembre 2009                                                          95
Code OK


                            •   Opérateur @

                            •




vendredi 13 novembre 2009                          96
vendredi 13 novembre 2009   97

Más contenido relacionado

Similar a Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 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 2009Philippe Gamache
 
Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009Philippe Gamache
 
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Philippe Gamache
 
soft-shake.ch - Clojure Values
soft-shake.ch - Clojure Valuessoft-shake.ch - Clojure Values
soft-shake.ch - Clojure Valuessoft-shake.ch
 
Ciel, mes développeurs PHP parlent chinois!
Ciel, mes développeurs PHP parlent chinois!Ciel, mes développeurs PHP parlent chinois!
Ciel, mes développeurs PHP parlent chinois!Damien Seguy
 

Similar a Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009 (6)

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
Auditing and securing PHP applications - FRHACK 2009Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009
 
Veille et Web 2.0
Veille et Web 2.0Veille et Web 2.0
Veille et Web 2.0
 
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
 
soft-shake.ch - Clojure Values
soft-shake.ch - Clojure Valuessoft-shake.ch - Clojure Values
soft-shake.ch - Clojure Values
 
Ciel, mes développeurs PHP parlent chinois!
Ciel, mes développeurs PHP parlent chinois!Ciel, mes développeurs PHP parlent chinois!
Ciel, mes développeurs PHP parlent chinois!
 

Más 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
 
Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continuePhilippe 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
 
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
 

Más de Philippe Gamache (15)

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
 
Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continue
 
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
 
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
 

Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009

  • 2. Ordre du jour • Présentation de l’atelier • Audit boîte noire • Audit à code ouvert vendredi 13 novembre 2009 2
  • 3. Qui parle? • Philippe Gamache • Parler haut, interagir librement : audit de sécurité, formations • Caviste de cidres de glace • info@ph-il.ca vendredi 13 novembre 2009 3
  • 4. Qui parle? • Damien Seguy • Alter Way Consulting : services experts en logiciels libres • Editeur de calendriers • damien.seguy@alterway.fr vendredi 13 novembre 2009 4
  • 5. Livre sécurité • Nouvelle édition 2009 • Bilan complet de la sécurité : système, MySQL, PHP, etc • Edité chez Eyrolles • Dédicaces sur demande vendredi 13 novembre 2009 5
  • 6. Cligraph CRM • CRM/GRC Open Source • Version 0.991 • Activement développé • Soutenu par Cogivea http://www.cogivea.com/ • Léger, rapide et puissant • http://www.cligraphcrm.com/ vendredi 13 novembre 2009 6
  • 7. Cligraph CRM • Technologies PHP et MySQL, Javascript • Code développé depuis 5 ans • 4970 fichiers • 1200 fichiers PHP • 320 000 lignes de code vendredi 13 novembre 2009 7
  • 8. L’atelier sécurité • Réveillez-vous : vous avez du travail! • Analyse des logs et identification des problèmes • Discussion des stratégies de protection et contextes • http://192.168.3.73/ de démonstration vendredi 13 novembre 2009 8
  • 9. Tests boîte noire 9 vendredi 13 novembre 2009 9
  • 10. Tests boîte noire • Recherche d’informations • Trouver de l’information sur l’application • Que puis-je faire sur cette application? • Où sont les points d'entrée les plus populaires? 10 vendredi 13 novembre 2009 10
  • 11. Tests boîte noire • Trouver des vulnérabilités • Trouver les trous dans l’application • Scanneurs automatiques • À la main • Fuzzing • Scénarios • Comment puis-je l'utiliser à mon avantage? 11 vendredi 13 novembre 2009 11
  • 12. Tests boîte noire • Attaquer • Attaquer une vulnérabilité avec un but précis 12 vendredi 13 novembre 2009 12
  • 13. Recherche d’informations • Moteurs de recherches • Facebook, LinkedIn, Joboom, Monster • Langage de programmation • Logiciels utilisés 13 vendredi 13 novembre 2009 13
  • 14. Recherche d’informations • Moteurs de recherches (suite) • Google : phpinfo, "Zend engine”, site:nomsite.com • Divulgation de renseignements <b>Notice</b>: undefined </b> on line <b> <b>Warning</b>: </b> on line <b> 14 vendredi 13 novembre 2009 14
  • 15. Recherche d’informations • Moteurs de recherches (suite) • Krugle : echo $_GET • Bases de données de vulnérabilités • BUGTRAQ • CERT • CVE • Milw0rm 15 vendredi 13 novembre 2009 15
  • 16. Recherche d’informations • Google codesearch : • XSS lang:php (echo|print).*$_(GET|POST|COOKIE| REQUEST) • Injection SQL lang:php query(.*$_(GET|POST|COOKIE| REQUEST).*) • Injection de code lang:php (include|include_once| require| require_once).*$_(GET| POST|COOKIE|REQUEST) 16 vendredi 13 novembre 2009 16
  • 17. Recherche d’informations • Google codesearch : • Injection d'en-tête HTTP lang:php headers*(.*$_(SERVER| GET|POST| COOKIE|REQUEST).*) • Fixation de session lang:php session_start() lang:php session_regenerate_id() 17 vendredi 13 novembre 2009 17
  • 18. Recherche d’informations • Google codesearch : • Affichage arbitraire de fichiers lang:php (fopen|readfile|file_get_contents)s* (.*$(_GET|_POST|HTTP_GET_VARS| HTTP_POST_VARS).*) 18 vendredi 13 novembre 2009 18
  • 19. Recherche d’informations • Google codesearch : • Mots de passes filetype:sql INSERT intitle:"phpinfo()" +".default_password" ! +"Zend Scripting Language Engine" lang:php _connects*(.*,.*,("|').*("|').*) lang:php "VBULLETIN IS NOT FREE SOFTWARE" lang:php "XCART_SESSION_START" lang:php $passw+s*=s*('|")w+('|"); 19 vendredi 13 novembre 2009 19
  • 20. Recherche d’informations • robots.txt • Alias Apache • /icons/ • Signatures dans les en têtes • curl, wget, Firefox, Rex Swain's HTTP Viewer • .phps 20 vendredi 13 novembre 2009 20
  • 21. Recherche d’informations • https • Page 404 • Page blanche • arrêt de code sans affichage d'erreur 21 vendredi 13 novembre 2009 21
  • 22. Recherche d’informations • Répertoires courants • includes • admin • tmp • data • db • uploads 22 vendredi 13 novembre 2009 22
  • 23. Recherche d’informations • theHarvester http://www.edge-security.com/theHarvester.php • MetaGoofil http://www.edge-security.com/metagoofil.php • Nikto http://www.cirt.net/ • SEAT (Search Engine Assessment Tool) http://midnightresearch.com/projects/search- engine-assessment-tool/ 23 vendredi 13 novembre 2009 23
  • 24. Recherche d’informations • Subdomainer http://www.edge-security.com/subdomainer.php 24 vendredi 13 novembre 2009 24
  • 25. Recherche d’informations • http://www.cligraphcrm.com/ vendredi 13 novembre 2009 25
  • 26. Recherche d’informations vendredi 13 novembre 2009 26
  • 27. Recherche d’informations • Google • Google codesearch • Milm0rm vendredi 13 novembre 2009 27
  • 28. Trouver des vulnérabilités • Où trouver des vulnérabilités? • XSS • CSRF • Injections • Remplacement de fichiers • etc. 28 vendredi 13 novembre 2009 28
  • 29. Trouver des vulnérabilités • Comment exploiter cette faiblesse? • Que faire avec cette faille? 29 vendredi 13 novembre 2009 29
  • 30. Outils manuels • Firefox • Access Me • Firebug • Firecookie • FirePHP • HackBar • Header Spy • JavaScript Debugger 30 vendredi 13 novembre 2009 30
  • 31. Outils manuels • Firefox • Poster • SQL Inject Me • SQL Injection! • User Agent Switcher • Web Developer • X-Forwarded-For Spoofer • XSS Me Data 31 vendredi 13 novembre 2009 31
  • 32. Outils manuels • Rex Swain's HTTP Viewer http://www.rexswain.com/httpview.html 32 vendredi 13 novembre 2009 32
  • 33. Scanneurs automatiques • Simple à mettre en oeuvre • Permets de trouver les attaques les plus courantes • Doivent être adaptés • Mis à jour régulièrement • Personnalisables 33 vendredi 13 novembre 2009 33
  • 34. Scanneurs automatiques • Acunetix Web Vulnerability Scanner http://www.acunetix.com/vulnerability-scanner/ • BeEF http://www.bindshell.net/tools/beef/ • Burp Suite http://portswigger.net/suite/ • Metasploit http://www.metasploit.com/ 34 vendredi 13 novembre 2009 34
  • 35. Scanneurs automatiques • Nikto http://www.cirt.net/ • PBlind http://www.edge-security.com/pblind.php • Scrawlr https://download.spidynamics.com/Products/scrawlr/ • SCRT Mini MySqlat0r http://www.scrt.ch/pages_en/minimysqlator.html 35 vendredi 13 novembre 2009 35
  • 36. Scanneurs automatiques • SCRT Webshag http://www.scrt.ch/pages_en/outils.html • XSSploit http://www.scrt.ch/pages_en/xssploit.html 36 vendredi 13 novembre 2009 36
  • 37. Fuzzing • Test par valeur aléatoire • Stress des formulaires • Bases de données • Test décomplexé 37 vendredi 13 novembre 2009 37
  • 38. Fuzzing • Tous les caractères de 0 à x255 • Tous les caractères Unicode • Les nombres 1, 0, -1, 0.99, extrêmes, infinis • Chaînes • Longues • courtes 38 vendredi 13 novembre 2009 38
  • 39. Fuzzing • Dictionnaires de valeurs • de vulnérabilités • GET, POST, COOKIE • Des variables tableaux • c[]=1 39 vendredi 13 novembre 2009 39
  • 40. Fuzzing • Excédents de variables • debug=1, task=view • Manque de variables • Encodages variés • UTF-8, Latin1, HTML, hexa 40 vendredi 13 novembre 2009 40
  • 41. Fuzzing • Burp Suite http://portswigger.net/suite/ • SCRT Webshag http://www.scrt.ch/pages_en/outils.html • WebSlayer http://www.edge-security.com/webslayer.php • Wfuzz http://www.edge-security.com/wfuzz.php 41 vendredi 13 novembre 2009 41
  • 42. Scénarios • Des tests plus adaptés • fragiles • Automatiser les tests • À utiliser avec le fuzzing • À utiliser avec des serveurs mandataires 42 vendredi 13 novembre 2009 42
  • 43. Scénarios • Burp Suite http://portswigger.net/suite/ • Firefox • Selenium IDE • Funkload http://funkload.nuxeo.org/ • ProxyStrike http://www.edge-security.com/proxystrike.php 43 vendredi 13 novembre 2009 43
  • 44. Scénarios • SCRT Webshag http://www.scrt.ch/pages_en/outils.html • WebScarab http://www.owasp.org/index.php/ Category:OWASP_WebScarab_Project 44 vendredi 13 novembre 2009 44
  • 45. Facilitez votre vie • Backtrack http://www.remote-exploit.org/backtrack.html vendredi 13 novembre 2009 45
  • 46. Facilitez votre vie • Samurai Web Testing Framework http://samurai.inguardians.com/ vendredi 13 novembre 2009 46
  • 47. Sécure ? vendredi 13 novembre 2009 47
  • 48. Les prolèmes • Faux sentiment sécurité • Ne marche pas toujours vendredi 13 novembre 2009 48
  • 49. Notre cas • La sécurité par l’insécurité • La sécurité par l’instabilité vendredi 13 novembre 2009 49
  • 50. Que faire? • Tests manuels • Les sources • Installer l’application vendredi 13 novembre 2009 50
  • 51. Les fichiers total 592 drwxrwxrwx 25 user group 850 23 Feb 12:03 accueil drwxrwxrwx 67 user group 2278 23 Feb 12:03 action drwxrwxrwx 39 user group 1326 23 Feb 12:03 agent drwxrwxrwx 13 user group 442 23 Feb 12:03 biblio drwxrwxrwx 39 user group 1326 23 Feb 12:03 compte -rwxrwxrwx 1 user group 7692 11 Sep 02:44 connect.php -rwxrwxrwx 1 user group 3856 11 Sep 02:44 err_navig.php -rwxrwxrwx 1 user group 3165 11 Sep 02:44 erreur404.php drwxrwxrwx 76 user group 2584 23 Feb 12:03 etat drwxrwxrwx 171 user group 5814 23 Feb 12:03 fonctions drwxrwxrwx 8 user group 272 23 Feb 12:03 images drwxrwxrwx 13 user group 442 23 Feb 12:03 include -rwxrwxrwx 1 user group 2784 11 Sep 02:44 index.php drwxrwxrwx 27 user group 918 23 Feb 12:03 install drwxrwxrwx 80 user group 2720 23 Feb 12:03 inter_pages drwxrwxrwx 6 user group 204 23 Feb 12:03 langue … drwxrwxrwx 7 user group 238 2 Mar 18:15 log drwxrwxrwx 36 user group 1224 23 Feb 12:03 mail vendredi 13 novembre 2009 51
  • 52. Les fichiers total 592 drwxrwxrwx 25 user group 850 23 Feb 12:03 accueil drwxrwxrwx 67 user group 2278 23 Feb 12:03 action drwxrwxrwx 39 user group 1326 23 Feb 12:03 agent drwxrwxrwx 13 user group 442 23 Feb 12:03 biblio drwxrwxrwx 39 user group 1326 23 Feb 12:03 compte -rwxrwxrwx 1 user group 7692 11 Sep 02:44 connect.php -rwxrwxrwx 1 user group 3856 11 Sep 02:44 err_navig.php -rwxrwxrwx 1 user group 3165 11 Sep 02:44 erreur404.php drwxrwxrwx 76 user group 2584 23 Feb 12:03 etat drwxrwxrwx 171 user group 5814 23 Feb 12:03 fonctions drwxrwxrwx 8 user group 272 23 Feb 12:03 images drwxrwxrwx 13 user group 442 23 Feb 12:03 include -rwxrwxrwx 1 user group 2784 11 Sep 02:44 index.php drwxrwxrwx 27 user group 918 23 Feb 12:03 install drwxrwxrwx 80 user group 2720 23 Feb 12:03 inter_pages drwxrwxrwx 6 user group 204 23 Feb 12:03 langue … drwxrwxrwx 7 user group 238 2 Mar 18:15 log drwxrwxrwx 36 user group 1224 23 Feb 12:03 mail vendredi 13 novembre 2009 52
  • 53. Les fichiers total 592 drwxrwxrwx 25 user group 850 23 Feb 12:03 accueil drwxrwxrwx 67 user group 2278 23 Feb 12:03 action drwxrwxrwx 39 user group 1326 23 Feb 12:03 agent drwxrwxrwx 13 user group 442 23 Feb 12:03 biblio drwxrwxrwx 39 user group 1326 23 Feb 12:03 compte -rwxrwxrwx 1 user group 7692 11 Sep 02:44 connect.php -rwxrwxrwx 1 user group 3856 11 Sep 02:44 err_navig.php -rwxrwxrwx 1 user group 3165 11 Sep 02:44 erreur404.php drwxrwxrwx 76 user group 2584 23 Feb 12:03 etat drwxrwxrwx 171 user group 5814 23 Feb 12:03 fonctions drwxrwxrwx 8 user group 272 23 Feb 12:03 images drwxrwxrwx 13 user group 442 23 Feb 12:03 include -rwxrwxrwx 1 user group 2784 11 Sep 02:44 index.php drwxrwxrwx 27 user group 918 23 Feb 12:03 install drwxrwxrwx 80 user group 2720 23 Feb 12:03 inter_pages drwxrwxrwx 6 user group 204 23 Feb 12:03 langue … drwxrwxrwx 7 user group 238 2 Mar 18:15 log drwxrwxrwx 36 user group 1224 23 Feb 12:03 mail vendredi 13 novembre 2009 53
  • 54. Les fichiers total 592 drwxrwxrwx 25 user group 850 23 Feb 12:03 accueil drwxrwxrwx 67 user group 2278 23 Feb 12:03 action drwxrwxrwx 39 user group 1326 23 Feb 12:03 agent drwxrwxrwx 13 user group 442 23 Feb 12:03 biblio drwxrwxrwx 39 user group 1326 23 Feb 12:03 compte -rwxrwxrwx 1 user group 7692 11 Sep 02:44 connect.php -rwxrwxrwx 1 user group 3856 11 Sep 02:44 err_navig.php -rwxrwxrwx 1 user group 3165 11 Sep 02:44 erreur404.php drwxrwxrwx 76 user group 2584 23 Feb 12:03 etat drwxrwxrwx 171 user group 5814 23 Feb 12:03 fonctions drwxrwxrwx 8 user group 272 23 Feb 12:03 images drwxrwxrwx 13 user group 442 23 Feb 12:03 include -rwxrwxrwx 1 user group 2784 11 Sep 02:44 index.php drwxrwxrwx 27 user group 918 23 Feb 12:03 install drwxrwxrwx 80 user group 2720 23 Feb 12:03 inter_pages drwxrwxrwx 6 user group 204 23 Feb 12:03 langue … drwxrwxrwx 7 user group 238 2 Mar 18:15 log drwxrwxrwx 36 user group 1224 23 Feb 12:03 mail vendredi 13 novembre 2009 54
  • 55. Les fichiers total 592 drwxrwxrwx 25 user group 850 23 Feb 12:03 accueil drwxrwxrwx 67 user group 2278 23 Feb 12:03 action drwxrwxrwx 39 user group 1326 23 Feb 12:03 agent drwxrwxrwx 13 user group 442 23 Feb 12:03 biblio drwxrwxrwx 39 user group 1326 23 Feb 12:03 compte -rwxrwxrwx 1 user group 7692 11 Sep 02:44 connect.php -rwxrwxrwx 1 user group 3856 11 Sep 02:44 err_navig.php -rwxrwxrwx 1 user group 3165 11 Sep 02:44 erreur404.php drwxrwxrwx 76 user group 2584 23 Feb 12:03 etat drwxrwxrwx 171 user group 5814 23 Feb 12:03 fonctions drwxrwxrwx 8 user group 272 23 Feb 12:03 images drwxrwxrwx 13 user group 442 23 Feb 12:03 include -rwxrwxrwx 1 user group 2784 11 Sep 02:44 index.php drwxrwxrwx 27 user group 918 23 Feb 12:03 install drwxrwxrwx 80 user group 2720 23 Feb 12:03 inter_pages drwxrwxrwx 6 user group 204 23 Feb 12:03 langue … drwxrwxrwx 7 user group 238 2 Mar 18:15 log drwxrwxrwx 36 user group 1224 23 Feb 12:03 mail vendredi 13 novembre 2009 55
  • 56. Les fichiers cligraphcrm/include/fpdf: total 376 -rwxrwxrwx 1 user group 46002 26 Jan 02:41 fpdf.php -rwxrwxrwx 1 user group 705 11 Sep 02:44 fpdf_entete.php -rwxrwxrwx 1 user group 47404 26 Jan 18:07 fpdf_facture.php -rwxrwxrwx 1 user group 14922 26 Jan 14:50 fpdf_html2pdf.php -rwxrwxrwx 1 user group 5238 11 Sep 02:44 fpdf_mem_image.php -rwxrwxrwx 1 user group 7629 11 Sep 02:44 fpdf_memoire.php -rwxrwxrwx 1 user group 1243 11 Sep 02:44 fpdf_table_def.inc -rwxrwxrwx 1 user group 27075 11 Sep 02:44 fpdf_tableau.php -rwxrwxrwx 1 user group 4317 11 Sep 02:44 fpdf_texte.php -rwxrwxrwx 1 user group 12852 11 Sep 02:44 fpdf_writetag.php vendredi 13 novembre 2009 56
  • 57. Les fichiers cligraphcrm/include/fpdf: total 376 -rwxrwxrwx 1 user group 46002 26 Jan 02:41 fpdf.php -rwxrwxrwx 1 user group 705 11 Sep 02:44 fpdf_entete.php -rwxrwxrwx 1 user group 47404 26 Jan 18:07 fpdf_facture.php -rwxrwxrwx 1 user group 14922 26 Jan 14:50 fpdf_html2pdf.php -rwxrwxrwx 1 user group 5238 11 Sep 02:44 fpdf_mem_image.php -rwxrwxrwx 1 user group 7629 11 Sep 02:44 fpdf_memoire.php -rwxrwxrwx 1 user group 1243 11 Sep 02:44 fpdf_table_def.inc -rwxrwxrwx 1 user group 27075 11 Sep 02:44 fpdf_tableau.php -rwxrwxrwx 1 user group 4317 11 Sep 02:44 fpdf_texte.php -rwxrwxrwx 1 user group 12852 11 Sep 02:44 fpdf_writetag.php vendredi 13 novembre 2009 57
  • 58. Les fichiers cligraphcrm/install/sql/tables: total 928 -rwxrwxrwx 1 user group 4750 29 Jan 10:44 acces.sql -rwxrwxrwx 1 user group 4802 29 Jan 10:44 acces_type.sql -rwxrwxrwx 1 user group 190 23 Nov 20:12 admin_crm.sql -rwxrwxrwx 1 user group 1111 3 Feb 14:45 adresse.sql -rwxrwxrwx 1 user group 1637 15 Jan 11:24 affaire.sql -rwxrwxrwx 1 user group 578 17 Jan 19:27 affaire_intvt.sql -rwxrwxrwx 1 user group 1544 22 Oct 17:49 affaire_pdt.sql -rwxrwxrwx 1 user group 3231 3 Dec 19:15 agent.sql -rwxrwxrwx 1 user group 581 22 Oct 17:49 argument.sql -rwxrwxrwx 1 user group 3062 25 Jan 09:45 avoir.sql -rwxrwxrwx 1 user group 1605 21 Jan 06:30 avoir_detail.sql -rwxrwxrwx 1 user group 741 22 Oct 17:49 campagne.sql -rwxrwxrwx 1 user group 701 22 Oct 17:49 campagne_promo.sql -rwxrwxrwx 1 user group 537 22 Oct 17:49 categorie_pdt.sql -rwxrwxrwx 1 user group 527 27 Jan 11:36 cgv.sql -rwxrwxrwx 1 user group 547 11 Sep 02:44 civilite.sql -rwxrwxrwx 1 user group 4871 22 Oct 17:49 client.sql vendredi 13 novembre 2009 58
  • 67. Audit de code vendredi 13 novembre 2009 67
  • 68. Ordre du jour • Lire les logs et repérer les vulnérabilités • Caractériser et supprimer les failles • Evaluation du volume de correction vendredi 13 novembre 2009 68
  • 69. Approche • Un point d’entrée • Lecture du code • Ouverture d’esprit et découverte • Identifier la faille • Comment l’exploiter vendredi 13 novembre 2009 69
  • 70. Outils existants • Rats http://www.fortifysoftware.com/security-resources/rats.jsp • Yasca http://www.yasca.org /accueil/accueil.php:478: High: fopen /action/facture_trt.php:170: High: eval /include/pear/File_Archive/Archive/Reader/Bzip2.php:80: High: bzopen /mail/mess_suppr_trt.php:193: High: mail /include/pear/PEAR/RunTest.php:449: High: system /fonctions/gallery.func.php:95: Medium: is_dir /include/pear/PEAR/Remote.php:296: Medium: fsockopen vendredi 13 novembre 2009 70
  • 71. Trois moteurs • Grep • Les expressions rationnelles • Le tokenizer vendredi 13 novembre 2009 71
  • 72. Approches Sémantique Rapide 700 • Sémantique : proche des concepts PHP et 525 de programmation 350 • Rapide à mettre en place et exécuter 175 0 Grep Regex Tokenizer vendredi 13 novembre 2009 72
  • 73. Occurrences $_GET $_POST $_REQUEST Grep 137 604 2650 Regex 139 667 3279 Token 11 617 1518 vendredi 13 novembre 2009 73
  • 74. Choix • One-liner contre temps de développement • Précision sémantique face à recherche brute • Rejouable ou jetable vendredi 13 novembre 2009 74
  • 75. Points d’intérêt • index.php • index_bis.php • err_nav.php • out.php • erreur404.php • verif.php vendredi 13 novembre 2009 75
  • 76. Points d’intérêt Entrée Filtrage Traitement Suivi Sortie Protection vendredi 13 novembre 2009 76
  • 77. Cheminement $_GET pdo_query pdo_fetch echo vendredi 13 novembre 2009 77
  • 78. Interfaces • Navigateur • Système • URL • Processus • Cookies • PHP • JavaScript • XML • SQL • LDAP ... vendredi 13 novembre 2009 78
  • 79. Navigateur • Entrées • $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE • Sorties • echo, print, var_dump • Protections • htmlentities, htmlspecialchars, strip_tags ext/xmlwriter vendredi 13 novembre 2009 79
  • 80. URL • Entrées • parse_url, urldecode, rawurldecode • Sorties • echo, print, http_build_url, http_build_query, http_build_str • Protections • url_encode, rawurlencode vendredi 13 novembre 2009 80
  • 81. Cookies • Entrées • $_COOKIES, $HTTP_COOKIE_VARS, http_parse_cookies, session_name • Sorties • setcookies, setrawcookie, stream_context_create, httpRequest::setcookies, http_build_cookie • Protections vendredi 13 novembre 2009 81
  • 82. JavaScript • Entrées • json_decode • Sorties • json_encode, echo, print • Protections • Rien vraiment vendredi 13 novembre 2009 82
  • 83. SQL • Entrées • pdo_query, mysqli_query, query, • Sorties • *fetch*, mysqli_error • Protections • pdo_quote, mysqli_real_escape_string, etc. vendredi 13 novembre 2009 83
  • 84. Fichiers • Entrées • fopen, file_get_contents, passthru • Sorties • fwrite, fread, mkdir, • Protections • pathinfo, realpath vendredi 13 novembre 2009 84
  • 85. PHP • Entrées • eval, include, require et _once, dl, preg_replace, assert • Sorties • var_export • Protections • Aucune pour le code, fichiers pour les autres. vendredi 13 novembre 2009 85
  • 86. Système • Entrées • ini_get, set_limit, getenv, getmypid, phpversion, phpinfo, • Sorties • ini_set, setenv • Protections • Aucune prévue vendredi 13 novembre 2009 86
  • 88. Register_globals • Register globals via fct_urldecode dans fonctions/ fonctions_gen.php • Utilisation des superglobales, puis intuition sur le nom de la fonction • $GLOBALS[$k] et affectation vendredi 13 novembre 2009 88
  • 89. Injections SQL • $query="select theme_nom from theme where theme_id="".$_REQUEST['theme_id']."""; • Passer par les requêtes SQL, et chercher les variables globales • Lire le contexte et repérer les variables sans filtrage vendredi 13 novembre 2009 89
  • 90. err_nav.php XSS • init_chem_crm est injecté directement • vendredi 13 novembre 2009 90
  • 91. Téléchargements • Via les fonctions header() • Téléchargement de fichiers dans lanceur_dl.php • Pas de protection des variables, ni par session vendredi 13 novembre 2009 91
  • 92. $_REQUEST DOS • $_REQUEST est utilisé pour le logout • if(isset($_REQUEST['opt']) && $_REQUEST['opt']==1) • $_REQUEST == $_GET && $_POST && $_COOKIE • Que se passe-t-il quand on pose un cookie ‘opt’ de 1? vendredi 13 novembre 2009 92
  • 93. include • $format=$_REQUEST['exp_formdoc']; • include(fct_lien_page_custom("action/facture_". $format.".php","abs")); • Maitrise du chemin d’inclusion • $exp_formdoc = "/../action/facture_fiche"; <- auto-inclusion! • ou bien, tentative d’inclusion d’un phpinfo qui traine vendredi 13 novembre 2009 93
  • 94. eval • $nom=addslashes($_REQUEST['nom']); • eval('insert_action_agent("'.$LANG_AGENT ['cgv_mod'].'",66,'.$param_id.',"","'.$date_du_jour.'", 2);'); • PHP injection! vendredi 13 novembre 2009 94
  • 95. die • $result2=$_SESSION['cligraph']->request($query2) or die($_SESSION['cligraph']->errormsg) • Interruption de script en cas de problème de requêtes • errormsg ne contient pas de message intéressant vendredi 13 novembre 2009 95
  • 96. Code OK • Opérateur @ • vendredi 13 novembre 2009 96