28

如何探测内网存活主机

 3 years ago
source link: http://network.51cto.com/art/202009/627302.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在渗透中,当我们拿下一台服务器作为跳板机进一步进行内网渗透时,往往需要通过主机存活探测和端口扫描来收集内网资产。

我们将主机扫描的场景大致可分为三种,1)直接在webshell下执行,通过系统自带命令或上传脚本工具进行扫描探测 ;2)通过反弹shell进行内网渗透,msf等渗透测试框架自带一些扫描模块;3)通过socks代理扫描内网(例如 proxychains+Nmap扫描)。

在合适的场景下,选择最合适的武器。比如支持存活探测的协议,包括了 ARP、ICMP、SMB、 UDP、NETBIOS、SNMP协议等;支持端口扫描的方式,包括ACK扫描、SYN扫描、TCP扫描、UDP扫描、ICMP扫描等。

01、ping命令

我们经常通过ping检查网络连通性,通过telnet来测试指定端口连通性。使用系统自带的命令来完成C段探测,虽然效率低,但不容易触发安全规则。如果服务器开启了防火墙或者禁ping,那么就会影响探测结果。

Windows下使用ping命令扫描C段:

for /l %i in (1,1,255) do @ping 192.168.64.%i -w 1 -n 1|find /i "ttl="

Linux 下使用ping命令扫描C段:

for k in $( seq 1 255);do ping -c 1 192.168.99.$k|grep "ttl"|awk -F "[ :]+" '{print $4}'; done

另外,还可以结合系统自带的traceroute、arp 、netstat等命令收集内网信息,curl、wget可以用来做端口探测。

02、Powershell

通过powershell脚本扫描IP地址存活:

powershell.exe -exec bypass -Command "Import-Module ./Invoke-TSPingSweep.ps1;Invoke-TSPingSweep -StartAddress 192.168.1.0 -EndAddress 192.168.1.255"脚本下载地址:

https://gallery.technet.microsoft.com/scriptcenter/Invoke-TSPingSweep-b71f1b9b

用PowerShell实现基本的端口扫描功能。

针对单个IP的多个端口的扫描:

PS C:\Users\Bypass> 1..1024 | % {echo ((new-object Net.Sockets.TcpClient).Connect("192.168.246.44",$_)) "Port $_ is open!"} 2>$null针对某IP段中单个端口的扫描:

foreach ($ip in 1..20) {Test-NetConnection -Port 80 -InformationLevel "Detailed" 192.168.1.$ip}针对某IP段 & 多个端口的扫描器

1..20 | % { $a = $_; 1..1024 | % {echo ((new-object Net.Sockets.TcpClient).Connect("10.0.0.$a",$_)) "Port $_ is open!"} 2>$null}

03、基于MSF的内网主机探测

使用msf进行反弹shell进行内网渗透时,通过msf自带的扫描模块进行快速扫描。

主机存活探测:

auxiliary/scanner/discovery/arp_sweep ARP扫描auxiliary/scanner/discovery/udp_sweep UDP扫描auxiliary/scanner/netbios/nbname NETBIOS扫描auxiliary/scanner/snmp/snmp_enum SNMP扫描auxiliary/scanner/smb/smb_version SMB扫描

端口扫描:

auxiliary/scanner/portscan/ack TCP ACK端口扫描auxiliary/scanner/portscan/ftpbounce FTP bounce端口扫描auxiliary/scanner/portscan/syn SYN端口扫描auxiliary/scanner/portscan/tcp TCP端口扫描 auxiliary/scanner/portscan/xmas TCP XMas端口扫描

04、Nmap扫描内网

Nmap是一个端口扫描器,可用于主机发现、端口扫描、版本检测、OS检测等。

使用场景:建立socks代理,proxychains+Nmap扫描内网。

支持多种扫描模式:

-sT: TCP 扫描-sS: SYN 扫描-sA: ACK 扫描-sF:FIN扫描-sU: UDP 扫描-sR: RPC 扫描-sP: ICMP扫描

快速扫描所有端口:

nmap -sS -p 1-65535 -v 192.168.99.177

【责任编辑:赵宁宁 TEL:(010)68476606】


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK