Skip to content

Latest commit

 

History

History
169 lines (89 loc) · 12.7 KB

File metadata and controls

169 lines (89 loc) · 12.7 KB

二、Metasploit 框架组织

在本章中,我们将研究元 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 接口和基础

首先,我们将了解如何从终端和其他方式访问 Metasploit 框架。打开终端并输入msfconsole。在终端中,它将显示为root@bt:~# msfconsole

Metasploit interfaces and basics

现在我们已经从终端程序中打开了msfconsole;然而,我们可以通过其他方式访问 Metasploit 框架,包括 MsfGUI、Msfconsole、Msfcli、Msfweb、Metasploit Pro 和 Armitage。出于我们的目的,在本书中,我们将主要使用msfconsole

Metasploit interfaces and basics

那么 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.

    Metasploit interfaces and basics

现在我们将进一步探索元 sploit 目录。只需按照以下步骤浏览目录:

  1. 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 in ls.

    Metasploit interfaces and basics

  2. 键入ls命令后,我们可以在这里看到一堆目录和脚本。所列的重要目录为dataexternaltoolspluginsscripts

我们将逐一探索所有这些重要目录:

  • We enter the data directory by typing the command cd data/. This directory contains a lot of helper modules such as meterpreter, exploits, wordlists, templates, and many more.

    Metasploit interfaces and basics

    • Next we will explore the meterpreter directory. To enter the directory, type in cd 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.

      Metasploit interfaces and basics

    • 另一个目录是data目录中的目录wordlist目录。此目录包含不同服务(如 HTTP、Oracle、Postgres、VNC、SNMP 等)的用户名和密码列表。让我们浏览单词列表目录,输入cd ..并按回车meterpreter目录返回data目录。之后,输入cd wordlists并按进入

    Metasploit interfaces and basics

  • Another interesting directory is external in msf3, which contains external libraries used by Metasploit. Let us explore the external directory by typing cd external.

    Metasploit interfaces and basics

  • Then have a look at the scripts directory, which is contained in the msf3 directory. This directory contains a lot of scripts that are used by Metasploit. To enter the scripts directory type in cd scripts and then type in the ls command to view the list of files and folders.

    Metasploit interfaces and basics

  • Another important directory in msf3 is the tools directory. This directory contains tools to be used in exploitation. We will explore the tools directory by typing in cd tools and then the ls command to see the list of tools such as pattern_create.rb and pattern_offset.rb, which are extremely useful for exploit research.

    Metasploit interfaces and basics

  • The last useful directory is plugins in the msf3 directory. The plugins 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 the plugins directory by typing cd plugins and then the ls command to see the list of plugins.

    Metasploit interfaces and basics

通过前面的解释,我们现在对 Metasploit 的目录结构及其功能有了简要的了解。一件重要的事情是更新 Metasploit 以获得最新版本的漏洞利用。打开终端并输入msfupdate。更新最新模块可能需要几个小时。

Metasploit interfaces and basics

利用模块

在讨论利用技术之前,首先我们应该了解利用的基本概念。漏洞攻击是利用特定漏洞的计算机程序。

现在看看msf3模块目录中的漏洞模块。打开您的终端并键入cd /opt/metasploit/msf3/modules/exploitsls命令以查看漏洞利用列表。

Exploit modules

在这里,我们可以看到利用漏洞模块的列表。基本上,漏洞利用是根据操作系统进行分类的。因此,让我们通过键入cd windows来查看漏洞模块的windows目录。

Exploit modules

windows目录中,我们可以看到许多根据 Windows 服务分类的漏洞模块,如ftpsmbtelnetbrowseremail等。在这里,我们将通过探索目录向您展示一种类型的服务利用。我们选择smb作为示例。

Exploit modules

我们看到了smb服务漏洞的列表,它们基本上都是 Ruby 脚本。因此,要查看我们在cat <exploitname>中键入的任何漏洞的代码。这里我们选择ms08_067_netapi.rb作为示例。所以我们输入了cat ms08_067_netapi.rb

Exploit modules

同样,我们可以根据操作系统及其服务探索所有类型的漏洞利用。

辅助模块

