Audit Sécurité 1
Ordre du jour Présentation de l atelier Audit boîte noire Audit à code ouvert 2
Qui parle? Philippe Gamache Parler haut, interagir librement : audit de sécurité, formations Caviste de cidres de glace info@ph-il.ca 3
Qui parle? Damien Seguy Alter Way Consulting : services experts en logiciels libres Editeur de calendriers damien.seguy@alterway.fr 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 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/ 6
Cligraph CRM Technologies PHP et MySQL, Javascript Code développé depuis 5 ans 4970 fichiers 1200 fichiers PHP 320 000 lignes de code 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 8
Tests boîte noire 9 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 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 11
Tests boîte noire Attaquer Attaquer une vulnérabilité avec un but précis 12 12
Recherche d informations Moteurs de recherches Facebook, LinkedIn, Joboom, Monster Langage de programmation Logiciels utilisés 13 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 14
Recherche d informations Moteurs de recherches (suite) Krugle : echo $_GET Bases de données de vulnérabilités BUGTRAQ CERT CVE Milw0rm 15 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 16
Recherche d informations Google codesearch : Injection d'en-tête HTTP lang:php header\s*\(.*\$_(server GET POST COOKIE REQUEST).*\) Fixation de session lang:php session_start\(\) lang:php session_regenerate_id\(\) 17 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 18
Recherche d informations Google codesearch : Mots de passes filetype:sql INSERT intitle:"phpinfo()" +".default_password"! +"Zend Scripting Language Engine" lang:php _connect\s*\(.*,.*,(" ').*(" ').*\) lang:php "VBULLETIN IS NOT FREE SOFTWARE" lang:php "XCART_SESSION_START" lang:php \$pass\w+\s*=\s*(' ")\w+(' "); 19 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 20
Recherche d informations https Page 404 Page blanche arrêt de code sans affichage d'erreur 21 21
Recherche d informations Répertoires courants includes admin tmp data db uploads 22 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/searchengine-assessment-tool/ 23 23
Recherche d informations Subdomainer http://www.edge-security.com/subdomainer.php 24 24
Recherche d informations http://www.cligraphcrm.com/ 25
Recherche d informations 26
Recherche d informations Google Google codesearch Milm0rm 27
Trouver des vulnérabilités Où trouver des vulnérabilités? XSS CSRF Injections Remplacement de fichiers etc. 28 28
Trouver des vulnérabilités Comment exploiter cette faiblesse? Que faire avec cette faille? 29 29
Outils manuels Firefox Access Me Firebug Firecookie FirePHP HackBar Header Spy JavaScript Debugger 30 30
Outils manuels Firefox Poster SQL Inject Me SQL Injection! User Agent Switcher Web Developer X-Forwarded-For Spoofer XSS Me Data 31 31
Outils manuels Rex Swain's HTTP Viewer http://www.rexswain.com/httpview.html 32 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 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 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 35
Scanneurs automatiques SCRT Webshag http://www.scrt.ch/pages_en/outils.html XSSploit http://www.scrt.ch/pages_en/xssploit.html 36 36
Fuzzing Test par valeur aléatoire Stress des formulaires Bases de données Test décomplexé 37 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 38
Fuzzing Dictionnaires de valeurs de vulnérabilités GET, POST, COOKIE Des variables tableaux c[]=1 39 39
Fuzzing Excédents de variables debug=1, task=view Manque de variables Encodages variés UTF-8, Latin1, HTML, hexa 40 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 41
Scénarios Des tests plus adaptés fragiles Automatiser les tests À utiliser avec le fuzzing À utiliser avec des serveurs mandataires 42 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 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 44
Facilitez votre vie Backtrack http://www.remote-exploit.org/backtrack.html 45
Facilitez votre vie Samurai Web Testing Framework http://samurai.inguardians.com/ 46
Sécure? 47
Les prolèmes Faux sentiment sécurité Ne marche pas toujours 48
Notre cas La sécurité par l insécurité La sécurité par l instabilité 49
Que faire? Tests manuels Les sources Installer l application 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 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 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 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 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 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 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 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 58
Installation 59
Installation 60
Installation 61
Installation 62
Installation 63
Installation 64
Installation 65
Installation 66
Audit de code 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 68
Approche Un point d entrée Lecture du code Ouverture d esprit et découverte Identifier la faille Comment l exploiter 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 70
Trois moteurs Grep Les expressions rationnelles Le tokenizer 71
Approches Sémantique Rapide Sémantique : proche des concepts PHP et de programmation Rapide à mettre en place et exécuter 700 525 350 175 0 Grep Regex Tokenizer 72
Occurrences $_GET $_POST $_REQUEST Grep 137 604 2650 Regex 139 667 3279 Token 11 617 1518 73
Choix One-liner contre temps de développement Précision sémantique face à recherche brute Rejouable ou jetable 74
Points d intérêt index.php index_bis.php err_nav.php out.php erreur404.php verif.php 75
Points d intérêt Entrée Filtrage Traitement Suivi Sortie Protection 76
Cheminement $_GET pdo_query pdo_fetch echo 77
Interfaces Navigateur URL Cookies JavaScript SQL Système Processus PHP XML LDAP... 78
Navigateur Entrées $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE Sorties echo, print, var_dump Protections htmlentities, htmlspecialchars, strip_tags ext/xmlwriter 79
URL Entrées parse_url, urldecode, rawurldecode Sorties echo, print, http_build_url, http_build_query, http_build_str Protections url_encode, rawurlencode 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 81
JavaScript Entrées json_decode Sorties json_encode, echo, print Protections Rien vraiment 82
SQL Entrées pdo_query, mysqli_query, query, Sorties *fetch*, mysqli_error Protections pdo_quote, mysqli_real_escape_string, etc. 83
Fichiers Entrées fopen, file_get_contents, passthru Sorties fwrite, fread, mkdir, Protections pathinfo, realpath 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. 85
Système Entrées ini_get, set_limit, getenv, getmypid, phpversion, phpinfo, Sorties ini_set, setenv Protections Aucune prévue 86
Trouvailles 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 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 89
err_nav.php XSS init_chem_crm est injecté directement 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 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? 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 93
eval $nom=addslashes($_request['nom']); eval('insert_action_agent("'.$lang_agent ['cgv_mod'].'",66,'.$param_id.',"","'.$date_du_jour.'", 2);'); PHP injection! 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 95
Code OK Opérateur @ 96
97