SlideShare a Scribd company logo
AVOIDING THE OWASP
Top 10 security exploits

Saturday, 5 October, 13
ME

Illustrator turned developer
PHP developer for 8 years
Architect/Developer at FreshBooks
Lead developer of CakePHP

Saturday, 5 October, 13
SECURITY

Saturday, 5 October, 13
SECURITY CONTINUUM

(

unusable

Saturday, 5 October, 13

)

unrestricted
OWASP
Open Web Application Security Project

Saturday, 5 October, 13
OWASP TOP 10

Saturday, 5 October, 13
1

INJECTION

Saturday, 5 October, 13

‘ OR 1=1 ‘--
RISKS

Command - Permits arbitrary shell commands.
SQL - Permits query manipulation, and arbitrary SQL.
Bad guys can run arbitrary code/queries.

Saturday, 5 October, 13
SQL INJECTION EXAMPLE
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$query = “SELECT * FROM user
WHERE username = ‘$username’
AND password = ‘$password’”;
$user = $db->query($query);
Saturday, 5 October, 13
USER INPUT
$username = “root”;
$password = “‘ OR 1 = 1 --”;

Saturday, 5 October, 13
FINAL QUERY

$query = “SELECT * FROM user
WHERE username = ‘root’
AND password = ‘‘ OR 1 = 1 --”;

Saturday, 5 October, 13
FINAL QUERY

$query = “SELECT * FROM user
WHERE username = ‘root’
AND password = ‘‘ OR 1 = 1 --”;

Saturday, 5 October, 13
PREVENTION
Use an ORM or Database abstraction layer that
provides escaping. Doctrine, ZendTable, and
CakePHP all do this.
Use PDO and prepared statements.
Never interpolate user data into a query.
Never use regular expressions, magic quotes, or
addslashes()

Saturday, 5 October, 13
EXAMPLE (PDO)
$query = “SELECT * FROM user
WHERE username = ?
AND password = ?”;
$stmt = $db->prepare($query);
$stmt->bindValue($username);
$stmt->bindValue($password);
$result = $db->execute();
Saturday, 5 October, 13
COMMAND INJECTION

$file = $_POST[‘file’];
$res = file_get_contents($file);
echo $res;

Saturday, 5 October, 13
USER INPUT
$f = “../../../../../../etc/passwd”;

Saturday, 5 October, 13
PREVENTION

Escape and validate input.
Check for ..
Check for ;
Ensure the realpath resolves to a file that is allowed.

Saturday, 5 October, 13
2

BROKEN AUTHENTICATION
& SESSION MANAGEMENT
/index.php?PHPSESSID=pwned

Saturday, 5 October, 13
RISKS

Identity theft.
Firesheep was an excellent example.

