auditing php applications

31
Auditing P HP applica tions Auditer les applicatio ns en PHP

Upload: ayanna

Post on 14-Jan-2016

64 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 2: Auditing PHP applications

Agenda Ordre du jour

Workshop presentation

Black box audit

Source code audit

Présentation de l’atelier

Audit boîte noire

Audit à code ouvert

Page 3: Auditing PHP applications

Who speak? Qui parle?

Philippe Gamache

Parler Haut, Interagir Librement : Web development, security audit, training

[email protected]

@SecureSymfony

Philippe Gamache

Parler haut, interagir librement : Développement Web, audit de sécurité, formations

Caviste de cidres de glace

[email protected]

@SecureSymfony

Page 4: Auditing PHP applications

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

Page 5: Auditing PHP applications

Yes, I take questionJe répond aux

questions

Page 6: Auditing PHP applications

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

Page 7: Auditing PHP applications

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

Page 8: Auditing PHP applications

Identification of the audit goals Identification des objectifs d’audit

Audit scope

Security

Performance

Étendue de l'audit

Sécurité

Performance

Page 9: Auditing PHP applications

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

Page 10: Auditing PHP applications

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

Page 11: Auditing PHP applications

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

Page 12: Auditing PHP applications

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

Page 13: Auditing PHP applications

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

Page 14: Auditing PHP applications

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

Page 15: Auditing PHP applications

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

Page 16: Auditing PHP applications

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

Page 17: Auditing PHP applications

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?

Page 18: Auditing PHP applications

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>

Page 19: Auditing PHP applications

What to search for?Que rechercher?

Injections

PHP

SQL

HTML

system

Injections

PHP

SQL

HTML

système

Page 20: Auditing PHP applications

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

Page 21: Auditing PHP applications

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!"); ?>

Page 22: Auditing PHP applications

PHP injectionsInjections PHP

dynamical inclusion

include, require and *_once

back ticks (`)

eval

Inclusions dynamiques d'inclusion

include, require and *_once

`

eval

Page 23: Auditing PHP applications

Input Entrées

HTML Forms:

form

input

$_GET

$_POST

$_REQUEST

Formulaire HTML:

form

input

$_GET

$_POST

$_REQUEST

Page 24: Auditing PHP applications

Input Entrées

Databases:

mysql_query()

SELECT

HTTP Headers:

$_COOKIE

$_SERVER

Bases de données:

mysql_query()

SELECT

Entête HTTP:

$_COOKIE

$_SERVER

Page 25: Auditing PHP applications

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’))

Page 26: Auditing PHP applications

Output Sorties

Client:

echo

print

<?=

die

print_r

var_dump

Client:

echo

print

<?=

die

print_r

var_dump

Page 27: Auditing PHP applications

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()

Page 28: Auditing PHP applications

Output Sorties

System:

exec()

passthru()

system()

Système:

exec()

passthru()

system()

Page 29: Auditing PHP applications

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

Page 30: Auditing PHP applications

Report Rapport

VulnerabilityVulnerability CriticalCritical LoadLoad

register_globalsregister_globals HighHigh HighHigh

InjectionsInjections HighHigh MediumMedium

SQL injectionSQL injection MediumMedium HighHigh

headersheaders LowLow LowLow

Page 31: Auditing PHP applications

Questions?

[email protected]

http://www.ph-il.ca

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

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