0x00 漏洞背景
2019年9月19日,360CERT观测到国外安全研究员Aviv Sasson 发现了Harbor存在权限提升漏洞,Harbor在默认配置下注册功能开放,攻击者可以通过注册功能利用该漏洞获取管理员权限。
Harbor是VMware的一个开源项目,可以帮助用户迅速搭建企业级的Registry服务。Harbor提供了管理图形界面,具有镜像远程复制、AD/LDAPj集成和审计日志等功能。 Harbor 1.7.6之前版本和Harbor 1.8.3之前版本均受此洞影响。
0x01 漏洞分析
在源码src/common/moudels/user.go中user的结构体如下:
type User struct {
UserID int orm:"pk;auto;column(user_id)" json:"user_id"
Username string orm:"column(username)" json:"username"
Email string orm:"column(email)" json:"email"
Password string orm:"column(password)" json:"password"
PasswordVersion string orm:"column(password_version)" json:"password_version"
Realname string orm:"column(realname)" json:"realname"
Comment string orm:"column(comment)" json:"comment"
Deleted bool orm:"column(deleted)" json:"deleted"
Rolename string orm:"-" json:"role_name"
// if this field is named as "RoleID", beego orm can not map role_id
// to it.
Role int orm:"-" json:"role_id"
// RoleList []Role json:"role_list"
HasAdminRole bool orm:"column(sysadmin_flag)" json:"has_admin_role"
ResetUUID string orm:"column(reset_uuid)" json:"reset_uuid"
Salt string orm:"column(salt)" json:"-"
CreationTime time.Time orm:"column(creation_time);auto_now_add" json:"creation_time"
UpdateTime time.Time orm:"column(update_time);auto_now" json:"update_time"
GroupIDs []int orm:"-" json:"-"
OIDCUserMeta *OIDCUser orm:"-" json:"oidc_user_meta,omitempty"
}
其中HasAdminRole参数用来标记用户是否为管理员。 分析一下路由,在src/core/router.go中第50行:
在src/core/api/user.go 中负责处理该路由提交的数据,在注册用户POST提交时来到user.go中的POST方法:
在判断允许自行注册用户后,创建User对象。之后验证用户和Email后插入数据库,整个过程并未对HasAdminRole进行校验。导致可以新用户可以注册为管理员。
在新版本中增加了对HasAdminRole 的校验:
0x02 修复建议
关闭自行注册功能
升级Harbor至1.7.6及以上版本或者1.8.3及以上版本
0x03 时间线
2019-09-10 漏洞公布
2019-09-19 漏洞详情公布
2019-09-19 360CERT发布预警
0x04 参考链接
https://github.com/goharbor/harbor/pull/8917
https://unit42.paloaltonetworks.com/critical-vulnerability-in-harbor-enables-privilege-escalation-from-zero-to-admin-cve-2019-16097/
https://github.com/goharbor/harbor/pull/8917/commits/b6db8a8a106259ec9a2c48be8a380cb3b37cf517#diff-fb70049a82e5abd89a68c8e2cccba44c
文章原文链接:https://www.anquanke.com/post/id/187041