辅助模块是无有效载荷的攻击。它们用于各种任务,如端口扫描、指纹识别、服务扫描仪等。有不同类型的辅助模块,如协议扫描器、网络协议模糊器、端口扫描器模块、无线、拒绝服务模块、服务器模块、管理访问漏洞攻击等。

现在让我们探索一下msf目录下的辅助模块目录。输入cd /opt/metasploit/msf3/modules/auxiliary然后输入ls命令以查看辅助模块列表。

Auxiliary modules

在这里我们可以看到辅助模块列表,如adminclientfuzzersscannervsploit等。现在我们将探索 scanner 目录作为一个辅助模块。

Auxiliary modules

scanner目录中,我们将看到根据服务扫描分类的模块。我们可以选择任何服务模块进行探索。这里我们将选择ftp作为扫描仪模块。

Auxiliary modules

ftp目录中,我们可以看到三个 Ruby 脚本。要查看利用 Ruby 漏洞的代码,只需输入cat <module name>;例如,我们在这里输入cat anonymous.rb

Auxiliary modules

有效载荷-深度

有效负载是在系统受损后运行的一段软件。有效载荷通常通过漏洞连接并交付。Metasploit 中有三种不同类型的有效载荷,即singlesstagersstages。阶段有效载荷的主要作用是,它们使用微小的阶段来适应小的利用空间。在利用过程中,利用人员可以使用的内存非常有限。分段器使用这个空间,他们的工作是拉下分段负载的其余部分。另一方面,单打是独立的,完全独立的。这就像运行一个小的可执行文件一样简单。

让我们看看下面截图中的payload``modules目录:

Payloads – in-depth

Single 是用于特定任务(如创建用户、绑定 shell 等)的自包含有效负载。例如,windows/adduser负载创建一个用户帐户。现在我们将探索singles有效负载目录。在这里,我们将看到有效负载是根据操作系统(如 AIX、BSD、Windows、Linux 等)进行分类的。

Payloads – in-depth

我们将使用目录 windows来演示有效负载是如何工作的。

Payloads – in-depth

我们将使用已经解释过的adduser有效载荷。我们可以通过键入cat adduser.rb来查看此有效负载的代码。

Payloads – in-depth

stager 是在攻击者和受害者机器之间建立连接的有效负载。作为一个示例,如果我们想要注入meterpreter有效负载,我们无法将整个 MeterMeter DLL 放入一个有效负载中,因此整个过程分为两部分。第一种是称为 stagers 的较小有效载荷。在执行 stager 之后,它们在攻击者和受害者之间建立网络连接。通过这个网络连接,一个较大的有效负载被传送到受害机器,这个较大的有效负载被称为阶段。

现在我们将探索stagers有效负载目录。正如我们在下面的屏幕截图中所看到的,有效负载根据不同的操作系统进行分类:

Payloads – in-depth

作为一个例子,我们将探索bsd目录并检查有效负载列表。

Payloads – in-depth

Stages 是由 stagers 有效负载(如 MeterMeter、VNC 服务器等)下载和执行的有效负载类型。

现在我们将浏览stages目录以查看有效负载列表。

Payloads – in-depth

在这里,我们得到了在singlesstagers目录中看到的相同结果;根据不同的操作系统对有效负载进行分类。我们打开netware目录查看列表。

Payloads – in-depth

总结

在本章中,我们介绍了 Metasploit 框架的不同接口和体系结构。本章流程包括 Metasploit 的操作技术,然后是架构基础。我们进一步介绍了各种 Metasploit 库和应用程序接口,如 Rex、Msf core 和 Msf base。然后,我们深入研究了 Metasploit 目录以及重要目录的描述。

然后,我们转到漏洞利用目录,简要说明了如何根据操作系统及其服务对漏洞利用进行分类。然后,我们转到辅助目录,探索如何根据扫描和模糊等服务对辅助模块进行分类。

我们讨论的另一个重要目录是 payload 目录,它显示了如何将有效负载分为三种不同的类型。我们根据操作系统对有效负载进行了进一步分类。

通过本章,我们能够涵盖基本 Metasploit 框架和体系结构的描述。在下一章中,我们将从利用的基础知识开始一些实际操作。

参考文献

以下是一些有用的参考资料,进一步阐明了本章所涵盖的一些主题: