白帽故事 · 2024年10月15日 0

【$1,060】GitLab HTML 注入漏洞

前言

假如 GitLab 配置为使用soft电子邮件确认设置,那么攻击者可以通过注册帐户并登录,然后更改包含 HTML Payloads的电子邮件,从而实施攻击。

如果管理员手动验证攻击者的电子邮件地址,则可能会在模式确认对话框中执行 HTML 代码。在显示之前,<form><script> 等标记似乎会被过滤掉。

https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/helpers/users_helper.rb 中的confirm_user_data方法有助于演示实现这一功能所需的条件:

  def confirm_user_data(user)
    message = if user.unconfirmed_email.present?
                _('This user has an unconfirmed email address (%{email}). You may force a confirmation.') % { email: user.unconfirmed_email }
              else
                _('This user has an unconfirmed email address. You may force a confirmation.')
              end

    modal_attributes = Gitlab::Json.dump({
      title: s_('AdminUsers|Confirm user %{username}?') % { username: sanitize_name(user.name) },
      messageHtml: message,
      actionPrimary: {
        text: s_('AdminUsers|Confirm user'),
        attributes: [{ variant: 'confirm', 'data-qa-selector': 'confirm_user_confirm_button' }]
      },
      actionSecondary: {
        text: _('Cancel'),
        attributes: [{ variant: 'default' }]
      }
    })

<rest of function trimmed>

我们需要通过 if user.unconfirmed_email.present? 检查才能在对话框中显示电子邮件。

这种情况只有在攻击者使用电子邮件确认注册账户,然后更改电子邮件时才会发生。如果攻击者设置后将电子邮件确认更改为 Hard,则攻击者仍会触发该漏洞,但新注册似乎会遵循 else 条件(那么电子邮件则不会显示在对话框内)。

漏洞复现

先决条件(管理员帐户):

  1. 转到Admin general settings页面 ( http://gitlab.example.com/admin/application_settings/general )

  2. 扩大注册限制并将“电子邮件确认设置”设置为“Soft”。

  3. 保存更改

(攻击者)步骤:

  1. 上注册一个帐户(例如,用户名: AttackerSoftEmail ,电子邮件: attackersoftemail@example.com )

  2. 登录帐户,然后在屏幕顶部会看到一条消息,“请检查你的电子邮件 ( attackersoftemail@example.com ) 以验证是否拥有此地址并解锁 CI/CD 的功能。没有收到它?电子邮件地址错误?请重新发送。”

  3. 转到用户的个人资料 ( http://gitlab.example.com/-/profile )

  4. 更改电子邮件地址,附加 <h2>testing<img/src=http://localhost:8000/test.png> 到邮件地址末尾

file

  1. 保存更改

  2. (可选)通过在空目录中运行python3 -m http.server来启动 python3 Web 服务器以捕获 Web 请求

(受害者)步骤:

  1. 以管理员/root 身份登录 GitLab

  2. 导航到管理员用户面板并选择 AttackerSoftEmail 用户 ( http://gitlab.example.com/admin/users/AttackerSoftEmail )

  3. 请注意 AttackerSoftEmail 的电子邮件地址不包含 HTML

file

  1. 使用F12打开浏览器开发工具并导航到“Network”选项卡

  2. 对话框文本由于<h2>标头而被修改,并且对话框中出现损坏的图像

  3. 确认使用浏览器请求的网络选项卡 http://localhost:8000/test.png 如果 python 服务器正在运行,则返回 404

file

file

该漏洞最终通过CVSS定级为“低危”,GitLab 向白帽用户发放1060美元的赏金奖励。

以上内容由骨哥翻译并整理。

原文:https://hackerone.com/reports/1935628