Saturday, 5 October, 13
SESSION FIXATION EXAMPLE
<?php
session_start();
if (isset($_GET[‘sessionid’]) {
session_id($_GET[‘sessionid’]);
}

Saturday, 5 October, 13
SESSION FIXATION EXAMPLE
<?php
session_start();
if (isset($_GET[‘sessionid’]) {
session_id($_GET[‘sessionid’]);
}

Saturday, 5 October, 13
PREVENTION

Rotate session identifiers upon login/logout
Set the HttpOnly flag on session cookies.
Use well tested / mature libraries for authentication.
SSL is always a good idea.

Saturday, 5 October, 13
3

XSS

<script>alert(‘cross site scripting’);</script>

Saturday, 5 October, 13
RISKS

Allows bad guys to do things as the person viewing a
page.
Steal identities, passwords, credit cards, hijack pages
and more.

Saturday, 5 October, 13
XSS EXAMPLE

<p>
<?php echo $user[‘bio’]; ?>
</p>

Saturday, 5 October, 13
XSS EXAMPLE

<p>
<?php echo $user[‘bio’]; ?>
</p>

Saturday, 5 October, 13
I know, I can use regular expressions!

Saturday, 5 October, 13
NO
Saturday, 5 October, 13
PREVENTION

Regular expressions and strip_tags leave you
vulnerable.
The only robust solution is output encoding.

Saturday, 5 October, 13
EXAMPLE
<p>
<?php echo htmlentities(
$user[‘bio’],
ENT_QUOTES,
‘UTF-8’
); ?>
</p>

Saturday, 5 October, 13
DANGERS

Manually encoding is error prone, and you will make
a mistake.
Using a template library like Twig that provides autoescaping reduces the chances of screwing up.
Encoding is dependent on context.

Saturday, 5 October, 13
4

INSECURE DIRECT OBJECT
REFERENCE

Saturday, 5 October, 13
RISKS

Bad guys can access information they shouldn’t
Bad guys can modify data they shouldn’t.

Saturday, 5 October, 13
BROKEN PASSWORD UPDATE
<form action=”/user/update” method=”post”>
<input type=”hidden” name=”userid” value=”4654” />
<input type=”text” name=”new_password” />
<button type=”submit”>Save</button>
</form>

Saturday, 5 October, 13
PREVENTION
Remember hidden inputs are not really hidden, and
can be changed by users.
Validate access to all things, don’t depend on things
being hidden/invisible.
If you need to refer to the current user, use session
data not form inputs.
Whitelist properties any form can update.

Saturday, 5 October, 13
5

SECURITY
MISCONFIGURATION

Saturday, 5 October, 13
RISKS

Default settings can be insecure, and intended for
development not production.
Attackers can use misconfigured software to gain
knowledge and access.

Saturday, 5 October, 13
PREVENTION

Know the tools you use, and configure them
correctly.
Keep up to date on vulnerabilities in the tools you
use.
Remove/disable any services/features you aren’t using.

Saturday, 5 October, 13
6

SENSITIVE DATA EXPOSURE
4012 8888 8888 1881

Saturday, 5 October, 13
RISKS

Bad guys get credit cards, personal identification,
passwords or health records.
Your company could be fined or worse.

Saturday, 5 October, 13
ASSESSING RISK
Do you have sensitive data?
Is it in plaintext?
Any old/bad crypto in use?
Missing SSL?
Who can access sensitive data?

Saturday, 5 October, 13
7

MISSING FUNCTION LEVEL
ACCESS CONTROL

Saturday, 5 October, 13
RISKS

Anyone on the internet can request things.
Missing access control could mean bad guys can do
things they shouldn’t be able to.

Saturday, 5 October, 13
PREVENTION

No simple solutions sadly.
Good automated tests help.

Saturday, 5 October, 13
8

CROSS SITE REQUEST
FORGERY

Saturday, 5 October, 13

(CSRF)
RISKS

Evil websites can perform actions for users logged
into your site.
Side effects on GET can be performed via images or
CSS files.
Remember the Gmail contact hack.

Saturday, 5 October, 13
CSRF EXAMPLE

Your app
Evil site

Saturday, 5 October, 13
CSRF EXAMPLE

Your app
Evil site

Login

Saturday, 5 October, 13
CSRF EXAMPLE

Your app
Evil site

Login
Accidentally visit
Saturday, 5 October, 13
CSRF EXAMPLE

Your app

Submit form for evil
Evil site

Login
Accidentally visit
Saturday, 5 October, 13
PREVENTION

Add opaque expiring tokens to all forms.
Requests missing tokens or containing invalid tokens
should be rejected.

Saturday, 5 October, 13
SAMPLE CSRF VALIDATION
<?php
if (!$this->validCsrfToken($data, ‘csrf’)) {
throw new ForbiddenException();
}

Saturday, 5 October, 13
9

USING COMPONENTS WITH
KNOWN VULNERABILITIES

Saturday, 5 October, 13

CVE bingo
RISK

Using old busted software can expose you to
documented issues.
CVE databases are filled with version numbers and
matching exploits.

Saturday, 5 October, 13
PREVENTION

Do routine upgrades. Keep up to date with all your
software.
Read mailing lists and keep an eye out for security
releases.

Saturday, 5 October, 13
PREVENTION

Several vulnerability databases around.
https://cve.mitre.org/cve/

Saturday, 5 October, 13
10

UNVALIDATED REDIRECTS &
FORWARDS

Saturday, 5 October, 13
RISKS

Trusting user input for redirects opens phishing
attacks.
Breach of trust with your users.

Saturday, 5 October, 13
PREVENTION

Don’t trust user data when handling redirects.

Saturday, 5 October, 13
THANK YOU

Saturday, 5 October, 13

More Related Content

PDF
OWASP Top 10 2013
PPT
Joomladay Switzerland - security
ODP
Joomladay Netherlands - Security
PPTX
Security Day - Chesf
PDF
2013 - Matías Paterlini: Escalando PHP con sharding y Amazon Web Services
PDF
2013 - Andrei Zmievski: Clínica Regex
PDF
2013 - Janis Janovskis: Liderando equipos de desarrollo Open Source
PDF
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
OWASP Top 10 2013
Joomladay Switzerland - security
Joomladay Netherlands - Security
Security Day - Chesf
2013 - Matías Paterlini: Escalando PHP con sharding y Amazon Web Services
2013 - Andrei Zmievski: Clínica Regex
2013 - Janis Janovskis: Liderando equipos de desarrollo Open Source
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...

Similar to 2013 - Mark story - Avoiding the Owasp (20)

PDF
Armorizing applications
PDF
Owasp top 10
PDF
Repsheet: A Behavior Based Approach to Web Application Security
PDF
Advanced App Building - Tips, Tricks & Lessons Learned
PDF
Storyplayer
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PDF
Passing a Front end Developer interview
PDF
Unmasking or De-Anonymizing You
PPT
Xss is more than a simple threat
PPT
Xss is more than a simple threat
PPTX
Bünyamin Demir - 10 Adımda Yazılım Güvenliği
PDF
Simplified security code review - BSidesQuebec2013
PDF
OWASP, PHP, life and universe
PDF
2014 06-05-mozilla-afup
ODP
2009 Barcamp Nashville Web Security 101
PDF
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
PDF
Engineering culture
PDF
OWASP, the life and the universe
PPT
OWASP Top10 2010
Armorizing applications
Owasp top 10
Repsheet: A Behavior Based Approach to Web Application Security
Advanced App Building - Tips, Tricks & Lessons Learned
Storyplayer
Keeping it small - Getting to know the Slim PHP micro framework
Passing a Front end Developer interview
Unmasking or De-Anonymizing You
Xss is more than a simple threat
Xss is more than a simple threat
Bünyamin Demir - 10 Adımda Yazılım Güvenliği
Simplified security code review - BSidesQuebec2013
OWASP, PHP, life and universe
2014 06-05-mozilla-afup
2009 Barcamp Nashville Web Security 101
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
Engineering culture
OWASP, the life and the universe
OWASP Top10 2010
Ad

More from PHP Conference Argentina (6)

PDF
2013 - Brian Stanley - Memcached, Cached all the things
PDF
2013 - Benjamin Eberlei - Doctrine 2
PDF
2013 - Nate Abele Wield AngularJS like a Pro
PDF
2013 - Dustin whittle - Escalando PHP en la vida real
PDF
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PDF
2013 - Andrei Zmievski: Machine learning para datos
2013 - Brian Stanley - Memcached, Cached all the things
2013 - Benjamin Eberlei - Doctrine 2
2013 - Nate Abele Wield AngularJS like a Pro
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Andrei Zmievski: Machine learning para datos
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
STKI Israel Market Study 2025 version august
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
1. Introduction to Computer Programming.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
August Patch Tuesday
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
NewMind AI Weekly Chronicles - August'25-Week II
STKI Israel Market Study 2025 version august
Module 1.ppt Iot fundamentals and Architecture
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Tartificialntelligence_presentation.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
cloud_computing_Infrastucture_as_cloud_p
observCloud-Native Containerability and monitoring.pptx
Enhancing emotion recognition model for a student engagement use case through...
1. Introduction to Computer Programming.pptx
Zenith AI: Advanced Artificial Intelligence
NewMind AI Weekly Chronicles – August ’25 Week III
August Patch Tuesday
Group 1 Presentation -Planning and Decision Making .pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Getting Started with Data Integration: FME Form 101
O2C Customer Invoices to Receipt V15A.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx

2013 - Mark story - Avoiding the Owasp