在本章中,我们将研究元 sploit 框架的组织。Metasploit 框架是一个开源项目,由HD Moore于 2003 年创建,并于 2009 年 10 月 21 日被 Rapid7 LLC 收购。Metasploit 2.0 于 2004 年 4 月发布,该版本包括 19 次漏洞利用,超过 27 次有效负载。从那以后一直在不断利用,现在我们有了 Metasploit 4.5.2,其中包括数百个漏洞和有效负载。Moore 创建了这个框架,用于利用漏洞代码和攻击易受攻击的远程系统。它被认为是支持使用 Nessus 和其他著名工具进行漏洞评估的最佳渗透测试工具之一。这个项目的利用从 Perl 开始,后来用 Ruby 重写。自收购以来,Rapid7 又增加了两个专有版本,即 Metasploit Express 和 Metasploit Pro。Metasploit 支持所有平台,包括 Windows、Linux 和 Mac OS。
首先,我们将了解如何从终端和其他方式访问 Metasploit 框架。打开终端并输入msfconsole
。在终端中,它将显示为root@bt:~# msfconsole
。
现在我们已经从终端程序中打开了msfconsole
;然而,我们可以通过其他方式访问 Metasploit 框架,包括 MsfGUI、Msfconsole、Msfcli、Msfweb、Metasploit Pro 和 Armitage。出于我们的目的,在本书中,我们将主要使用msfconsole
。
那么 Metasploit 是如何组织的呢?我们可以在这里看到许多接口。在深入研究 Metasploit 的各个方面时,我们将查看架构的细节。现在我们需要了解的重要事情是总体架构。该体系结构是开源的,这允许您在 Metasploit 中创建自己的模块、脚本和许多其他有趣的东西。
Metasploit 中的库架构如下:
-
Rex:此是 Metasploit 中用于各种协议、转换和套接字处理的基本库。它支持 SSL、SMB、HTTP、XOR、Base64 和随机文本。
-
Msf::Core:这个库定义了框架,为 Metasploit 提供了基本的应用接口。
-
Msf::Base: This library provides a simplified and friendly application interface for the Metasploit Framework.
现在我们将进一步探索元 sploit 目录。只需按照以下步骤浏览目录:
-
Open your BackTrack5 R2 virtual machine and your terminal. Type
cd /opt/metasploit/msf3
and then press Enter. Now we have entered the Metasploit Framework directory. To view the list of files and directories in the Metasploit directory type inls
. -
键入
ls
命令后,我们可以在这里看到一堆目录和脚本。所列的重要目录为data
、external
、tools
、plugins
和scripts
。
我们将逐一探索所有这些重要目录:
-
We enter the
data
directory by typing the commandcd data/
. This directory contains a lot of helper modules such asmeterpreter
,exploits
,wordlists
,templates
, and many more.-
Next we will explore the
meterpreter
directory. To enter the directory, type incd meterpreter/
and we will see many.dll
files. Actually it contains.dll
files as well as other interesting things, which are typically required to enable the Meterpreter functionality called post exploitation. As an example we can see different types of DLL files here, such as OLE, Java version, PHP version, and so on. -
另一个目录是
data
目录中的目录wordlist
目录。此目录包含不同服务(如 HTTP、Oracle、Postgres、VNC、SNMP 等)的用户名和密码列表。让我们浏览单词列表目录,输入cd ..
并按回车从meterpreter
目录返回data
目录。之后,输入cd wordlists
并按进入。
-
-
Another interesting directory is
external
inmsf3
, which contains external libraries used by Metasploit. Let us explore theexternal
directory by typingcd external
. -
Then have a look at the
scripts
directory, which is contained in themsf3
directory. This directory contains a lot of scripts that are used by Metasploit. To enter thescripts
directory type incd scripts
and then type in thels
command to view the list of files and folders. -
Another important directory in
msf3
is thetools
directory. This directory contains tools to be used in exploitation. We will explore thetools
directory by typing incd tools
and then thels
command to see the list of tools such aspattern_create.rb
andpattern_offset.rb
, which are extremely useful for exploit research. -
The last useful directory is
plugins
in themsf3
directory. Theplugins
directory contains plugins for integrating third-party tools such as nessus plugins, nexpose plugins, wmap plugins, and other plugins with Metasploit. Let us have a look at theplugins
directory by typingcd plugins
and then thels
command to see the list of plugins.
通过前面的解释,我们现在对 Metasploit 的目录结构及其功能有了简要的了解。一件重要的事情是更新 Metasploit 以获得最新版本的漏洞利用。打开终端并输入msfupdate
。更新最新模块可能需要几个小时。
在讨论利用技术之前,首先我们应该了解利用的基本概念。漏洞攻击是利用特定漏洞的计算机程序。
现在看看msf3
模块目录中的漏洞模块。打开您的终端并键入cd /opt/metasploit/msf3/modules/exploits
和ls
命令以查看漏洞利用列表。
在这里,我们可以看到利用漏洞模块的列表。基本上,漏洞利用是根据操作系统进行分类的。因此,让我们通过键入cd windows
来查看漏洞模块的windows
目录。
在windows
目录中,我们可以看到许多根据 Windows 服务分类的漏洞模块,如ftp
、smb
、telnet
、browser
、email
等。在这里,我们将通过探索目录向您展示一种类型的服务利用。我们选择smb
作为示例。
我们看到了smb
服务漏洞的列表,它们基本上都是 Ruby 脚本。因此,要查看我们在cat <exploitname>
中键入的任何漏洞的代码。这里我们选择ms08_067_netapi.rb
作为示例。所以我们输入了cat ms08_067_netapi.rb
。
同样,我们可以根据操作系统及其服务探索所有类型的漏洞利用。
辅助模块是无有效载荷的攻击。它们用于各种任务,如端口扫描、指纹识别、服务扫描仪等。有不同类型的辅助模块,如协议扫描器、网络协议模糊器、端口扫描器模块、无线、拒绝服务模块、服务器模块、管理访问漏洞攻击等。
现在让我们探索一下msf
目录下的辅助模块目录。输入cd /opt/metasploit/msf3/modules/auxiliary
然后输入ls
命令以查看辅助模块列表。
在这里我们可以看到辅助模块列表,如admin
、client
、fuzzers
、scanner
、vsploit
等。现在我们将探索 scanner 目录作为一个辅助模块。
在scanner
目录中,我们将看到根据服务扫描分类的模块。我们可以选择任何服务模块进行探索。这里我们将选择ftp
作为扫描仪模块。
在ftp
目录中,我们可以看到三个 Ruby 脚本。要查看利用 Ruby 漏洞的代码,只需输入cat <module name>
;例如,我们在这里输入cat anonymous.rb
。
有效负载是在系统受损后运行的一段软件。有效载荷通常通过漏洞连接并交付。Metasploit 中有三种不同类型的有效载荷,即singles
、stagers
和stages
。阶段有效载荷的主要作用是,它们使用微小的阶段来适应小的利用空间。在利用过程中,利用人员可以使用的内存非常有限。分段器使用这个空间,他们的工作是拉下分段负载的其余部分。另一方面,单打是独立的,完全独立的。这就像运行一个小的可执行文件一样简单。
让我们看看下面截图中的payload``modules
目录:
Single 是用于特定任务(如创建用户、绑定 shell 等)的自包含有效负载。例如,windows
/adduser
负载创建一个用户帐户。现在我们将探索singles
有效负载目录。在这里,我们将看到有效负载是根据操作系统(如 AIX、BSD、Windows、Linux 等)进行分类的。
我们将使用目录 windows
来演示有效负载是如何工作的。
我们将使用已经解释过的adduser
有效载荷。我们可以通过键入cat adduser.rb
来查看此有效负载的代码。
stager 是在攻击者和受害者机器之间建立连接的有效负载。作为一个示例,如果我们想要注入meterpreter
有效负载,我们无法将整个 MeterMeter DLL 放入一个有效负载中,因此整个过程分为两部分。第一种是称为 stagers 的较小有效载荷。在执行 stager 之后,它们在攻击者和受害者之间建立网络连接。通过这个网络连接,一个较大的有效负载被传送到受害机器,这个较大的有效负载被称为阶段。
现在我们将探索stagers
有效负载目录。正如我们在下面的屏幕截图中所看到的,有效负载根据不同的操作系统进行分类:
作为一个例子,我们将探索bsd
目录并检查有效负载列表。
Stages 是由 stagers 有效负载(如 MeterMeter、VNC 服务器等)下载和执行的有效负载类型。
现在我们将浏览stages
目录以查看有效负载列表。
在这里,我们得到了在singles
和stagers
目录中看到的相同结果;根据不同的操作系统对有效负载进行分类。我们打开netware
目录查看列表。
在本章中,我们介绍了 Metasploit 框架的不同接口和体系结构。本章流程包括 Metasploit 的操作技术,然后是架构基础。我们进一步介绍了各种 Metasploit 库和应用程序接口,如 Rex、Msf core 和 Msf base。然后,我们深入研究了 Metasploit 目录以及重要目录的描述。
然后,我们转到漏洞利用目录,简要说明了如何根据操作系统及其服务对漏洞利用进行分类。然后,我们转到辅助目录,探索如何根据扫描和模糊等服务对辅助模块进行分类。
我们讨论的另一个重要目录是 payload 目录,它显示了如何将有效负载分为三种不同的类型。我们根据操作系统对有效负载进行了进一步分类。
通过本章,我们能够涵盖基本 Metasploit 框架和体系结构的描述。在下一章中,我们将从利用的基础知识开始一些实际操作。
以下是一些有用的参考资料,进一步阐明了本章所涵盖的一些主题:
- http://en.wikipedia.org/wiki/Metasploit_Project
- http://www.offensive-security.com/metasploit-unleashed/Metasploit_Architecture
- http://www.offensive-security.com/metasploit-unleashed/Metasploit_Fundamentals
- http://www.offensive-security.com/metasploit-unleashed/Exploits
- http://www.offensive-security.com/metasploit-unleashed/Payloads
- http://www.securitytube.net/video/2635
- http://metasploit.hackplanet.in/2012/07/architecture-of-metasploit.html