一个反序列化问题
{
"name":"",
"error":{
"@type":"xxx.xxx.ErrorType",
"message":"xxxxx"
}
}
@type和AutoType
static class VehicleStore {
private String name;
private Vehicle vehicle;
// 省略 setter/getter
}
interface Vehicle {
}
static class Car implements Vehicle {
private BigDecimal price;
// 省略 setter/getter
}
@Test
public void deserializer() {
VehicleStore store = new VehicleStore();
store.setName("vehicleStore");
Car car = new Car();
car.setPrice(new BigDecimal(5000000));
store.setVehicle(car);
String jsonString = JSON.toJSONString(store);
}
{"name":"vehicleStore","vehicle":{"price":5000000}}
JSON.toJSONString(xxxObj, SerializerFeature.WriteClassName);
{"@type":"com.test.FastJsonTest$VehicleStore","name":"vehicleStore","vehicle":{"@type":"com.test.FastJsonTest$Car","price":5000000}}
@Test
public void deserializer() {
VehicleStore store = new VehicleStore();
store.setName("vehicleStore");
Car car = new Car();
car.setPrice(new BigDecimal(5000000));
store.setVehicle(car);
String jsonString = JSON.toJSONString(store, SerializerFeature.WriteClassName);
VehicleStore newStore = JSON.parseObject(jsonString, VehicleStore.class);
Car car = (Car) newStore.getVehicle();
}
问题解决
VehicleStore newStore1 = JSON.parseObject(jsonStr, VehicleStore.class, Feature.IgnoreAutoType);
public void setDataSourceName(String var1) throws SQLException {
if (this.getDataSourceName() != null) {
if (!this.getDataSourceName().equals(var1)) {
super.setDataSourceName(var1);// 注入攻击rmi源
this.conn = null;
this.ps = null;
this.rs = null;
}
} else {
super.setDataSourceName(var1);
}
}
private Connection connect() throws SQLException {
if (this.conn != null) {
return this.conn;
} else if (this.getDataSourceName() != null) {
try {
InitialContext var1 = new InitialContext();
DataSource var2 = (DataSource)var1.lookup(this.getDataSourceName());// 调用rmi方法
return this.getUsername() != null && !this.getUsername().equals("") ? var2.getConnection(this.getUsername(), this.getPassword()) : var2.getConnection();
} catch (NamingException var3) {
throw new SQLException(this.resBundle.handleGetObject("jdbcrowsetimpl.connect").toString());
}
} else {
return this.getUrl() != null ? DriverManager.getConnection(this.getUrl(), this.getUsername(), this.getPassword()) : null;
}
}
原文始发于微信公众号(小李哥编程):多次触发FastJson漏洞的AutoType机制,你了解吗?
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧
相关推荐
暂无评论内容