【THM】Metasploit: Exploitation(利用)-初级渗透测试

本文档介绍了如何使用Metasploit进行端口扫描、服务识别(如UDP和SMB)以及漏洞利用。它详细阐述了Metasploit数据库的管理和工作区创建,以简化多目标渗透测试。此外,还讲解了使用msfvenom生成有效负载和启动Meterpreter会话的方法。通过实例展示了如何在目标系统上执行端口扫描、识别NetBIOS名称、SMB扫描以及利用HTTP服务漏洞。
摘要由CSDN通过智能技术生成

介绍

在这个房间里,我们将学习如何使用Metasploit进行漏洞扫描和利用。我们还将介绍数据库功能如何使管理更广泛范围的渗透测试活动变得更容易。最后,我们将研究使用msfvenom生成有效负载以及如何在大多数目标平台上启动Meterpreter会话。

更具体地说,我们将讨论的主题是:

  • 如何使用Metasploit扫描目标系统。
  • 如何使用Metasploit数据库功能。
  • 如何使用Metasploit进行漏洞扫描。
  • 如何使用Metasploit来利用目标系统上的易受攻击的服务。
  • 如何msfvenom 用于创建有效负载并在目标系统上获取Meterpreter会话。

请注意,对于所有需要使用单词列表的问题(例如暴力攻击),我们将使用位于 以下路径的 AttackBox 上的单词列表:

/usr/share/wordlists/MetasploitRoom/MetasploitWordlist.txt 

如果您选择使用自己的机器,请单击右侧的“下载任务文件”按钮下载单词表。

启动 AttackBox 并使用该房间中的命令运行Metasploit 。msfconsole

扫描

端口扫描

Metasploit有许多模块来扫描目标系统和网络上的开放端口。您可以使用该命令列出可用的潜在端口扫描模块search portscan 。

搜索端口扫描

msf6 > search portscan

Matching Modules

================

   #  Name                                              Disclosure Date  Rank    Check  Description

   -  ----                                              ---------------  ----    -----  -----------

   0  auxiliary/scanner/http/wordpress_pingback_access                   normal  No     Wordpress Pingback Locator

   1  auxiliary/scanner/natpmp/natpmp_portscan                           normal  No     NAT-PMP External Port Scanner

   2  auxiliary/scanner/portscan/ack                                     normal  No     TCP ACK Firewall Scanner

   3  auxiliary/scanner/portscan/ftpbounce                               normal  No     FTP Bounce Port Scanner

   4  auxiliary/scanner/portscan/syn                                     normal  No     TCP SYN Port Scanner

   5  auxiliary/scanner/portscan/tcp                                     normal  No     TCP Port Scanner

   6  auxiliary/scanner/portscan/xmas                                    normal  No     TCP "XMas" Port Scanner

   7  auxiliary/scanner/sap/sap_router_portscanner                       normal  No     SAPRouter Port Scanner

Interact with a module by name or index, for example use 7 or use auxiliary/scanner/sap/sap_router_portscanner

msf6 >

 端口扫描模块将要求您设置一些选项:        

端口扫描选项

msf6 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 host(s), range CIDR identifier, or hosts file with syntax 'file:'

   THREADS      1                yes       The number of concurrent threads (max one per host)

   TIMEOUT      1000             yes       The socket connect timeout in milliseconds

msf6 auxiliary(scanner/portscan/tcp) >

  • CONCURRENCY:同时扫描的目标数量。
  • PORTS:要扫描的端口范围。请注意,此处的 1-1000与使用默认配置的Nmap不同。 Nmap将扫描最常用的 1000 个端口,而Metasploit将扫描从 1 到 10000 的端口号。
  • RHOTS:要扫描的目标或目标网络。
  • THREADS:将同时使用的线程数。更多线程将导致更快的扫描。

您可以直接从 msfconsole 提示符执行Nmap扫描,如下所示,速度更快:

使用地图从 Msfconsole 提示符

msf6 > nmap -sS 10.10.12.229

[*] exec: nmap -sS 10.10.12.229

Starting Nmap 7.60 ( https://nmap.org ) at 2021-08-20 03:54 BST

Nmap scan report for ip-10-10-12-229.eu-west-1.compute.internal (10.10.12.229)

Host is up (0.0011s latency).

Not shown: 992 closed ports

PORT      STATE SERVICE

135/tcp   open  msrpc

139/tcp   open  netbios-ssn

445/tcp   open  microsoft-ds

3389/tcp  open  ms-wbt-server

49152/tcp open  unknown

49153/tcp open  unknown

49154/tcp open  unknown

49158/tcp open  unknown

MAC Address: 02:CE:59:27:C8:E3 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 64.19 seconds

msf6 >

至于信息收集,如果您的参与需要更快的端口扫描方法,Metasploit可能不是您的首选。然而,许多模块使Metasploit成为扫描阶段的有用工具。

UDP服务识别

scanner/discovery/udp_sweep 模块将允许您快速识别通过UDP(用户数据报协议)运行的服务。如下所示,该模块不会对所有可能的UDP服务进行广泛扫描,但确实提供了一种快速方法来识别DNS​​ 或 NetBIOS等服务。

UDP扫描

msf6 auxiliary(scanner/discovery/udp_sweep) > run

[*] Sending 13 probes to 10.10.12.229->10.10.12.229 (1 hosts)

[*] Discovered NetBIOS on 10.10.12.229:137 (JON-PC::U :WORKGROUP::G :JON-PC::U :WORKGROUP::G :WORKGROUP::U :__MSBROWSE__::G :02:ce:59:27:c8:e3)

[*] Scanned 1 of 1 hosts (100% complete)

[*] Auxiliary module execution completed

msf6 auxiliary(scanner/discovery/udp_sweep) >

SMB扫描

Metasploit 提供了几个有用的辅助模块,使我们能够扫描特定的服务。以下是SMB的示例。在企业网络中尤其有用 smb_enumshares ,smb_version 但请花一些时间来识别系统上安装的Metasploit版本提供的扫描仪。

中小企业扫描

msf6 auxiliary(scanner/smb/smb_version) > run

[+] 10.10.12.229:445      - Host is running Windows 7 Professional SP1 (build:7601) (name:JON-PC) (workgroup:WORKGROUP ) (signatures:optional)

[*] 10.10.12.229:445      - Scanned 1 of 1 hosts (100% complete)

[*] Auxiliary module execution completed

msf6 auxiliary(scanner/smb/smb_version) >

执行服务扫描时,重要的是不要忽略更多“奇异”服务,例如 NetBIOS。 NetBIOS(网络基本输入输出系统)与SMB类似,允许计算机通过网络进行通信以共享文件或将文件发送到打印机。目标系统的 NetBIOS 名称可以让您了解其角色甚至重要性(例如 CORP- DC、DEVOPS、SALES 等)。您还可能会遇到一些无需密码即可访问或受简单密码保护的共享文件和文件夹(例如 admin、administrator、root、toor 等)。

请记住,Metasploit有许多模块可以帮助您更好地了解目标系统,并可能帮助您发现漏洞。执行快速搜索总是值得的,看看是否有任何模块可以根据您的目标系统提供帮助。

2.1目标系统上打开了多少个端口?5

提示:您可以在 Metasploit 上使用 portscanner 模块。,nmap运行结果

用portscan模块

search portscan

use 5(use auxiliary/scanner/portscan/tcp)

show options

set rhosts 10.10.116.149

set THREADS 4

show options

run

 

2.2使用相关扫描仪,您可以看到什么 NetBIOS 名称?ACME IT SUPPORT

use auxiliary/scanner/discovery/udp_sweep

set rhosts 10.10.116.149

run

因为前面提到scanner/discovery/udp_sweep 模块能扫描部分UDP服务,还提供快速方法来识别DNS​​ 或 NetBIOS等服务。

方法2提示:使用 netbios/nbname 模块

search netbios/nbname

use 0

show options

set RHOSTS 10.10.43.5

run

2.2 8000端口上正在运行什么?提示:使用 http_version 模块。答案:webfs/1.21

search http_version

use 0

show options

set rhosts 10.10.152.168

set rport 8000

show options

run

或者用nmap

nmap -sC -sV -p8000 10.10.43.5

 

2.4“penny”用户的 SMB 密码是什么?使用上一个任务中提到的单词表。 提示:使用 smb_login 模块。

search smb_login
use 0
show options
set PASS_FILE /usr/share/wordlists/MetasploitWordlist.txt  #此处文件路径 对应的是TryHackMe提供的攻击机中的字典文件路径
set SMBUser penny
set RHOSTS 10.10.43.5
run

Metasploit 数据库

虽然在 TryHackMe 上与单个目标交互时不需要这样做,但实际的渗透测试活动可能会有多个目标。 

Metasploit具有数据库功能,可以简化项目管理并避免设置参数值时可能出现的混乱。 

您首先需要启动 PostgreSQL 数据库,Metasploit将通过以下命令使用该数据库: 

systemctl start postgresql

然后您需要使用该命令初始化Metasploitmsfdb init数据库。

启动 Postgresql

root@attackbox:~# systemctl start postgresql

root@attackbox:~# msfdb init

[i] Database already started

[+] Creating database user 'msf'

[+] Creating databases 'msf'

[+] Creating databases 'msf_test'

[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'

[+] Creating initial database schema

/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil

root@attackbox:~#

您现在可以 msfconsole使用该命令启动并检查数据库状态db_status

检查数据库状态

msf6 > db_status

[*] Connected to msf. Connection type: postgresql.

msf6 >

数据库功能将允许您创建工作区来隔离不同的项目。首次启动时,您应该位于默认工作区中。您可以使用该命令列出可用的工作区workspace 。 

列出工作空间

msf6 > wor

  • 23
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值