This presentation is biligual (french/english).
In this laboratory, we will carry out a safety audit on the code of a web application. The technical objective is to provide a report and treat all phases of investigative work: source analysis, identifying vulnerabilities (XSS, injections, disclosure, etc.), recommendations for strengthening, and prioritization of tasks.
Une application en deux heure - PHP Québec Janvier 2009
Auditing and securing PHP applications - FRHACK 2009
1. Auditing
PHP
applications
Audit des
applications
en PHP
vendredi 13 novembre 2009 1
2. Agenda Ordre du jour
Workshop presentation Présentation de l’atelier
Black box audit Audit boîte noire
Source code audit Audit à code ouvert
vendredi 13 novembre 2009 2
3. Who speak? Qui parle?
Philippe Gamache Philippe Gamache
Parler Haut, Interagir Parler Haut, Interagir
Librement : Librement :
Web development, security Développement Web, audit
audit, training de sécurité, formations
info@ph-il.ca info@ph-il.ca
@SecureSymfony @SecureSymfony
vendredi 13 novembre 2009 3
4. Security book
Livre de sécurité
New 2009 edition
Comprehensive review of security
system for MySQL, PHP, etc.
Published in French
Planning translation
Nouvelle édition 2009
Bilan complet de la sécurité :
système, MySQL, PHP, etc.
Édité chez Eyrolles
Dédicaces sur demande
vendredi 13 novembre 2009 4
5. Yes, I take question
Je réponds aux questions
vendredi 13 novembre 2009 5
6. Why? Pourquoi?
Confidence does not La confiance n'exclut pas le
exclude control™ contrôle™
Pour valider un travail
To validate external work
externe
To validate internal work Pour valider un travail
Round-up interne
Pour faire le point
For an external
Pour avoir un regard
perspective
externe
As often as possible Aussi souvent que
possible
vendredi 13 novembre 2009 6
7. Full audit synopsis
Synopsis d’un audit
Identification of the audit Identification des objectifs
goals d'audit
Interview with the Entretien avec les équipes
development teams de développement
Black box testing Test boîte noire
Open Code audit Audit de code
Report Rapport
vendredi 13 novembre 2009 7
8. Identification of the audit goals
Identification des objectifs d’audit
Audit scope Étendue de l'audit
Security Sécurité
Performance Performance
Code quality Qualité du code
vendredi 13 novembre 2009 8
9. Interview with the development teams
Entretien avec les équipes de développement
Check if development Vérifiez si l’équipe de
teams knows what to développement sait ce qu’il
secure faut sécurisé
Have the design explained Demandez d’expliquer la
first conception
Have them explains their Demandez d’expliquer leur
approach approche
Check what they say Vérifiez ce qu'ils disent
Check what they don’t Vérifiez ce qu'ils ne
say disent pas
vendredi 13 novembre 2009 9
10. The shy version
La version timide
We know there are security Nous savons qu’il y a des
problems problèmes de sécurité :
but we have no time to mais nous n'avons pas le
secure them temps de les sécuriser
this app has been written ce logiciel a été écrit il y a
years ago quelques années
we can’t keep up with nous ne pouvons pas
the threats suivre les menaces
vendredi 13 novembre 2009 10
11. The strong version
La version forte
We have secured the Nous avons sécurisé
application l'application
Nous utilisons le
We use SSL and crypto
protocole SSL et la
All content is validated cryptographie
and filtered Tout le contenu est validé
et filtré
We don’t do any
Nous ne faisons aucune
dynamical include inclusion dynamique
Our frameworks doesn’t Nos cadres
allow this d’applications sont
sécurisées
vendredi 13 novembre 2009 11
12. Black box testing
Test boîte noire
Easy to set up Facile de mise en place
Take into account the Prendre en compte le
context of the application contexte de la demande
Often spectacular Souvent spectaculaires
Generally shallow Généralement peu
profondes
vendredi 13 novembre 2009 12
13. Black box testing
Test boîte noire
Finding informations Recherche d’informations
Look for vulnerabilities Rechercher les
vulnérabilités
Automatic scanners
Scanneurs automatiques
By hand
À la main
Fuzzing
Fuzzing
Scenarios Scénarios
Strikes Attaquer
vendredi 13 novembre 2009 13
15. Black box testing
Test boîte noire
Typical files Fichiers typiques
.phps, .inc, .class .phps, .inc, .class
xml, ini, yaml, cfg xml, ini, yaml, cfg
.tar, .gz, .zip, .rar, .bz2 .tar, .gz, .zip, .rar, .bz2
Apache Alias : /icons/ Apache Alias : /icons/
robots.txt robots.txt
vendredi 13 novembre 2009 15
16. Open Code audit
Audit de code
Look into the PHP code Rechercher dans le code
PHP
Search for hidden problems
Rechercher les problèmes
Usually less spectacular cachés
than black box Habituellement, moins
spectaculaire que les tests
Easy to loose focus
boîte noire
Tempting to audit Facile de perdre sa
everything concentration
Tentant de tout vérifier
vendredi 13 novembre 2009 16
17. Approch Approche
What to search for? Que rechercher?
Quels sont les points
What are the entry points?
d'entrée?
What are the exit points? Quels sont les points de
sortie?
Open-mindedness and
Ouverture d’esprit et
discovery
découverte
How can they be exploited Comment peuvent-ils être
exploités
Or protected ?
Ou protégés?
vendredi 13 novembre 2009 17
18. Assessing the code
Évaluer le code
One liners En une ligne
One line of code is Une ligne de code est
sufficiently to be bad suffisamment pour être
Even though mauvais
you must follow the code Malgré tous
forward (for input) vous devez suivre le code
in reverse (for output) vers l’avant (entrées)
sens inverse (sorties)
<?php
$action = $_POST['action'];
$query_string = "action=$action";
$link = "index.php?$query_string";
?>
<a href="<?php echo $link; ?>"> Click Here </a>
vendredi 13 novembre 2009 18
19. What to search for?
Que rechercher?
Injections Injections
PHP PHP
SQL SQL
HTML HTML
system système
vendredi 13 novembre 2009 19
20. Tools Outils
Your eyes Vos yeux
Text editors Éditeurs de texte
grep grep
Fast, available, Rapide, disponible,
convenient pratique
Tokenizer Tokenizer
Semantic, accurate Sémantique, précis
vendredi 13 novembre 2009 20
29. Gotchas Pièges
Trust of HTTP Headers: Confiance des en-têtes
HTTP :
Referer
Referer
Trust of $_SERVER:
Confiance de $_SERVER :
$_SERVER['PHP_SELF']
$_SERVER['PHP_SELF']
Trust of Client-Side Confiance des restrictions
Restrictions: clients:
maxlength maxlength
vendredi 13 novembre 2009 29
30. Report Rapport
Vulnerability Critical Load
register_globals High High
Injections High Medium
SQL injection Medium High
headers Low Low
vendredi 13 novembre 2009 30