滲透技巧——離線導出Chrome瀏覽器中保存的密碼
0x00 前言
在上篇文章《滲透技巧——導出Chrome瀏覽器中保存的密碼》介紹了導出Chrome瀏覽器密碼的原理和利用方法,文末留下一個問題:如果只獲得了用戶的ntlm hash,能否導出Chrome瀏覽器保存的明文密碼呢?
該部分的參考資料較少,而想要解答這個問題,需要了解加解密的原理,所以本文嘗試對該部分內容做介紹,得出最終結論。
0x01 簡介
本文將要介紹以下內容:
·DPAPI簡介及相關概念
·DPAPI加解密流程
·離線導出原理
·離線導出方法
·得出最終結論
0x02 DPAPI簡介
本節內容參考自如下鏈接,加入個人理解:
https://msdn.microsoft.com/en-us/library/ms995355.aspx
https://www.passcape.com/index.php?section=docsys&cmd=details&id=28
DPAPI全稱Data Protection Application Programming Interface
作為Windows系統的一個數據保護介面被廣泛使用
主要用於保護加密的數據,常見的應用如:
·EFS文件加密
·存儲無線連接密碼
·Windows Credential Manager
·Internet Explorer
·Outlook
·Skype
·Windows CardSpace
·Windows Vault
·Google Chrome
使用簡單,加密使用函數CryptProtectData,解密使用函數CryptUnprotectData即可,系統在後台自動完成其他複雜的加解密操作
CryptProtectData的說明可參考:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa380261(v=vs.85).aspx
CryptUnprotectData的說明可參考:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa380882(v=vs.85).aspx
專有名詞
DPAPI blob:
一段密文,可使用Master Key對其解密
結構如下圖
該圖引用自https://www.passcape.com/index.php?section=docsys&cmd=details&id=28
Master Key:
64位元組,用於解密DPAPI blob
通過用戶登錄密碼、SID和16位元組隨機數加密後保存在Master Key file中
Master Key file:
二進位文件,可使用用戶登錄密碼對其解密,獲得Master Key
包含以下五個部分:
·Header and system information
·User』s Master Key
·Local backup encryption key
·Unique CREDHIST file identifier
·Domain Master Key backup
位於固定位置: %APPDATA%MicrosoftProtect\%SID%
例如:
C:UsersaAppDataRoamingMicrosoftProtectS-1-5-21-3453529135-4164765056-1075703908-1001
包含文件329c4147-0011-4ad6-829d-e32dcbd1bbd7(系統文件,隱藏屬性)
無法直接查看
可通過mimikatz對其解析,命令如下:
mimikatz.exe log "dpapi::masterkey /in:"329c4147-0011-4ad6-829d-e32dcbd1bbd7"
輸出如下:
mimikatz(commandline) # dpapi::masterkey /in:329c4147-0011-4ad6-829d-e32dcbd1bbd7
**MASTERKEYS**
dwVersion : 00000002 - 2
szGuid :
dwFlags : 00000005 - 5
dwMasterKeyLen : 000000b0 - 176
dwBackupKeyLen : 00000090 - 144
dwCredHistLen : 00000014 - 20
dwDomainKeyLen : 00000000 - 0
[masterkey]
**MASTERKEY**
dwVersion : 00000002 - 2
salt : 9917a47f1949226e4e8c5b8a3aaf4808
rounds : 00000ce4 - 3300
algHash : 0000800e - 32782 (CALG_SHA_512)
algCrypt : 00006610 - 26128 (CALG_AES_256)
pbKey : cf2634535384431da063fd9a240ab575d13dc1daee8ea545d5c9a0628fa5cc63cf825b3b24642b3d7fe98a3703c1e7cdc7e49132a017e3e45fe34f8512fdb8b224e5c30a754683ff6e098a94a1ee396c026a6022323aff6903b3cdad1185a719accadb924f80482dcf426996fb3f662323d7c9e885504f39baa080d63eaddd2621171b3d780cef9c47d9a0b79a4afc20
[backupkey]
**MASTERKEY**
dwVersion : 00000002 - 2
salt : 57fb6f4228e9ca7d686c7f174f1691b0
rounds : 00000ce4 - 3300
algHash : 0000800e - 32782 (CALG_SHA_512)
algCrypt : 00006610 - 26128 (CALG_AES_256)
pbKey : 1ae34b8395375465871a999c0d04365cc5089cad4bea139344ecb8f9cf0da1abe5d7b096e9594506a0d8c772469b1f81118d608823e2be33020a8a86bb6d190d61865d270e299dfec9aca011531313dd2a2cd6dc4a53adc77b17a410d15ac4c6b11b3450d1c9739e869f67a8278d60ee
[credhist]
**CREDHIST INFO**
dwVersion : 00000003 - 3
guid :
0x03 DPAPI解密思路
1、使用用戶登錄密碼解密Master Key file,獲得Master Key
固定位置: %APPDATA%MicrosoftProtect\%SID%下往往有多個Master Key file
這是為了安全起見,系統每隔90天會自動生成一個新的Master Key(舊的不會刪除)
%APPDATA%MicrosoftProtect\%SID%下存在一個固定文件Preferred,包含最後一個Master Key file的名稱和創建時間,文件結構如下:
typedef struct _tagPreferredMasterKey
{
GUID guidMasterKey;
FILETIME ftCreated;
} PREFERREDMASTERKEY, *PPREFERREDMASTERKEY;
2、使用Master Key解密DPAPI blob,獲得明文
0x04 離線導出Chrome瀏覽器中保存的密碼
1、獲得DPAPI blob
DPAPI blob位於SQLite資料庫文件Login Data的password段,如下圖
使用python腳本對其讀取並保存到文件中,代碼如下:
from os import getenv
import sqlite3
import binascii
conn = sqlite3.connect("Login Data")
cursor = conn.cursor()
cursor.execute("SELECT action_url, username_value, password_value FROM logins")
for result in cursor.fetchall():
print (binascii.b2a_hex(result[2]))
f = open("test.txt", "wb")
f.write(result[2])
f.close()
2、解密Master Key獲得明文
使用工具Windows Password Recovery,下載地址:
https://www.passcape.com/index.php?section=downloads&category=28
選擇Utils -> DPAPI Decoder and Analyser -> Decrypt DPAPI data blob
設置DPAPI blob file指向保存DPAPI blob的文件test.txt,如下圖
設置Master Key file指向待破解的Master Key file,如下圖
接下來輸入用戶登錄密碼
獲得明文,如下圖
成功解密
使用ChromePass對結果進行驗證
ChromePass下載地址:
http://www.nirsoft.net/utils/chromepass.html
參數說明:
/external
命令如下:
ChromePass.exe /external c:123 test123
如下圖
0x05 最終結論
1、無法定位Master Key file
如果用戶sid文件夾下包含多個Master Key file,使用Windows Password Recovery嘗試解密時,需要逐個測試
使用ChromePass不存在這個問題,填入文件上級目錄的路徑即可
2、無法使用用戶登錄密碼的NTLM hash解密Master Key
目前版本的DPAPI在設計上考慮到了這個隱患,使用SHA1演算法(NTLM hash使用MD4加密)
所以說,無法使用用戶登錄密碼的NTLM hash解密Master Key
3、DPAPI很安全,符合密碼安全性的要求
以上測試基於已獲得了目標系統的訪問許可權,也就是說目標系統已經變得不安全
對於一個未獲得訪問許可權的Windows系統,目前使用DPAPI不會造成密碼被破解的問題
0x06 小結
本文通過分析DPAPI加解密流程,得出結論: 使用用戶的ntlm hash,無法導出Chrome瀏覽器保存的明文密碼


※因配置錯誤,25000個Jenkins伺服器泄漏了大量敏感數據
※真實案例:當間諜軟體變成「男友追蹤器」……
TAG:嘶吼RoarTalk |