Bypassing SOP with Iframes - part 2
Bypassing SOP with Iframes - 2
Iframes in SOP-2
In the solution for this challenge, @Strellic_ proposes a similar method to the previous section. Let's check it.
In this challenge the attacker needs to bypass this:
If he does, he can send a postmessage with HTML content that is going to be written in the page with innerHTML
without sanitation (XSS).
The way to bypass the first check is by making window.calc.contentWindow
to undefined
and e.source
to null
:
window.calc.contentWindow
is actuallydocument.getElementById("calc")
. You can clobberdocument.getElementById
with<img name=getElementById />
(note that Sanitizer API -here- is not configured to protect against DOM clobbering attacks in its default state).Therefore, you can clobber
document.getElementById("calc")
with<img name=getElementById /><div id=calc></div>
. Then,window.calc
will beundefined
.Now, we need
e.source
to beundefined
ornull
(because==
is used instead of===
,null == undefined
isTrue
). Getting this is "easy". If you create an iframe and send a postMessage from it and immediately remove the iframe,e.origin
is going to benull
. Check the following code
In order to bypass the second check about token is by sending token
with value null
and making window.token
value undefined
:
Sending
token
in the postMessage with valuenull
is trivial.window.token
in calling the functiongetCookie
which usesdocument.cookie
. Note that any access todocument.cookie
innull
origin pages tigger an error. This will makewindow.token
haveundefined
value.
The final solution by @terjanq is the following:
Last updated