Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Cross-Site
Scripting (XSS) 1
We have a search box over here which can be used as our injection point. Lets first try
to inject a simple search query.
Perfect! We are getting a reflection on the page. You can also check how it's reflected
by viewing the source code of the application.
Now, as we know we an inject a malicious javascript code into the source code
which will eventually reflect the same to the user through the browser, lets try to
inject a simple payload: <script>alert(1)</script>
Notice the alert box, that means our payload got triggered successfully. Now, you can
check the source code and see your input is perfectly injected into the source code.
Types of XSS
1. Reflected XSS: The malicious script comes from the current HTTP request when
injected in the source code of the application.
2. Stored XSS: The malicious script comes from the website's database which
eventually gets executed in user's browser.
Reflected XSS
Reflected cross-site scripting (or RXSS) arises when an application receives data in
an HTTP request and includes that data within the source code which initiates that
immediate response in an unsafe way.
1. Test every entry input point i.e. each and every parameter or input fields.
2. Determine the reflection context, check where your injected payload gets
reflected in the source code.
3. Now you can check if you need to balance your supplied input and frame a
payload accordingly.
4. Test that payload and see if that give you a popup, if not see if you have
balanced your payload properly.
Severity
The Reflected XSS has a severity of P3 with a CVSS score of 5.8 which is Medium.
This can be used to steal cookies from a victim and also can be used for capturing
victim's credentials.
Stored XSS
Stored XSS (also known as persistent or second-order XSS) arises when an application
receives data from an untrusted source and includes that data within its later HTTP
responses in an unsafe way. This type of XSS happens when the server saves your
supplied input somewhere into the server, i.e) Database, cache server.
Currently, we are on the profile page. In the name field, we will be adding our XSS
payload and then updating the profile.
Cross-Site Scripting (XSS) 4
This happened because the payload gets stored in the name field and every time we
load the page the alert box will be alerted.
Cross-Site Scripting (XSS) 5
1. Test every field which stores values in the server, for example username,
firstname, lastname, email id, comment fields etc.
2. Follow the same process as Reflected XSS and see if it gets stored and rendered
back to the browser.
3. Test alternative payloads and other different techniques if one payload don't work.
Severity
The Stored XSS has a severity of P2 with a CVSS score of 7-8.9 which is High.
This type of XSS can be used to steal cookies of large number of users or even
admin as well, because everytime someone loads the page they get affected by
this.
DOM XSS
DOM-based XSS (also known as DOM XSS) arises when an application contains some
client side JavaScript that processes data from an untrusted source in an unsafe way,
usually by writing the data back to the DOM. This is a source and sink process, the user
input which can be any malicious code when goes into the source and comes out from
the sink results in a DOM XSS.
Notice the name parameter in the URL. If we change its value, it will be reflected on the
website.
Severity
The DOM XSS has a severity of P1 with a CVSS score of 10 which is Critical. This type
of XSS is generally found less but it can cause certain amount of damage as well.
Impact of XSS
Impersonate or masquerade as the victim user.
XSS Polyglots
Polyglots means someone who knows many languages. Combining it with XSS
Payloads, it basically means a payload combination of 2 or more payloads in order
to trick the web server and bypass many input checks.
XSS Prevention
Filter input on arrival. At the point where user input is received, filter as
strictly as possible based on what is expected or valid input.
Content Security Policy. As a last line of defense, you can use Content
Security Policy (CSP) to reduce the severity of any XSS vulnerabilities that still
occur.
Implementing WAFs. Web application firewall (WAF) can also be used to stop this
type of attack, developers can implement WAF's and properly configure them to
block certain malicious user inputs.
References
Awesome XSS : https://github.com/s0md3v/AwesomeXSS