SlideShare a Scribd company logo
CNIT 129S: Securing
Web Applications
Ch 12: Attacking Users:
Cross-Site Scripting (XSS)
Part 2
Finding and Exploiting XSS
Vunerabilities
Basic Approach
• Inject this string into every parameter on every
page of the application
• If the attack string appears unmodified in the
response, that indicates an XSS vulnerability
• This is the fastest way to find an XSS, but it
won't find them all
When the Simple Attack
Fails
• Applications with rudimentary blacklist-based
filters
• Remove <script>, or < > " /
• Crafted attacks may still work
Response Different from
Input
• XSS attacks that don't simply return the attack
string
• Sometimes input string is sanitized, decoded,
or otherwise modified
• In DOM-based XSS, the input string isn't
necessarily returned in the browser's
immediate response, but is retained in the
DOM and accessed via client-side JavaScript
Finding and Exploiting
Reflected XSS Vulnerabilities
Identifying Reflections of
User Input
• Choose a unique string that doesn't appear
anyhere in the application and includes only
alphabetical characters that won't be filtered,
like "myxsstestdmqlwp"
• Submit it as every parameter, one at a time,
including GET, POST, query string, and headers
such as User-Agent
• Monitor responses for any appearance of the
string
Testing Reflections to
Introduce Script
• Manually test each instance of reflected input to
see if it's exploitable
• You'll have to customize the attack for each
situation
1. A Tag Attribute Value
• Here are two ways to exploit it
Demos (Use Firefox)
2. A JavaScript String
• This attack works
3. An Attribute Containing a URL
• Use the javascript: handler to make your script
into a URL
• Or use the onclick event handler
Probing Defensive Filters
• Three common types
Beating Signature-Based
Filters
• You may see an error message like this
Remove Parts of the String
• Until the error goes away
• Find the substring that triggered the error,
usually something like <script>
• Test bypass methods
Ways to Introduce Script
Code
Script Tags
• If <script> is blocked, try these
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
Event Handlers
• All these run without user interaction
Event Handlers in HTML 5
• Autofocus
• In closing tags
• New tags
Script Pseudo-Protocols
• Used where a URL is expected
• IE allows the vbs: protocol
• HTML 5 provides these new ways:
Dynamically Evaluated
Styles
• IE 7 and earlier allowed this:
• Later IE versions allow this:
Bypassing Filters: HTML
• Ways to obfuscate this attack
Inserted NULL Butes
• Causes C code to terminate the string
• Will bypass many filters
• IE allows NULL bytes anywhere
• Web App Firewalls (WAFs) are typically coded in
C for performance and this trick fools them
Invalid Tags
• Browser will let it run
• Filter may not see it due to invalid tag "x"
Base Tag Hijacking
• Set <base> and later relative-path URLs will be
resolved relative to it
Space Following the Tag Name
• Replace the space with other characters
• Add extra characters when there's no space
NULL Byte in Attribute
Name
• Attribute delimiters
• Backtick works in IE
Attribute Delimiters
• If filter is unaware that backticks work as attribute
delimiters, it treats this as a single attribute
• Attack with no spaces
Attribute Values
• Insert NULL, or HTML-encode characters
HTML Encoding
• Can use decimal and hexadecimal format, add
leading zeroes, omit trailing semicolon
• Some browsers will accept these
Tag Brackets
• Some applications perform URL decoding twice,
so this input
• becomes this, which has no < or >
• and it's then decoded to this
• Some app frameworks translate unusual
Unicode characters into their nearest ASCII
equivalents, so double-angle quotation marks
%u00AB and %u00BB work:
Tag Brackets
• Browsers tolerate extra brackets
• This strange format is accepted by Firefox,
despite not having a valid <script> tag
Tag Brackets
Web Developer Add-on
• View Generated Source shows HTML after
Firefox has tried to "fix" the code
Character Sets
Telling Browser the
Character Set
• Set it in the HTTP Content-Type header
• Or an HTTP META tag
• Or a CHARSET parameter, if one is used
Shift-JIS
• Suppose two pieces of input are used in the
app's response
• input1 blocks quotes, input2 blocks < and >
• This attack works, because %f0 starts a two-byte
character, breaking the quotation mark
Bypassing Filters: Script
Code
JavaScript Escaping
• Unicode
• Eval
• Superfluous escape characters
Dynamically Constructing
Strings
• Third example works in Firefox
• And in other browsers too, according to link Ch
12f
Alternatives
• Alternatives to eval
• Alternatives to dots
Combining Multiple
Techniques
• The "e" in "alert" uses Unicode escaping:
u0065
• The backslash is URL-encoded: &#x5c;
• With more HTML-encoding
VBScript
• Skip this section
• Microsoft abandoned VBScript with Edge
• Link Ch 12g
Beating Sanitization
• Encoding certain characters
• < becomes &lt;
• > becomes &gt;
• Test to see what characters are sanitized
• Try to make an attack string without those
characters
Examples
• Your injection may already be in a script, so you
don't need <script> tag
• Sneak in <script> using layers of encoding, null
bytes, nonstandard syntax, or obfuscates scrip
code
Mistakes in Sanitizing Code
• Not removing all instances
• Not acting recursively
Stages of Encoding
• Filter first strips <script> recursively
• Then strips <object> recursively
• This attack succeeds
Injecting into an Event
Handler
• You control foo
• This attack string
• Turns into this, and executes in some browsers
Beating Length Limits
1. Short Attacks
• This sends cookies to server with hostname a
• This tag executes a script from the server with
hostname a
JavaScript Packer
• Link Ch 12h
• Use multiple injection points
• Inject part of the code in each point
• Consider this URL
Beating Length Limits
2. Span Multiple Locations
• It returns three hidden fields
• Inject this way
Beating Length Limits
2. Span Multiple Locations
• Result
Beating Length Limits
2. Span Multiple Locations
• Inject this JavaScript, which evaluates the
fragment string from the URL
• The part after #
Beating Length Limits
3. Convert Reflected XSS to DOM
• First attack works in a straightforward manner
• Second one works because http: is interpreted
as a code label, // as a comment, and %0A
terminates the comment
Beating Length Limits
3. Convert Reflected XSS to DOM

