Metasploit 渗透测试手册第三版 第二章 信息收集与扫描(翻译)

栏目: 编程工具 · 发布时间: 5年前

内容简介:在本章中,我们将学习以下内容使用使用

在本章中,我们将学习以下内容

使用 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_dns
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  Carlos Perez <carlos_perez@darkoperator.com>
  Nixawk

Check supported:
  No

Basic options:
  Name         Current Setting                                              Required  Description
  ----         ---------------                                              --------  -----------
  DOMAIN                                                                    yes       The target domain
  ENUM_A       true                                                         yes       Enumerate DNS A record
  ENUM_AXFR    true                                                         yes       Initiate a zone transfer against each NS record
  ENUM_BRT     false                                                        yes       Brute force subdomains and hostnames via the supplied wordlist
  ENUM_CNAME   true                                                         yes       Enumerate DNS CNAME record
  ENUM_MX      true                                                         yes       Enumerate DNS MX record
  ENUM_NS      true                                                         yes       Enumerate DNS NS record
  ENUM_RVL     false                                                        yes       Reverse lookup a range of IP addresses
  ENUM_SOA     true                                                         yes       Enumerate DNS SOA record
  ENUM_SRV     true                                                         yes       Enumerate the most common SRV records
  ENUM_TLD     false                                                        yes       Perform a TLD expansion by replacing the TLD with the IANA TLD list
  ENUM_TXT     true                                                         yes       Enumerate DNS TXT record
  IPRANGE                                                                   no        The target address range or CIDR identifier
  NS                                                                        no        Specify the nameserver to use for queries (default is system DNS)
  STOP_WLDCRD  false                                                        yes       Stops bruteforce enumeration if wildcard resolution is detected
  THREADS      1                                                            no        Threads for ENUM_BRT
  WORDLIST     /usr/share/metasploit-framework/data/wordlists/namelist.txt  no        Wordlist of subdomains

Description:
  This module can be used to gather information about a domain from a
  given DNS server by performing various DNS queries such as zone
  transfers, reverse lookups, SRV record brute forcing, and other
  techniques.

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 记录

Metasploit 渗透测试手册第三版 第二章 信息收集与扫描(翻译)

更多

dns 扫描和枚举模块也可以用于主动信息收集,通过爆破的方式,设置 ENUM_BRTtrue ,可以通过字典暴力枚举子域名和主机名。 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

YahooBing 收集域名的子域信息

切换到这个模块,设置好要要查询的域名,然后运行

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 每日通过 ZMapZGrab 扫描互联网上的主机和网站,持续监控互联网上所有可访问的服务器和设备。

我们可以使用 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             City        Country         Hostname
 -------             ----        -------         --------
 83.166.169.228:80   Nottingham  United Kingdom  packtpub.com
 83.166.169.248:443  Nottingham  United Kingdom  imap.packtpub.com
 83.166.169.248:80   Nottingham  United Kingdom  imap.packtpub.com

[*] Auxiliary module execution completed
复制代码

通过 Shodan 搜索模块可以找到更多目标的信息,比如 IP 地址,开放的端口,位置信息等。

Shodan 蜜罐检查

检测目标是否为蜜罐,避免浪费时间或因为试图攻击蜜罐而被封锁。使用 Shodan Honeyscore Client 模块,可以利用 Shodan 搜索引擎检测目标是否为蜜罐。结果返回为 01 的评级分数,如果是 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
复制代码

从输出信息来看,可以看到该模块利用 GoogleBingYohoo 搜索目标有关的电子邮件地址。

2、使用Metasploit进行主动信息收集

通常来说,通过扫描进行主动信息收集,从这一步开始,我们将直接与目标进行逻辑连接。

端口扫描是一个有趣的信息收集过程,它涉及对目标系统更深入的搜索,但是由于主动端口扫描涉及对目标系统直接访问,可能会被防火墙和入侵检测系统检测到。

怎么做

Metasploit 框架中,有各种各样的端口扫描模块可供我们使用,从而允许我们准确的对目标系统进行探测。我们可以通过 search portscan 命令查看这些模块。

msf5 > search portscan

