URLDNS利用链我们将ysoserial-all.jar进行导入ysoserial-all.jar原理分析具体的利用点在URL类的hashcode函数中在java中hashcode()是Object类中的一个方法用于返回一个对象的哈希码(hashcode)该哈希码是一个int类型的数值代表了该对象的特定标识符。哈希码的主要作用是在集合中进行元素的快速查找比如在HashMap和HashSet中我们写一个demoimport java.net.MalformedURLException;import java.net.URL;public class urldns {public static void main(String[] args) throws MalformedURLException {URL url new URL(http://rpttv7.dnslog.cn);url.hashCode();}}其中域名是我们自己生成的用于被java访问这样在DNS服务会有记录回到顶部hashcode去看hashcode方法可以看到这里先做了一个判断然后调用handler的hashcode方法。而handler是URL类中的一个属性接着进入handler对象protected int hashCode(URL u) {int h 0;// Generate the protocol part.String protocol u.getProtocol();if (protocol ! null)h protocol.hashCode();// Generate the host part.InetAddress addr getHostAddress(u);if (addr ! null) {h addr.hashCode();} else {String host u.getHost();if (host ! null)h host.toLowerCase().hashCode();}// Generate the file part.String file u.getFile();if (file ! null)h file.hashCode();// Generate the port part.if (u.getPort() -1)h getDefaultPort();elseh u.getPort();// Generate the ref part.String ref u.getRef();if (ref ! null)h ref.hashCode();return h;}这个方法传入一个URL类作为参数依次通过调用getProtocol,getHostAddressgetFilegetPortgetRef等方法获取到传入的URL链接的Protocol协议HostAddress主机地址File文件路径Port端口Ref锚点即#后面的部分获取完之后对每部分调用他们的hashcode方法将结果加到h上最后将h返回不过我们需要重点关注的是getHostAddress方法该方法会返回一个IP地址如果遇到的是域名那么就需要发起DNS请求来将其解析成IP地址protected synchronized InetAddress getHostAddress(URL u) {if (u.hostAddress ! null)return u.hostAddress;String host u.getHost();if (host null || host.equals()) {return null;} else {try {u.hostAddress InetAddress.getByName(host);} catch (UnknownHostException ex) {return null;} catch (SecurityException se) {return null;}}return u.hostAddress;}如果 u.hostAddress 为空那么调用 URL 类的 getHost 方法获取主机地址可以是 IP 也可以是域名如果获取到的主机地址不为空那么会调用 InetAddress 类的静态方法 getByName 并将主机名作为参数传入。重点来了InetAddress.getByName 是一个强大而实用的方法它允许我们根据主机名获取对应的 IP 地址并在各种网络应用场景中发挥巨大的作用。发起请求有了反序列化在哪里呢这就要看hashmap类。回到顶部HashMap类作用是用来存储内容内容以键值对的形式存放。import java.util.HashMap;public class RunoobTest {public static void main(String[] args) {// 创建 HashMap 对象 SitesHashMapInteger, String Sites new HashMapInteger, String();// 添加键值对Sites.put(1, Google);Sites.put(2, Runoob);Sites.put(3, Taobao);Sites.put(4, Zhihu);System.out.println(Sites);}}首先该类继承了Serializable接口一个类继承该接口可以进行反序列化处理并且该类还有对数据序列化的writeObject和对数据反序列化的readObject对于java对象序列化操作的类是ObjectOutputStream反序列化的类是ObjectInputStream左键点击ObjectOutputStream类ObjectOutputStream它提供了不同的方法用来序列化不同类型的对象比如writeInt等对于自定义类型提供了writeBoolean、writeObject等方法。