shiro工具学习
如果反序列化流中包含非 Java 自身的数组,则会出现无法加载类的错误。
总结下来,这可能还是类加载器的问题。网上多篇文章中都给出了此问题的两个解决方案:
-
使用 RMI 中的 Gadget 做跳板,再执行 CC 反序列化链,这样可以加载;
-
改造 CC 链,组合 InvokerTransformer 与 TemplatesImpl,避免使用 Transformer 数组。
-
素十八师傅的总结 https://su18.org/post/shiro-2/#小坑
-
内存马的注入
https://blog.csdn.net/weixin_43263451/article/details/125902345
https://xz.aliyun.com/t/10696 -
rmi的知识
https://su18.org/post/rmi-attack
https://javasec.org/javase/RMI/有关攻击 Registry 端的问题
Java对远程访问RMI Registry做了限制,只有来源地址是localhost的时候,才能调用rebind、bind、unbind等方法。不过list和lookup方法可以远程调用
点击查看代码
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ChangeKey {
public static void main(String[] args) throws IOException {
String result = new String(Files.readAllBytes(Paths.get("src/main/java/com/govuln/shiroattack/Evil.java")), StandardCharsets.UTF_8);
String reg = "key = \"(.*?)\";";
String key = "12";
StringBuilder operatorStr=new StringBuilder(result);
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(operatorStr);
if (m.find()){
operatorStr.replace(m.start(1),m.end(1),key);
}
System.out.println(operatorStr.toString());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src/main/java/com/govuln/shiroattack/Evil.java")) ;
bos.write("".getBytes(StandardCharsets.UTF_8));
bos.write(operatorStr.toString().getBytes(StandardCharsets.UTF_8));
bos.close();
}
}