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

第二章 信息收集和扫描

在本章中,咱们将学习如下内容javascript

使用Metasploit被动收集信息php

使用Metasploit主动收集信息java

使用Nmap进行端口扫描ios

使用db_nmap方式进行端口扫描web

使用ARP进行主机发现shell

UDP服务探测数据库

SMB扫描和枚举apache

SSH版本扫描windows

FTP扫描api

SMTP枚举

SNMP枚举

HTTP扫描

WinRM扫描和爆破

Nessus结合使用

NeXpose结合使用

OpenVAS结合使用

简介

信息收集是渗透测试中首先要作的重要事项之一,目的是尽量多的查找关于目标的信息,咱们掌握的信息越多,渗透成功的机会越大。在信息收集阶段,咱们主要任务是收集关于目标机器的一切信息,好比IP地址,开放的服务,开放的端口。这些信息在渗透测试过程当中启到了相当重要的做用。为了实现这一目的,咱们将在本章学习各类扫描技术、如SMB扫描、SSH服务扫描,FTP扫描、SNMP枚举、HTTP扫描以及WinRM扫描和暴力破解。

收集信息的方式主要有三种:

一、被动信息收集:这种方式是指在不物理链接或访问目标的时候,获取目标的相关信息,这意味着咱们须要使用其余信息来源得到目标信息。好比查询whois信息。假设咱们的目标是一个在线的Web服务,那么经过whois查询能够得到它的ip地址,域名信息,子域信息,服务器位置信息等。

二、主动信息收集:这种方式是指与目标创建逻辑链接获取信息,这种方式能够进一步的为咱们提供目标信息,让咱们对目标的安全性进一步理解。在端口扫描中,使用最经常使用的主动扫描技术,探测目标开放的端口和服务。

三、社会工程学:这种方式相似于被动信息收集,主要是针对人为错误,信息以打印输出、电话交谈、电子邮件等形式泄露。使用这种方法的技术有不少,收集信息的方式也不尽相同,所以,社会工程学自己就是一个技术范畴。

社会工程的受害者被诱骗发布他们没有意识到会被用来攻击企业网络的信息。例如,企业中的员工可能会被骗向伪装是她信任的人透露员工的身份号码。尽管该员工编号对员工来讲彷佛没有价值,这使得他在一开始就更容易泄露信息,但社会工程师能够将该员工编号与收集到的其余信息一块儿使用,以便更快的找到进入企业网络的方法。

一、使用Metasploit进行被动信息收集

在本章中,咱们将详细学习信息收集的各类被动和主动技术。首先,咱们将学习分析最经常使用和最容易被忽视的被动信息收集技术,而后,咱们将重点关注经过端口扫描获取信息。Metasploit 具备多种内置扫描功能,以及一些与之集成的第三方工具,以进一步加强端口扫描功能。咱们将学习使用内置的扫描仪,以及一些与Metasploit 框架结合使用的第三方扫描工具。让咱们开始吧。

准备工做

咱们将从公司域名开始收集信息,获取公司有关信息,收集子域名,检测蜜罐、收集电子邮件地址等。

怎么作

Metasploit中有好几个信息收集模块,在本节中,咱们将学习使用其中的一些模块,建议你自行探索学习全部的信息收集模块。

DNS记录扫描和枚举

DNS扫描和枚举模块可用于从给定的DNS服务器收集有关域名的信息,执行各类DNS查询(如域传送,反向查询,SRV记录等)

一、程序位于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) >
复制代码

二、设置须要查询的域名,设置线程数量,而后运行它

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_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搜索目标有关的电子邮件地址。

二、使用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
复制代码

三、端口扫描:Nmap 方式

Nmap是安全人员首选的强大网络扫描工具,咱们将从初级到高级,详细分析Nmap的各类扫描技术。

准备工做

你能够直接在msfconsole中运行Nmap,可是若是要将结果导入到Metasploit数据库中,须要使用-oX选项导出XML格式的报告文件,而后使用db_import命令将结果导入进来。

怎么作

一、启动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
复制代码

二、进行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个端口。

三、进行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参数设置咱们想要扫描的端口范围。

四、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地址,否则会影响扫描结果。所以,只要使用必定数量的地址就行。

四、端口扫描: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等。

五、基于ARP的主机发现

经过ARP请求能够枚举本地网络中的存活主机,为咱们提供了一种简单而快速识别目标方法。

准备工做

当攻击者和目标机器处于同一个局域网时,能够经过执行ARP扫描发现主机

怎么作

一、使用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) >
复制代码

二、若是启动了数据库,结果将存储在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

复制代码

六、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) >
复制代码

七、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扫描模块,让咱们看看其余模块的用法。

三、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
复制代码

四、用户枚举模块能够经过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) >
复制代码

五、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) >
复制代码

六、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) >
复制代码

七、其余的模块,都在 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
.....         
复制代码

八、SSH 版本扫描和检测

SSH是一个普遍使用的远程登陆程序。它使用强大的加密提供身份认证和保证机密性。在本节中,咱们将经过SSH版本扫描模块,肯定目标使用的SSH版本,肯定是否为易受攻击的SSH版本,若是是,咱们能够利用它。

准备工做

在以前的扫描中,咱们发现目标机器开放了TCP 22端口,这也是SSH的默认端口,咱们用SSH版本探测模块来获取目标系统上运行的SSH版本信息。

怎么作

一、模块名称: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 选项也能够指定为网络地址,从而扫描整个网段。

获取版本信息以后,咱们就能够搜索该版本的漏洞。

二、测试经常使用口令登陆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
复制代码

三、若是登陆成功了,能够用sessions 查看会话和与目标进行会话交互

msf5 auxiliary(scanner/ssh/ssh_login) > sessions

Active sessions
===============

No active sessions.

复制代码

九、FTP扫描

使用FTP扫描模块对网络中全部的FTP服务进行版本扫描

准备工做

FTP版本扫描模块运行咱们检测正在运行的FTP版本

怎么作

一、使用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) >
复制代码

二、与以前的扫描同样,扫描结果会保存到数据库中,可使用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                     
复制代码

十、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用户

十一、SNMP枚举

简单网络管理协议(SNMP)是用于管理网络设备的协议,好比监控设备的状态信息,接口信息,网络接口的数据吞吐量等。经过SNMP扫描器能够找到特定系统的大量信息。本节中,咱们将学习如何使用它。

准备工做

Metasploit有一个专门用于扫描 SNMP 设备的内置辅助模块。在进行攻击以前必须先了解它。首先,团体字符串(只读/读写)在能够在设备自己上挖掘或修改的信息类型中起着重要做用。管理信息库 (MIB) 接口容许咱们查询设备和提取信息。

Tip:若是目标系统为Windows且配置了SNMP(一般是RO/RW团体字符串),咱们能够提取系统重启时间,系统上的用户名,系统网络信息,运行的服务等各类有价值的信息。

当经过SNMP查询时候,能够经过MIB API进行设备信息提取。Metasploit在其数据库中加载默认MIB列表,它们用于查询设备获取更多信息。

怎么作

一、经过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) >
复制代码

二、经过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                   : :::::
....
复制代码

十二、HTTP扫描

超文本传输协议(HTTP)是一个应用层协议,它是万维网通讯的基础。它被众多的应用程序使用,从物联网(IoT)设备到移动应用程序。它也是搜索漏洞的好地方。

准备工做

HTTP SSL证书检测模块能够检测Web服务器的证书。

Robots.txt内容检测模块能够搜索robots.txt文件并分析里面的内容。

若是服务端容许未受权的PUT请求方法,则能够将任意的Web页面插入到网站目录中,从而致使执行破坏性的代码或者往服务器填充垃圾数据,从而形成拒绝服务攻击。

Jenkins-CI HTTP扫描模块能够枚举未受权的Jenkins-CI服务。

怎么作

一、检测目标的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)
复制代码

二、检测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) >
复制代码

三、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) >
复制代码

四、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
复制代码

1三、WinRM扫描和爆破

Windows远程管理(WinRM)是WS-Management协议的Microsoft实现。该协议是基于简单对象访问协议(SOAP)的、防火墙友好的标准协议,使来自不一样供应商的硬件和操做系统可以互相交互。

准备工做

WinRM身份认证方法检测模块经过向目标发现HTTP/HTTPS请求,检测是否为WinRM服务,若是是,将会检测支持的身份认证方法。

经过SMB_login模块能够检索目标的登陆凭证。咱们能够用WinRM命令运行模块测试是否能够经过WinRM服务运行Windows命令。

怎么作

一、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) >
复制代码

二、使用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结合使用的技术和方法将在下一篇文章中讲解,敬请期待

1四、与Nessus结合使用

1五、与NeXpose结合使用

1六、与OpenVAS结合使用

第二章 信息收集与扫描-续

说明

原书:《Metasploit Penetration Testing Cookbook - Third Edition》

www.packtpub.com/networking-…

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

关于合天网安实验室

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

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

相关文章
相关标签/搜索