Matching Modules
================

   #  Name                                              Disclosure Date  Rank    Check  Description
   -  ----                                              ---------------  ----    -----  -----------
   1  auxiliary/scanner/http/wordpress_pingback_access                   normal  Yes    Wordpress Pingback Locator
   2  auxiliary/scanner/natpmp/natpmp_portscan                           normal  Yes    NAT-PMP External Port Scanner
   3  auxiliary/scanner/portscan/ack                                     normal  Yes    TCP ACK Firewall Scanner
   4  auxiliary/scanner/portscan/ftpbounce                               normal  Yes    FTP Bounce Port Scanner
   5  auxiliary/scanner/portscan/syn                                     normal  Yes    TCP SYN Port Scanner
   6  auxiliary/scanner/portscan/tcp                                     normal  Yes    TCP Port Scanner
   7  auxiliary/scanner/portscan/xmas                                    normal  Yes    TCP "XMas" Port Scanner
   8  auxiliary/scanner/sap/sap_router_portscanner                       normal  No     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 Setting  Required  Description
   ----         ---------------  --------  -----------
   CONCURRENCY  10               yes       The number of concurrent ports to check per host
   DELAY        0                yes       The delay between connections, per thread, in milliseconds
   JITTER       0                yes       The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds.
   PORTS        1-10000          yes       Ports to scan (e.g. 22-25,80,110-900)
   RHOSTS                        yes       The target address range or CIDR identifier
   THREADS      1                yes       The number of concurrent threads
   TIMEOUT      1000             yes       The socket connect timeout in milliseconds

msf5 auxiliary(scanner/portscan/tcp) > show missing

Module options (auxiliary/scanner/portscan/tcp):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   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 CST              
Nmap scan report for 192.168.177.144                                         
Host is up (0.00044s latency).                                               
Not shown: 990 filtered ports                                                
PORT      STATE SERVICE                                                      
21/tcp    open  ftp                                                          
22/tcp    open  ssh                                                          
80/tcp    open  http                                                         
4848/tcp  open  appserv-http                                                 
8022/tcp  open  oa-system                                                    
8080/tcp  open  http-proxy                                                   
8383/tcp  open  m2mservices                                                  
9200/tcp  open  wap-wsp                                                      
49153/tcp open  unknown                                                      
49154/tcp open  unknown                                                      
MAC Address: 00:0C:29:D7:02:F6 (VMware)                                      
                                                                             
Nmap done: 1 IP address (1 host up) scanned in 5.31 seconds                  
msf5 >                                                                       
复制代码

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   open  ssh
80/tcp   open  http
1617/tcp open  nimrod-agent
4848/tcp open  appserv-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
PORT    STATE SERVICE
137/udp open  netbios-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
PORT      STATE SERVICE
21/tcp    open  ftp
22/tcp    open  ssh
80/tcp    open  http
4848/tcp  open  appserv-http
8022/tcp  open  oa-system
8080/tcp  open  http-proxy
8383/tcp  open  m2mservices
9200/tcp  open  wap-wsp
49153/tcp open  unknown
49154/tcp open  unknown
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
PORT      STATE SERVICE           VERSION
21/tcp    open  ftp               Microsoft ftpd
22/tcp    open  ssh               OpenSSH 7.1 (protocol 2.0)
80/tcp    open  http              Microsoft IIS httpd 7.5
4848/tcp  open  ssl/appserv-http?
8022/tcp  open  http              Apache Tomcat/Coyote JSP engine 1.1
8080/tcp  open  http              Sun GlassFish Open Source Edition  4.0
8383/tcp  open  ssl/http          Apache httpd
9200/tcp  open  http              Elasticsearch REST API 1.1.1 (name: Turac; Lucene 4.7)
49153/tcp open  msrpc             Microsoft Windows RPC
49154/tcp open  msrpc             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: PORT      STATE SERVICE           VERSION
[*] Nmap: 21/tcp    open  ftp               Microsoft ftpd
[*] Nmap: 22/tcp    open  ssh               OpenSSH 7.1 (protocol 2.0)
[*] Nmap: 80/tcp    open  http              Microsoft IIS httpd 7.5
[*] Nmap: 1617/tcp  open  rmiregistry       Java RMI
[*] Nmap: 4848/tcp  open  ssl/appserv-http?
[*] Nmap: 5985/tcp  open  http              Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
[*] Nmap: 8020/tcp  open  http              Apache httpd
[*] Nmap: 8022/tcp  open  http              Apache Tomcat/Coyote JSP engine 1.1
[*] Nmap: 8027/tcp  open  unknown
[*] Nmap: 8080/tcp  open  http              Sun GlassFish Open Source Edition  4.0
[*] Nmap: 8282/tcp  open  http              Apache Tomcat/Coyote JSP engine 1.1
[*] Nmap: 8383/tcp  open  ssl/http          Apache httpd
[*] Nmap: 8484/tcp  open  http              Jetty winstone-2.8
[*] Nmap: 8585/tcp  open  http              Apache httpd 2.2.21 ((Win64) PHP/5.3.10 DAV/2)
[*] Nmap: 9200/tcp  open  http              Elasticsearch REST API 1.1.1 (name: Turac; Lucene 4.7)
[*] Nmap: 49153/tcp open  msrpc             Microsoft Windows RPC
[*] Nmap: 49154/tcp open  msrpc             Microsoft Windows RPC
[*] Nmap: 49207/tcp open  rmiregistry       Java RMI
[*] Nmap: 49209/tcp open  tcpwrapped
[*] 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 SERVICE  VERSION  
[*] Nmap: 80/tcp   open  http     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 open  http     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
=====

