理解 Metasploit 模块类型

Kali LinuxBeginner
立即练习

引言

Metasploit Framework 是一个强大的开源工具,用于渗透测试和安全研究。它围绕模块的概念构建,模块是执行特定任务的可互换代码片段。理解不同类型的模块是有效使用 Metasploit 的基础。

在本实验中,你将探索 Metasploit 中的主要模块类型:

  • Exploits:利用系统漏洞的代码。
  • Auxiliary:用于扫描、模糊测试和其他非直接利用操作的模块。
  • Post-Exploitation:在成功获取目标系统访问权限后使用的模块。
  • Payloads:在成功利用后在目标系统上运行的代码。

你将学习如何使用 Metasploit 控制台 (msfconsole) 列出和识别这些模块。

列出可用的 exploit 模块

在此步骤中,你将学习如何列出 Metasploit Framework 中所有可用的 exploit 模块。Exploit 模块旨在利用系统、服务或应用程序中的特定缺陷或漏洞来获得未经授权的访问。

首先,你需要启动 Metasploit Framework 控制台。我们将使用 -q 标志来抑制启动横幅,以获得更简洁的界面。进入控制台后,你可以使用 show exploits 命令。

打开你的终端并运行以下命令来启动 msfconsole

msfconsole -q

msfconsole 提示符 (msf6 >) 出现后,输入以下命令来列出所有 exploit 模块:

show exploits

你将看到一个长长的可用 exploit 列表,以及它们的披露日期、rank(等级)和简要描述。Rank 表示 exploit 的可靠性。

msf6 > show exploits

Matching Modules
================

   ##   Name                                 Disclosure Date  Rank       Check  Description
   -   ----                                 ---------------  ----       -----  -----------
   0   exploit/aix/local/ibstat_exec        2009-07-27       excellent  No     AIX ibstat Command Execution
   1   exploit/aix/local/invscout_priv_esc  2012-03-30       excellent  Yes    AIX invscout Privilege Escalation
   2   exploit/aix/rpc_catd                 1995-01-01       great      No     AIX CDE ToolTalk rpc.catd Command Execution
...
   2300 exploit/windows/smb/ms17_010_psexec  2017-03-14       excellent  Yes    MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
...

查看列表后,你可以通过输入 exit 来退出 Metasploit 控制台:

exit

列出可用的 auxiliary 模块

在此步骤中,你将列出 auxiliary 模块。与 exploits 不同,auxiliary 模块不会直接导致获得系统访问权限。相反,它们用于各种任务,例如扫描开放端口、识别服务、模糊测试、拒绝服务攻击和信息收集。

与上一步一样,启动 Metasploit 控制台,然后使用 show 命令。

在终端中再次启动 msfconsole

msfconsole -q

msf6 > 提示符下,使用 show auxiliary 命令查看所有可用的 auxiliary 模块:

show auxiliary

输出将显示一个用于侦察和其他非 exploit 活动的全面模块列表。

msf6 > show auxiliary

Matching Modules
================

   ##   Name                                                 Disclosure Date  Rank     Check  Description
   -   ----                                                 ---------------  ----     -----  -----------
   0   auxiliary/admin/2wire/xslt_password_reset                             normal   No     2Wire Cross-Site Scripting and Password Reset
   1   auxiliary/admin/appletv/appletv_display_image                         normal   No     AppleTV Display Image
...
   450 auxiliary/scanner/http/http_login                                     normal   No     HTTP Login Utility
   451 auxiliary/scanner/http/http_put                                       normal   Yes    HTTP PUT File Upload Utility
...

完成后,退出控制台:

exit

列出可用的 post-exploitation 模块

在此步骤中,你将探索 post-exploitation 模块。这些模块在你成功攻陷目标系统 之后 使用。它们旨在帮助你维持访问权限、收集敏感信息、提升权限以及在网络内转向其他系统。

列出这些模块的过程与之前的步骤类似。

启动 Metasploit 控制台:

msfconsole -q

在提示符下,输入 show post 来列出所有 post-exploitation 模块:

show post

你将看到一个按目标操作系统(例如,Windows、Linux、OSX)和它们执行的功能(例如,gather、manage、escalate)分类的模块列表。

msf6 > show post

Matching Modules
================

   ##   Name                                                 Disclosure Date  Rank    Check  Description
   -   ----                                                 ---------------  ----    -----  -----------
   0   post/android/capture/screen                                           normal  No     Android Screen Capture
   1   post/android/gather/contacts                                          normal  No     Android Gather Contacts
...
   250 post/linux/gather/enum_configs                                        normal  No     Linux Gather Configurations
   251 post/linux/gather/enum_protections                                    normal  No     Linux Gather Protection Mechanisms
...
   400 post/windows/gather/credentials/total_commander                       normal  No     Windows Gather Total Commander FTP Passwords
...

完成探索列表后,请记住退出控制台:

exit

列出可用的 payload 模块

在此步骤中,你将列出可用的 payload 模块。Payload 是 exploit 发送到目标系统的代码。一旦 exploit 成功攻陷系统,payload 就会被执行,从而使攻击者获得控制权。Payload 的范围可以从简单的命令 shell 到高度先进的 Meterpreter,后者提供了对受害者机器的广泛控制。

让我们使用 msfconsole 来列出它们。

启动 Metasploit 控制台:

msfconsole -q

msf6 > 提示符下,使用 show payloads 命令:

show payloads

输出将显示各种 payload,通常按它们建立的连接类型(例如,reverse shell、bind shell)和目标架构进行分类。

msf6 > show payloads

Matching Modules
================

   ##   Name                                   Disclosure Date  Rank    Check  Description
   -   ----                                   ---------------  ----    -----  -----------
   0   payload/aix/ppc/shell_bind_tcp                          normal  No     AIX PowerPC Command Shell, Bind TCP Inline
   1   payload/aix/ppc/shell_find_port                         normal  No     AIX PowerPC Command Shell, Find Port Inline
...
   500 payload/linux/x86/meterpreter/reverse_tcp               normal  No     Linux Meterpreter, Reverse TCP Stager
...
   1000 payload/windows/x64/meterpreter/reverse_tcp             normal  No     Windows Meterpreter (Reflective Injection), Reverse TCP Stager (x64)
...

最后,退出控制台:

exit

区分 exploit 和 payload

在最后一步中,我们将巩固你对 exploit 和 payload 之间关键区别的理解。虽然它们协同工作,但它们服务于不同的目的。

  • Exploit:这是“递送载体”。它的唯一作用是利用漏洞将 payload 送入目标系统。可以将其视为打开门的钥匙。
  • Payload:这是“货物”。它是 exploit 成功后运行的代码。它定义了你在被攻陷的系统上可以做什么。可以将其视为你打开门并进入后所做的事情。

exploit 没有 payload 就无法运行,payload 没有 exploit 也无法递送。

为了展示你的理解,请在你的项目目录中创建一个名为 difference.txt 的简单文本文件,该文件总结了这个概念。

在你的终端中执行以下命令:

echo "Exploit: Gains access. Payload: Runs after access." > /home/labex/project/difference.txt

你可以使用 cat 命令验证文件是否已正确创建:

cat /home/labex/project/difference.txt

你应该会看到以下输出:

Exploit: Gains access. Payload: Runs after access.

这个简单的练习有助于巩固这两个 Metasploit 核心组件之间的基本关系。

总结

恭喜你完成了本次实验!你已成功探索了 Metasploit Framework 中的基本模块类型。

你了解到:

  • Exploit 模块 用于利用漏洞来获得初始访问权限。
  • Auxiliary 模块 用于扫描、侦察和其他非 exploit 操作。
  • Post-exploitation 模块 在系统被攻陷后运行。
  • Payload 模块 是由 exploit 递送并在目标上执行的代码。

最重要的是,你现在理解了 exploit(入口方法)和 payload(入口后运行的代码)之间的关键区别。这些基础知识对于使用 Metasploit 进行有效的渗透测试至关重要。