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: 13: Attacking Users: Other Techniques (Part 2 of 2)
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
PDF
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
PDF
API_Testing_with_Postman
PDF
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
PPTX
POSTMAN.pptx
PDF
CNIT 129S - Ch 3: Web Application Technologies
PPTX
Attacking thru HTTP Host header
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
API_Testing_with_Postman
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
POSTMAN.pptx
CNIT 129S - Ch 3: Web Application Technologies
Attacking thru HTTP Host header

What's hot (20)

ODP
Accelerate Quality with Postman - Basics
PPTX
Json Web Token - JWT
PPTX
Http Introduction
PDF
CNIT 129S: 11: Attacking Application Logic
PPTX
Cross site scripting
PPTX
Test automation of ap is using postman
PDF
Postman: An Introduction for API Ops Professionals
PDF
ES2015 / ES6: Basics of modern Javascript
PDF
Secure coding guidelines
PDF
PPT
Ppt of soap ui
ODP
OAuth2 - Introduction
PPTX
API Testing Presentations.pptx
PPT
Listeners and filters in servlet
PPT
Postman.ppt
PDF
Ch 3: Web Application Technologies
PDF
Attacker's Perspective of Active Directory
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
ODP
Testing RESTful Webservices using the REST-assured framework
PDF
Postman: An Introduction for Testers
Accelerate Quality with Postman - Basics
Json Web Token - JWT
Http Introduction
CNIT 129S: 11: Attacking Application Logic
Cross site scripting
Test automation of ap is using postman
Postman: An Introduction for API Ops Professionals
ES2015 / ES6: Basics of modern Javascript
Secure coding guidelines
Ppt of soap ui
OAuth2 - Introduction
API Testing Presentations.pptx
Listeners and filters in servlet
Postman.ppt
Ch 3: Web Application Technologies
Attacker's Perspective of Active Directory
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Testing RESTful Webservices using the REST-assured framework
Postman: An Introduction for Testers
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 129S: 9: Attacking Data Stores (Part 2 of 2)
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
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 129S: 9: Attacking Data Stores (Part 2 of 2)
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
Ad

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

PDF
Ch 12 Attacking Users - XSS
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PPTX
Web Hacking Series Part 4
PDF
CNIT 129S: 10: Attacking Back-End Components
PPTX
Design Like a Pro: Scripting Best Practices
PPTX
Design Like a Pro: Scripting Best Practices
PPTX
gdscWorkShopJavascriptintroductions.pptx
PPTX
04. xss and encoding
PPTX
External JavaScript Widget Development Best Practices (updated) (v.1.1)
PPTX
Web technologies-course 08.pptx
PDF
Hacking sites for fun and profit
PPTX
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
PDF
ASP.NET MVC 3
PPT
Exception handling
PPTX
SQLi for Security Champions
PDF
PPTX
Cm9 secure code_training_1day_input sanitization
PPTX
Security Code Review 101
Ch 12 Attacking Users - XSS
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
Web Hacking Series Part 4
CNIT 129S: 10: Attacking Back-End Components
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
gdscWorkShopJavascriptintroductions.pptx
04. xss and encoding
External JavaScript Widget Development Best Practices (updated) (v.1.1)
Web technologies-course 08.pptx
Hacking sites for fun and profit
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
Case Study of Django: Web Frameworks that are Secure by Default
ASP.NET MVC 3
Exception handling
SQLi for Security Champions
Cm9 secure code_training_1day_input sanitization
Security Code Review 101

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)

PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
RMMM.pdf make it easy to upload and study
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Classroom Observation Tools for Teachers
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Trump Administration's workforce development strategy
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
RMMM.pdf make it easy to upload and study
Anesthesia in Laparoscopic Surgery in India
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Classroom Observation Tools for Teachers
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
2.FourierTransform-ShortQuestionswithAnswers.pdf
Trump Administration's workforce development strategy
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
A systematic review of self-coping strategies used by university students to ...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
O5-L3 Freight Transport Ops (International) V1.pdf

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