address          mac                name  os_name  os_flavor  os_sp  purpose  info  comments
-------          ---                ----  -------  ---------  -----  -------  ----  --------
34.240.217.226
34.248.41.77
54.171.32.62
192.168.177.1    00:50:56:c0:00:08        Unknown                    device
192.168.177.2    00:50:56:fa:c4:65
192.168.177.139  00:0c:29:c6:a9:e5        Unknown                    device
192.168.177.142  00:0c:29:92:63:8c        Linux               2.6.X  server
192.168.177.144  00:0c:29:d7:02:f6        Unknown                    device
192.168.177.254  00: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-0101 永恒之蓝漏洞检测模块

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/dcomexec      
use 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   - Scanned  78 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   proto  name              state  info                                           
----             ----   -----  ----              -----  ----                                           
192.168.177.1    21     tcp    ftp               open   220 Serv-U FTP Server v15.0 ready...\x0d\x0a   
192.168.177.144  21     tcp    ftp               open   220 Microsoft FTP Service\x0d\x0a           
192.168.177.144  22     tcp    ssh               open   SSH-2.0-OpenSSH_7.1                         
192.168.177.144  80     tcp    http              open   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_enum                                                        
msf5 auxiliary(scanner/smtp/smtp_enum) > set RHOSTS 192.168.177.145                               
RHOSTS => 192.168.177.145                         
msf5 auxiliary(scanner/smtp/smtp_enum) > set THREADS 256  
THREADS => 256                                      
msf5 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                   : 128                
TCP segments received         : 70121              
TCP segments sent             : 70024               
TCP segments retrans          : 23                   
Input datagrams               : 634                
Delivered 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 文件访问模块可以通过 PUTDELETE 请求上传和删除 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》

www.packtpub.com/networking-…

本文由合天网安实验室编译,转载请注明来源。

关于合天网安实验室

合天网安实验室(www.hetianlab.com)-国内领先的实操型网络安全在线教育平台

真实环境,在线实操学网络安全 ; 实验内容涵盖:系统安全,软件安全,网络安全,Web安全,移动安全,CTF,取证分析,渗透测试,网安意识教育等。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Redis设计与实现

Redis设计与实现

黄健宏 / 机械工业出版社 / 2014-6 / 79.00

【官方网站】 本书的官方网站 www.RedisBook.com 提供了书本试读、相关源码下载和勘误回报等服务,欢迎读者浏览和使用。 【编辑推荐】 系统而全面地描述了 Redis 内部运行机制 图示丰富,描述清晰,并给出大量参考信息,是NoSQL数据库开发人员案头必备 包括大部分Redis单机特征,以及所有多机特性 【读者评价】 这本书描述的知识点很丰富,......一起来看看 《Redis设计与实现》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器