升级到Apache Commons Text 1.9及以上版本。
在Cassandra 3.11.x中运行以下命令以检查是否存在该漏洞:
grep -r "org.apache.commons.text.lookup.StringLookupFactory" /path/to/cassandra/
如果返回非空,则表示存在漏洞。
检查Cassandra配置文件中的“secure_distributed_cache_credentials”参数是否被设置,如果设置了,则需要禁用或重新配置该参数。
如果无法升级Apache Commons Text,可以在Cassandra中实现限制,以防止在反序列化字符串时利用漏洞执行恶意代码。示例如下:
public class NoOpStringLookupFactory implements StringLookupFactory {
@Override
public StringLookup createStringLookup(Map map)
throws Exception {
return new NoOpStringLookup();
}
}
public class NoOpStringLookup implements StringLookup {
@Override
public String lookup(String key) {
return null;
}
}
String str = deserializeString();
if (str.indexOf("$") >= 0) {
str = StringSubstitutor.replace(str, new NoOpStringLookupFactory());
}
该代码通过将“$”字符替换为空值来规避漏洞。