Metasploit+渗透测试手册第三版+第二章+信息收集与扫描(翻译)
第二章 信息收集和扫描
在本章中,我们将学习以下内容
使用Metasploit被动收集信息
使用Metasploit主动收集信息
使用Nmap进行端口扫描
使用db_nmap方式进行端口扫描
使用ARP进行主机发现
UDP服务探测
SMB扫描和枚举
SSH版本扫描
FTP扫描
SMTP枚举
SNMP枚举
HTTP扫描
WinRM扫描和爆破
与Nessus结合使用
与NeXpose结合使用
与OpenVAS结合使用
简介
信息收集是渗透测试中首先要做的重要事项之一,目的是尽可能多的查找关于目标的信息,我们掌握的信息越多,渗透成功的机会越大。在信息收集阶段,我们主要任务是收集关于目标机器的一切信息,比如IP地址,开放的服务,开放的端口。这些信息在渗透测试过程中启到了至关重要的作用。为了实现这一目的,我们将在本章学习各种扫描技术、如SMB扫描、SSH服务扫描,FTP扫描、SNMP枚举、HTTP扫描以及WinRM扫描和暴力破解。
收集信息的方式主要有三种:
1、被动信息收集:这种方式是指在不物理连接或访问目标的时候,获取目标的相关信息,这意味着我们需要使用其他信息来源获得目标信息。比如查询whois信息。假设我们的目标是一个在线的Web服务,那么通过whois查询可以获得它的ip地址,域名信息,子域信息,服务器位置信息等。
2、主动信息收集:这种方式是指与目标建立逻辑连接获取信息,这种方式可以进一步的为我们提供目标信息,让我们对目标的安全性进一步理解。在端口扫描中,使用最常用的主动扫描技术,探测目标开放的端口和服务。
3、社会工程学:这种方式类似于被动信息收集,主要是针对人为错误,信息以打印输出、电话交谈、电子邮件等形式泄露。使用这种方法的技术有很多,收集信息的方式也不尽相同,因此,社会工程学本身就是一个技术范畴。
社会工程的受害者被诱骗发布他们没有意识到会被用来攻击企业网络的信息。例如,企业中的员工可能会被骗向假装是她信任的人透露员工的身份号码。尽管该员工编号对员工来说似乎没有价值,这使得他在一开始就更容易泄露信息,但社会工程师可以将该员工编号与收集到的其他信息一起使用,以便更快的找到进入企业网络的方法。
1、使用Metasploit进行被动信息收集
在本章中,我们将详细学习信息收集的各种被动和主动技术。首先,我们将学习分析最常用和最容易被忽视的被动信息收集技术,然后,我们将重点关注通过端口扫描获取信息。Metasploit 具有多种内置扫描功能,以及一些与之集成的第三方工具,以进一步增强端口扫描功能。我们将学习使用内置的扫描仪,以及一些与Metasploit 框架结合使用的第三方扫描工具。让我们开始吧。
准备工作
我们将从公司域名开始收集信息,获取公司有关信息,收集子域名,检测蜜罐、收集电子邮件地址等。
怎么做
Metasploit中有好几个信息收集模块,在本节中,我们将学习使用其中的一些模块,建议你自行探索学习所有的信息收集模块。
DNS记录扫描和枚举
DNS扫描和枚举模块可用于从给定的DNS服务器收集有关域名的信息,执行各种DNS查询(如域传送,反向查询,SRV记录等)
1、程序位于auxiliary模块中,进入msfconsole后,我们可以使用use命令调用我们想要的模块,我们要使用的auxiliary/gather/enum_dns模块。使用use auxiliary/gather/enum_dns 进入模块,输入info可以查看模块的信息,包括作者,描述,基本配置信息等。
msf5 > use auxiliary/gather/enum_dns //切换到 enum_dns模块
msf5 auxiliary(gather/enum_dns) > info //查看模块信息 Name: DNS Record Scanner and Enumerator Module: auxiliary/gather/enum_dnsLicense: Metasploit Framework License (BSD) Rank: Normal
Provided by:Carlos Perez <carlos_perez@darkoperator.com>Nixawk
Check supported:No
Basic options:Name Current SettingRequiredDescription---- ----------------------------------DOMAINyes The target domainENUM_A true yes Enumerate DNS A recordENUM_AXFRtrue yes Initiate a zone transfer against each NS recordENUM_BRT falseyes Brute force subdomains and hostnames via the supplied wordlistENUM_CNAME true yes Enumerate DNS CNAME recordENUM_MXtrue yes Enumerate DNS MX recordENUM_NStrue yes Enumerate DNS NS recordENUM_RVL falseyes Reverse lookup a range of IP addressesENUM_SOA true yes Enumerate DNS SOA recordENUM_SRV true yes Enumerate the most common SRV recordsENUM_TLD falseyes Perform a TLD expansion by replacing the TLD with the IANA TLD listENUM_TXT true yes Enumerate DNS TXT recordIPRANGE noThe target address range or CIDR identifierNSnoSpecify the nameserver to use for queries (default is system DNS)STOP_WLDCRDfalseyes Stops bruteforce enumeration if wildcard resolution is detectedTHREADS1noThreads for ENUM_BRTWORDLIST /usr/share/metasploit-framework/data/wordlists/namelist.txtnoWordlist of subdomains
Description:This module can be used to gather information about a domain from agiven DNS server by performing various DNS queries such as zonetransfers, reverse lookups, SRV record brute forcing, and othertechniques.
References:https://cvedetails.com/cve/CVE-1999-0532/OSVDB (492)
msf5 auxiliary(gather/enum_dns) >
2、设置需要查询的域名,设置线程数量,然后运行它
msf5 auxiliary(gather/enum_dns) > set DOMAIN packtpub.com//设置需要查询的域名
DOMAIN => packtpub.com
msf5 auxiliary(gather/enum_dns) > set THREADS 10 //设置线程数
THREADS => 10
msf5 auxiliary(gather/enum_dns) > run
[*] querying DNS NS records for packtpub.com
[+] packtpub.com NS: dns3.easydns.org.
[+] packtpub.com NS: dns4.easydns.info.[+] packtpub.com NS: dns1.easydns.com.[+] packtpub.com NS: dns2.easydns.net....
[*] Auxiliary module execution completed
msf5 auxiliary(gather/enum_dns) >
从输出信息中可以看到获取的DNS记录
更多
dns扫描和枚举模块也可以用于主动信息收集,通过爆破的方式,设置ENUM_BRT为true,可以通过字典暴力枚举子域名和主机名。WORDLIST选项可以设置字典文件。
CorpWatch 公司名称信息收集
收集公司信息也是必不可少的,我们可以使用 CorpWatch公司名称信息搜索模块:auxiliary/gather/corpwatch_lookup_name,通过该模块可以收集公司的名称,地址,部门和行业信息。该模块与CorpWatch API连接,以获取给定公司名称的公开可用信息。
API申请:api.corpwatch.org
切换到auxiliary/gather/corpwatch_lookup_name模块,设置好公司名字,设置信息显示的数量
msf5 > use auxiliary/gather/corpwatch_lookup_name
msf5 auxiliary(gather/corpwatch_lookup_name) > set COMPANY_NAME Microsoft
COMPANY_NAME => Microsoft
msf5 auxiliary(gather/corpwatch_lookup_name) > set LIMIT 1
LIMIT => 1
msf5 auxiliary(gather/corpwatch_lookup_name) > run
[*] Company Information
---------------------------------
[*] CorpWatch (cw) ID): cw_4803
[*] Company Name: MICROSOFT CORP
[*] Address: ONE MICROSOFT WAY, REDMOND WA 98052-6399
[*] Sector: Business services
[*] Industry: Services-prepackaged software
[*] Auxiliary module execution completed
msf5 auxiliary(gather/corpwatch_lookup_name) >
Tip:此网站被Q,需要配置代理才能使用这个服务。
搜索引擎子域名搜集器
收集子域名是寻找新目标的好办法,我们可以使用搜索引擎子域名收集模块。
模块名:auxiliary/gather/searchengine_subdomains_collector
从Yahoo和Bing收集域名的子域信息
切换到这个模块,设置好要要查询的域名,然后运行
msf5 > use auxiliary/gather/searchengine_subdomains_collector
msf5 auxiliary(gather/searchengine_subdomains_collector) > set TARGET packtpub.com
TARGET => packtpub.com
msf5 auxiliary(gather/searchengine_subdomains_collector) > run
[*] Searching Bing for subdomains from domain:packtpub.com
[*] Searching Yahoo for subdomains from domain:packtpub.com
[+] domain:packtpub.com subdomain: subscription.packtpub.com
[*] Searching Bing for subdomains from ip:54.171.32.62
[*] Searching Yahoo for subdomains from ip:54.171.32.62
[+] ip:54.171.32.62 subdomain: niobase.com
[+] ip:54.171.32.62 subdomain: demandpeoples.vote
[*] Searching Bing for subdomains from ip:34.240.217.226
[-] ip:34.240.217.226 - getaddrinfo: Name or service not known
[*] Searching Yahoo for subdomains from ip:34.240.217.226
[+] ip:34.240.217.226 subdomain: www.snp.org
[+] ip:34.240.217.226 subdomain: answerthepublic.com
[*] Searching Bing for subdomains from ip:34.243.45.171
[-] ip:34.243.45.171 - getaddrinfo: Name or service not known
[*] Searching Yahoo for subdomains from ip:34.243.45.171
[*] Searching Bing for subdomains from ip:34.248.41.77
[*] Searching Yahoo for subdomains from ip:34.248.41.77
[+] ip:34.248.41.77 subdomain: www.buzzi.space
[+] ip:34.248.41.77 subdomain: www.bookishfirst.com
[+] ip:34.248.41.77 subdomain: www.vizlib.com
[+] ip:34.248.41.77 subdomain: www.alphacodeincubate.club
[+] ip:34.248.41.77 subdomain: www.appliedmldays.org
[+] ip:34.248.41.77 subdomain: www.accessable.co.uk
[*] Searching Bing for subdomains from ip:34.254.137.88
[-] ip:34.254.137.88 - getaddrinfo: Name or service not known
[*] Searching Yahoo for subdomains from ip:34.254.137.88
通过这个模块,我们收集到了一些新的目标。
我们已经学习了一些基础模块的使用,让我们来学习使用一些更强大的工具吧。
Censys 搜索
Censys是一个互联网设备搜索引擎,Censys每日通过ZMap和ZGrab扫描互联网上的主机和网站,持续监控互联网上所有可访问的服务器和设备。
我们可以使用Censys搜索模块,通过Censys REST API进行信息查询。可以检索超过100W的网站和设备信息。
Tip:如果需要使用Censys搜索模块,需要去https://censys.io注册获得API和密钥
msf5 > use auxiliary/gather/censys_search
msf5 auxiliary(gather/censys_search) > set CENSYS_DORK packtpub.com //设置目标站点
CENSYS_DORK => packtpub.com
msf5 auxiliary(gather/censys_search) > set CENSYS_SEARCHTYPE ipv4 //设置搜索类型
CENSYS_SEARCHTYPE => ipv4
msf5 auxiliary(gather/censys_search) > set CENSYS_SECRET l5xZ******Z4xzVmIPZ0P //设置censys密钥
CENSYS_SECRET => l5xZa0zJ*******VlCZ4xzVmIPZ0P
msf5 auxiliary(gather/censys_search) > set CENSYS_UID 24d813a********c1b3e80c9e //设置 API_ID
CENSYS_UID => 24d813a******2-89c1b3e80c9e
msf5 auxiliary(gather/censys_search) > run
[+] 109.234.207.108 - 443/https,80/http
[+] 109.234.207.108 - 443/https,80/http
[+] 34.253.81.66 - 443/https,80/http
[+] 34.253.81.66 - 443/https,80/http
[+] 123.252.235.122 - 443/https
[+] 109.234.200.116 - 443/https
[+] 83.166.169.240 - 443/https,22/ssh,80/http
......
[+] 67.198.37.17 - 443/https,80/http,25/smtp,53/dns
[+] 67.198.37.17 - 443/https,80/http,25/smtp,53/dns
[+] 67.198.37.17 - 443/https,80/http,25/smtp,53/dns
[+] 67.198.37.17 - 443/https,80/http,25/smtp,53/dns
[+] 172.104.243.217 - 80/http
[+] 66.42.34.69 - 443/https,80/http
[+] 66.42.34.69 - 443/https,80/http
[*] Auxiliary module execution completed
msf5 auxiliary(gather/censys_search) >
收集到了非常多的IP信息和端口信息
Shodan 搜索引擎
Shodan搜索引擎是一个付费的互联网设备搜索引擎,Shodan运行你搜索网站的Banners信息,设备的元数据,比如设备的位置,主机名,操作系统等。
Tip:同样要使用Shodan搜索模块,需要先去Shodan官网( www.shodan.io)注册获取API Key。
msf5 > use auxiliary/gather/shodan_search
msf5 auxiliary(gather/shodan_search) > set QUERY hostname:packtpub.com //设置目标机器
QUERY => hostname:packtpub.com
msf5 auxiliary(gather/shodan_search) > set SHODAN_APIKEY SDaE*******ABKTxJ3 //设置shodan api key
SHODAN_APIKEY => SDaEijF******dudxCABKTxJ3
msf5 auxiliary(gather/shodan_search) > run
[*] Total: 3 on 1 pages. Showing: 1 page(s)
[*] Collecting data, please wait...
Search Results
==============
IP:Port CityCountry Hostname
------- ----------- --------
83.166.169.228:80 NottinghamUnited Kingdompacktpub.com
83.166.169.248:443NottinghamUnited Kingdomimap.packtpub.com
83.166.169.248:80 NottinghamUnited Kingdomimap.packtpub.com
[*] Auxiliary module execution completed
通过Shodan搜索模块可以找到更多目标的信息,比如 IP 地址,开放的端口,位置信息等。
Shodan 蜜罐检查
检测目标是否为蜜罐,避免浪费时间或因为试图攻击蜜罐而被封锁。使用Shodan Honeyscore Client模块,可以利用Shodan搜索引擎检测目标是否为蜜罐。结果返回为0到1的评级分数,如果是1,则是一个蜜罐。
msf5 > use auxiliary/gather/shodan_honeyscore
msf5 auxiliary(gather/shodan_honeyscore) > set SHODAN_APIKEY SDa******CABKTxJ3
SHODAN_APIKEY => SDaEij*****xCABKTxJ3
msf5 auxiliary(gather/shodan_honeyscore) > set TARGET 83.166.169.248
TARGET => 83.166.169.248
msf5 auxiliary(gather/shodan_honeyscore) > run
[*] Scanning 83.166.169.248
[-] 83.166.169.248 is not a honeypot
[*] 83.166.169.248 honeyscore: 0.0/1.0
[*] Auxiliary module execution completed
msf5 auxiliary(gather/shodan_honeyscore) >
邮箱信息收集
收集邮箱信息是渗透测试中常见的部分,它可以让我们了解互联网上目标的痕迹,以便用于后续的暴力攻击以及网络钓鱼等活动。
我们可以使用auxiliary/gather/search_email_collector模块,该模块是利用搜索引擎获取与目标有关的电子邮件信息。
msf5 > use auxiliary/gather/search_email_collector
msf5 auxiliary(gather/search_email_collector) > set DOMAIN packtpub.com
DOMAIN => packtpub.com
msf5 auxiliary(gather/search_email_collector) > run
[*] Harvesting emails .....
[*] Searching Google for email addresses from packtpub.com
[*] Extracting emails from Google search results...
[*] Searching Bing email addresses from packtpub.com
[*] Extracting emails from Bing search results...
[*] Searching Yahoo for email addresses from packtpub.com
[*] Extracting emails from Yahoo search results...
[*] Located 3 email addresses for packtpub.com
....
[*] Auxiliary module execution completed
从输出信息来看,可以看到该模块利用Google、Bing和Yohoo搜索目标有关的电子邮件地址。
2、使用Metasploit进行主动信息收集
通常来说,通过扫描进行主动信息收集,从这一步开始,我们将直接与目标进行逻辑连接。
端口扫描是一个有趣的信息收集过程,它涉及对目标系统更深入的搜索,但是由于主动端口扫描涉及对目标系统直接访问,可能会被防火墙和入侵检测系统检测到。
怎么做
在Metasploit框架中,有各种各样的端口扫描模块可供我们使用,从而允许我们准确的对目标系统进行探测。我们可以通过search portscan 命令查看这些模块。
msf5 > search portscan
Matching Modules
================ #NameDisclosure DateRankCheckDescription ---------------------------------------- 1auxiliary/scanner/http/wordpress_pingback_access normalYesWordpress Pingback Locator 2auxiliary/scanner/natpmp/natpmp_portscan normalYesNAT-PMP External Port Scanner 3auxiliary/scanner/portscan/ack normalYesTCP ACK Firewall Scanner 4auxiliary/scanner/portscan/ftpbounce normalYesFTP Bounce Port Scanner 5auxiliary/scanner/portscan/syn normalYesTCP SYN Port Scanner 6auxiliary/scanner/portscan/tcp normalYesTCP Port Scanner 7auxiliary/scanner/portscan/xmasnormalYesTCP "XMas" Port Scanner 8auxiliary/scanner/sap/sap_router_portscanner normalNo SAPRouter Port Scanner
TCP 端口扫描
让我们从TCP端口扫描模块开始,看看我们能获取目标的哪些信息?
我们要使用的模块是use auxiliary/scanner/portscan/tcp
Tip:我们将利用此模块扫描渗透测试实验环境的网络,请遵守当地法律法规,请勿直接扫描互联网设备。
msf5 > use auxiliary/scanner/portscan/tcp
msf5 auxiliary(scanner/portscan/tcp) > set RHOSTS 192.168.177.0/24 //设置目标网络
RHOSTS => 192.168.177.0/24
msf5 auxiliary(scanner/portscan/tcp) > set THREADS 100 //设置线程数
THREADS => 100
msf5 auxiliary(scanner/portscan/tcp) > run
[+] 192.168.177.1:- 192.168.177.1:22 - TCP OPEN
[+] 192.168.177.1:- 192.168.177.1:21 - TCP OPEN
Tip:扫描器模块一般使用RHOSTS,表示扫描整个网络,而不是RHOST(单机)
当我们使用Metasploit模块的时候,可以使用show options查看所有可配置的选项,使用show missing查看必须要配置的选项。
msf5 auxiliary(scanner/portscan/tcp) > show options
Module options (auxiliary/scanner/portscan/tcp): Name Current SettingRequiredDescription ---- ---------------------------------- CONCURRENCY10 yes The number of concurrent ports to check per host DELAY0yes The delay between connections, per thread, in milliseconds JITTER 0yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds. PORTS1-10000yes Ports to scan (e.g. 22-25,80,110-900) RHOSTSyes The target address range or CIDR identifier THREADS1yes The number of concurrent threads TIMEOUT1000 yes The socket connect timeout in milliseconds
msf5 auxiliary(scanner/portscan/tcp) > show missing
Module options (auxiliary/scanner/portscan/tcp): NameCurrent SettingRequiredDescription -------------------------------------- RHOSTS yes The target address range or CIDR identifier
msf5 auxiliary(scanner/portscan/tcp) >
TCP SYN 扫描
相对普通的TCP扫描来说,SYN扫描速度更快,因为它不会完成TCP三次握手,而且可以在一定程度上躲避防火墙和入侵检测系统的检测。
使用的模块是auxiliary/scanner/portscan/syn,使用该模块,需要指定端口范围。
msf5 > use auxiliary/scanner/portscan/syn
msf5 auxiliary(scanner/portscan/syn) > set INTERFACE eth0 //设置网卡
INTERFACE => eth0
msf5 auxiliary(scanner/portscan/syn) > set PORTS 1-10000 //设置端口范围
PORTS => 1-10000
msf5 auxiliary(scanner/portscan/syn) > set THREADS 256 //设置线程数
THREADS => 256
msf5 auxiliary(scanner/portscan/syn) > set RHOSTS 192.168.177.0/24 //设置目标网络
RHOSTS => 192.168.177.0/24
msf5 auxiliary(scanner/portscan/syn) > run
3、端口扫描:Nmap 方式
Nmap是安全人员首选的强大网络扫描工具,我们将从初级到高级,详细分析Nmap的各种扫描技术。
准备工作
你可以直接在msfconsole中运行Nmap,但是如果要将结果导入到Metasploit数据库中,需要使用-oX选项导出XML格式的报告文件,然后使用db_import命令将结果导入进来。
怎么做
1、启动msfconsole,然后输入nmap
msf5 > nmap
[*] exec: nmap
Nmap 7.70 ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:Can pass hostnames, IP addresses, networks, etc.Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254-iL <inputfilename>: Input from list of hosts/networks-iR <num hosts>: Choose random targets--exclude <host1[,host2][,host3],...>: Exclude hosts/networks--excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:-sL: List Scan - simply list targets to scan-sn: Ping Scan - disable port scan-Pn: Treat all hosts as online -- skip host discovery-PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes-PO[protocol list]: IP Protocol Ping
2、进行TCP扫描,使用-sT 参数,这是默认和最基本的扫描方式,它会完成TCP三次握手来检测目标机器上的端口。
msf5 > nmap -sT 192.168.177.144[*] exec: nmap -sT 192.168.177.144
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 12:20 CSTNmap scan report for 192.168.177.144
Host is up (0.00044s latency).
Not shown: 990 filtered portsPORTSTATE SERVICE21/tcpopenftp22/tcpopenssh80/tcpopenhttp
4848/tcpopenappserv-http
8022/tcpopenoa-system8080/tcpopenhttp-proxy
8383/tcpopenm2mservices9200/tcpopenwap-wsp49153/tcp openunknown49154/tcp openunknownMAC Address: 00:0C:29:D7:02:F6 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 5.31 secondsmsf5 >
Tip:当未指定端口范围的时候,nmap默认扫描常见的1000个端口。
3、进行TCP SYN扫描,使用-sS参数,SYN扫描不会建立完整的TCP三次握手过程,也称半开连接扫描,SYN扫描被认为是一种比较隐蔽的扫描技术。
msf5 > nmap -sS 192.168.177.144 -p 22-5000
[*] exec: nmap -sS 192.168.177.144 -p 22-5000
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 12:29 CST
Nmap scan report for 192.168.177.144
Host is up (0.00037s latency).
Not shown: 4975 filtered ports
PORT STATE SERVICE
22/tcp openssh
80/tcp openhttp
1617/tcp opennimrod-agent
4848/tcp openappserv-http
MAC Address: 00:0C:29:D7:02:F6 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 14.45 seconds
msf5 >
大多数情况下,TCP连接扫描和SYN扫描输出结果是相似的,唯一的区别是,SYN更难被防火墙和IDS检测到。当然现代的防火墙几乎都能捕获SYN扫描,-p参数设置我们想要扫描的端口范围。
4、UDP扫描使用-sU参数,用于识别目标机器上开放的UDP端口扫描技术,UDP扫描会发送空的(没有数据)UDP报头到目标端口,仅通过ICMP消息来判断目标端口是否开放。
msf5 > nmap -sU 192.168.177.144
[*] exec: nmap -sU 192.168.177.144
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 12:36 CST
Nmap scan report for 192.168.177.144
Host is up (0.00035s latency).
Not shown: 999 open|filtered ports
PORTSTATE SERVICE
137/udp opennetbios-ns
MAC Address: 00:0C:29:D7:02:F6 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 16.36 seconds
msf5 >
TIp:不指定端口范围的情况下,默认扫描常见的1000个UDP端口
它是如何工作的
我们分析了三种不同类型的nmap扫描,它们在渗透测试中非常有用。Nmap提供了许多种不同的扫描方是,这里我们只重点讨论这三种,即TCP连接扫描、SYN隐蔽扫描和UDP扫描。可以将Nmap的不同扫描选项组合到一起使用,已便对目标进行更高级和更复杂的扫描。
在渗透测试中,扫描过程可以提供很多有用的结果。扫描中收集的信息构成了后续渗透测试的基础,因此强烈建议你掌握扫描类型的相关知识,让我们更深入了解下我们刚刚学习的这些扫描技术。
TCP连接扫描是最基本的扫描技术,此扫描过程会与目标建立完整的TCP连接。它使用操作系统网络功能建立连接,扫描程序向目标发送SYN数据包,如果端口开放,目标会返回ACK消息。然后扫描程序向目标发送ACK报文,成功建立连接,这就是所谓的三次握手过程。连接打开后立即终止,这种技术有它的优点,但很容易被防火墙和IDS检测到。
SYN扫描是另一种类型的TCP扫描,但它不会与目标建立完整的连接。 它不使用操作系统的网络功能,而上生成原始IP包并监视响应报文。如果目标端口是开放的,目标会响应ACK消息,然后扫描程序会发送RST结束连接。因此又称为半开扫描。这也被认为是一种隐蔽扫描技术,可以避免被一些防火墙和IDS检测到。
UDP扫描是一种无连接扫描技术,因此,无论目标是否收到数据包,都不会返回信息给扫描程序。如果目标端口关闭,则扫描程序会收到ICMP端口不可达的消息。如果没有消息,扫描器会认为端口是开放的。由于防火墙会阻止数据包,此方法会返回错误结果,因此不会生成响应消息,扫描器会报告端口为打开状态。
更多
让我们进一步探索Nmap扫描,学习如何将不同扫描类型组合到一起
操作系统和版本检测
除了端口扫描之外,Nmap还提供一些高级的选项,这些选项可以帮助我们获取目标的更多信息。其他使用最广泛的选项之一是操作系统识别选项:-O。可以帮助我们识别目标计算机的操作系统类型。
以下是操作系统识别扫描结果:
msf5 > nmap -O 192.168.177.144
[*] exec: nmap -O 192.168.177.144
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 13:12 CST
Nmap scan report for 192.168.177.144
Host is up (0.00035s latency).
Not shown: 990 filtered ports
PORTSTATE SERVICE
21/tcpopenftp
22/tcpopenssh
80/tcpopenhttp
4848/tcpopenappserv-http
8022/tcpopenoa-system
8080/tcpopenhttp-proxy
8383/tcpopenm2mservices
9200/tcpopenwap-wsp
49153/tcp openunknown
49154/tcp openunknown
MAC Address: 00:0C:29:D7:02:F6 (VMware)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|specialized|phone
Running: Microsoft Windows 2008|8.1|7|Phone|Vista
OS CPE: cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8.1 cpe:/o:microsoft:windows_7::-:professional cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows cpe:/o:microsoft:windows_vista::- cpe:/o:microsoft:windows_vista::sp1
OS details: Microsoft Windows Server 2008 R2 or Windows 8.1, Microsoft Windows 7 Professional or Windows 8, Microsoft Windows Embedded Standard 7, Microsoft Windows Phone 7.5 or 8.0, Microsoft Windows Vista SP0 or SP1, Windows Server 2008 SP1, or Windows 7, Microsoft Windows Vista SP2, Windows 7 SP1, or Windows Server 2008
Network Distance: 1 hop
OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.51 seconds
如你所见,Nmap成功识别了目标机器的操作系统类型。
另外一种广泛使用的高级选项是对开放端口服务的版本检测,参数是-sV。它可以与之前的扫描参数结合使用。
msf5 > nmap -sV 192.168.177.144
[*] exec: nmap -sV 192.168.177.144
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 13:17 CST
Nmap scan report for 192.168.177.144
Host is up (0.00043s latency).
Not shown: 990 filtered ports
PORTSTATE SERVICE VERSION
21/tcpopenftp Microsoft ftpd
22/tcpopenssh OpenSSH 7.1 (protocol 2.0)
80/tcpopenhttpMicrosoft IIS httpd 7.5
4848/tcpopenssl/appserv-http?
8022/tcpopenhttpApache Tomcat/Coyote JSP engine 1.1
8080/tcpopenhttpSun GlassFish Open Source Edition4.0
8383/tcpopenssl/httpApache httpd
9200/tcpopenhttpElasticsearch REST API 1.1.1 (name: Turac; Lucene 4.7)
49153/tcp openmsrpc Microsoft Windows RPC
49154/tcp openmsrpc Microsoft Windows RPC
MAC Address: 00:0C:29:D7:02:F6 (VMware)
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 82.54 seconds
msf5 >
隐蔽扫描
有时候必须以隐蔽方式进行扫描,默认情况下,防火墙和IDS日志会记录你的IP,nmap中提供了-D选项来增加迷惑性。
此选项并不能阻止防火墙和IDS记录你的IP,只是增加迷惑性,它会通过添加其他IP地址,让目标以为是多个IP在攻击。比如,你添加了两个诱导IP,防火墙或IDS日志会显示数据包是从三个不同的IP地址发送的,一个是你的,其他两个是你添加的虚假地址。
msf5 > nmap -sT 192.168.177.144 -D 192.168.177.34,192.168.177.56
这个例子中-D后面的IP地址是虚假的IP地址,它会和原始IP地址一同出现在目标机器的网络日志文件中,这会迷惑对方的网络管理员,让他们以为这三个IP都是伪造的。但不能添加太多虚假IP地址,不然会影响扫描结果。因此,只要使用一定数量的地址就行。
4、端口扫描:db_nmap 方式
使用db_nmap的好处在于可以将结果直接存储到Metasploit数据库中,而不再需要db_import进行导入。
准备工作
db_nmap命令是msfconsole中的一部分,所以只需要启动msfconsole并使用就好了。参数就和在命令行中单独使用nmap一样。
怎么做
在第一章中,我们已经学习了db_nmap的一些基本用法,所以现在我们将了解一些更高级的特性。在下面的例子中,你将学习如何使用其中的一些特性。
msf5 > db_nmap -Pn -sTV -T4 --open --min-parallelism 64 --version-all 192.168.177.144 -p -
-Pn:跳过主机发现过程
-sTV:TCP扫描和检测开放端口服务版本信息
-T4:设置时间模板,加速扫描
--open:只显示开放端口
--min-parallelism:探测报文的并发数
--version-all:尝试每个探测,保证对每个端口尝试每个探测报文,获取服务更具体的版本
-p -:表示扫描所有的端口(1-65535)
输出结果如下:
msf5 > db_nmap -Pn -sTV -T4 --open --min-parallelism 64 --version-all 192.168.177.144 -p -
[*] Nmap: Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 13:41 CST
[*] Nmap: Nmap scan report for 192.168.177.144
[*] Nmap: Host is up (0.00059s latency).
[*] Nmap: Not shown: 65516 filtered ports
[*] Nmap: Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
[*] Nmap: PORTSTATE SERVICE VERSION
[*] Nmap: 21/tcpopenftp Microsoft ftpd
[*] Nmap: 22/tcpopenssh OpenSSH 7.1 (protocol 2.0)
[*] Nmap: 80/tcpopenhttpMicrosoft IIS httpd 7.5
[*] Nmap: 1617/tcpopenrmiregistry Java RMI
[*] Nmap: 4848/tcpopenssl/appserv-http?
[*] Nmap: 5985/tcpopenhttpMicrosoft HTTPAPI httpd 2.0 (SSDP/UPnP)
[*] Nmap: 8020/tcpopenhttpApache httpd
[*] Nmap: 8022/tcpopenhttpApache Tomcat/Coyote JSP engine 1.1
[*] Nmap: 8027/tcpopenunknown
[*] Nmap: 8080/tcpopenhttpSun GlassFish Open Source Edition4.0
[*] Nmap: 8282/tcpopenhttpApache Tomcat/Coyote JSP engine 1.1
[*] Nmap: 8383/tcpopenssl/httpApache httpd
[*] Nmap: 8484/tcpopenhttpJetty winstone-2.8
[*] Nmap: 8585/tcpopenhttpApache httpd 2.2.21 ((Win64) PHP/5.3.10 DAV/2)
[*] Nmap: 9200/tcpopenhttpElasticsearch REST API 1.1.1 (name: Turac; Lucene 4.7)
[*] Nmap: 49153/tcp openmsrpc Microsoft Windows RPC
[*] Nmap: 49154/tcp openmsrpc Microsoft Windows RPC
[*] Nmap: 49207/tcp openrmiregistry Java RMI
[*] Nmap: 49209/tcp opentcpwrapped
[*] Nmap: Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
[*] Nmap: Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 593.00 seconds
msf5 >
Nmap 脚本引擎
Nmap脚本引擎(NSE)是Nmap最强大和最灵活的特性之一,它可以将Nmap转为漏洞扫描器使用。NSE有超过600个脚本,分为好几类,有非侵入式的,也有侵入式的,比如暴力破解,漏洞利用和拒绝服务攻击。你可以在Kali的/user/share/nmap/scripts目录中找到这些脚本。或者用locate搜索*.nse也可以找到。
root@osboxes:~# locate *.nse
/usr/share/nmap/scripts/targets-xml.nse
/usr/share/nmap/scripts/teamspeak2-version.nse
/usr/share/nmap/scripts/telnet-brute.nse
/usr/share/nmap/scripts/telnet-encryption.nse
/usr/share/nmap/scripts/telnet-ntlm-info.nse
/usr/share/nmap/scripts/tftp-enum.nse
/usr/share/nmap/scripts/tls-alpn.nse
/usr/share/nmap/scripts/tls-nextprotoneg.nse
/usr/share/nmap/scripts/tls-ticketbleed.nse
/usr/share/nmap/scripts/tn3270-screen.nse
/usr/share/nmap/scripts/tor-consensus-checker.nse
/usr/share/nmap/scripts/traceroute-geolocation.nse
/usr/share/nmap/scripts/tso-brute.nse
/usr/share/nmap/scripts/tso-enum.nse
/usr/share/nmap/scripts/unittest.nse
/usr/share/nmap/scripts/unusual-port.nse
它的用法如下:
nmap --script <scriptname> <host ip>
在db_nmap中同样可以使用,我们试试用NSE脚本来查找目标的HTTP/HTTPS漏洞
msf5 > db_nmap --open -sTV -Pn -p 80,8020,8022,8080,8282,8383,8484,8585,9200 --script=http-vhosts,http-userdir-enum,http-apache-negotiation,http-backup-
finder,http-config-backup,http-default-accounts,http-methods,http-method-tamper,http-passwd,http-robots.txt,ssl-poodle,ssl-heartbleed,http-webdav-scan,h
ttp-iis-webdav-vuln 192.168.177.144
[*] Nmap: Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-12 14:03 CST
[*] Nmap: Nmap scan report for 192.168.177.144
[*] Nmap: Host is up (0.00052s latency).[*] Nmap: PORT STATE SERVICEVERSION[*] Nmap: 80/tcp openhttp Microsoft IIS httpd 7.5
[*] Nmap: | http-methods:
[*] Nmap: | Supported Methods: OPTIONS TRACE GET HEAD POST[*] Nmap: |_Potentially risky methods: TRACE[*] Nmap: |_http-server-header: Microsoft-IIS/7.5[*] Nmap: | http-vhosts:[*] Nmap: |_127 names had status 200[*] Nmap: 8020/tcp openhttp Apache httpd
[*] Nmap: |_http-iis-webdav-vuln: WebDAV is DISABLED. Server is not currently vulnerable.
[*] Nmap: | http-methods:[*] Nmap: | Supported Methods: GET HEAD POST PUT DELETE OPTIONS
[*] Nmap: |_Potentially risky methods: PUT DELETE
[*] Nmap: |_http-server-header: Apache
[*] Nmap: | http-vhosts:
从输出结果看到,目标主机的HTTP/HTTPS服务启用了一些危险的方法,比如DELETE/PUT等。
5、基于ARP的主机发现
通过ARP请求可以枚举本地网络中的存活主机,为我们提供了一种简单而快速识别目标方法。
准备工作
当攻击者和目标机器处于同一个局域网时,可以通过执行ARP扫描发现主机
怎么做
1、使用ARP扫描模块(auxiliary/scanner/discovery/arp_sweep),设置目标地址范围和并发线程,然后运行。
msf5 > use auxiliary/scanner/discovery/arp_sweep
msf5 auxiliary(scanner/discovery/arp_sweep) > set RHOSTS 192.168.177.0/24
RHOSTS => 192.168.177.0/24
msf5 auxiliary(scanner/discovery/arp_sweep) > set THREADS 256
THREADS => 256
msf5 auxiliary(scanner/discovery/arp_sweep) > run
[+] 192.168.177.1 appears to be up (VMware, Inc.).
[+] 192.168.177.2 appears to be up (VMware, Inc.).
[+] 192.168.177.144 appears to be up (VMware, Inc.).
[+] 192.168.177.254 appears to be up (VMware, Inc.).
[+] 192.168.177.2 appears to be up (VMware, Inc.).
[+] 192.168.177.254 appears to be up (VMware, Inc.).
[*] Scanned 256 of 256 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/discovery/arp_sweep) >
2、如果启动了数据库,结果将存储在Metasploit数据库中,可以使用hosts显示已经发现的主机。
msf5 auxiliary(scanner/discovery/arp_sweep) > hosts
Hosts
=====
addressmacnameos_nameos_flavoros_sppurposeinfocomments
------------------------------------------------------
34.240.217.226
34.248.41.77
54.171.32.62
192.168.177.100:50:56:c0:00:08Unknowndevice
192.168.177.200:50:56:fa:c4:65
192.168.177.13900:0c:29:c6:a9:e5Unknowndevice
192.168.177.14200:0c:29:92:63:8cLinux 2.6.Xserver
192.168.177.14400:0c:29:d7:02:f6Unknowndevice
192.168.177.25400:50:56:ec:3c:cf
6、UDP 服务识别
UDP服务扫描模块运行我们检测模板系统的UDP服务。由于UDP是一个无连接协议(不面向连接),所以探测比TCP困难。使用UDP服务探测模块可以帮助我们找到一些有用的信息。
怎么做
选择auxiliary/scanner/discovery/udp_sweep模块,设置目标范围,然后运行扫描即可
msf5 > use auxiliary/scanner/discovery/udp_sweep
msf5 auxiliary(scanner/discovery/udp_sweep) > set RHOSTS 192.168.177.0/24
RHOSTS => 192.168.177.144/24
msf5 auxiliary(scanner/discovery/udp_sweep) > run
[*] Sending 13 probes to 192.168.177.0->192.168.177.255 (256 hosts)
[*] Discovered NetBIOS on 192.168.177.144:137 (METASPLOITABLE3:<20>:U :METASPLOITABLE3:<00>:U :WORKGROUP:<00>:G :00:0c:29:d7:02:f6)
[*] Discovered SNMP on 192.168.177.144:161 (Hardware: Intel64 Family 6 Model 94 Stepping 3 AT/AT COMPATIBLE - Software: Windows Version 6.1 (Build 7601 Multiprocessor Free))
[*] Scanned 256 of 256 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/discovery/udp_sweep) >
7、SMB扫描和枚举
多年来,SMB协议(一种在 Microsoft Windows系统中使用网络文件共享的协议)已被证明是最容易被攻击的协议之一,它允许攻击者枚举目标文件和用户,甚至远程代码执行。
怎么做
使用无需身份验证的SMB共享枚举模块,可以帮助我们收集一些有价值的信息,比如共享名称,操作系统版本等。
模块名:auxiliary/scanner/smb/smb_enumshares
msf5 > use auxiliary/scanner/smb/smb_enumshares
msf5 auxiliary(scanner/smb/smb_enumshares) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_enumshares) > run
[-] 192.168.177.144:139 - Login Failed: Unable to Negotiate with remote host
[*] 192.168.177.144:- Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
SMB共享枚举模块在后续的攻击阶段也非常有用,通过提供凭据,可以轻松的枚举共享和文件列表
msf5 auxiliary(scanner/smb/smb_enumshares) > set SMBUSER vagrant
SMBUSER => vagrant
msf5 auxiliary(scanner/smb/smb_enumshares) > set SMBPASS vagrant
SMBPASS => vagrant
msf5 auxiliary(scanner/smb/smb_enumshares) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_enumshares) > set ShowFiles true
ShowFiles => true
msf5 auxiliary(scanner/smb/smb_enumshares) > set SpiderShares true
SpiderShares => true
msf5 auxiliary(scanner/smb/smb_enumshares) > run
[-] 192.168.177.144:139 - Login Failed: Unable to Negotiate with remote host
[+] 192.168.177.144:445 - ADMIN$ - (DS) Remote Admin
[+] 192.168.177.144:445 - C$ - (DS) Default share
[+] 192.168.177.144:445 - IPC$ - (I) Remote IPC
[*] 192.168.177.144:- Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smb/smb_enumshares) >
Metasploit还提供其他的一些SMB扫描模块,让我们看看其他模块的用法。
3、SMB版本检测模块可以检测SMB的版本
msf5 > use auxiliary/scanner/smb/smb_version
msf5 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_version) > run
[+] 192.168.177.144:445 - Host is running Windows 2008 R2 Standard SP1 (build:7601) (name:METASPLOITABLE3) (workgroup:WORKGROUP )
[*] 192.168.177.144:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
4、用户枚举模块可以通过SAM RPC服务枚举哪些用户存在
msf5 > use auxiliary/scanner/smb/smb_enumusers
msf5 auxiliary(scanner/smb/smb_enumusers) > set SMBUSER vagrant
SMBUSER => vagrant
msf5 auxiliary(scanner/smb/smb_enumusers) > set SMBPASS vagrant
SMBPASS => vagrant
msf5 auxiliary(scanner/smb/smb_enumusers) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_enumusers) > run
[+] 192.168.177.144:445 - METASPLOITABLE3 [ Administrator, anakin_skywalker, artoo_detoo, ben_kenobi, boba_fett, chewbacca, c_three_pio, darth_vader, greedo, Guest, han_solo, jabba_hutt, jarjar_binks, kylo_ren, lando_calrissian, leah_organa, luke_skywalker, sshd, sshd_server, vagrant ] ( LockoutTries=0 PasswordMin=0 )
[*] 192.168.177.144:- Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smb/smb_enumusers) >
5、SMB登录检测模块可以测试SMB登录
msf5 > use auxiliary/scanner/smb/smb_login
msf5 auxiliary(scanner/smb/smb_login) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_login) > set SMBUSER vagrant
SMBUSER => vagrant
msf5 auxiliary(scanner/smb/smb_login) > set PASS_FILE /root/password.lst
PASS_FILE => /root/password.lst
msf5 auxiliary(scanner/smb/smb_login) > run
[*] 192.168.177.144:445 - 192.168.177.144:445 - Starting SMB login bruteforce
[-] 192.168.177.144:445 - 192.168.177.144:445 - Failed: '.\vagrant:admin',
[-] 192.168.177.144:445 - 192.168.177.144:445 - Failed: '.\vagrant:admin123',
[+] 192.168.177.144:445 - 192.168.177.144:445 - Success: '.\vagrant:vagrant' Administrator
[*] 192.168.177.144:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smb/smb_login) >
6、MS17-010永恒之蓝漏洞检测模块
msf5 > use auxiliary/scanner/smb/smb_ms17_010
msf5 auxiliary(scanner/smb/smb_ms17_010) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/smb/smb_ms17_010) > run
[+] 192.168.177.144:445 - Host is likely VULNERABLE to MS17-010! - Windows Server 2008 R2 Standard 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.177.144:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smb/smb_ms17_010) >
7、其他的模块,都在 auxiliary/scanner/smb/中,可以敲 TAB键查看,你可以一个个学习,这里就不一一举例讲解。
msf5 > use auxiliary/scanner/smb/
use auxiliary/scanner/smb/impacket/dcomexecuse auxiliary/scanner/smb/smb1
use auxiliary/scanner/smb/smb_login
.....
8、SSH 版本扫描和检测
SSH是一个广泛使用的远程登录程序。它使用强大的加密提供身份认证和保证机密性。在本节中,我们将通过SSH版本扫描模块,确定目标使用的SSH版本,确定是否为易受攻击的SSH版本,如果是,我们可以利用它。
准备工作
在之前的扫描中,我们发现目标机器开放了TCP 22端口,这也是SSH的默认端口,我们用SSH版本探测模块来获取目标系统上运行的SSH版本信息。
怎么做
1、模块名称:auxiliary/scanner/ssh/ssh_version
msf5 > use auxiliary/scanner/ssh/ssh_version
msf5 auxiliary(scanner/ssh/ssh_version) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/ssh/ssh_version) > run
[+] 192.168.177.144:22- SSH server version: SSH-2.0-OpenSSH_7.1 ( service.version=7.1 service.vendor=OpenBSD service.family=OpenSSH service.product=OpenSSH service.cpe23=cpe:/a:openbsd:openssh:7.1 service.protocol=ssh fingerprint_db=ssh.banner )
[*] 192.168.177.144:22- Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/ssh_version) >
当然这里的RHOSTS 选项也可以指定为网络地址,从而扫描整个网段。
获取版本信息之后,我们就可以搜索该版本的漏洞。
2、测试常用口令登录SSH,可以使用SSH登录测试模块
msf5 > use auxiliary/scanner/ssh/ssh_login
msf5 auxiliary(scanner/ssh/ssh_login) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/ssh/ssh_login) > set USERNAME user
USERNAME => user
msf5 auxiliary(scanner/ssh/ssh_login) > set PASS_FILE /root/password.lst
PASS_FILE => /root/password.lst
msf5 auxiliary(scanner/ssh/ssh_login) > run
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
3、如果登录成功了,可以用sessions 查看会话和与目标进行会话交互
msf5 auxiliary(scanner/ssh/ssh_login) > sessions
Active sessions
===============
No active sessions.
9、FTP扫描
使用FTP扫描模块对网络中所有的FTP服务进行版本扫描
准备工作
FTP版本扫描模块运行我们检测正在运行的FTP版本
怎么做
1、使用auxiliary/scanner/ftp/ftp_version模块,设置好扫描范围和线程,就可以运行扫描了。
msf5 > use auxiliary/scanner/ftp/ftp_version
msf5 auxiliary(scanner/ftp/ftp_version) > set RHOSTS 192.168.177.0/24
RHOSTS => 192.168.177.0/24
msf5 auxiliary(scanner/ftp/ftp_version) > set THREADS 256
THREADS => 256
msf5 auxiliary(scanner/ftp/ftp_version) > run
[+] 192.168.177.1:21- FTP Banner: '220 Serv-U FTP Server v15.0 ready...\x0d\x0a'
[+] 192.168.177.144:21- FTP Banner: '220 Microsoft FTP Service\x0d\x0a'
[*] 192.168.177.0/24:21 - Scanned78 of 256 hosts (30% complete)
[*] 192.168.177.0/24:21 - Scanned 123 of 256 hosts (48% complete)
[*] 192.168.177.0/24:21 - Scanned 125 of 256 hosts (48% complete)
[*] 192.168.177.0/24:21 - Scanned 129 of 256 hosts (50% complete)
[*] 192.168.177.0/24:21 - Scanned 130 of 256 hosts (50% complete)
[*] 192.168.177.0/24:21 - Scanned 255 of 256 hosts (99% complete)
[*] 192.168.177.0/24:21 - Scanned 256 of 256 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ftp/ftp_version) >
2、与之前的扫描一样,扫描结果会保存到数据库中,可以使用services命令查看已经检测的服务信息。
msf5 auxiliary(scanner/ftp/ftp_version) > services
Services ========
host port protonamestateinfo
---- ---- ------------------
192.168.177.121 tcpftp open 220 Serv-U FTP Server v15.0 ready...\x0d\x0a
192.168.177.14421 tcpftp open 220 Microsoft FTP Service\x0d\x0a
192.168.177.14422 tcpssh open SSH-2.0-OpenSSH_7.1
192.168.177.14480 tcphttpopen Microsoft IIS httpd 7.5
10、SMTP枚举
SMTP服务偶两个允许枚举用户的内部命令:VRFY(确认有效用户名)和EXPN(显示用户的实际地址,别名和邮件列表)
准备工作
SMTP用户枚举模块通过实现这些SMTP命令从而枚举有效的用户列表
怎么做
默认情况下,SMTP枚举模块使用unix_users.txt(文件位于: /usr/share/metasploit- framework/data/wordlists/)文件作为字典,你也可以指定自己的字典文件。切换到auxiliary/scanner/smtp/smtp_enum模块,设置好目标和线程,然后开始。
msf5 > use auxiliary/scanner/smtp/smtp_enummsf5 auxiliary(scanner/smtp/smtp_enum) > set RHOSTS 192.168.177.145
RHOSTS => 192.168.177.145
msf5 auxiliary(scanner/smtp/smtp_enum) > set THREADS 256THREADS => 256msf5 auxiliary(scanner/smtp/smtp_enum) > run[*] 192.168.177.145:25- 192.168.177.145:25 Banner: 220 metasploitable.localdomain ESMTP Postfix (Ubuntu)
[+] 192.168.177.145:25- 192.168.177.145:25 Users found: , backup, bin, daemon, distccd, ftp, games, gnats, irc, libuuid, list, lp, mail, man, news, nobody, postgres, postmaster, proxy, service, sshd, sync, sys, syslog, user, uucp, www-data
[*] 192.168.177.145:25- Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smtp/smtp_enum) >
输出结果中显示了目标Metasploitable 2中有效的SMTP用户
11、SNMP枚举
简单网络管理协议(SNMP)是用于管理网络设备的协议,比如监控设备的状态信息,接口信息,网络接口的数据吞吐量等。通过SNMP扫描器可以找到特定系统的大量信息。本节中,我们将学习如何使用它。
准备工作
Metasploit有一个专门用于扫描 SNMP 设备的内置辅助模块。在进行攻击之前必须先了解它。首先,团体字符串(只读/读写)在可以在设备本身上挖掘或修改的信息类型中起着重要作用。管理信息库 (MIB) 接口允许我们查询设备和提取信息。
Tip:如果目标系统为Windows且配置了SNMP(通常是RO/RW团体字符串),我们可以提取系统重启时间,系统上的用户名,系统网络信息,运行的服务等各种有价值的信息。
当通过SNMP查询时候,可以通过MIB API进行设备信息提取。Metasploit在其数据库中加载默认MIB列表,它们用于查询设备获取更多信息。
怎么做
1、通过SNMP登录模块可以通过公共团体名登录到目标系统。
msf5 > use auxiliary/scanner/snmp/snmp_login
msf5 auxiliary(scanner/snmp/snmp_login) > set RHOSTS 192.168.177.144,145
RHOSTS => 192.168.177.144,145
msf5 auxiliary(scanner/snmp/snmp_login) > run
[+] 192.168.177.144:161 - Login Successful: public (Access level: read-only); Proof (sysDescr.0): Hardware: Intel64 Family 6 Model 94 Stepping 3 AT/AT COMPATIBLE - Software: Windows Version 6.1 (Build 7601 Multiprocessor Free)
[*] Scanned 1 of 2 hosts (50% complete)
[*] Scanned 2 of 2 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/snmp/snmp_login) >
2、通过SNMP扫描模块收集信息,比如端口,服务,主机名,进程等信息。
msf5 > use auxiliary/scanner/snmp/snmp_enum
msf5 auxiliary(scanner/snmp/snmp_enum) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/snmp/snmp_enum) > run[+] 192.168.177.144, Connected.
[*] System information:
Host IP : 192.168.177.144
Hostname: metasploitable3
Description : Hardware: Intel64 Family 6 Model 94 Stepping 3 AT/AT COMPATIBLE - Software: Windows Version 6.1 (Build 7601 Multiprocess
r Free)Contact : -Location: -
Uptime snmp : 01:18:04.40
Uptime system : 01:16:09.69
System date : 2019-4-12 16:44:05.7[*] User accounts:
["sshd"]
["Guest"]
["greedo"]
["vagrant"]
["han_solo"]
["kylo_ren"]
["boba_fett"]
["chewbacca"]
["ben_kenobi"] .....
[*] Network information:IP forwarding enabled : no
Default TTL : 128TCP segments received : 70121TCP segments sent : 70024
TCP segments retrans: 23
Input datagrams : 634Delivered datagrams : 825
....
[*] Network interfaces:
Interface : [ up ] Software Loopback Interface 1
Id: 1
Mac Address : :::::
....
12、HTTP扫描
超文本传输协议(HTTP)是一个应用层协议,它是万维网通信的基础。它被众多的应用程序使用,从物联网(IoT)设备到移动应用程序。它也是搜索漏洞的好地方。
准备工作
HTTP SSL证书检测模块可以检测Web服务器的证书。
Robots.txt内容检测模块可以搜索robots.txt文件并分析里面的内容。
如果服务端允许未授权的PUT请求方法,则可以将任意的Web页面插入到网站目录中,从而导致执行破坏性的代码或者往服务器填充垃圾数据,从而造成拒绝服务攻击。
Jenkins-CI HTTP扫描模块可以枚举未授权的Jenkins-CI服务。
怎么做
1、检测目标的HTTP SSL证书
msf5 > use auxiliary/scanner/http/cert
msf5 auxiliary(scanner/http/cert) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/http/cert) > set RPORT 8383
RPORT => 8383
msf5 auxiliary(scanner/http/cert) > run
[*] 192.168.177.144:8383- 192.168.177.144 - 'Desktop Central' : '2010-09-08 12:24:44 UTC' - '2020-09-05 12:24:44 UTC'
[*] 192.168.177.144:8383- Scanned 1 of 1 hosts (100% complete)
2、检测robots.txt文件
msf5 > use auxiliary/scanner/http/robots_txt
msf5 auxiliary(scanner/http/robots_txt) > set PATH /mutillidae
PATH => /mutillidae
msf5 auxiliary(scanner/http/robots_txt) > set RHOSTS 192.168.177.145
RHOSTS => 192.168.177.145
msf5 auxiliary(scanner/http/robots_txt) > run
[*] [192.168.177.145] /mutillidae/robots.txt found
[+] Contents of Robots.txt:
User-agent: *
Disallow: ./passwords/
Disallow: ./config.inc
Disallow: ./classes/
Disallow: ./javascript/
Disallow: ./owasp-esapi-php/
Disallow: ./documentation/
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/http/robots_txt) >
3、HTTP可写路径 PUT/DELETE 文件访问模块可以通过PUT和DELETE请求上传和删除Web服务器上的内容。
msf5 > use auxiliary/scanner/http/http_put
msf5 auxiliary(scanner/http/http_put) > set PATH /uploads
PATH => /uploads
msf5 auxiliary(scanner/http/http_put) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/http/http_put) > set RPORT 8585
RPORT => 8585
msf5 auxiliary(scanner/http/http_put) > run
[+] File uploaded: http://192.168.177.144:8585/uploads/msf_http_put_test.txt
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/http/http_put) >
4、Jenkins-CI扫描模块
msf5 > use auxiliary/scanner/http/jenkins_enum
msf5 auxiliary(scanner/http/jenkins_enum) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/http/jenkins_enum) > set RPORT 8484
RPORT => 8484
msf5 auxiliary(scanner/http/jenkins_enum) > set TARGETURI /
TARGETURI => /
msf5 auxiliary(scanner/http/jenkins_enum) > run
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
13、WinRM扫描和爆破
Windows远程管理(WinRM)是WS-Management协议的Microsoft实现。该协议是基于简单对象访问协议(SOAP)的、防火墙友好的标准协议,使来自不同供应商的硬件和操作系统能够互相交互。
准备工作
WinRM身份认证方法检测模块通过向目标发现HTTP/HTTPS请求,检测是否为WinRM服务,如果是,将会检测支持的身份认证方法。
通过SMB_login模块可以检索目标的登录凭证。我们可以用WinRM命令运行模块测试是否可以通过WinRM服务运行Windows命令。
怎么做
1、WinRM身份认证检测
msf5 > use auxiliary/scanner/winrm/winrm_auth_methods
msf5 auxiliary(scanner/winrm/winrm_auth_methods) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/winrm/winrm_auth_methods) > run
[+] 192.168.177.144:5985: Negotiate protocol supported
[+] 192.168.177.144:5985: Basic protocol supported
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/winrm/winrm_auth_methods) >
2、使用WinRM命令运行模块
msf5 > use auxiliary/scanner/winrm/winrm_cmd
msf5 auxiliary(scanner/winrm/winrm_cmd) > set CMD hostname
CMD => hostname
msf5 auxiliary(scanner/winrm/winrm_cmd) > set RHOSTS 192.168.177.144
RHOSTS => 192.168.177.144
msf5 auxiliary(scanner/winrm/winrm_cmd) > set USERNAME Administrator
USER => Administrator
msf5 auxiliary(scanner/winrm/winrm_cmd) > set PASSWORD vagrant
PASSWORD => vagrant
msf5 auxiliary(scanner/winrm/winrm_cmd) > run
[+] 192.168.177.144:5985 : metasploitable3
[+] Results saved to /root/.msf4/loot/20190412172543_default_192.168.177.144_winrm.cmd_result_858044.txt
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/winrm/winrm_cmd) >
可以看到,我们成功在目标机上执行了命令。
到目前为止,我们已经了解了端口扫描的基础知识,以及学会了Nmap的使用。通过其他一些工具的许欸,进一步提高了扫描和信息收集的技术。在接下来的小节中,我们将介绍其他几种扫描目标可用服务和端口的工具,这些工具还可以帮助我们确定特定服务和端口可能存在的漏洞类型。
剩下的三小节,关于三种漏洞扫描器与Metasploit结合使用的技术和方法将在下一篇文章中讲解,敬请期待
14、与Nessus结合使用
15、与NeXpose结合使用
16、与OpenVAS结合使用
说明
原书:《Metasploit Penetration Testing Cookbook - Third Edition》
本文由合天网安实验室编译,转载请注明来源。
文章来自于网络,如果侵犯了您的权益,请联系站长删除!