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