Bypassing SOP with Iframes - 2
Iframes in SOP-2
U rešenju za ovaj izazov, @Strellic_ predlaže sličnu metodu kao u prethodnom odeljku. Hajde da proverimo.
U ovom izazovu napadač treba da bypasses ovo:
Ako to učini, može poslati postmessage sa HTML sadržajem koji će biti napisan na stranici sa innerHTML
bez sanitizacije (XSS).
Način da se zaobiđe prva provera je da se window.calc.contentWindow
postavi na undefined
i e.source
na null
:
window.calc.contentWindow
je zapravodocument.getElementById("calc")
. Možete prebrisatidocument.getElementById
sa<img name=getElementById />
(napomena da Sanitizer API -ovde- nije konfiguran da štiti od DOM clobbering napada u svom podrazumevanom stanju).Stoga, možete prebrisati
document.getElementById("calc")
sa<img name=getElementById /><div id=calc></div>
. Tada ćewindow.calc
bitiundefined
.Sada, potrebno je da
e.source
budeundefined
ilinull
(jer se koristi==
umesto===
,null == undefined
jeTrue
). Dobijanje ovoga je "lako". Ako kreirate iframe i pošaljete postMessage iz njega i odmah uklonite iframe,e.origin
će bitinull
. Proverite sledeći kod
Da bi se zaobišao drugi proveren o tokenu, potrebno je poslati token
sa vrednošću null
i postaviti vrednost window.token
na undefined
:
Slanje
token
u postMessage sa vrednošćunull
je trivijalno.window.token
se koristi u pozivu funkcijegetCookie
koja koristidocument.cookie
. Imajte na umu da svaki pristupdocument.cookie
na stranicama sanull
poreklom izaziva grešku. Ovo će učiniti dawindow.token
ima vrednostundefined
.
Konačno rešenje od @terjanq je sledeće:
Last updated