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 的校验: