• 漏洞挖掘之Spring Cloud注入漏洞


    漏洞描述

    Spring框架为现代基于java的企业应用程序(在任何类型的部署平台上)提供了一个全面的编程和配置模型。

    Spring Cloud 中的 serveless框架 Spring Cloud Function 中的 RoutingFunction 类的 apply 方法将请求头中的“spring.cloud.function.routing-expression”参数作为 Spel 表达式进行处理,造成Spel表达式注入,攻击者可通过该漏洞执行任意代码。

    利用条件

    3.0.0.RELEASE <= Spring Cloud Function <= 3.2.2

    环境搭建

    在官方网页新建一个 Spring boot 项目(https://start.spring.io/)、使用idea启动。

    t01a6390da1a7dc96bc.jpg

    修改 pom.xml配置文件

    
    
    4.0.0
    
    org.springframework.boot
    spring-boot-starter-parent
    2.6.5
     
    
    com.example
    demo
    0.0.1-SNAPSHOT
    demo
    Demo project for Spring Boot
    
    17
    2021.0.1
    
    
    
    org.springframework.cloud
    spring-cloud-function-context
    
    
    org.springframework.cloud
    spring-cloud-starter
    
    
    org.springframework.cloud
    spring-cloud-starter-task
    
    
    
    org.springframework.boot
    spring-boot-starter-test
    test
    
    
    
    org.springframework.cloud
    spring-cloud-starter-function-webflux
    
    
    
    org.springframework.cloud
    spring-cloud-function-dependencies
    3.2.2
    pom
    
    
    
    org.springframework.cloud
    spring-cloud-function-web
    3.2.2
    
    
    
    
    
    org.springframework.cloud
    spring-cloud-dependencies
    ${spring-cloud.version}
    pom
    import
    
    
    
    
    
    
    
    org.springframework.boot
    spring-boot-maven-plugin
    
    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79

    最后访问 http://127.0.0.1:8080. 出现以下页面表示成功。

    【一>所有资源获取<一】
    1、很多已经买不到的绝版电子书
    2、安全大厂内部的培训资料
    3、全套工具包
    4、100份src源码技术文档
    5、网络安全基础入门、Linux、web安全、攻防方面的视频
    6、应急响应笔记 7、 网络安全学习路线
    8、ctf夺旗赛解析
    9、WEB安全入门笔记

    t0164527df56ee9a243.jpg

    漏洞复现

    漏洞原理

    apply方法会将http头部中的Spel表达式进行解析,从而造成Spel表达式注入。

    查看官方diff

    t015d7efaef903a9715.jpg

    t01318b79c886f8c416.jpg

    进入springframework/cloud/function/context/config/RoutingFunction文件。进入调试模式、将断点添加到apply()方法。

    t011224341ff22fadbb.jpg

    进入到apply()方法后、会调用route() 在该方法中会去判读input是否为 message的实例,function 是否为空、然后进入else if 去获取头信息、获取key值 spring.cloud.function.routing-expression 、在中间会对有无空格做判断。然后继续向下走。

    t014d2f96789d58f2fd.jpg

    会进入到springframework/cloud/function/context/config/RoutingFunction/functionFromExpression()方法。

    t01a01d3622b0bdfe47.jpg

    routingExpression 会做为参数传入到springframework/expression/common/TemplateAwareExpressionParser/parseExpression()方法中。

    t0161908062a2cbcf89.jpg

    判读其context是否为none值 在进入

    springframework/expression/spel/standard/SpelExpressionParser/doPareExpression() 会new 一个 InternalSpelExpressionParser 类调用 doPareExpression() 继续跟进。

    t0102a1a099bc8c5e27.jpg

    在springframeworl/expression/spel/stand/InternalSpelExpressionParser/doParseExpression()方法中、会在tokenizer.process()中 对token进行 源码与字节码的判断操作、继续向下。

    t0186bd3a27048b16bd.jpg

    会new 一个SpelExpression() 跟进到

    springframwork/expression/spel/standard/SpelExpression/SpelExpression()。

    t014d24dc80dca4e616.jpg

    SpelExpression()方法中会将将表达式赋值到this.expression继续跟进 return到 springframework/expression/spel/standard/SpelpressionParser/doParseExpression()、继续return到springframework/expression/common/TemplateAwareExpressionPareser/pareExpression()、return
    springframework/cloud/function/context/config/RoutingFunction/functionFromExpression()

    t013c4af6eb1ef249bc.jpg

    在functionFromExpression()方法中会进入MessageUtils.toCaseInsensitiveHeadersStructure()。

    t01998ffbb758a487c1.jpg

    调用MessageStructureWithCaseInsensitiveHeaderKeys(),进入到putAll()方法 获取message中头信息。

    t017b4852c2849bc934.jpg

    最后会进入漏洞触发点。

    t011f93cfffb35c7ef0.jpg

    漏洞测试

    Payload 的构造可以参考官方测试用例。

    image.png

    本次利用创建文件测试。使用payloadtouch/tmp/xxxxxx.test.test。

    image.png

    t01e6aa507c11faa341.jpg

  • 相关阅读:
    14届蓝桥青少STEMA-C++组12月评测
    【matplotlib基础】--样式表
    bamboo is currently exporting
    PCB懂王,你是吗?我不是
    MacBook Pro(M1 Pro芯片)兼容Tensorflow1.X版本的解决方法
    在springboot应用程序中按大小或日期滚动日志文件
    Feign-Hystrix 熔断降级,一文看透本质
    在Jetson Nano上安装ncnn深度学习框架
    全文搜索引擎对比:RedisSearch 和 Elasticsearch 的优劣分析
    数据结构——线性表之顺序表的基本操作讲解
  • 原文地址:https://blog.csdn.net/m0_67391377/article/details/126616348