ccf csp 运行错误_在Safari阅读器模式下执行脚本以绕过CSP

本文探讨了如何利用Safari阅读模式绕过内容安全策略(CSP)。通过实验,作者发现虽然大部分JavaScript代码在阅读模式下被剥离,但特定的JavaScript URL构造仍能在该模式下执行,从而可能导致CSP绕过和潜在的安全风险。
摘要由CSDN通过智能技术生成

  翻译文章,原文:Executing Scripts In Safari Reader Mode To CSP Bypass[1]

阅读模式是大多数浏览器中实现的一项功能,该功能允许用户在一个简洁的视图中阅读文章,以便易于阅读且不会分散注意力。

这一张图很好的解释阅读模式。

65866938037e212cd893b77bc423b24f.png

图1

您是否想过浏览器如何实现它?在页面渲染过程中,浏览器移除了所有的不必要的代码,像javascript, iframes,和其他的嵌入的元素。

让我们尝试运行包含一些元素的示例代码,以了解Safari的响应。

    Safari Reader Preview JavaScript Code execution

macOS. It’s why there’s nothing else like a Mac

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.


Source: Apple.com

alert(1)

我们在Safari中得到下面的页面:

085b4da8f848a46b93a598dea6032cc5.png

图2

然后你能看在地址栏开始的位置,你能看到一个线条的按钮; 它表示页面是否可以使用阅读模式。我们用阅读模式打开这个页面:

f7470ecd585986f57a1d8fcfaf726587.png

图3

正如预料的那样,safari通过修改DOM创建了一个简洁视图。我们看一下这个DOM树,到底修改了什么地方。

8254c425e2fb172088de940bdc17cc5a.png

图4

你可能注意到 iframe, embed, object,script和onmouseover已经被移除。但是有趣的是指向apple.com的超链接,因此,当您单击链接时,您将被重定向到apple.com。

由于可以使用超链接标签(), 紧接着能想到的是使用javascript URI。我们修改几行代码看看发生什么问题。

Source: Apple.com
Evil link

safari删除了指向javascript URI的链接,而指向apple.com的链接没有变化,如下图。

3a5bcad27ed6a18086730c67af954e29.png

图5

在我看到来自Erling的这篇博文 Safari Reader UXSS[2] 之后,他提供了一种绕过方式:使用javascript:的URL被过滤,但是使用JaVASCRiPT:或javaScript:的URL不被过滤。

这种绕过方式已经是被修复了,然而我们想再次尝试绕过它,一个点就是使用HTML5 实体构建javascript URI, 最明显的payload:

Evil link

成功绕过!

41b193acfd7ba540558d3edda98a8376.png

图6

但是,如果您尝试单击链接,它将不起作用。如下图所示,即使控制台没有错误。

8589488ca7dfc7fe0ad67fdb935b8364.png

图7

似乎对我来说还有另一个挑战。接下来,就是找到为什么会这样。

为了找出为什么我们的JavaScript代码不起作用,我们可以定义一个无效的JavaScript代码来识别浏览器是否正在解释它。让我们再次修改示例代码中的几行,如下所示

Source: Apple.com
Evil link

正如您在下面看到的那样,它引发了一个错误

b8909c78c3b1391ae24f29bc3c820ed0.png

图8

我们可以得出的结论是,浏览器以某种方式识别了某些JavaScript代码,并且不允许我们执行它。

在这段时间里,我已经测试了几个功能,并且发现至少window.open可以正常工作。让我们修改示例代码并检查结果

修改后的代码:

Source: Apple.com
Evil link
1eb90ed835085de5d121deb8011e3eab.png

图9

如你所见,JavaScript代码是在safari-reader上下文执行的,这是一个在阅读模式下的伪协议。

让我们再次修改最后几行,看看它是如何工作的

Source: Apple.com
';document.documentElement.appendChild(p)">Evil link

它将在屏幕上创建一个令人讨厌的移动南瓜图像,如以下屏幕截图所示

0cbef174daa7fec95289ba6d2b2fdd80.png

图10

CSP 绕过

此漏洞也可用于绕过Safari中的CSP检查。你可以想象一个情况,当攻击者能够在完全由CSP实现的页面上注入XSS有效负载时,例如:

<?php header("Content-Security-Policy: default-src 'self'");?>    Safari Reader Preview JavaScript Code execution

macOS. It’s why there’s nothing else like a Mac

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.


macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.

macOS is the operating system that powers every Mac. It lets you do things you simply can’t with other computers. That’s because it’s designed specifically for the hardware it runs on — and vice versa. macOS comes with an entire suite of beautifully designed apps. It works hand in hand with iCloud to keep photos, documents and other stuff up to date on all your devices. It makes your Mac work like magic with your iPhone and other Apple devices. And it’s been built from the ground up with privacy and security in mind.


Source: Apple.com
Evil link

现在,如果您尝试单击注入链接,您将收到CSP违规错误。但是,如果将同一文档置于阅读模式,然后尝试再次单击注入的链接,它将执行javascript代码以窃取当前页面中的内容。

References

[1] Executing Scripts In Safari Reader Mode To CSP Bypass: https://payatu.com/blog/nikhil-mittal/executing-scripts-in-safari-reader-mode--to-csp-bypass

[2] Safari Reader UXSS: https://alf.nu/SafariReaderUXSS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值