More Related Content

PDF
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
PDF
CNIT 129S: 10: Attacking Back-End Components
PDF
Ch 12 Attacking Users - XSS
PPTX
Command injection
PDF
HTTP Security Headers
PPT
Shared preferences
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 10: Attacking Back-End Components
Ch 12 Attacking Users - XSS
Command injection
HTTP Security Headers
Shared preferences

What's hot (20)

PDF
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
PPTX
PDF
CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)
PDF
Lecture 12: React-Native Firebase Authentication
PDF
CNIT 129S: Ch 3: Web Application Technologies
PPTX
SQLite database in android
PPTX
How to Test for The OWASP Top Ten
ODP
OWASP Secure Coding
PPTX
Attacking thru HTTP Host header
PPT
Security Vulnerabilities
PPT
PPTX
Cross Site Scripting ( XSS)
PDF
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PDF
HTTP Request Smuggling via higher HTTP versions
PDF
CNIT 126 9: OllyDbg
PPTX
Secure coding practices
PDF
Hunting for security bugs in AEM webapps
PPTX
Sql injection
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 1 of 2)
Lecture 12: React-Native Firebase Authentication
CNIT 129S: Ch 3: Web Application Technologies
SQLite database in android
How to Test for The OWASP Top Ten
OWASP Secure Coding
Attacking thru HTTP Host header
Security Vulnerabilities
Cross Site Scripting ( XSS)
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
HTTP Request Smuggling via higher HTTP versions
CNIT 126 9: OllyDbg
Secure coding practices
Hunting for security bugs in AEM webapps
Sql injection
Ad

Viewers also liked (20)

PDF
CNIT 127 Ch 3: Shellcode
PDF
CNIT 127 Ch 2: Stack overflows on Linux
PDF
CNIT 127 Ch Ch 1: Before you Begin
PDF
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
PDF
CNIT 129S: Ch 7: Attacking Session Management
PDF
Is Your Mobile App Secure?
PDF
Ch 9: Embedded Operating Systems: The Hidden Threat
PDF
Ch 6: Enumeration
PDF
Ch 7: Programming for Security Professionals
PDF
Ch 10: Hacking Web Servers
PDF
CNIT 128 5: Mobile malware
PDF
CNIT 123: Ch 3: Network and Computer Attacks
PPTX
Ethical hacking Chapter 3 - Network and Computer Attacks - Eric Vanderburg
PDF
CNIT 121: 9 Network Evidence
PDF
CNIT 121: 14 Investigating Applications
PDF
CNIT 121: 17 Remediation Introduction (Part 1)
PDF
iOS Threats - Malicious Configuration Profiles, Threat, Detection & Mitigation
PDF
Ch 4: Footprinting and Social Engineering
PDF
CNIT 40: 5: Prevention, protection, and mitigation of DNS service disruption
PDF
Practical Malware Analysis: Ch 8: Debugging
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 129S: Ch 7: Attacking Session Management
Is Your Mobile App Secure?
Ch 9: Embedded Operating Systems: The Hidden Threat
Ch 6: Enumeration
Ch 7: Programming for Security Professionals
Ch 10: Hacking Web Servers
CNIT 128 5: Mobile malware
CNIT 123: Ch 3: Network and Computer Attacks
Ethical hacking Chapter 3 - Network and Computer Attacks - Eric Vanderburg
CNIT 121: 9 Network Evidence
CNIT 121: 14 Investigating Applications
CNIT 121: 17 Remediation Introduction (Part 1)
iOS Threats - Malicious Configuration Profiles, Threat, Detection & Mitigation
Ch 4: Footprinting and Social Engineering
CNIT 40: 5: Prevention, protection, and mitigation of DNS service disruption
Practical Malware Analysis: Ch 8: Debugging
Ad

