14

渗透技巧——离线导出Chrome浏览器中保存的密码

 3 years ago
source link: https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-%E7%A6%BB%E7%BA%BF%E5%AF%BC%E5%87%BAChrome%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%AD%E4%BF%9D%E5%AD%98%E7%9A%84%E5%AF%86%E7%A0%81/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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对其解密

结构如下图

Alt text

该图引用自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%\Microsoft\Protect\%SID%

C:\Users\a\AppData\Roaming\Microsoft\Protect\S-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             : {329c4147-0011-4ad6-829d-e32dcbd1bbd7}
  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             : {58680bc7-055e-4728-ab96-c34d64c565f2}

0x03 DPAPI解密思路


1、使用用户登录密码解密Master Key file,获得Master Key

固定位置: %APPDATA%\Microsoft\Protect\%SID%下往往有多个Master Key file

这是为了安全起见,系统每隔90天会自动生成一个新的Master Key(旧的不会删除)

%APPDATA%\Microsoft\Protect\%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段,如下图

Alt text

使用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,如下图

Alt text

设置Master Key file指向待破解的Master Key file,如下图

Alt text

接下来输入用户登录密码

获得明文,如下图

Alt text

使用ChromePass对结果进行验证

ChromePass下载地址:

http://www.nirsoft.net/utils/chromepass.html

参数说明:

/external <User Profile Path> <Last Log-On Password>

命令如下:

ChromePass.exe /external c:\1\2\3\ test123 
Alt text

0x05 最终结论


1、无法自动定位Master Key file

如果用户sid文件夹下包含多个Master Key file,使用Windows Password Recovery尝试解密时,需要逐个测试,也可通过读取文件Preferred的前16字节获得对应的Master Key file

使用ChromePass不存在这个问题,填入文件上级目录的路径即可

2、无法使用用户登录密码的NTLM hash解密Master Key

目前版本的DPAPI在设计上考虑到了这个隐患,使用SHA1算法(NTLM hash使用MD4加密)

所以说,无法使用用户登录密码的NTLM hash解密Master Key

3、DPAPI很安全,符合密码安全性的要求

以上测试基于已获得了目标系统的访问权限,也就是说目标系统已经变得不安全

对于一个未获得访问权限的Windows系统,目前使用DPAPI不会造成密码被破解的问题

0x06 小结


本文通过分析DPAPI加解密流程,得出结论: 使用用户的ntlm hash,无法导出Chrome浏览器保存的明文密码

0x07 补充


离线导出Chrome浏览器中保存的密码还可以通过lsass进程提取出Master Key进行解密,不需要获得用户的明文密码,详情可参考《渗透技巧——利用Masterkey离线导出Chrome浏览器中保存的密码》


LEAVE A REPLY


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK