Metasploit 安装与初始设置

LinuxBeginner
立即练习

介绍

欢迎来到 Metasploit 安装和初始设置实验(Lab)。Metasploit Framework 是一个强大的开源工具,用于针对远程目标机器开发、测试和执行漏洞利用代码。它是渗透测试和安全研究中最常用的工具之一。

在这个实验中,你将完成在 Ubuntu 系统上启动并运行 Metasploit 的整个过程。你将从更新系统软件包开始,然后安装 Metasploit Framework,配置其所需的 PostgreSQL 数据库,最后启动 Metasploit 控制台。完成本实验后,你将拥有一个功能齐全的 Metasploit 环境,可供使用。

这是一个实验(Guided Lab),提供逐步指导来帮助你学习和实践。请仔细按照说明完成每个步骤,获得实际操作经验。根据历史数据,这是一个 中级 级别的实验,完成率为 60%。获得了学习者 96% 的好评率。

使用 apt update 和 apt upgrade 更新 Ubuntu 软件包

在这一步,你将更新系统的软件包列表并升级任何过时的软件包。这是安装新软件之前至关重要的一步,可以确保你拥有最新的安全补丁和依赖项,有助于防止潜在的冲突。

首先,使用 apt update 命令从软件源(repositories)更新软件包列表。你需要 sudo 权限,因为此操作需要管理员权限。

sudo apt update

你将看到显示从 Ubuntu 源获取软件包列表的输出。

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
...
Fetched 1,589 kB in 2s (924 kB/s)
Reading package lists... Done
Building dependency tree... Done

系统更新完毕后,你现在就可以安装 Metasploit 了。

使用官方安装脚本安装 Metasploit Framework

在这一步,你将使用 Rapid7 提供的官方安装脚本来安装 Metasploit Framework。此脚本会将 Metasploit 软件源(repository)添加到你的系统,并安装最新版本的框架。

首先,将安装脚本下载到临时位置:

curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > /tmp/msfinstall

接下来,使脚本可执行:

chmod 755 /tmp/msfinstall

现在,使用管理员权限运行安装脚本:

sudo /tmp/msfinstall

脚本将把 Metasploit Framework 软件源添加到你的软件包源列表中,更新软件包缓存,并安装 metasploit-framework 软件包及其依赖项。你将看到类似以下的输出:

  % Total    % Received % Xferd  Average Speed   Time    Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6144  100  6144    0     0  34855      0 --:--:-- --:--:-- --:--:-- 34909
Adding metasploit-framework to your repository list..Updating package cache..OK
Checking for and installing update..
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  metasploit-framework
...
Setting up metasploit-framework (6.4.x~...) ...
update-alternatives: using /opt/metasploit-framework/bin/msfconsole to provide /usr/bin/msfconsole (msfconsole) in auto mode
...
Run msfconsole to get started

安装完成后,Metasploit Framework 就已安装在你的系统上了。

启动 Metasploit 控制台并完成初始设置

在最后一步,你将首次启动 Metasploit 控制台,这将触发初始设置过程。这包括设置 Metasploit 用于存储项目信息(包括主机数据、漏洞和收集到的证据)的数据库。

要启动控制台,只需在终端中输入 msfconsole 并按 Enter 键。

msfconsole

首次运行 Metasploit 时,它将显示初始设置向导:

 ** Welcome to Metasploit Framework Initial Setup **
    Please answer a few questions to get started.


Would you like to use and setup a new database (recommended)?

输入 yes 并按 Enter 键继续进行数据库设置。

Would you like to use and setup a new database (recommended)? yes
Running the 'init' command for the database:
Creating database at /home/labex/.msf4/db
Creating db socket file at /tmp
Starting database at /home/labex/.msf4/db...waiting for server to start.... done
server started
success
Creating database users
Writing client authentication configuration file /home/labex/.msf4/db/pg_hba.conf
Stopping database at /home/labex/.msf4/db
Starting database at /home/labex/.msf4/db...waiting for server to start.... done
server started
success
Creating initial database schema
Database initialization successful
Database initialization successful

 ** Metasploit Framework Initial Setup Complete **

设置完成后,你将看到熟悉的 Metasploit 启动横幅和提示符:

Metasploit tip: Display the Framework log using the log command, learn
more with help log

Call trans opt: received. 2-19-98 13:24:18 REC:Loc

     Trace program: running

           wake up, Neo...
        the matrix has you
      follow the white rabbit.

          knock, knock, Neo.

                        (`.         ,-,
                        ` `.    ,;' /
                         `.  ,'/ .'
                          `. X /.'
                .-;--''--.._` ` (
              .'            /   `
             ,           ` '   Q '
             ,         ,   `._    \
          ,.|         '     `-.;_'
          :  . `  ;    `  ` --,.._;
           ' `    ,   )   .'
              `._ ,  '   /_
                 ; ,''-,;' ``-
                  ``-..__``--`

                             https://metasploit.com


       =[ metasploit v6.4.x-dev-                               ]
+ -- --=[ 2,564 exploits - 1,315 auxiliary - 1,680 payloads     ]
+ -- --=[ 431 post - 49 encoders - 13 nops - 9 evasion          ]

Metasploit Documentation: https://docs.metasploit.com/
The Metasploit Framework is a Rapid7 Open Source Project

msf >

为了确认数据库已正确连接,请在 Metasploit 控制台中运行 db_status 命令。

db_status

预期的输出是:

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

这确认你的 Metasploit 实例已成功连接到 PostgreSQL 数据库。要退出 Metasploit 控制台,只需输入 exit

exit

总结

恭喜你!你已在你的 Ubuntu 系统上成功完成了 Metasploit Framework 的安装和初始设置。

在这个实验(Lab)中,你学会了如何:

  • 使用 apt 更新和升级你的系统软件包。
  • 使用 Rapid7 提供的官方安装脚本安装 Metasploit Framework。
  • 首次启动 Metasploit 控制台(msfconsole),这会自动触发初始数据库设置过程。
  • 在 Metasploit 控制台中验证数据库连接。

现在你拥有了一个功能强大且完全可用的渗透测试工具。Metasploit Framework 现已配置好其独立的 PostgreSQL 数据库实例,并可投入使用。你已准备好进入更高级的实验(Labs),在那里你可以探索其在安全测试和研究方面的广泛能力。