Similar to CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3) (20)

PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
PPT
XSS Primer - Noob to Pro in 1 hour
PDF
주로사용되는 Xss필터와 이를 공격하는 방법
PPTX
04. xss and encoding
PPT
PPT
&lt;img src="xss.com">
PDF
Rich Web App Security - Keeping your application safe
PPT
Same Origin Policy Weaknesses
PDF
Scriptless Attacks - Stealing the Pie without touching the Sill
PPTX
RSA Conference 2010 San Francisco
PDF
Bypassing Web Application Firewalls and other security filters
PDF
Ultimate xss
KEY
Cross Site Scripting - Mozilla Security Learning Center
PPTX
Secure Coding
KEY
Application Security for Rich Internet Applicationss (Jfokus 2012)
PPTX
Web Hacking Series Part 4
PPT
Bh europe-01-grossman
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
XSS Primer - Noob to Pro in 1 hour
주로사용되는 Xss필터와 이를 공격하는 방법
04. xss and encoding
&lt;img src="xss.com">
Rich Web App Security - Keeping your application safe
Same Origin Policy Weaknesses
Scriptless Attacks - Stealing the Pie without touching the Sill
RSA Conference 2010 San Francisco
Bypassing Web Application Firewalls and other security filters
Ultimate xss
Cross Site Scripting - Mozilla Security Learning Center
Secure Coding
Application Security for Rich Internet Applicationss (Jfokus 2012)
Web Hacking Series Part 4
Bh europe-01-grossman

More from Sam Bowne (20)

PDF
Introduction to the Class & CISSP Certification
PDF
Cyberwar
PDF
3: DNS vulnerabilities
PDF
8. Software Development Security
PDF
4 Mapping the Application
PDF
3. Attacking iOS Applications (Part 2)
PDF
12 Elliptic Curves
PDF
11. Diffie-Hellman
PDF
2a Analyzing iOS Apps Part 1
PDF
9 Writing Secure Android Applications
PDF
12 Investigating Windows Systems (Part 2 of 3)
PDF
10 RSA
PDF
12 Investigating Windows Systems (Part 1 of 3
PDF
9. Hard Problems
PDF
8 Android Implementation Issues (Part 1)
PDF
11 Analysis Methodology
PDF
8. Authenticated Encryption
PDF
7. Attacking Android Applications (Part 2)
PDF
7. Attacking Android Applications (Part 1)
PDF
5. Stream Ciphers
Introduction to the Class & CISSP Certification
Cyberwar
3: DNS vulnerabilities
8. Software Development Security
4 Mapping the Application
3. Attacking iOS Applications (Part 2)
12 Elliptic Curves
11. Diffie-Hellman
2a Analyzing iOS Apps Part 1
9 Writing Secure Android Applications
12 Investigating Windows Systems (Part 2 of 3)
10 RSA
12 Investigating Windows Systems (Part 1 of 3
9. Hard Problems
8 Android Implementation Issues (Part 1)
11 Analysis Methodology
8. Authenticated Encryption
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 1)
5. Stream Ciphers

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
master seminar digital applications in india
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
2.FourierTransform-ShortQuestionswithAnswers.pdf
master seminar digital applications in india
Supply Chain Operations Speaking Notes -ICLT Program
TR - Agricultural Crops Production NC III.pdf
PPH.pptx obstetrics and gynecology in nursing
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Module 4: Burden of Disease Tutorial Slides S2 2025
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial diseases, their pathogenesis and prophylaxis
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Microbial disease of the cardiovascular and lymphatic systems
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)