SlideShare a Scribd company logo
Dip Your Toes
in the Sea of Security
James Titcumb
PHP Cambridge
28th January 2015
James Titcumb
www.jamestitcumb.com
www.protected.co.uk
www.phphants.co.uk
www.phpsouthcoast.co.uk
@asgrim
Who is this guy?
Some simple code...
<?php
$a = (int)$_GET['a'];
$b = (int)$_GET['b'];
$result = $a + $b;
printf('The answer is %d', $result);
The Golden Rules
The Golden Rules
(my made up golden rules)
1. Keep it simple
2. Know the risks
3. Fail securely
4. Don’t reinvent the wheel
5. Never trust anything
OWASP
& the OWASP Top 10
https://www.owasp.org/
Application Security
(mainly PHP applications)
Always remember…
Filter Input
Escape Output
SQL Injection (#1)
http://xkcd.com/327/
SQL Injection (#1)
1. Use PDO / mysqli
2. Use prepared / parameterized statements
SQL Injection (#1)
<?php
// user_id=1; DROP TABLE users; --
$user_id = $_GET['user_id'];
$sql = "
SELECT * FROM users
WHERE user_id = {$user_id}";
$db->execute($sql);
✘
SQL Injection (#1)
<?php
$user_id = $_GET['user_id'];
$sql = "
SELECT * FROM users
WHERE user_id = :userid";
$stmt = $db->prepare($sql);
$stmt->bind('userid', $user_id);
$stmt->execute();
✓
exec($_GET)
https://github.com/search?q=exec%28%24_GET&ref=cmdform&type=Code
eval()
https://github.com/search?q=eval%28%24_GET&type=Code&ref=searchresults
Cross-Site Scripting / XSS
(#3)
Cross-Site Scripting / XSS (#3)
● Escape output
<?php
$unfilteredInput = '<script type="text/javascript">...</script>';
// Unescaped - JS will run :'(
echo $unfilteredInput;
// Escaped - JS will not run :)
echo htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
Cross-Site Request
Forgery / CSRF (#8)
<?php
if (!$isPost) {
$csrfToken = hash("sha512",mt_rand(0,mt_getrandmax()));
$_SESSION['csrf_token'] = $csrfToken;
// ... output the form ...
echo '<input type="hidden" name="csrf_token" value="'.$csrfToken.'"
/>';
} else if ($isPost) {
if ($_SESSION['csrf_token'] != $_POST['csrf_token']) {
die("Token invalid...");
}
// ... handle the form ...
}
Cross-Site Request Forgery / CSRF (#8)
Errors, Exceptions &
Logging (#6)
curl + https
<?php
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
✘
curl + https
<?php
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/certificate");
✓
WordPress
WordPress
Urgh.
We are not security
experts!
We are not security
experts!
… but we CAN write secure code
Be the threat
Think Differently
What do you want?
Think Differently
How do you get it?
Think Differently
Threat Modelling
D.R.E.A.D.
Authentication
& Authorization
Authentication
Verifying Identity
CRYPTOGRAPHY
IS
HARD
CRYPTOGRAPHY
IS
HARD
NEVER EVER “ROLL YOUR OWN”
CRYPTOGRAPHY
IS
HARD
NEVER EVER “ROLL YOUR OWN”
EVER!!!
Case Study: Custom Authentication
We thought about doing this…
Case Study: Custom Authentication
We thought about doing this…
Case Study: Custom Authentication
We thought about doing this…
✘
Password Hashing
password_hash()
Authorization
Verifying Access
Linux Server Security
Create an SSH Fortress
Firewalls
IPTABLES
#!/bin/bash
IPT="/sbin/iptables"
$IPT --flush
$IPT --delete-chain
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT DROP
# Loopback
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT
# Inbound traffic
$IPT -A INPUT -p tcp --dport ssh -j
ACCEPT
$IPT -A INPUT -p tcp --dport 80 -j ACCEPT
# Outbound traffic
$IPT -A OUTPUT -p tcp --dport 80 -j
ACCEPT
$IPT -A OUTPUT -p udp --dport 53 -m state
Mitigate Brute Force
Attacks
Install Only
What You Need
Case Study: Be Minimal
Internets
Postfix
Squid Proxy
(badly configured)
hacker
spam
Resources
● http://securingphp.com/
● https://www.owasp.org/
● http://blog.ircmaxell.com/
The Golden Rules
1. Keep it simple
2. Know the risks
3. Fail securely
4. Don’t reinvent the wheel
5. Never trust anything / anyone
If you follow all this, you get...
If you follow all this, you get...
Questions?
James Titcumb
@asgrim
Thanks for watching!

More Related Content

PDF
Dip Your Toes in the Sea of Security (DPC 2015)
PDF
Dip Your Toes in the Sea of Security (PHP UK 2016)
PDF
Dip Your Toes in the Sea of Security (PHP Dorset, 2nd June 2014)
PDF
OWASP PHPIDS talk slides
PDF
PHP Secure Programming
PDF
Open source e cloud per il non profit - settembre 2016 -
PPT
UPFRONT TRANSPLANT IN ALL-HL
DOC
Trabalhoredes
Dip Your Toes in the Sea of Security (DPC 2015)
Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP Dorset, 2nd June 2014)
OWASP PHPIDS talk slides
PHP Secure Programming
Open source e cloud per il non profit - settembre 2016 -
UPFRONT TRANSPLANT IN ALL-HL
Trabalhoredes

Viewers also liked (19)

PDF
Michael Durante Western Reserve Blackwall Partners 1Q12
PDF
Reputation Advocate - The Value of Reviews
PDF
Инструкция по настройке сервиса Daas на базе мини пк
PDF
Composer Tutorial (PHP Hampshire Sept 2013)
PPTX
программа «пять ролей менеджера компании франчайзора
PDF
Инструкция по настройке сервиса Daas для Windows
PPTX
krishna
PPT
Aula nefropatias agudas e cronicas 2
PPTX
Thalassemia and Stem cell transplant
PDF
Rockin Online Course for All Learners
DOCX
Floating Point Unit (FPU)
PPTX
스펙 없이 대기업 들어가기
PPTX
unity in diversity
DOCX
DOCX
Trabajo de carlos salazar
PDF
Sickle cell disease” (SCD): a project of curative treatment and informatics...
PDF
DOCX
คำราชาศัพท์
Michael Durante Western Reserve Blackwall Partners 1Q12
Reputation Advocate - The Value of Reviews
Инструкция по настройке сервиса Daas на базе мини пк
Composer Tutorial (PHP Hampshire Sept 2013)
программа «пять ролей менеджера компании франчайзора
Инструкция по настройке сервиса Daas для Windows
krishna
Aula nefropatias agudas e cronicas 2
Thalassemia and Stem cell transplant
Rockin Online Course for All Learners
Floating Point Unit (FPU)
스펙 없이 대기업 들어가기
unity in diversity
Trabajo de carlos salazar
Sickle cell disease” (SCD): a project of curative treatment and informatics...
คำราชาศัพท์
Ad

Similar to Dip Your Toes in the Sea of Security (PHP Cambridge) (20)

PDF
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
PDF
Dip Your Toes in the Sea of Security
PDF
Dip Your Toes in the Sea of Security (PHP Berkshire Nov 2015)
PDF
Dip Your Toes In The Sea Of Security (PHPNW16)
PDF
Dip Your Toes in the Sea of Security (phpDay 2016)
PDF
Dip Your Toes in the Sea of Security (CoderCruise 2017)
PDF
Proposed PHP function: is_literal()
PDF
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
PDF
Dip Your Toes in the Sea of Security (IPC Fall 2017)
PDF
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
PPT
PHPUG Presentation
PDF
Slides
 
PDF
Ajax Security
PPT
Eight simple rules to writing secure PHP programs
PDF
My app is secure... I think
PDF
Security 202 - Are you sure your site is secure?
PDF
Application Security around OWASP Top 10
PDF
Php Security
PDF
Questioning the status quo
KEY
Php Code Audits (PHP UK 2010)
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of Security (PHP Berkshire Nov 2015)
Dip Your Toes In The Sea Of Security (PHPNW16)
Dip Your Toes in the Sea of Security (phpDay 2016)
Dip Your Toes in the Sea of Security (CoderCruise 2017)
Proposed PHP function: is_literal()
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (IPC Fall 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
PHPUG Presentation
Slides
 
Ajax Security
Eight simple rules to writing secure PHP programs
My app is secure... I think
Security 202 - Are you sure your site is secure?
Application Security around OWASP Top 10
Php Security
Questioning the status quo
Php Code Audits (PHP UK 2010)
Ad

More from James Titcumb (20)

PDF
Living the Best Life on a Legacy Project (phpday 2022).pdf
PDF
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
PDF
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
PDF
Best practices for crafting high quality PHP apps (Bulgaria 2019)
PDF
Climbing the Abstract Syntax Tree (php[world] 2019)
PDF
Best practices for crafting high quality PHP apps (php[world] 2019)
PDF
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
PDF
Climbing the Abstract Syntax Tree (PHP Russia 2019)
PDF
Best practices for crafting high quality PHP apps - PHP UK 2019
PDF
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
PDF
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
PDF
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
PDF
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
PDF
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
PDF
Crafting Quality PHP Applications (PHPkonf 2018)
PDF
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
PDF
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
PDF
Climbing the Abstract Syntax Tree (PHP UK 2018)
Living the Best Life on a Legacy Project (phpday 2022).pdf
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Best practices for crafting high quality PHP apps - PHP UK 2019
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Crafting Quality PHP Applications (PHPkonf 2018)
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
A Presentation on Artificial Intelligence
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
20250228 LYD VKU AI Blended-Learning.pptx
A Presentation on Artificial Intelligence
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Chapter 3 Spatial Domain Image Processing.pdf
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...

Dip Your Toes in the Sea of Security (PHP Cambridge)