githubEdit

XSS (Cross-Site Scripting)

Commonly known as cross-site scripting (XSS), JavaScript injection is where an attacker can inject arbitrary JavaScript to be executed.

JavaScript injection (XSS)

A simple example

  • A vulnerable webapp allows users to post comments.

  • When a user submits a comment, the website stores it and then displays it on the homepage without any validation or sanitization.

  • An attacker could exploit this by posting <script>prompt(1)</script> to the site.

  • When a user visits the homepage, the payload is executed in that users browser.

Other learning resources:

Writeups:

  • Bullets

Checklist

Exploitation

XSS (Cross-Site Scripting)

XSS enables attackers to injection client-side scripts into web applications.

Automation

Payloads

We can insert them into URL params, POST params or HTTP headers. Additionary, we can also find CVE related XSS herearrow-up-right.

To find more payloads, we can see Port Swigger's XSS Cheat Sheetarrow-up-right.

HTML Entity

Reference: https://cheatsheetseries.owasp.org/cheatsheets/XSS_Filter_Evasion_Cheat_Sheet.html#img-onerror-and-javascript-alert-encodearrow-up-right

JQuery

AngularJS

If you find <html ng-app>, <body ng-app> or <div ng-app> in the HTML source code, you may be able to abuse it by XSS.

To perform XSS without $eval function and quotes, we might be able to take another approach. This PortSwigger's labarrow-up-right provides the following payload. But sorry, I don’t understand how it works at the moment.

AngularJS and CSP (Content Security Policy)

Reference: PortSwigger's labarrow-up-right

If the website uses AngularJS with CSP (ng-csp) as below,

We need to bypass them by using a focus event (ng-focus),

Polyglot XSS

Exploit

After finding the XSS vulnerability, we can abuse it with

Load External JavaScript Code

We may be able to execute our JavaScript file which is hosted on our server.

We can steal a victim's cookie with the following payload:

Alternatively, inject the following payload into input fields in a target website.

To retrieve data, start web server or listener in local machine.

When victims access to the target page, we may get their request headers in our server log.

Filter Evasion

  • Base64 & Eval

    Website may sanitize inputs to prevent from malicious code. However, we might be able to circumvent by modifying our code. For example, convert JavaScript code to Base64 string, then insert the base64 string into the “eval” function as below.

  • Charcode & Eval

    We can use charcode (we can generate easily in CiberChef with the Base10 option) of the payload as below.

    Then create eval function to use it.

Steal Contents of Restricted Pages or Files

If JavaScript code can be executed via XSS, we can let victims to get contents of restricted pages and send them to our server.

Interact with Another Host via XML HTTP Request

We might be able to send request the another host and retrieve the response. First, create a JavaScript file named exploit.js here. Replace http://evil.com with your local ip address. By this script, we send a request to http://sub.victim.com then fetch the response from the host.

  • GET Request

  • POST Request

    Now we start web server to host the exploit.js and listener to receive the response.

    Then send a request with XSS to execute our payload (exploit.js). Replace the evil.com with your local ip address.

    We might fetch the response.

CSRF

The example below sends request to /admin on the victim site at first. And retrieve HTML document and get CSRF token. Next, insert the new form element to submit arbitrary POST data.

After that, we can inject the script above in XSS. For example, encode the script as Base64, then put it into the XSS payload as below.

We might be able to get sensitive information or change crucial data on the target.

Register New User with XSS

If the user name is reflected in the website, we might be able to inject XSS when registration.

Key Logging

Reference: https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS Injection#javascript-keyloggerarrow-up-right

References

XSS

circle-info

Try XSS in every input field, host headers, url redirections, URI paramenters and file upload namefiles.

Actions: phising through iframe, cookie stealing, always try convert self to reflected.

Tools

Oneliners

XSS recopilation

Basics

By tag

Blind

Bypasses

Encoded

Polyglots

XSS in files

DOM XSS

XSS to CSRF

AngularJS Sandbox

XSS in JS

XSS Waf Bypasses

XSS Methodology

  1. Discovery and Mapping:

  2. Generate Test Inputs:

  3. Submit and Observe:

  4. Context Analysis:

  5. Crafting XSS Payloads:

  6. Payload Testing:

  7. Browser Execution:

  8. Document Reflections and Payload Execution:

  9. Exploit Refinement:

  10. Automated Scanning:

  11. Test for Browser Quirks:

  12. Confirm Persistent Storage (Stored XSS):

  13. Check for Execution Context (DOM-based XSS):

XSS Mindmap

Last updated